[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / user-notifications-admin / user.notifications.modal.controller.js
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23
24     class userNotificationsModalCtrl {
25         constructor($scope, $log, functionalMenuService, confirmBoxService, notificationService, $modal, ngDialog, $state, $filter) {
26
27             let newNotifModel = {
28                 'isOnlineUsersOnly': null,
29                 'isForAllRolesOptions': null,
30                 'selectedPriority': null,
31                 'isActive': null,
32                 'startTime': null,
33                 'endTime': null,
34                 'msgHeader': null,
35                 'msgDescription': null,
36                 'roleIds': null,
37                 'roleObj': {notificationRoleIds:null}
38             };
39             
40             $scope.notificationId = null;
41             $scope.selectedCat = null;
42             $scope.selectedEcompFunc = null;
43             this.YN_index_mapping = {
44                 "Y": 0,
45                 "N": 1
46             }
47             
48             $scope.onlineAllUsersOptions = [
49                 { "index": 0, "value": "Y", "title": "Online Users Only" },
50                 { "index": 1, "value": "N", "title": "Online & Offline Users" }
51                 
52             ];
53
54             $scope.isForAllRolesOptions = [
55                 { "index": 0, "value": "Y", "title": "Yes" },
56                 { "index": 1, "value": "N", "title": "No" }
57             ];
58
59             $scope.priorityOptions  = [
60                 { "index": 0, "value": 1, "title": "Normal" },
61                 { "index": 1, "value": 2, "title": "Important" }
62             ];
63
64             $scope.isActiveOptions = [
65                 { "index": 0, "value": "Y", "title": "Yes" },
66                 { "index": 1, "value": "N", "title": "No" }
67             ];
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";
73
74           $scope.selectedPriority=$scope.priorityOptions[0].value;
75
76             // $scope.notificationRoleIds = [];
77             $scope.msgHeader = '';
78             $scope.msgDescription = '';
79             $scope.treeTitle="Functional Menu";
80             $scope.notifObj= {isCategoriesFunctionalMenu:true};
81
82             let init = () => {
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};
108                 } else {
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};
115                 }
116             };
117             this.conflictMessages = {};
118             this.scrollApi = {};
119             let handleConflictErrors = err => {
120                 if(!err.data){
121                     return;
122                 }
123                 if(!err.data.length){ // support objects
124                     err.data = [err.data]
125                 }
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]();
134                     });
135                 });
136                 this.scrollApi.scrollTop();
137             };
138
139             let resetConflict = fieldName => {
140                 delete this.conflictMessages[fieldName];
141                 if($scope.appForm[fieldName]){
142                     $scope.appForm[fieldName].$setValidity('conflict', true);
143                 }
144             };
145             $scope.addUserNotificationValidation = function () {
146                 // // pre-processing
147                 if (!($scope.isEditMode)) {                    
148                     var validation=false;
149
150                if($scope.startTime && $scope.endTime && $scope.msgHeader != '' && $scope.msgDescription != '' && ($scope.startTime<$scope.endTime)){
151                    validation=true;
152                    if( $scope.isForAllRoles=='N'){
153                        validation =  $scope.checkBoxObj.isAnyRoleSelected;
154                    }
155                }
156                else{
157                    validation=false;
158                    }
159                     
160                         
161                    return !validation; 
162                 }
163             }
164             
165             /* format the value for viewing a notification */
166             $scope.formatStartDate = function () {
167                 if ($scope.startTime) {
168                         $scope.startTime = $filter('date')($scope.startTime, 'medium'); 
169                 }               
170             }
171             
172             /* format the value for viewing a notification */
173             $scope.formatEndDate = function () {
174                 if($scope.endTime){
175                         $scope.endTime = $filter('date')($scope.endTime, 'medium');
176                 }
177             }
178             
179             $scope.addUserNotification = function () {
180                 $scope.notificationRoleIds = [];
181                 // pre-processing
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]);
188                             }
189                         }
190                     }
191                 }
192
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 =
197                         {
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()
209                         };
210
211                     // POST ajax call here;
212                     if ($scope.isEditMode) {
213                         notificationService.updateAdminNotification(this.newUserNotification)
214                             .then(() => {
215                                 //$log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');
216                                 $scope.closeThisDialog(true);
217                                 // emptyCookies();
218                             }).catch(err => {
219                                 $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));
220                                 switch (err.status) {
221                                     case '409':         // Conflict
222                                         // handleConflictErrors(err);
223                                         break;
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 => { });
227                                         break;
228                                     case '403':         // Forbidden... possible
229                                                                                                                 // webjunction error to
230                                                                                                                 // try again
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 => { });
233                                         break;
234                                     default:
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 => { });
237                                 }
238                             }).finally(() => {
239                                 // for bug in IE 11
240                                 var objOffsetVersion = objAgent.indexOf("MSIE");
241                                 if (objOffsetVersion != -1) {
242                                     $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
243                                     $window.location.reload();   
244                                 }
245                                 // for bug in IE 11
246                             });
247
248                     } else {
249                         notificationService.addAdminNotification(this.newUserNotification)
250                             .then((res) => {
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 => { });
255
256                                         
257                                 }
258                                 else{
259                                          $scope.closeThisDialog(true);
260                                 }
261                                
262                                 // emptyCookies();
263                             }).catch(err => {
264                                 switch (err.status) {
265                                     case '409':         // Conflict
266                                         // handleConflictErrors(err);
267                                         break;
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 => { });
271                                         break;
272                                     default:
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 => { });
276                                 }
277                                 $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));
278                             })
279                     }
280
281                    
282                 } else {
283                     $log.warn('please fill in all required fields');
284                         confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });
285                 }
286             }
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];
297                         } else {
298                             menu_role_dict[role_res[i].menuId].push(role_res[i].roleId);
299                         }
300                     }
301                     functionalMenuService.getManagedFunctionalMenuForNotificationTree().then(res => {
302                         let actualData = [];
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 };
315                         }
316
317                         // Adding actual child items to children array in res
318                                                 // objects
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
331                                     if (res[j].roleId) {
332                                         for (let k in res[j].roleId) {
333                                             $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
334                                         }
335                                         
336                                     }
337                                 }
338                             }
339                         }
340                         
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;
349                                                         break;
350                                                 }
351                                         }
352                                 }
353                                 if (isGrandParent) {
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]]) {
358                                                                 
359                                                                 if ($scope.parentChildRoleIdDict[key].indexOf($scope.parentChildRoleIdDict[children[i]][j]) === -1) {
360                                                                         $scope.parentChildRoleIdDict[key].push($scope.parentChildRoleIdDict[children[i]][j]);
361                                                                 }
362                                                         }
363                                                 } else {
364                                                          
365                                                 }
366                                         }
367                                 }
368
369                             };                            
370                                                         
371
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);
380                                 }
381                             }
382                         }
383
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;                                
393                                     } else {
394                                         $scope.toShowItemDict[res[i].menuId]=true;                                
395                                     }
396                                 }
397                             } else {
398                                 $scope.toShowItemDict[res[i].menuId]=true;
399                             }
400                         }
401  
402                         // Sort the top-level menu items in order based on the
403                                                 // column
404                         res.sort(function (a, b) {
405                             return a.column - b.column;
406                         });
407
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;
412                             });
413                         }
414
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]);
420                             }
421                         }
422
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])
429                             }
430                         }
431
432                     }).catch(err => {
433                         $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
434                     }).finally(() => {
435                         this.isLoadingTable = false;
436                     })
437
438                 }).catch(err => {
439                     $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
440                 })
441                     ;
442             }
443      
444             
445             let getAppRoleIds = () => {
446                 $scope.notifObj= {isCategoriesFunctionalMenu:false};
447                 notificationService.getAppRoleIds().then(res => {
448                         
449                     res = res.data;
450                     let actualData = [];
451                     // var exclude_list = ['Favorites']
452                     var app_id_name_list = {};
453                         $scope.checkboxIdDict = {};
454                         $scope.checkBoxObj = {isAnyRoleSelected:false};
455
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;
459                         }
460
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};   
469                     }
470                     
471                     for (var app_id in app_id_name_list) {
472                         var new_res = {};
473                         new_res.children = [];
474                         new_res.label = app_id_name_list[app_id];
475                         new_res.id = 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 };
482                         res.push(new_res);
483                     }
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]);
493                                 if (res[j].roleId) {
494                                         for (let k in res[j].roleId) {
495                                         $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
496                                         }
497                                         
498                                 }
499                             }
500                         }
501                     }
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]);
507                         }
508                     }
509
510                     $scope.treedata = actualData;
511                 }).catch(err => {
512                     $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
513                 }).finally(() => {
514                     this.isLoadingTable = false;
515                 })
516             }
517             $scope.getFunctionalMenu= function() {
518             $scope.treeTitle="Functional Menu";
519             getFunctionalMenu();
520             }
521             $scope.getAppRoleIds = function() {
522             $scope.treeTitle="Applications/Roles";
523                 getAppRoleIds();
524             }
525              
526             init();
527             getFunctionalMenu();
528
529         }
530         
531     }
532     
533     userNotificationsModalCtrl.$inject = ['$scope', '$log', 'functionalMenuService', 'confirmBoxService', 'notificationService', '$modal', 'ngDialog', '$state', '$filter'];
534     angular.module('ecompApp').controller('userNotificationsModalCtrl', userNotificationsModalCtrl);
535     
536     angular.module('ecompApp').directive('attDatepickerCustom', ['$log', function($log) {
537         return {
538             restrict: 'A',
539           require: 'ngModel',
540             scope: {},
541             
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');
549                
550                 $element.attr('maxlength', 10);
551
552                 var wrapperElement = angular.element('<div></div>');
553                 wrapperElement.attr('datepicker-popup', '');
554                 wrapperElement.attr('current', 'current');
555
556                 datepickerService.setAttributes($attrs, wrapperElement);
557                 datepickerService.bindScope($attrs, $scope);
558
559                 wrapperElement.html('');
560                 wrapperElement.append($element.prop('outerHTML'));
561                 if (navigator.userAgent.match(/MSIE 8/) === null) {
562                     wrapperElement.append(selectedDateMessage);
563                 }
564                 var elm = wrapperElement.prop('outerHTML');
565                 elm = $compile(elm)($scope);
566                 $element.replaceWith(elm);
567             }],
568             link: function(scope, elem, attr, ctrl) {
569                 if (!ctrl) {
570                     // do nothing if no ng-model
571                     $log.error("ng-model is required.");
572                     return;
573                 }
574
575                 scope.$watch('current', function(value) {
576                     ctrl.$setViewValue(value);
577                 });
578                 ctrl.$render = function() {
579                     scope.current = ctrl.$viewValue;
580                 };
581               
582             }
583         };
584     }]);
585
586     angular.module('ecompApp').directive('jqTreeUserNotif', ['functionalMenuService', '$log', 'confirmBoxService', '$compile', function (functionalMenuService, $log, confirmBoxService, $compile) {
587         return {
588             scope: true,
589             templateUrl: 'jq-tree-tmpl-user-notif.html',
590             link: function (scope, el, attrs) {
591
592                 var $jqTree = el.find('#jqTreeUserNotif').tree({
593                     data: scope.treedata,
594                     autoOpen: scope.editModeObj.isEditMode,
595                     dragAndDrop: false,
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);
600                         }                        
601                         if (typeof node.id =="string"){
602                             $li.attr('id', node.id.replace(/\s+/g, '_'));
603                         }
604                         var isChecked = '';
605                         if (node.is_checked) {
606                             isChecked = 'checked="checked"';
607                         }
608                         if (node.can_check) {
609                             var toShow = true;
610                             if (scope.notifObj.isCategoriesFunctionalMenu) {
611                                 toShow = scope.toShowItemDict[node.menuId];
612                             }
613                             var isDisabled = "";
614                             if (scope.editModeObj.isEditMode) {
615                                 isDisabled = " disabled"
616                                         
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) {
621                                                 toShow=true;
622                                                 if (scope.parentChildRoleIdDict[node.menuId].length==_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {
623                                                 isChecked = 'checked="checked"';                                                        
624                                                 }
625                                         } else {
626                                                 toShow=false;
627                                         }
628                                     } 
629                                     //if node is a child node
630                                     else {
631                                         if (node.is_checked) {
632                                                 toShow=true;                                    
633                                         } else {
634                                                 toShow=false;
635                                         }
636                                     }
637
638                               }
639
640                             
641
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+ '/>'
643
644                             var templateEl = angular.element(template);
645                             var $jqCheckbox = $compile(templateEl)(scope);
646                                                         if (toShow){
647                                                                         $li.find('.jqtree-element').prepend($jqCheckbox);
648                                                                 } else {
649                                                                         $li.find('.jqtree-element').remove();
650                                                                         }
651                         }
652                     }
653                 });
654
655                 scope.thisCheckboxClicked = function (e) {
656                 
657                         var nodeId = e.target.attributes[4].value;
658                         
659              
660                
661                         var sBrowser, sUsrAg = window.navigator.userAgent;
662                         //if (sUsrAg.indexOf("Firefox") > -1) {
663                         
664                         if (sUsrAg.indexOf("Trident") > -1) {
665                                 nodeId = e.target.attributes[5].value;
666                         }
667                     
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);
672 //                      }
673 //                      
674                         var version = navigator.userAgent.match(/Firefox\/(.*)$/);
675                         
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){
680                                 
681                                 nodeId = e.target.attributes[2].value;
682                         }
683                 }
684                         var thisNode = el.find('#jqTreeUserNotif').tree('getNodeById', nodeId);
685                     var isChecked = e.target.checked;
686                     scope.checkboxIdDict[nodeId]['is_box_checked'] = isChecked;
687
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);
693
694                         for (var i in jsNodeCheckList) {
695                             var singlediv = jsNodeCheckList[i];
696                             if (typeof singlediv == 'object' & (!singlediv.length)) {
697                                 
698                                 var tempNodeId = angular.element(singlediv)[0].attributes[4].value;
699                             
700                                 
701                                 
702                                 if (sUsrAg.indexOf("Trident") > -1) {
703                                         
704                                         var tempNodeId = angular.element(singlediv)[0].attributes[5].value;
705                                         
706                                
707                                 }
708                                 
709 //                                if (sUsrAg.indexOf("MSIE") > 0) {
710 //                                    var tempNodeId = angular.element(singlediv)[0].attributes[3].value;
711 //                                    alert('tempNodeId 2 FF 45 : '+tempNodeId);
712 //                                    }
713                                 if(version && version.length > 1){
714                                         if(parseInt(version[1]) >= 50){
715                                                 tempNodeId = angular.element(singlediv)[0].attributes[3].value;
716                                         } 
717                                         else if(parseInt(version[1]) >= 45){
718                                                 tempNodeId = angular.element(singlediv)[0].attributes[2].value;
719                                         }
720                                 }
721                                 scope.checkboxIdDict[tempNodeId]['is_box_checked'] = isChecked;
722                             }
723                         }
724                     }
725
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;
730                             break;
731                         }
732                     }
733                 }
734
735
736
737                 scope.$watch('treedata', function (oldValue, newValue) {
738                     if (oldValue !== newValue) {
739                         $jqTree.tree('loadData', scope.treedata);
740                         $jqTree.tree('reload', function () {
741                         });
742                     }
743                 });
744             }
745         };
746     }]);
747 })();