[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / user-notifications-admin / user.notifications.modal.controller.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 'use strict';\r
21 \r
22 (function () {\r
23 \r
24     class userNotificationsModalCtrl {\r
25         constructor($scope, $log, functionalMenuService, confirmBoxService, notificationService, $modal, ngDialog, $state, $filter) {\r
26 \r
27             let newNotifModel = {\r
28                 'isOnlineUsersOnly': null,\r
29                 'isForAllRolesOptions': null,\r
30                 'selectedPriority': null,\r
31                 'isActive': null,\r
32                 'startTime': null,\r
33                 'endTime': null,\r
34                 'msgHeader': null,\r
35                 'msgDescription': null,\r
36                 'roleIds': null,\r
37                 'roleObj': {notificationRoleIds:null}\r
38             };\r
39             \r
40             $scope.notificationId = null;\r
41             $scope.selectedCat = null;\r
42             $scope.selectedEcompFunc = null;\r
43             this.YN_index_mapping = {\r
44                 "Y": 0,\r
45                 "N": 1\r
46             }\r
47             \r
48             $scope.onlineAllUsersOptions = [\r
49                 { "index": 0, "value": "Y", "title": "Online Users Only" },\r
50                 { "index": 1, "value": "N", "title": "Online & Offline Users" }\r
51                 \r
52             ];\r
53 \r
54             $scope.isForAllRolesOptions = [\r
55                 { "index": 0, "value": "Y", "title": "Yes" },\r
56                 { "index": 1, "value": "N", "title": "No" }\r
57             ];\r
58 \r
59             $scope.priorityOptions  = [\r
60                 { "index": 0, "value": 1, "title": "Normal" },\r
61                 { "index": 1, "value": 2, "title": "Important" }\r
62             ];\r
63 \r
64             $scope.isActiveOptions = [\r
65                 { "index": 0, "value": "Y", "title": "Yes" },\r
66                 { "index": 1, "value": "N", "title": "No" }\r
67             ];\r
68             $scope.isActive = $scope.isActiveOptions[0];\r
69             $scope.selectPriority = $scope.priorityOptions[0];\r
70             $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[1];\r
71           $scope.isForAllRoles=$scope.isForAllRolesOptions[0].value;\r
72           $scope.isFunctionalMenu ="Y";\r
73 \r
74           $scope.selectedPriority=$scope.priorityOptions[0].value;\r
75 \r
76             // $scope.notificationRoleIds = [];\r
77             $scope.msgHeader = '';\r
78             $scope.msgDescription = '';\r
79             $scope.treeTitle="Functional Menu";\r
80             $scope.notifObj= {isCategoriesFunctionalMenu:true};\r
81 \r
82             let init = () => {\r
83                 // $log.info('userNotificationsModalCtrl::init');\r
84                 this.isSaving = false;\r
85                 var today = new Date();\r
86                 $scope.minDate = today.toISOString().substring(0, 10);\r
87                 var threeMonthsFromNow = new Date();\r
88                 threeMonthsFromNow.setMonth(threeMonthsFromNow.getMonth() + 3);\r
89                 $scope.maxDate = threeMonthsFromNow.toISOString().substring(0, 10);\r
90                 if ($scope.ngDialogData && $scope.ngDialogData.notif) {\r
91                     // $log.debug('userNotificationsModalCtrl:init:: Edit\r
92                                         // notification mode for', $scope.ngDialogData.notif);\r
93                     $scope.isEditMode = true;\r
94                     $scope.editModeObj = {isEditMode: true};\r
95                     this.notif = _.clone($scope.ngDialogData.notif);\r
96                     $scope.modalPgTitle = 'View Notification'\r
97                     $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[this.YN_index_mapping[this.notif.isForOnlineUsers]];\r
98                     $scope.isForAllRoles = $scope.isForAllRolesOptions[this.YN_index_mapping[this.notif.isForAllRoles]].value;\r
99                     $scope.isActive = $scope.isActiveOptions[this.YN_index_mapping[this.notif.activeYn]];\r
100                     $scope.selectedPriority = $scope.priorityOptions[this.notif.priority - 1].value;\r
101                     $scope.startTime = new Date(this.notif.startTime);\r
102                     $scope.endTime = new Date(this.notif.endTime);\r
103                     $scope.msgHeader = this.notif.msgHeader;\r
104                     $scope.msgDescription = this.notif.msgDescription;\r
105                     $scope.notificationId = this.notif.notificationId;\r
106                     $scope.notificationRoleIds = this.notif.roleIds;\r
107                     $scope.roleObj = {notificationRoleIds:this.notif.roleIds};\r
108                 } else {\r
109                         // $log.debug('AppDetailsModalCtrl:init:: New app mode');\r
110                     $scope.isEditMode = false;\r
111                     $scope.editModeObj = {isEditMode: false};\r
112                     $scope.modalPgTitle = 'Add a New Notification'\r
113                     this.notif = _.clone(newNotifModel);\r
114                     $scope.roleObj = {notificationRoleIds:null};\r
115                 }\r
116             };\r
117             this.conflictMessages = {};\r
118             this.scrollApi = {};\r
119             let handleConflictErrors = err => {\r
120                 if(!err.data){\r
121                     return;\r
122                 }\r
123                 if(!err.data.length){ // support objects\r
124                     err.data = [err.data]\r
125                 }\r
126                 _.forEach(err.data, item => {\r
127                     _.forEach(item.fields, field => {\r
128                         // set conflict message\r
129                         this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];\r
130                         // set field as invalid\r
131                         $scope.appForm[field.name].$setValidity('conflict', false);\r
132                         // set watch once to clear error after user correction\r
133                         watchOnce[field.name]();\r
134                     });\r
135                 });\r
136                 this.scrollApi.scrollTop();\r
137             };\r
138 \r
139             let resetConflict = fieldName => {\r
140                 delete this.conflictMessages[fieldName];\r
141                 if($scope.appForm[fieldName]){\r
142                     $scope.appForm[fieldName].$setValidity('conflict', true);\r
143                 }\r
144             };\r
145             $scope.addUserNotificationValidation = function () {\r
146                 // // pre-processing\r
147                 if (!($scope.isEditMode)) {                    \r
148                     var validation=false;\r
149 \r
150                if($scope.startTime && $scope.endTime && $scope.msgHeader != '' && $scope.msgDescription != '' && ($scope.startTime<$scope.endTime)){\r
151                    validation=true;\r
152                    if( $scope.isForAllRoles=='N'){\r
153                        validation =  $scope.checkBoxObj.isAnyRoleSelected;\r
154                    }\r
155                }\r
156                else{\r
157                    validation=false;\r
158                    }\r
159                     \r
160                         \r
161                    return !validation; \r
162                 }\r
163             }\r
164             \r
165             /* format the value for viewing a notification */\r
166             $scope.formatStartDate = function () {\r
167                 if ($scope.startTime) {\r
168                         $scope.startTime = $filter('date')($scope.startTime, 'medium'); \r
169                 }               \r
170             }\r
171             \r
172             /* format the value for viewing a notification */\r
173             $scope.formatEndDate = function () {\r
174                 if($scope.endTime){\r
175                         $scope.endTime = $filter('date')($scope.endTime, 'medium');\r
176                 }\r
177             }\r
178             \r
179             $scope.addUserNotification = function () {\r
180                 $scope.notificationRoleIds = [];\r
181                 // pre-processing\r
182                 for (var key in $scope.checkboxIdDict) {\r
183                     if ($scope.checkboxIdDict[key].is_box_checked && ($scope.checkboxIdDict[key].role_id != null)) {\r
184                         var role_ids = $scope.checkboxIdDict[key].role_id;\r
185                         for (var i in role_ids) {\r
186                             if (!($scope.notificationRoleIds.indexOf(role_ids[i]) > -1)) {\r
187                                 $scope.notificationRoleIds.push(role_ids[i]);\r
188                             }\r
189                         }\r
190                     }\r
191                 }\r
192 \r
193                 $scope.notificationRoleIds.sort();\r
194                 if (($scope.isOnlineUsersOnly) && ($scope.isForAllRoles) && ($scope.selectedPriority) && ($scope.isActive)\r
195                     && ($scope.startTime) && ($scope.endTime) && ($scope.msgHeader != '') && ($scope.msgDescription != '')) {\r
196                     this.newUserNotification =\r
197                         {\r
198                             'notificationId':$scope.notificationId,\r
199                             'isForOnlineUsers': $scope.isOnlineUsersOnly.value,\r
200                             'isForAllRoles': $scope.isForAllRoles,\r
201                             'priority': $scope.selectedPriority,\r
202                             'activeYn': $scope.isActive.value,\r
203                             'startTime': $scope.startTime,\r
204                             'endTime': $scope.endTime,\r
205                             'msgHeader': $scope.msgHeader,\r
206                             'msgDescription': $scope.msgDescription,\r
207                             'roleIds': $scope.notificationRoleIds,\r
208                             'createdDate': new Date()\r
209                         };\r
210 \r
211                     // POST ajax call here;\r
212                     if ($scope.isEditMode) {\r
213                         notificationService.updateAdminNotification(this.newUserNotification)\r
214                             .then(() => {\r
215                                 //$log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');\r
216                                 $scope.closeThisDialog(true);\r
217                                 // emptyCookies();\r
218                             }).catch(err => {\r
219                                 $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));\r
220                                 switch (err.status) {\r
221                                     case '409':         // Conflict\r
222                                         // handleConflictErrors(err);\r
223                                         break;\r
224                                     case '500':         // Internal Server Error\r
225                                         confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
226                                             'Please try again later. Error: ' + err.status).then(isConfirmed => { });\r
227                                         break;\r
228                                     case '403':         // Forbidden... possible\r
229                                                                                                                 // webjunction error to\r
230                                                                                                                 // try again\r
231                                         confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
232                                             'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });\r
233                                         break;\r
234                                     default:\r
235                                         confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
236                                             'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });\r
237                                 }\r
238                             }).finally(() => {\r
239                                 // for bug in IE 11\r
240                                 var objOffsetVersion = objAgent.indexOf("MSIE");\r
241                                 if (objOffsetVersion != -1) {\r
242                                     $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');\r
243                                     $window.location.reload();   \r
244                                 }\r
245                                 // for bug in IE 11\r
246                             });\r
247 \r
248                     } else {\r
249                         notificationService.addAdminNotification(this.newUserNotification)\r
250                             .then((res) => {\r
251                                 $log.debug('notificationService:addAdminNotification:: Admin notification creation succeeded!,',res);\r
252                                 if(res.status=='ERROR'){\r
253                                          confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
254                                              ' Error: ' + res.response).then(isConfirmed => { });\r
255 \r
256                                         \r
257                                 }\r
258                                 else{\r
259                                          $scope.closeThisDialog(true);\r
260                                 }\r
261                                \r
262                                 // emptyCookies();\r
263                             }).catch(err => {\r
264                                 switch (err.status) {\r
265                                     case '409':         // Conflict\r
266                                         // handleConflictErrors(err);\r
267                                         break;\r
268                                     case '500':         // Internal Server Error\r
269                                         confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
270                                             'Please try again later. Error: ' + err.status).then(isConfirmed => { });\r
271                                         break;\r
272                                     default:\r
273                                         confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
274                                             'Please try again. If the problem persists, then try again later. Error: ' +\r
275                                             err.status).then(isConfirmed => { });\r
276                                 }\r
277                                 $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));\r
278                             })\r
279                     }\r
280 \r
281                    \r
282                 } else {\r
283                     $log.warn('please fill in all required fields');\r
284                         confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });\r
285                 }\r
286             }\r
287             // Populate the category list for category dropdown list\r
288             let getFunctionalMenu = () => {\r
289                 this.isLoadingTable = true;\r
290                 $scope.notifObj= {isCategoriesFunctionalMenu:true};\r
291                 functionalMenuService.getFunctionalMenuRole().then(role_res => {\r
292                     var menu_role_dict = {};\r
293                     for (var i in role_res) {\r
294                         // if first time appear in menu_role_dict\r
295                         if (!(role_res[i].menuId in menu_role_dict)) {\r
296                             menu_role_dict[role_res[i].menuId] = [role_res[i].roleId];\r
297                         } else {\r
298                             menu_role_dict[role_res[i].menuId].push(role_res[i].roleId);\r
299                         }\r
300                     }\r
301                     functionalMenuService.getManagedFunctionalMenuForNotificationTree().then(res => {\r
302                         let actualData = [];\r
303                         var exclude_list = ['Favorites']\r
304                         // Adding children and label attribute to all objects in\r
305                         $scope.checkboxIdDict = {};\r
306                         $scope.checkBoxObj = {isAnyRoleSelected:false};\r
307                         for (let i = 0; i < res.length; i++) {\r
308                             res[i].children = [];\r
309                             res[i].label = res[i].text;\r
310                             res[i].id = res[i].text;\r
311                             // res[i].is_box_checked = false;\r
312                             res[i].can_check = true;\r
313                             res[i].roleId = menu_role_dict[res[i].menuId];\r
314                             $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId };\r
315                         }\r
316 \r
317                         // Adding actual child items to children array in res\r
318                                                 // objects\r
319                         $scope.parentChildDict ={};\r
320                         $scope.parentChildRoleIdDict ={};\r
321                         for (let i = 0; i < res.length; i++) {\r
322                             let parentId = res[i].menuId;\r
323                             $scope.parentChildDict[parentId] = [];\r
324                             $scope.parentChildRoleIdDict[parentId]=[];\r
325                             for (let j = 0; j < res.length; j++) {\r
326                                 let childId = res[j].parentMenuId;\r
327                                 if (parentId === childId) {\r
328                                     res[i].children.push(res[j]);\r
329                                     $scope.parentChildDict[parentId].push(res[j].menuId);\r
330                                     //if res[j].roleId is defined\r
331                                     if (res[j].roleId) {\r
332                                         for (let k in res[j].roleId) {\r
333                                             $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);\r
334                                         }\r
335                                         \r
336                                     }\r
337                                 }\r
338                             }\r
339                         }\r
340                         \r
341                         //check if grand children exist\r
342                             for (var key in $scope.parentChildDict){\r
343                                 var children = $scope.parentChildDict[key];\r
344                                 var isGrandParent = false;\r
345                                 if (children.length>0) {\r
346                                         for (var i in children) {\r
347                                                 if ($scope.parentChildDict[children[i]].length>0){\r
348                                                         isGrandParent = true;\r
349                                                         break;\r
350                                                 }\r
351                                         }\r
352                                 }\r
353                                 if (isGrandParent) {\r
354                                         for (var i in children) {\r
355                                                 // if the child has children\r
356                                                 if ($scope.parentChildDict[children[i]].length>0) {\r
357                                                         for (var j in $scope.parentChildRoleIdDict[children[i]]) {\r
358                                                                 \r
359                                                                 if ($scope.parentChildRoleIdDict[key].indexOf($scope.parentChildRoleIdDict[children[i]][j]) === -1) {\r
360                                                                         $scope.parentChildRoleIdDict[key].push($scope.parentChildRoleIdDict[children[i]][j]);\r
361                                                                 }\r
362                                                         }\r
363                                                 } else {\r
364                                                          \r
365                                                 }\r
366                                         }\r
367                                 }\r
368 \r
369                             };                            \r
370                                                         \r
371 \r
372                                 var ListMenuIdToRemove = [];\r
373                         //$scope.parentObj = {ListMenuIdToRemove : []};\r
374                         //get the list of menuId that needs to be removed \r
375                         for (let i = 0; i < res.length; i++) {\r
376                             if ((res[i].children.length==0)&&(!res[i].roleId)) {\r
377                                 var menuIdToRemove = res[i].menuId;\r
378                                 if (ListMenuIdToRemove.indexOf(menuIdToRemove) === -1){\r
379                                     ListMenuIdToRemove.push(menuIdToRemove);\r
380                                 }\r
381                             }\r
382                         }\r
383 \r
384                         // a scope variable that marks whether each functional menu item should be displayed.\r
385                         $scope.toShowItemDict = {};                        \r
386                         for (let i = 0; i < res.length; i++) {\r
387                             if (res[i].roleId==null) {\r
388                                 if (res[i].children.length==0) {\r
389                                     $scope.toShowItemDict[res[i].menuId]=false;                                \r
390                                 } else if(res[i].children.length>0){\r
391                                     if($scope.parentChildDict[res[i].menuId].length === _.intersection($scope.parentChildDict[res[i].menuId], ListMenuIdToRemove).length){\r
392                                         $scope.toShowItemDict[res[i].menuId]=false;                                \r
393                                     } else {\r
394                                         $scope.toShowItemDict[res[i].menuId]=true;                                \r
395                                     }\r
396                                 }\r
397                             } else {\r
398                                 $scope.toShowItemDict[res[i].menuId]=true;\r
399                             }\r
400                         }\r
401  \r
402                         // Sort the top-level menu items in order based on the\r
403                                                 // column\r
404                         res.sort(function (a, b) {\r
405                             return a.column - b.column;\r
406                         });\r
407 \r
408                         // Sort all the children in order based on the column\r
409                         for (let i = 0; i < res.length; i++) {\r
410                             res[i].children.sort(function (a, b) {\r
411                                 return a.column - b.column;\r
412                             });\r
413                         }\r
414 \r
415                         // Forming actual parent items\r
416                         for (let i = 0; i < res.length; i++) {\r
417                             let parentId = res[i].parentMenuId;\r
418                             if (parentId === null) {\r
419                                 actualData.push(res[i]);\r
420                             }\r
421                         }\r
422 \r
423                         // $scope.treedata = actualData;\r
424                         var treedata = actualData[0].children;\r
425                         $scope.treedata = [];\r
426                         for (var i in treedata) {\r
427                             if (!(treedata[i].label.indexOf(exclude_list) > -1)) {\r
428                                 $scope.treedata.push(treedata[i])\r
429                             }\r
430                         }\r
431 \r
432                     }).catch(err => {\r
433                         $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
434                     }).finally(() => {\r
435                         this.isLoadingTable = false;\r
436                     })\r
437 \r
438                 }).catch(err => {\r
439                     $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
440                 })\r
441                     ;\r
442             }\r
443      \r
444             \r
445             let getAppRoleIds = () => {\r
446                 $scope.notifObj= {isCategoriesFunctionalMenu:false};\r
447                 notificationService.getAppRoleIds().then(res => {\r
448                         \r
449                     res = res.data;\r
450                     let actualData = [];\r
451                     // var exclude_list = ['Favorites']\r
452                     var app_id_name_list = {};\r
453                         $scope.checkboxIdDict = {};\r
454                         $scope.checkBoxObj = {isAnyRoleSelected:false};\r
455 \r
456                     for (let i = 0; i < res.length; i++) {\r
457                         if (!(res[i].appId in app_id_name_list)) {\r
458                             app_id_name_list[res[i].appId] = res[i].appName;\r
459                         }\r
460 \r
461                         res[i].children = [];\r
462                         res[i].label = res[i].roleName;\r
463                         res[i].id = res[i].roleId;\r
464                         res[i].menuId = res[i].roleId;\r
465                         res[i].parentMenuId = res[i].appId;\r
466                         res[i].can_check = true;\r
467                         res[i].roleId = [res[i].roleId];\r
468                         $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId};   \r
469                     }\r
470                     \r
471                     for (var app_id in app_id_name_list) {\r
472                         var new_res = {};\r
473                         new_res.children = [];\r
474                         new_res.label = app_id_name_list[app_id];\r
475                         new_res.id = app_id;\r
476                         new_res.menuId = app_id;\r
477                         new_res.parentMenuId = null;\r
478                         new_res.appId = null;\r
479                         new_res.can_check = true;\r
480                         new_res.roleId = null;\r
481                         $scope.checkboxIdDict[new_res.id]= { 'is_box_checked': false, 'role_id': new_res.roleId };\r
482                         res.push(new_res);\r
483                     }\r
484                     $scope.parentChildRoleIdDict ={};\r
485                     //Adding actual child items to children array in res objects\r
486                     for (let i = 0; i < res.length; i++) {\r
487                         let parentId = res[i].menuId;\r
488                         $scope.parentChildRoleIdDict[parentId]=[];\r
489                         for (let j = 0; j < res.length; j++) {\r
490                             let childId = res[j].parentMenuId;\r
491                             if (parentId == childId) {\r
492                                 res[i].children.push(res[j]);\r
493                                 if (res[j].roleId) {\r
494                                         for (let k in res[j].roleId) {\r
495                                         $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);\r
496                                         }\r
497                                         \r
498                                 }\r
499                             }\r
500                         }\r
501                     }\r
502                     //Forming actual parent items\r
503                     for (let i = 0; i < res.length; i++) {\r
504                         let parentId = res[i].parentMenuId;\r
505                         if (parentId === null) {\r
506                             actualData.push(res[i]);\r
507                         }\r
508                     }\r
509 \r
510                     $scope.treedata = actualData;\r
511                 }).catch(err => {\r
512                     $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
513                 }).finally(() => {\r
514                     this.isLoadingTable = false;\r
515                 })\r
516             }\r
517             $scope.getFunctionalMenu= function() {\r
518             $scope.treeTitle="Functional Menu";\r
519             getFunctionalMenu();\r
520             }\r
521             $scope.getAppRoleIds = function() {\r
522             $scope.treeTitle="Applications/Roles";\r
523                 getAppRoleIds();\r
524             }\r
525              \r
526             init();\r
527             getFunctionalMenu();\r
528 \r
529         }\r
530         \r
531     }\r
532     \r
533     userNotificationsModalCtrl.$inject = ['$scope', '$log', 'functionalMenuService', 'confirmBoxService', 'notificationService', '$modal', 'ngDialog', '$state', '$filter'];\r
534     angular.module('ecompApp').controller('userNotificationsModalCtrl', userNotificationsModalCtrl);\r
535     \r
536     angular.module('ecompApp').directive('attDatepickerCustom', ['$log', function($log) {\r
537         return {\r
538             restrict: 'A',\r
539           require: 'ngModel',\r
540             scope: {},\r
541             \r
542             controller: ['$scope', '$element', '$attrs', '$compile', 'datepickerConfig', 'datepickerService', function($scope, $element, $attrs, $compile, datepickerConfig, datepickerService) {\r
543                var dateFormatString = angular.isDefined($attrs.dateFormat) ? $scope.$parent.$eval($attrs.dateFormat) : datepickerConfig.dateFormat;\r
544                var selectedDateMessage = '<div class="sr-focus hidden-spoken" tabindex="-1">the date you selected is {{$parent.current | date : \'' + dateFormatString + '\'}}</div>';\r
545                $element.removeAttr('att-datepicker-custom');\r
546                 $element.removeAttr('ng-model');\r
547                 $element.attr('ng-value', '$parent.current |  date:"EEEE, MMMM d, y"');\r
548                 $element.attr('aria-describedby', 'datepicker');\r
549                \r
550                 $element.attr('maxlength', 10);\r
551 \r
552                 var wrapperElement = angular.element('<div></div>');\r
553                 wrapperElement.attr('datepicker-popup', '');\r
554                 wrapperElement.attr('current', 'current');\r
555 \r
556                 datepickerService.setAttributes($attrs, wrapperElement);\r
557                 datepickerService.bindScope($attrs, $scope);\r
558 \r
559                 wrapperElement.html('');\r
560                 wrapperElement.append($element.prop('outerHTML'));\r
561                 if (navigator.userAgent.match(/MSIE 8/) === null) {\r
562                     wrapperElement.append(selectedDateMessage);\r
563                 }\r
564                 var elm = wrapperElement.prop('outerHTML');\r
565                 elm = $compile(elm)($scope);\r
566                 $element.replaceWith(elm);\r
567             }],\r
568             link: function(scope, elem, attr, ctrl) {\r
569                 if (!ctrl) {\r
570                     // do nothing if no ng-model\r
571                     $log.error("ng-model is required.");\r
572                     return;\r
573                 }\r
574 \r
575                 scope.$watch('current', function(value) {\r
576                     ctrl.$setViewValue(value);\r
577                 });\r
578                 ctrl.$render = function() {\r
579                     scope.current = ctrl.$viewValue;\r
580                 };\r
581               \r
582             }\r
583         };\r
584     }]);\r
585 \r
586     angular.module('ecompApp').directive('jqTreeUserNotif', ['functionalMenuService', '$log', 'confirmBoxService', '$compile', function (functionalMenuService, $log, confirmBoxService, $compile) {\r
587         return {\r
588             scope: true,\r
589             templateUrl: 'jq-tree-tmpl-user-notif.html',\r
590             link: function (scope, el, attrs) {\r
591 \r
592                 var $jqTree = el.find('#jqTreeUserNotif').tree({\r
593                     data: scope.treedata,\r
594                     autoOpen: scope.editModeObj.isEditMode,\r
595                     dragAndDrop: false,\r
596                     onCreateLi: function (node, $li) {\r
597                         node.is_checked = false;\r
598                         if (node.roleId&&scope.roleObj.notificationRoleIds) {\r
599                             node.is_checked = (node.roleId.length === _.intersection(node.roleId, scope.roleObj.notificationRoleIds).length);\r
600                         }                        \r
601                         if (typeof node.id =="string"){\r
602                             $li.attr('id', node.id.replace(/\s+/g, '_'));\r
603                         }\r
604                         var isChecked = '';\r
605                         if (node.is_checked) {\r
606                             isChecked = 'checked="checked"';\r
607                         }\r
608                         if (node.can_check) {\r
609                             var toShow = true;\r
610                             if (scope.notifObj.isCategoriesFunctionalMenu) {\r
611                                 toShow = scope.toShowItemDict[node.menuId];\r
612                             }\r
613                             var isDisabled = "";\r
614                             if (scope.editModeObj.isEditMode) {\r
615                                 isDisabled = " disabled"\r
616                                         \r
617                                         //if node is a parent/grandparent node\r
618                                     if (node.children.length>0){\r
619                                                 //whether to show node first\r
620                                         if (_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {\r
621                                                 toShow=true;\r
622                                                 if (scope.parentChildRoleIdDict[node.menuId].length==_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {\r
623                                                 isChecked = 'checked="checked"';                                                        \r
624                                                 }\r
625                                         } else {\r
626                                                 toShow=false;\r
627                                         }\r
628                                     } \r
629                                     //if node is a child node\r
630                                     else {\r
631                                         if (node.is_checked) {\r
632                                                 toShow=true;                                    \r
633                                         } else {\r
634                                                 toShow=false;\r
635                                         }\r
636                                     }\r
637 \r
638                               }\r
639 \r
640                             \r
641 \r
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+ '/>'\r
643 \r
644                             var templateEl = angular.element(template);\r
645                             var $jqCheckbox = $compile(templateEl)(scope);\r
646                                                         if (toShow){\r
647                                                                         $li.find('.jqtree-element').prepend($jqCheckbox);\r
648                                                                 } else {\r
649                                                                         $li.find('.jqtree-element').remove();\r
650                                                                         }\r
651                         }\r
652                     }\r
653                 });\r
654 \r
655                 scope.thisCheckboxClicked = function (e) {\r
656                 \r
657                         var nodeId = e.target.attributes[4].value;\r
658                         \r
659              \r
660                \r
661                         var sBrowser, sUsrAg = window.navigator.userAgent;\r
662                         //if (sUsrAg.indexOf("Firefox") > -1) {\r
663                         \r
664                         if (sUsrAg.indexOf("Trident") > -1) {\r
665                                 nodeId = e.target.attributes[5].value;\r
666                         }\r
667                     \r
668 //                      if (sUsrAg.indexOf("MSIE") > 1) {\r
669 //                              alert("hELLO tHIS IS IE10");\r
670 //                              nodeId = e.target.attributes[3].value;\r
671 //                              alert('nodeId 26 of IE 45 : '+nodeId);\r
672 //                      }\r
673 //                      \r
674                         var version = navigator.userAgent.match(/Firefox\/(.*)$/);\r
675                         \r
676                         if(version && version.length > 1){\r
677                         if(parseInt(version[1]) >= 50){\r
678                                 nodeId = e.target.attributes[3].value;\r
679                         } else if(parseInt(version[1]) >= 45){\r
680                                 \r
681                                 nodeId = e.target.attributes[2].value;\r
682                         }\r
683                 }\r
684                         var thisNode = el.find('#jqTreeUserNotif').tree('getNodeById', nodeId);\r
685                     var isChecked = e.target.checked;\r
686                     scope.checkboxIdDict[nodeId]['is_box_checked'] = isChecked;\r
687 \r
688                     thisNode = angular.element(thisNode);\r
689                     if (thisNode[0].hasOwnProperty('children') && thisNode[0].children.length > 0) {\r
690                         var jsNodeCheckList = angular.element(e.target).parent().next().find('.js-node-check')\r
691                         // check/uncheck children items\r
692                         jsNodeCheckList.prop('checked', isChecked);\r
693 \r
694                         for (var i in jsNodeCheckList) {\r
695                             var singlediv = jsNodeCheckList[i];\r
696                             if (typeof singlediv == 'object' & (!singlediv.length)) {\r
697                                 \r
698                                 var tempNodeId = angular.element(singlediv)[0].attributes[4].value;\r
699                             \r
700                                 \r
701                                 \r
702                                 if (sUsrAg.indexOf("Trident") > -1) {\r
703                                         \r
704                                         var tempNodeId = angular.element(singlediv)[0].attributes[5].value;\r
705                                         \r
706                                \r
707                                 }\r
708                                 \r
709 //                                if (sUsrAg.indexOf("MSIE") > 0) {\r
710 //                                    var tempNodeId = angular.element(singlediv)[0].attributes[3].value;\r
711 //                                    alert('tempNodeId 2 FF 45 : '+tempNodeId);\r
712 //                                    }\r
713                                 if(version && version.length > 1){\r
714                                         if(parseInt(version[1]) >= 50){\r
715                                                 tempNodeId = angular.element(singlediv)[0].attributes[3].value;\r
716                                         } \r
717                                         else if(parseInt(version[1]) >= 45){\r
718                                                 tempNodeId = angular.element(singlediv)[0].attributes[2].value;\r
719                                         }\r
720                                 }\r
721                                 scope.checkboxIdDict[tempNodeId]['is_box_checked'] = isChecked;\r
722                             }\r
723                         }\r
724                     }\r
725 \r
726                     scope.checkBoxObj.isAnyRoleSelected = false;\r
727                     for (var key in scope.checkboxIdDict) {\r
728                         if (scope.checkboxIdDict[key]['is_box_checked']&&scope.checkboxIdDict[key]['role_id']) {\r
729                             scope.checkBoxObj.isAnyRoleSelected = true;\r
730                             break;\r
731                         }\r
732                     }\r
733                 }\r
734 \r
735 \r
736 \r
737                 scope.$watch('treedata', function (oldValue, newValue) {\r
738                     if (oldValue !== newValue) {\r
739                         $jqTree.tree('loadData', scope.treedata);\r
740                         $jqTree.tree('reload', function () {\r
741                         });\r
742                     }\r
743                 });\r
744             }\r
745         };\r
746     }]);\r
747 })();\r