UNPKG

consumerportal

Version:

mydna Custimised for you

109 lines (92 loc) 2.8 kB
/// <reference path="../../includes.ts" /> module emailPreferencesCtrl { interface IEmailPreferencesCtrl { getEmailPreferences(): any; updatePreferences(): any; } interface IEmailPreferencesScope extends angular.IScope { myForm : angular.IFormController } class EmailPreferencesController implements IEmailPreferencesCtrl { static $inject = [ '$scope', 'authenSrvc', 'apiSrvc', 'mydnaApis', 'errorHandlerSrvc', 'scrollerSrvc' ]; showErrors: boolean; frm: any; updateSuccess: any; items:any; globalItems:any; noUserChanges:boolean; hasSubscription:boolean; constructor( private $scope : IEmailPreferencesScope, private authenSrvc: authenSrvc.IAuthenService, private apiSrvc: apiSrvc.IApiService, private mydnaApis: ImyDNAApis, private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService, private scrollerSrvc: scrollerSrvc.IScrollerService, ){ const vm = this; vm.globalItems =[]; vm.items = []; vm.hasSubscription = false; vm.getEmailPreferences(); vm.showErrors = false; vm.noUserChanges = false; vm.updateSuccess = false; } getEmailPreferences(){ this.$scope.$emit("disable-on-save-on"); this.apiSrvc.get_request_params( this.mydnaApis.Subscription , "").then((data) => { this.items = data; this.hasSubscription = true; //this.appMemorySrvc.setEmailPreferences(data); this.$scope.$emit("disable-on-save-off"); }, err => { this.errorHandlerSrvc.errorHandler(err, 'debug', ''); this.$scope.$emit("disable-on-save-off"); }); } updatePreferences(){ this.noUserChanges = false; this.updateSuccess = false; this.showErrors = false; this.scrollerSrvc.TopScroll(); this.showErrors= false; if (this.$scope.myForm.$valid && this.items.length > 0) { if(!this.$scope.myForm.$dirty){ this.noUserChanges = true; //this.updateSuccess = false; } else { this.$scope.$emit("disable-on-save-on"); this.apiSrvc.post_request( this.mydnaApis.Subscription , this.items).then(data => { //this.noUserChanges = false; this.updateSuccess = true; var neItems = this.items; //this.appMemorySrvc.setEmailPreferences(neItems); this.$scope.$emit("disable-on-save-off"); }, err => { this.$scope.$emit("disable-on-save-off"); this.errorHandlerSrvc.errorHandler(err, 'debug', ''); }); } } else { this.showErrors = true; } this.$scope.myForm.$setPristine(); } } angular.module('app').controller('emailPreferencesCtrl', EmailPreferencesController); }