CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-common / src / main / webapp / common / js / fm_light.js
1 /*\r
2  * Copyright 2016-2017, CMCC Technologies Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *         http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 (function($) {\r
17     String.prototype.trim = function() { \r
18                 return this.replace(/(^\s*)|(\s*$)/g, ""); \r
19         };\r
20         String.prototype.format=function() {  \r
21                 if(arguments.length==0) return this;  \r
22                         for(var s=this, i=0; i<arguments.length; i++)  \r
23                         s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);  \r
24                 return s;  \r
25    };  \r
26    //告警计数点击事件\r
27         $(function(){\r
28                    $("#hd_alarmcount_critical_value").parentsUntil('a').parent().click(function() {\r
29                               openNewPage(1);\r
30                                 });\r
31 \r
32                    $("#hd_alarmcount_major_value").parentsUntil('a').parent().click(function() {\r
33                               openNewPage(2);\r
34                                 });\r
35 \r
36                    $("#hd_alarmcount_minor_value").parentsUntil('a').parent().click(function() {\r
37                               openNewPage(3);\r
38                                 });\r
39 \r
40                    $("#hd_alarmcount_warning_value").parentsUntil('a').parent().click(function() {\r
41                               openNewPage(4);\r
42                                 });\r
43                    function openNewPage(severity)\r
44                    {\r
45                            window.open("default.html?showNav=false&severity=" + severity + "#_uep-ict-fm-currentAlarm",\r
46                                      "fm_portlet_page_title");\r
47                    }\r
48                 });     \r
49     try{\r
50           //base版本不加载告警统计,并在界面隐藏\r
51     $().ready(function(){\r
52                 if(typeof(base) == "undefined" || !base){\r
53                          if($("#header_notification_bar")&&$("#header_notification_bar").length>0&&$("#header_notification_bar").children().length>0){\r
54                                 // å¯¹å\91\8aè­¦ç\81¯è¿\9bè¡\8cé\89´æ\9d\83ï¼\8cå¦\82æ\9e\9cæ\9c\89å½\93å\89\8då\91\8aè­¦æ\9d\83é\99\90ï¼\8cæ\98¾ç¤ºå\91\8aè­¦ç\81¯ï¼\8cå\90¦å\88\99è¿\94å\9b\9eã\80?\r
55                                 var operations = new Array();\r
56                                 operations.push("common.fm.currentview");               \r
57                                 var rightObj = getAllOperCodeRights(operations);\r
58                                 var operation = $("#uep-ict-fm-currentAlarm").attr("operation");;\r
59                                 if (!hasRight(operation, rightObj)) {\r
60                                         $('#header_notification_bar').html("<div>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</div>");\r
61                                         return;\r
62                                 }\r
63                                 // get total alarm count\r
64                                 $("#hd_heighestAlarmcount_label").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_none_label'));\r
65                                 $("#hd_alarmcount_total_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_total_label'));\r
66                                 $("#hd_alarmcount_critical_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_critical_label'));\r
67                                 $("#hd_alarmcount_major_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_major_label'));\r
68                                 $("#hd_alarmcount_minor_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_minor_label'));\r
69                                 $("#hd_alarmcount_warning_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_warning_label'));\r
70                         \r
71                                 function alarmLight(alarmcount){\r
72                                     if (!alarmcount || !alarmcount.unAckedCount || (alarmcount.unAckedCount.length < 4) || !alarmcount.ackedCount || (alarmcount.ackedCount.length < 4)) {\r
73                                                 return;\r
74                                         }\r
75                                         var criticalNum = alarmcount.unAckedCount[0] + alarmcount.ackedCount[0];\r
76                                         var majorNum = alarmcount.unAckedCount[1] + alarmcount.ackedCount[1];\r
77                                         var minorNum = alarmcount.unAckedCount[2] + alarmcount.ackedCount[2];\r
78                                         var warningNum = alarmcount.unAckedCount[3] + alarmcount.ackedCount[3];\r
79                                         var totalNum= criticalNum+ majorNum+  minorNum+  warningNum;\r
80                                         var heighestAlarmcount=0;\r
81                                         var hd_heighestAlarmcount_label="";\r
82                                         if(criticalNum>0){\r
83                                                 heighestAlarmcount =criticalNum;\r
84                                                 hd_heighestAlarmcount_label=$.i18n.prop('com_zte_ums_ict_alarmcount_critical_label');\r
85                                                 // $("#hd_heighestAlarmcount_li").attr("class",$("#hd_alarmcount_critical_li").attr("class"));\r
86                                         }else if(majorNum>0){\r
87                                                 heighestAlarmcount =majorNum;\r
88                                                 hd_heighestAlarmcount_label=$.i18n.prop('com_zte_ums_ict_alarmcount_major_label');\r
89                                         }else if(minorNum>0){\r
90                                                 heighestAlarmcount =minorNum;\r
91                                                 hd_heighestAlarmcount_label=$.i18n.prop('com_zte_ums_ict_alarmcount_minor_label');\r
92                                         }else if(warningNum>0){\r
93                                                 heighestAlarmcount =warningNum;\r
94                                                 hd_heighestAlarmcount_label=$.i18n.prop('com_zte_ums_ict_alarmcount_warning_label');\r
95                                         }else{\r
96                                                 heighestAlarmcount =0;\r
97                                                 hd_heighestAlarmcount_label=$.i18n.prop('com_zte_ums_ict_alarmcount_none_label');\r
98                                         }\r
99                                                  \r
100                                                 $("#hd_heighestAlarmcount_value").text(heighestAlarmcount);\r
101                                                 $("#hd_alarmcount_total_value").text(totalNum);\r
102                                                 $("#hd_alarmcount_critical_value").text(criticalNum);\r
103                                                 $("#hd_alarmcount_major_value").text(majorNum);\r
104                                                 $("#hd_alarmcount_minor_value").text(minorNum);\r
105                                                 $("#hd_alarmcount_warning_value").text(warningNum);\r
106 \r
107                                                 $("#hd_heighestAlarmcount_value").attr("title",hd_heighestAlarmcount_label.format(heighestAlarmcount ));  \r
108                                           $("#hd_alarmcount_total_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_total_label').format(totalNum ));                                                                        \r
109                                           $("#hd_alarmcount_critical_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_critical_label').format( criticalNum ));\r
110                                                 $("#hd_alarmcount_major_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_major_label').format(majorNum));\r
111                                                 $("#hd_alarmcount_minor_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_minor_label').format(minorNum));\r
112                                                 $("#hd_alarmcount_warning_value").attr("title",$.i18n.prop('com_zte_ums_ict_alarmcount_warning_label').format(warningNum));\r
113                                 \r
114                                                 $("#hd_alarmcount_critical_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_critical_text'));\r
115                                                 $("#hd_alarmcount_major_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_major_text'));\r
116                                                 $("#hd_alarmcount_minor_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_minor_text'));\r
117                                                 $("#hd_alarmcount_warning_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_warning_text'));\r
118                                         \r
119                                                 $("#hd_alarmcount_total_before_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_total_before_text'));\r
120                                                 $("#hd_alarmcount_total_after_text").text($.i18n.prop('com_zte_ums_ict_alarmcount_total_after_text'));\r
121                                                 $("#header_notification_bar").css('display','block');\r
122                                 }\r
123                                 function queryAlarmTotalCount() {\r
124                                         $.getJSON("/web/rest/web/fm/count/total", function(data) {\r
125                                                 //var alarmcount = $.parseJSON(data);\r
126                                                 alarmLight(data);\r
127                                                 if($("#header_notification_bar")&&$("#header_notification_bar").length>0&&$("#header_notification_bar").children().length>0){\r
128                                                         registerAlarmTotalCountToCometd();\r
129                                                 }\r
130                                         })\r
131                                 }\r
132                                 if($("#header_notification_bar")&&$("#header_notification_bar").length>0&&$("#header_notification_bar").children().length>0){\r
133                                         queryAlarmTotalCount();\r
134                                 }\r
135                                 var registerAlarmTotalCountToCometd = function () {\r
136                                         var self = this;\r
137                                         var cometd = $.cometd;\r
138                                         var cometURL = location.protocol + "//" + location.host + "/web/cometd";\r
139                                         cometd.configure({\r
140                                         url: cometURL,\r
141                                         logLevel: 'debug'\r
142                                         });\r
143                                         cometd.addListener('/meta/handshake', function (handshake){             \r
144                                                 if (handshake.successful === true) {\r
145                                                         cometd.batch(function () {                       \r
146                                                                 cometd.subscribe('/alarm/usercount', function (message) {\r
147                                                                 var alarmcount =message.data;\r
148                                                                 alarmLight(alarmcount);                                                  \r
149                                                                 })\r
150                                                         })\r
151                                                 }\r
152                                         });\r
153                                         cometd.handshake();\r
154                                 };\r
155                                         \r
156                                 // if($("#header_notification_bar")&&$("#header_notification_bar").length>0&&$("#header_notification_bar").children().length>0){\r
157                                         // registerAlarmTotalCountToCometd();\r
158                                 // }\r
159                                 //setInterval(queryAlarmTotalCount, 30 * 1000);         \r
160                         }\r
161                 }\r
162                 else if(base){\r
163                         //$("#header_notification_bar").hide();\r
164                         //$('#header_notification_bar').empty();\r
165                         $('#header_notification_bar').html("<div>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</div>");\r
166                 }\r
167     });\r
168     }catch(e){} \r
169 })(jQuery); \r