2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
24 class userNotificationsModalCtrl {
25 constructor($scope, $log, functionalMenuService, confirmBoxService, notificationService, $modal, ngDialog, $state, $filter) {
28 'isOnlineUsersOnly': null,
29 'isForAllRolesOptions': null,
30 'selectedPriority': null,
35 'msgDescription': null,
37 'roleObj': {notificationRoleIds:null}
40 $scope.notificationId = null;
41 $scope.selectedCat = null;
42 $scope.selectedEcompFunc = null;
43 this.YN_index_mapping = {
48 $scope.onlineAllUsersOptions = [
49 { "index": 0, "value": "Y", "title": "Online Users Only" },
50 { "index": 1, "value": "N", "title": "Online & Offline Users" }
54 $scope.isForAllRolesOptions = [
55 { "index": 0, "value": "Y", "title": "Yes" },
56 { "index": 1, "value": "N", "title": "No" }
59 $scope.priorityOptions = [
60 { "index": 0, "value": 1, "title": "Normal" },
61 { "index": 1, "value": 2, "title": "Important" }
64 $scope.isActiveOptions = [
65 { "index": 0, "value": "Y", "title": "Yes" },
66 { "index": 1, "value": "N", "title": "No" }
68 $scope.isActive = $scope.isActiveOptions[0];
69 $scope.selectPriority = $scope.priorityOptions[0];
70 $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[1];
71 $scope.isForAllRoles=$scope.isForAllRolesOptions[0].value;
72 $scope.isFunctionalMenu ="Y";
74 $scope.selectedPriority=$scope.priorityOptions[0].value;
76 // $scope.notificationRoleIds = [];
77 $scope.msgHeader = '';
78 $scope.msgDescription = '';
79 $scope.treeTitle="Functional Menu";
80 $scope.notifObj= {isCategoriesFunctionalMenu:true};
83 // $log.info('userNotificationsModalCtrl::init');
84 this.isSaving = false;
85 var today = new Date();
86 $scope.minDate = today.toISOString().substring(0, 10);
87 var threeMonthsFromNow = new Date();
88 threeMonthsFromNow.setMonth(threeMonthsFromNow.getMonth() + 3);
89 $scope.maxDate = threeMonthsFromNow.toISOString().substring(0, 10);
90 if ($scope.ngDialogData && $scope.ngDialogData.notif) {
91 // $log.debug('userNotificationsModalCtrl:init:: Edit
92 // notification mode for', $scope.ngDialogData.notif);
93 $scope.isEditMode = true;
94 $scope.editModeObj = {isEditMode: true};
95 this.notif = _.clone($scope.ngDialogData.notif);
96 $scope.modalPgTitle = 'View Notification'
97 $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[this.YN_index_mapping[this.notif.isForOnlineUsers]];
98 $scope.isForAllRoles = $scope.isForAllRolesOptions[this.YN_index_mapping[this.notif.isForAllRoles]].value;
99 $scope.isActive = $scope.isActiveOptions[this.YN_index_mapping[this.notif.activeYn]];
100 $scope.selectedPriority = $scope.priorityOptions[this.notif.priority - 1].value;
101 $scope.startTime = new Date(this.notif.startTime);
102 $scope.endTime = new Date(this.notif.endTime);
103 $scope.msgHeader = this.notif.msgHeader;
104 $scope.msgDescription = this.notif.msgDescription;
105 $scope.notificationId = this.notif.notificationId;
106 $scope.notificationRoleIds = this.notif.roleIds;
107 $scope.roleObj = {notificationRoleIds:this.notif.roleIds};
109 // $log.debug('AppDetailsModalCtrl:init:: New app mode');
110 $scope.isEditMode = false;
111 $scope.editModeObj = {isEditMode: false};
112 $scope.modalPgTitle = 'Add a New Notification'
113 this.notif = _.clone(newNotifModel);
114 $scope.roleObj = {notificationRoleIds:null};
117 this.conflictMessages = {};
119 let handleConflictErrors = err => {
123 if(!err.data.length){ // support objects
124 err.data = [err.data]
126 _.forEach(err.data, item => {
127 _.forEach(item.fields, field => {
128 // set conflict message
129 this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];
130 // set field as invalid
131 $scope.appForm[field.name].$setValidity('conflict', false);
132 // set watch once to clear error after user correction
133 watchOnce[field.name]();
136 this.scrollApi.scrollTop();
139 let resetConflict = fieldName => {
140 delete this.conflictMessages[fieldName];
141 if($scope.appForm[fieldName]){
142 $scope.appForm[fieldName].$setValidity('conflict', true);
145 $scope.addUserNotificationValidation = function () {
147 if (!($scope.isEditMode)) {
148 var validation=false;
150 if($scope.startTime && $scope.endTime && $scope.msgHeader != '' && $scope.msgDescription != '' && ($scope.startTime<$scope.endTime)){
152 if( $scope.isForAllRoles=='N'){
153 validation = $scope.checkBoxObj.isAnyRoleSelected;
165 /* format the value for viewing a notification */
166 $scope.formatStartDate = function () {
167 if ($scope.startTime) {
168 $scope.startTime = $filter('date')($scope.startTime, 'medium');
172 /* format the value for viewing a notification */
173 $scope.formatEndDate = function () {
175 $scope.endTime = $filter('date')($scope.endTime, 'medium');
179 $scope.addUserNotification = function () {
180 $scope.notificationRoleIds = [];
182 for (var key in $scope.checkboxIdDict) {
183 if ($scope.checkboxIdDict[key].is_box_checked && ($scope.checkboxIdDict[key].role_id != null)) {
184 var role_ids = $scope.checkboxIdDict[key].role_id;
185 for (var i in role_ids) {
186 if (!($scope.notificationRoleIds.indexOf(role_ids[i]) > -1)) {
187 $scope.notificationRoleIds.push(role_ids[i]);
193 $scope.notificationRoleIds.sort();
194 if (($scope.isOnlineUsersOnly) && ($scope.isForAllRoles) && ($scope.selectedPriority) && ($scope.isActive)
195 && ($scope.startTime) && ($scope.endTime) && ($scope.msgHeader != '') && ($scope.msgDescription != '')) {
196 this.newUserNotification =
198 'notificationId':$scope.notificationId,
199 'isForOnlineUsers': $scope.isOnlineUsersOnly.value,
200 'isForAllRoles': $scope.isForAllRoles,
201 'priority': $scope.selectedPriority,
202 'activeYn': $scope.isActive.value,
203 'startTime': $scope.startTime,
204 'endTime': $scope.endTime,
205 'msgHeader': $scope.msgHeader,
206 'msgDescription': $scope.msgDescription,
207 'roleIds': $scope.notificationRoleIds,
208 'createdDate': new Date()
211 // POST ajax call here;
212 if ($scope.isEditMode) {
213 notificationService.updateAdminNotification(this.newUserNotification)
215 //$log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');
216 $scope.closeThisDialog(true);
219 $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));
220 switch (err.status) {
221 case '409': // Conflict
222 // handleConflictErrors(err);
224 case '500': // Internal Server Error
225 confirmBoxService.showInformation('There was a problem updating the notification. ' +
226 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
228 case '403': // Forbidden... possible
229 // webjunction error to
231 confirmBoxService.showInformation('There was a problem updating the notification. ' +
232 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
235 confirmBoxService.showInformation('There was a problem updating the notification. ' +
236 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
240 var objOffsetVersion = objAgent.indexOf("MSIE");
241 if (objOffsetVersion != -1) {
242 $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
243 $window.location.reload();
249 notificationService.addAdminNotification(this.newUserNotification)
251 $log.debug('notificationService:addAdminNotification:: Admin notification creation succeeded!,',res);
252 if(res.status=='ERROR'){
253 confirmBoxService.showInformation('There was a problem adding the notification. ' +
254 ' Error: ' + res.response).then(isConfirmed => { });
259 $scope.closeThisDialog(true);
264 switch (err.status) {
265 case '409': // Conflict
266 // handleConflictErrors(err);
268 case '500': // Internal Server Error
269 confirmBoxService.showInformation('There was a problem adding the notification. ' +
270 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
273 confirmBoxService.showInformation('There was a problem adding the notification. ' +
274 'Please try again. If the problem persists, then try again later. Error: ' +
275 err.status).then(isConfirmed => { });
277 $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));
283 $log.warn('please fill in all required fields');
284 confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });
287 // Populate the category list for category dropdown list
288 let getFunctionalMenu = () => {
289 this.isLoadingTable = true;
290 $scope.notifObj= {isCategoriesFunctionalMenu:true};
291 functionalMenuService.getFunctionalMenuRole().then(role_res => {
292 var menu_role_dict = {};
293 for (var i in role_res) {
294 // if first time appear in menu_role_dict
295 if (!(role_res[i].menuId in menu_role_dict)) {
296 menu_role_dict[role_res[i].menuId] = [role_res[i].roleId];
298 menu_role_dict[role_res[i].menuId].push(role_res[i].roleId);
301 functionalMenuService.getManagedFunctionalMenuForNotificationTree().then(res => {
303 var exclude_list = ['Favorites']
304 // Adding children and label attribute to all objects in
305 $scope.checkboxIdDict = {};
306 $scope.checkBoxObj = {isAnyRoleSelected:false};
307 for (let i = 0; i < res.length; i++) {
308 res[i].children = [];
309 res[i].label = res[i].text;
310 res[i].id = res[i].text;
311 // res[i].is_box_checked = false;
312 res[i].can_check = true;
313 res[i].roleId = menu_role_dict[res[i].menuId];
314 $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId };
317 // Adding actual child items to children array in res
319 $scope.parentChildDict ={};
320 $scope.parentChildRoleIdDict ={};
321 for (let i = 0; i < res.length; i++) {
322 let parentId = res[i].menuId;
323 $scope.parentChildDict[parentId] = [];
324 $scope.parentChildRoleIdDict[parentId]=[];
325 for (let j = 0; j < res.length; j++) {
326 let childId = res[j].parentMenuId;
327 if (parentId === childId) {
328 res[i].children.push(res[j]);
329 $scope.parentChildDict[parentId].push(res[j].menuId);
330 //if res[j].roleId is defined
332 for (let k in res[j].roleId) {
333 $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
341 //check if grand children exist
342 for (var key in $scope.parentChildDict){
343 var children = $scope.parentChildDict[key];
344 var isGrandParent = false;
345 if (children.length>0) {
346 for (var i in children) {
347 if ($scope.parentChildDict[children[i]].length>0){
348 isGrandParent = true;
354 for (var i in children) {
355 // if the child has children
356 if ($scope.parentChildDict[children[i]].length>0) {
357 for (var j in $scope.parentChildRoleIdDict[children[i]]) {
359 if ($scope.parentChildRoleIdDict[key].indexOf($scope.parentChildRoleIdDict[children[i]][j]) === -1) {
360 $scope.parentChildRoleIdDict[key].push($scope.parentChildRoleIdDict[children[i]][j]);
372 var ListMenuIdToRemove = [];
373 //$scope.parentObj = {ListMenuIdToRemove : []};
374 //get the list of menuId that needs to be removed
375 for (let i = 0; i < res.length; i++) {
376 if ((res[i].children.length==0)&&(!res[i].roleId)) {
377 var menuIdToRemove = res[i].menuId;
378 if (ListMenuIdToRemove.indexOf(menuIdToRemove) === -1){
379 ListMenuIdToRemove.push(menuIdToRemove);
384 // a scope variable that marks whether each functional menu item should be displayed.
385 $scope.toShowItemDict = {};
386 for (let i = 0; i < res.length; i++) {
387 if (res[i].roleId==null) {
388 if (res[i].children.length==0) {
389 $scope.toShowItemDict[res[i].menuId]=false;
390 } else if(res[i].children.length>0){
391 if($scope.parentChildDict[res[i].menuId].length === _.intersection($scope.parentChildDict[res[i].menuId], ListMenuIdToRemove).length){
392 $scope.toShowItemDict[res[i].menuId]=false;
394 $scope.toShowItemDict[res[i].menuId]=true;
398 $scope.toShowItemDict[res[i].menuId]=true;
402 // Sort the top-level menu items in order based on the
404 res.sort(function (a, b) {
405 return a.column - b.column;
408 // Sort all the children in order based on the column
409 for (let i = 0; i < res.length; i++) {
410 res[i].children.sort(function (a, b) {
411 return a.column - b.column;
415 // Forming actual parent items
416 for (let i = 0; i < res.length; i++) {
417 let parentId = res[i].parentMenuId;
418 if (parentId === null) {
419 actualData.push(res[i]);
423 // $scope.treedata = actualData;
424 var treedata = actualData[0].children;
425 $scope.treedata = [];
426 for (var i in treedata) {
427 if (!(treedata[i].label.indexOf(exclude_list) > -1)) {
428 $scope.treedata.push(treedata[i])
433 $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
435 this.isLoadingTable = false;
439 $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
445 let getAppRoleIds = () => {
446 $scope.notifObj= {isCategoriesFunctionalMenu:false};
447 notificationService.getAppRoleIds().then(res => {
451 // var exclude_list = ['Favorites']
452 var app_id_name_list = {};
453 $scope.checkboxIdDict = {};
454 $scope.checkBoxObj = {isAnyRoleSelected:false};
456 for (let i = 0; i < res.length; i++) {
457 if (!(res[i].appId in app_id_name_list)) {
458 app_id_name_list[res[i].appId] = res[i].appName;
461 res[i].children = [];
462 res[i].label = res[i].roleName;
463 res[i].id = res[i].roleId;
464 res[i].menuId = res[i].roleId;
465 res[i].parentMenuId = res[i].appId;
466 res[i].can_check = true;
467 res[i].roleId = [res[i].roleId];
468 $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId};
471 for (var app_id in app_id_name_list) {
473 new_res.children = [];
474 new_res.label = app_id_name_list[app_id];
476 new_res.menuId = app_id;
477 new_res.parentMenuId = null;
478 new_res.appId = null;
479 new_res.can_check = true;
480 new_res.roleId = null;
481 $scope.checkboxIdDict[new_res.id]= { 'is_box_checked': false, 'role_id': new_res.roleId };
484 $scope.parentChildRoleIdDict ={};
485 //Adding actual child items to children array in res objects
486 for (let i = 0; i < res.length; i++) {
487 let parentId = res[i].menuId;
488 $scope.parentChildRoleIdDict[parentId]=[];
489 for (let j = 0; j < res.length; j++) {
490 let childId = res[j].parentMenuId;
491 if (parentId == childId) {
492 res[i].children.push(res[j]);
494 for (let k in res[j].roleId) {
495 $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
502 //Forming actual parent items
503 for (let i = 0; i < res.length; i++) {
504 let parentId = res[i].parentMenuId;
505 if (parentId === null) {
506 actualData.push(res[i]);
510 $scope.treedata = actualData;
512 $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
514 this.isLoadingTable = false;
517 $scope.getFunctionalMenu= function() {
518 $scope.treeTitle="Functional Menu";
521 $scope.getAppRoleIds = function() {
522 $scope.treeTitle="Applications/Roles";
533 userNotificationsModalCtrl.$inject = ['$scope', '$log', 'functionalMenuService', 'confirmBoxService', 'notificationService', '$modal', 'ngDialog', '$state', '$filter'];
534 angular.module('ecompApp').controller('userNotificationsModalCtrl', userNotificationsModalCtrl);
536 angular.module('ecompApp').directive('attDatepickerCustom', ['$log', function($log) {
542 controller: ['$scope', '$element', '$attrs', '$compile', 'datepickerConfig', 'datepickerService', function($scope, $element, $attrs, $compile, datepickerConfig, datepickerService) {
543 var dateFormatString = angular.isDefined($attrs.dateFormat) ? $scope.$parent.$eval($attrs.dateFormat) : datepickerConfig.dateFormat;
544 var selectedDateMessage = '<div class="sr-focus hidden-spoken" tabindex="-1">the date you selected is {{$parent.current | date : \'' + dateFormatString + '\'}}</div>';
545 $element.removeAttr('att-datepicker-custom');
546 $element.removeAttr('ng-model');
547 $element.attr('ng-value', '$parent.current | date:"EEEE, MMMM d, y"');
548 $element.attr('aria-describedby', 'datepicker');
550 $element.attr('maxlength', 10);
552 var wrapperElement = angular.element('<div></div>');
553 wrapperElement.attr('datepicker-popup', '');
554 wrapperElement.attr('current', 'current');
556 datepickerService.setAttributes($attrs, wrapperElement);
557 datepickerService.bindScope($attrs, $scope);
559 wrapperElement.html('');
560 wrapperElement.append($element.prop('outerHTML'));
561 if (navigator.userAgent.match(/MSIE 8/) === null) {
562 wrapperElement.append(selectedDateMessage);
564 var elm = wrapperElement.prop('outerHTML');
565 elm = $compile(elm)($scope);
566 $element.replaceWith(elm);
568 link: function(scope, elem, attr, ctrl) {
570 // do nothing if no ng-model
571 $log.error("ng-model is required.");
575 scope.$watch('current', function(value) {
576 ctrl.$setViewValue(value);
578 ctrl.$render = function() {
579 scope.current = ctrl.$viewValue;
586 angular.module('ecompApp').directive('jqTreeUserNotif', ['functionalMenuService', '$log', 'confirmBoxService', '$compile', function (functionalMenuService, $log, confirmBoxService, $compile) {
589 templateUrl: 'jq-tree-tmpl-user-notif.html',
590 link: function (scope, el, attrs) {
592 var $jqTree = el.find('#jqTreeUserNotif').tree({
593 data: scope.treedata,
594 autoOpen: scope.editModeObj.isEditMode,
596 onCreateLi: function (node, $li) {
597 node.is_checked = false;
598 if (node.roleId&&scope.roleObj.notificationRoleIds) {
599 node.is_checked = (node.roleId.length === _.intersection(node.roleId, scope.roleObj.notificationRoleIds).length);
601 if (typeof node.id =="string"){
602 $li.attr('id', node.id.replace(/\s+/g, '_'));
605 if (node.is_checked) {
606 isChecked = 'checked="checked"';
608 if (node.can_check) {
610 if (scope.notifObj.isCategoriesFunctionalMenu) {
611 toShow = scope.toShowItemDict[node.menuId];
614 if (scope.editModeObj.isEditMode) {
615 isDisabled = " disabled"
617 //if node is a parent/grandparent node
618 if (node.children.length>0){
619 //whether to show node first
620 if (_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {
622 if (scope.parentChildRoleIdDict[node.menuId].length==_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {
623 isChecked = 'checked="checked"';
629 //if node is a child node
631 if (node.is_checked) {
642 var template = '<input ng-click="thisCheckboxClicked($event)" type="checkbox" class="edit js-node-check" data-node-menu-id="' + node.menuId + '" data-node-id="' + node.id + '" ' + isChecked + ' ng-show="' + toShow + '"' + isDisabled+ '/>'
644 var templateEl = angular.element(template);
645 var $jqCheckbox = $compile(templateEl)(scope);
647 $li.find('.jqtree-element').prepend($jqCheckbox);
649 $li.find('.jqtree-element').remove();
655 scope.thisCheckboxClicked = function (e) {
657 var nodeId = e.target.attributes[4].value;
661 var sBrowser, sUsrAg = window.navigator.userAgent;
662 //if (sUsrAg.indexOf("Firefox") > -1) {
664 if (sUsrAg.indexOf("Trident") > -1) {
665 nodeId = e.target.attributes[5].value;
668 // if (sUsrAg.indexOf("MSIE") > 1) {
669 // alert("hELLO tHIS IS IE10");
670 // nodeId = e.target.attributes[3].value;
671 // alert('nodeId 26 of IE 45 : '+nodeId);
674 var version = navigator.userAgent.match(/Firefox\/(.*)$/);
676 if(version && version.length > 1){
677 if(parseInt(version[1]) >= 50){
678 nodeId = e.target.attributes[3].value;
679 } else if(parseInt(version[1]) >= 45){
681 nodeId = e.target.attributes[2].value;
684 var thisNode = el.find('#jqTreeUserNotif').tree('getNodeById', nodeId);
685 var isChecked = e.target.checked;
686 scope.checkboxIdDict[nodeId]['is_box_checked'] = isChecked;
688 thisNode = angular.element(thisNode);
689 if (thisNode[0].hasOwnProperty('children') && thisNode[0].children.length > 0) {
690 var jsNodeCheckList = angular.element(e.target).parent().next().find('.js-node-check')
691 // check/uncheck children items
692 jsNodeCheckList.prop('checked', isChecked);
694 for (var i in jsNodeCheckList) {
695 var singlediv = jsNodeCheckList[i];
696 if (typeof singlediv == 'object' & (!singlediv.length)) {
698 var tempNodeId = angular.element(singlediv)[0].attributes[4].value;
702 if (sUsrAg.indexOf("Trident") > -1) {
704 var tempNodeId = angular.element(singlediv)[0].attributes[5].value;
709 // if (sUsrAg.indexOf("MSIE") > 0) {
710 // var tempNodeId = angular.element(singlediv)[0].attributes[3].value;
711 // alert('tempNodeId 2 FF 45 : '+tempNodeId);
713 if(version && version.length > 1){
714 if(parseInt(version[1]) >= 50){
715 tempNodeId = angular.element(singlediv)[0].attributes[3].value;
717 else if(parseInt(version[1]) >= 45){
718 tempNodeId = angular.element(singlediv)[0].attributes[2].value;
721 scope.checkboxIdDict[tempNodeId]['is_box_checked'] = isChecked;
726 scope.checkBoxObj.isAnyRoleSelected = false;
727 for (var key in scope.checkboxIdDict) {
728 if (scope.checkboxIdDict[key]['is_box_checked']&&scope.checkboxIdDict[key]['role_id']) {
729 scope.checkBoxObj.isAnyRoleSelected = true;
737 scope.$watch('treedata', function (oldValue, newValue) {
738 if (oldValue !== newValue) {
739 $jqTree.tree('loadData', scope.treedata);
740 $jqTree.tree('reload', function () {