define(['dashboard/dashboard'], function (dashboard) { dashboard.controller('DashboardNotifications', ['$scope', '$state', '$http', '$mdDialog', 'Helpers', '$window', function ($scope, $state, $http, $mdDialog, Helpers, $window) { $scope.UpdateSuccess = null; $scope.UpdateMessage = null; $scope.Submitting = false; $scope.HouseholdMemberDetailsLoading = []; $scope.CellphoneDetailsLoading = []; $scope.VehicleDetailsLoading = []; $scope.FinanceDetailsLoading = []; $scope.EmploymentDetailsLoading = []; ////Split Employee details object //$scope.$watch("employmentDetailCode", function (value) { // if (value && value.Item1) { // $scope.employmentDetail.EmployerCompany = value.Item1; // $scope.employmentDetail.EmployerCompanyName = value.Item2; // } //});//Will rather implement in CS Controller $scope.CloseSuccessMessage = function () { $scope.UpdateSuccess = null; $scope.UpdateMessage = null; } $scope.GetInspectionUrl = function (inspectionRequest) { return $scope.DashboardGetActionUrl('dashboardvehicleinspection', { 'vehicleSequenceNumber': inspectionRequest.VehicleSequenceNumber }); } //for suburb autocomplete. TODO: replace with directive $scope.suburbAutocompleteFormatter = function suburbAutocompleteFormatter(value) { if (value && value.SuburbName) { return value.SuburbName + ' ' + value.PostCode; } else { return value; } } $scope.employmentAutocompleteFormatter = function employmentAutocompleteFormatter(value) { if (value && value.Description) { return value.Description; } } $scope.FinanceCompanyListAutocompleteFormatter = function FinanceCompanyListAutocompleteFormatter(value) { if (value && value.Description) { return value.Description; } } $scope.PersonListAutocompleteFormatter = function PersonListAutocompleteFormatter(value) { if (value && value.FirstName && value.Surname) { return value.FirstName + " " + value.Surname; } if (value && value.Description) return value.Description; } function completedNotificationSubmit(response) { //$window.scrollTo(0, 0); //change this method to handle the carousel elememts $scope.UpdateMessage = response.Message; $scope.UpdateSuccess = response.Success; var overridenPolicy = response.OverridePolicy; //Overwrite current policy if one is passed through if (overridenPolicy && overridenPolicy != null) { $scope.InitializePolicy(overridenPolicy); } $scope.Submitting = false; } $scope.isVehicleSerialised = function (vehicle) { //If the vehicle has serial numbers such as a chassis number and an engine number return vehicle.VehicleType == 'BM' || vehicle.VehicleType == 'SD' || vehicle.VehicleType == 'SV' || vehicle.VehicleType == 'PU' || vehicle.VehicleType == 'MP' || vehicle.VehicleType == 'OR' || vehicle.VehicleType == 'SW' || vehicle.VehicleType == 'BU'; } //file upload restrictions $scope.isFileUploadInvalid = function (maxFileSize, certificatesArr, type) { $scope.fileSize = maxFileSize; maxFileSize = maxFileSize * 1024 * 1024; $scope[type + "InvalidCount"] = 0; certificatesArr = certificatesArr || []; for (var x = 0; x < certificatesArr.length; x++) { if (certificatesArr[x].size > maxFileSize) { $scope[type + "InvalidCount"]++; } } if ($scope[type + "InvalidCount"] > 0) return true; else return false; } //Submit IMEI CellphoneDetails $scope.SubmitCellphoneDetails = function (cellphone, index) { $scope.CellphoneDetailsLoading[index] = true; $scope.Submitting = true; $scope.DashboardPost('DashboardNotifications/SubmitCellphoneDetails/', cellphone) .then(function (data) { var response = data.data; if (response.Success){ completedNotificationSubmit(data.data); } else { completedNotificationSubmit({ Success: false, Message: "Failed to update IMEI" }); } $scope.CellphoneDetailsLoading[index] = false; }); } //Submit EmploymentDetails $scope.SubmitEmploymentDetails = function (person, index) { $scope.EmploymentDetailsLoading[index] = true; $scope.Submitting = true; $scope.DashboardPost('DashboardNotifications/SubmitEmploymentDetails/', person) .then(function (data) { var response = data.data; if (response.Success) { completedNotificationSubmit(data.data); } else { completedNotificationSubmit({ Success: false, Message: "Failed to update employment information" }); } $scope.EmploymentDetailsLoading[index] = false; }); } //Submit IdNumber/HouseholdMemberDetails $scope.SubmitHouseholdMemberDetails = function (person, index) { $scope.HouseholdMemberDetailsLoading[index] = true; $scope.Submitting = true; $scope.DashboardPost('DashboardNotifications/SubmitHouseholdMemberDetails/', person) .then(function (data) { var response = data.data; if (response.Success) { completedNotificationSubmit(data.data); } else { completedNotificationSubmit({ Success: false, Message: "Failed to update household member" }); } $scope.HouseholdMemberDetailsLoading[index] = false; }); } $scope.SubmitVehicleDetails = function (vehicle, index) { $scope.VehicleDetailsLoading[index] = true; $scope.Submitting = true; $scope.DashboardPost('DashboardNotifications/SubmitVehicleDetails/', vehicle) .then(function (data) { var response = data.data; if (response.Success) { completedNotificationSubmit(data.data); } else { completedNotificationSubmit({ Success: false, Message: "Failed to update details" }); } $scope.VehicleDetailsLoading[index] = false; }); } //Submit FinanceDetails $scope.SubmitFinanceDetails = function (vehicle, index) { $scope.FinanceDetailsLoading[index] = true; $scope.Submitting = true; var accountHolder = null; var vehicleAccountHolderObj = vehicle.FinanceDetailRequest.AccountHolderObj; var companyNameObj = vehicle.CompanyNameObj; if (vehicleAccountHolderObj && vehicleAccountHolderObj.Code == '-1' && vehicleAccountHolderObj.Description) { accountHolder = vehicleAccountHolderObj.Description; } else if (vehicleAccountHolderObj && vehicleAccountHolderObj.FirstName && vehicleAccountHolderObj.Surname) { accountHolder = vehicleAccountHolderObj.FirstName + ' ' + vehicleAccountHolderObj.Surname; } vehicle.FinanceDetailRequest.AccountHolder = accountHolder; vehicle.FinanceDetailRequest.CompanyName = companyNameObj.Description; $scope.DashboardPost('DashboardNotifications/SubmitFinanceDetails/', vehicle) .then(function (data) { var response = data.data; if (response.Success) { completedNotificationSubmit(data.data); } else { completedNotificationSubmit({ Success: false, Message: "Failed to update details" }); } $scope.FinanceDetailsLoading[index] = false; }); } }]); });