define(['dashboard/dashboard'], function (dashboard) { dashboard.controller('DashboardHome', ['$scope', '$mdDialog', function ($scope, $mdDialog) { $scope.getRemoveVehicleMessage = function (riskItem) { var msg = ''; for (item in riskItem.WarningMessages) { msg += riskItem.WarningMessages[item] || "" + ' '; } if ($scope.getAmendType(riskItem) == 'car' && $scope.getVehicleCarCount() < 2 && !$scope.hasHomeContents() && $scope.Dashboard.Policy.RiskItemDetails.PortablePossessions && $scope.Dashboard.Policy.RiskItemDetails.PortablePossessions.PortableCount > 0) { msg += 'Your portable possesions will also be removed.'; } return msg; } $scope.loadScript = function (url) { var script = document.createElement("script"); script.type = "text/javascript"; script.defer = "true"; script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; if ($scope.Dashboard.Policy.VehiclesRequireInspection !== null && $scope.Dashboard.Policy.VehiclesRequireInspection.length > 0) $scope.loadScript("https://maps.googleapis.com/maps/api/js?key=AIzaSyA2tH25ZeVp4T1iJwzjJC3mtxgMq8K90LI&libraries=places&sensor=false"); $scope.getRemoveHomeContentsMessage = function () { var msg = ""; var portables = $scope.Dashboard.Policy.RiskItemDetails.PortablePossessions; var hasPortable = false; if (portables.Bicycles != null || portables.Cellphones != null || portables.Glasses != null || portables.Specified != null || portables.SwimmingPoolBorehole != null || portables.Unspecified.InsuranceValue > 0) { hasPortable = true; } if ($scope.getVehicleCarCount() > 0 && hasPortable == true) { msg = "If you remove home contents cover it may affect the amount of portable possessions you can insure, you will not be able to undo this."; //need to manually change if neccessary } else { msg = "If you remove home contents cover you will also remove any linked portable possession, you will not be able to undo this."; //need to manually change if neccessary } return msg; } var RemoveDialog = function (ev, message) { return $mdDialog.confirm() .title('Are you sure?') .content(message || 'If you remove this item, you will not be able to undo it.') .ok('Remove') .cancel('Cancel') .disableParentScroll(false) .targetEvent(ev); }; var CantRemoveDialog = function (ev, message, $scope) { var parentEl = angular.element(document.body); return $mdDialog.show({ parent: parentEl, Content: message, disableParentScroll: false, targetEvent: ev, scope: $scope, preserveScope: true, template: '' + ' ' + '

Remove item

' + '
' + message + '
' + '
' + ' ' + ' ' + ' ' + '
' }); }; $scope.BrokerPrefix = ""; if (window.location.href.indexOf("brokers") > 0) $scope.BrokerPrefix = "/brokers"; $scope.onlyRiskItemRemove = function (ev, riskItem) { //need to add the vdn number dynamically, &scope.dashboard.activevdn displays incorrect number CantRemoveDialog(ev, 'You have requested to remove your ' + riskItem.Description + ', this is the only item on your policy. By removing this item your policy will cancel which can impact cash back plus pay-outs, insurance history and your risk. If you wish to cancel your policy let us help you, contact us on 0861 555 580 and we will gladly assist. Alternatively schedule a call back that is convenient for you.', $scope); }; $scope.removeLoading = false; $scope.RemoveVehicle = function (ev, referenceNumber, riskItem, warningMessage) { $scope.removeLoading = true; $scope.GetMvdValues = function () { $scope.DashboardPost('/MVD/GetMVDDetails', { referenceNumber: $scope.Dashboard.Policy.ReferenceNumber }) .then(function (data) { $scope.Dashboard.Policy.DiscountAmount = data.data.DiscountAmount; $scope.Dashboard.Policy.DiscountDetail = data.data.DiscountDetails; $scope.removeLoading = false; if ($scope.Dashboard.Policy.CanAmmend) { if ($scope.Dashboard.Policy.RiskItemDetails.AllowRemoving) { var vehicleCheck = $scope.Dashboard.Policy.DiscountDetail.filter(function (x) { return x.vehicleSequenceNumber == riskItem.SequenceNumber.toString() }); var mdvMessage = vehicleCheck.length > 0 && vehicleCheck[0].hasDiscount == "1" && $scope.Dashboard.Policy.DiscountAmount.length != 0 ? "By removing a vehicle, you may affect the comprehensive vehicle insurance discount you qualified for, which works as follows: " + $scope.Dashboard.Policy.DiscountAmount[0].NumberOfVehicles + " car = no discount, " + $scope.Dashboard.Policy.DiscountAmount[1].NumberOfVehicles + " cars = up to " + $scope.Dashboard.Policy.DiscountAmount[1].DiscountPercentage + "%, " + $scope.Dashboard.Policy.DiscountAmount[2].NumberOfVehicles + " cars = up to " + $scope.Dashboard.Policy.DiscountAmount[2].DiscountPercentage + "%, " + $scope.Dashboard.Policy.DiscountAmount[3].NumberOfVehicles + " cars = up to " + $scope.Dashboard.Policy.DiscountAmount[3].DiscountPercentage + "% each." : ""; var confirm = RemoveDialog(ev, 'If you remove ' + riskItem.Description + ' from your policy, you will not be able to undo it. ' + warningMessage + mdvMessage); $mdDialog.show(confirm).then(function () { window.location = $scope.BrokerPrefix + '/quote/?quoteType=amendment&amendmentType=car&amendmentMode=delete&referenceNumber=' + referenceNumber + '&sequenceNumber=' + riskItem.SequenceNumber; $scope.Dashboard.LoadingData = true; }); } else { $scope.onlyRiskItemRemove(ev, riskItem); } } }); }(); }; $scope.RemoveHome = function (ev, referenceNumber, msg) { if ($scope.Dashboard.Policy.CanAmmend) { if ($scope.Dashboard.Policy.RiskItemDetails.AllowRemoving) { var confirm = RemoveDialog(ev, msg); $mdDialog.show(confirm).then(function () { window.location = $scope.BrokerPrefix + '/quote/?quoteType=amendment&amendmentType=home&amendmentMode=delete&referenceNumber=' + referenceNumber; $scope.Dashboard.LoadingData = true; }); } else { $scope.onlyRiskItemRemove(ev, $scope.Dashboard.Policy.RiskItemDetails.Home); } } }; $scope.RemoveBuilding = function (ev, referenceNumber) { if ($scope.Dashboard.Policy.CanAmmend) { if ($scope.Dashboard.Policy.RiskItemDetails.AllowRemoving) { var confirm = RemoveDialog(ev, 'If you remove this building (borehole and swimming pool equipment will also be removed), you will not be able to undo it.'); $mdDialog.show(confirm).then(function () { window.location = $scope.BrokerPrefix + '/quote/?quoteType=amendment&amendmentType=building&amendmentMode=delete&referenceNumber=' + referenceNumber; $scope.Dashboard.LoadingData = true; }); } else { $scope.onlyRiskItemRemove(ev, $scope.Dashboard.Policy.RiskItemDetails.Building); } } }; $scope.hideDialog = function () { $mdDialog.hide(); }; //Counter intuitive, but we only show the message with razor. This is used to allow the user to close the message to replicate dashboard behaviour. $scope.CannotAmendMessage = true; $scope.CloseCannotAmendMessage = function () { $scope.CannotAmendMessage = false; }; }]); });