rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / monitor / src / main / webapp / monitor / js / monitorSettingUtil.js
1 /*
2  * Copyright 2016-2017, CMCC Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 var monitorUtil = {};
17
18 monitorUtil.growl=function(message,type){
19         var delay;
20           if(type=="success"){
21                 delay=3000;
22           }
23           else{
24                 delay=0;
25           }
26
27       $.growl({
28                 icon: "fa fa-envelope-o fa-lg",
29                 title: "  "+$.i18n.prop('com_zte_openo_umc_monitor_tip')+"  ",
30                 message: message+"        "
31                         },{
32                                 type: type,
33                                 delay:delay
34                         });
35 }
36
37
38 $.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings) {
39     return {
40         "iEnd": oSettings.fnDisplayEnd(),
41         "iLength": oSettings._iDisplayLength,
42         "iTotal": oSettings.fnRecordsTotal(),
43         "iFilteredTotal": oSettings.fnRecordsDisplay(),
44         "iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
45         "iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
46     };
47 };
48
49 $.extend($.fn.dataTableExt.oPagination, {
50     "bootstrap_extended": {
51         "fnInit": function (oSettings, nPaging, fnDraw) {
52             var oLang = oSettings.oLanguage.oPaginate;
53             var oPaging = oSettings.oInstance.fnPagingInfo();
54
55             var fnClickHandler = function (e) {
56                 e.preventDefault();
57                 if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
58                     fnDraw(oSettings);
59                 }
60             };
61
62             $(nPaging).append(
63                 '<div class="pagination-panel"> ' + oLang.sPage + ' ' +
64                 '<a href="#" class="btn btn-sm default prev disabled" title="' + oLang.sPrevious + '"><i class="fa fa-angle-left"></i></a>' +
65                 '<input type="text" class="pagination-panel-input input-mini input-inline input-sm" maxlenght="5" style="text-align:center; margin: 0 4px; border: 1px solid rgb(169, 169, 169);height: 28px;">' +
66                 '<a href="#" class="btn btn-sm default next disabled" title="' + oLang.sNext + '"><i class="fa fa-angle-right"></i></a> ' +
67                 oLang.sPageOf + ' <span class="pagination-panel-total"></span>' +
68                 '</div>'
69             );
70
71             var els = $('a', nPaging);
72
73             $(els[0]).bind('click.DT', {action: "previous"}, fnClickHandler);
74             $(els[1]).bind('click.DT', {action: "next"}, fnClickHandler);
75
76             $('.pagination-panel-input', nPaging).bind('change.DT', function (e) {
77                 var oPaging = oSettings.oInstance.fnPagingInfo();
78                 e.preventDefault();
79                 var page = parseInt($(this).val());
80                 if (page > 0 && page < oPaging.iTotalPages) {
81                     if (oSettings.oApi._fnPageChange(oSettings, page - 1)) {
82                         fnDraw(oSettings);
83                     }
84                 } else {
85                     $(this).val(oPaging.iPage + 1);
86                 }
87             });
88
89             $('.pagination-panel-input', nPaging).bind('keypress.DT', function (e) {
90                 var oPaging = oSettings.oInstance.fnPagingInfo();
91                 if (e.which == 13) {
92                     var page = parseInt($(this).val());
93                     if (page > 0 && page < oSettings.oInstance.fnPagingInfo().iTotalPages) {
94                         if (oSettings.oApi._fnPageChange(oSettings, page - 1)) {
95                             fnDraw(oSettings);
96                         }
97                     } else {
98                         $(this).val(oPaging.iPage + 1);
99                     }
100                     e.preventDefault();
101                 }
102             });
103         },
104
105         "fnUpdate": function (oSettings, fnDraw) {
106             var iListLength = 5;
107             var oPaging = oSettings.oInstance.fnPagingInfo();
108             var an = oSettings.aanFeatures.p;
109             var i, j, sClass, iStart, iEnd, iHalf = Math.floor(iListLength / 2);
110
111             if (oPaging.iTotalPages < iListLength) {
112                 iStart = 1;
113                 iEnd = oPaging.iTotalPages;
114             }
115             else if (oPaging.iPage <= iHalf) {
116                 iStart = 1;
117                 iEnd = iListLength;
118             } else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
119                 iStart = oPaging.iTotalPages - iListLength + 1;
120                 iEnd = oPaging.iTotalPages;
121             } else {
122                 iStart = oPaging.iPage - iHalf + 1;
123                 iEnd = iStart + iListLength - 1;
124             }
125
126
127             for (i = 0, iLen = an.length; i < iLen; i++) {
128                 var wrapper = $(an[i]).parents(".dataTables_wrapper");
129
130                 if (oPaging.iTotalPages <= 0) {
131                     $('.pagination-panel, .dataTables_length', wrapper).hide();
132                 } else {
133                     $('.pagination-panel, .dataTables_length', wrapper).show();
134                 }
135
136                 $('.pagination-panel-total', an[i]).html(oPaging.iTotalPages);
137                 $('.pagination-panel-input', an[i]).val(oPaging.iPage + 1);
138
139                 // Remove the middle elements
140                 $('li:gt(1)', an[i]).filter(':not(.next)').remove();
141
142                 // Add the new list items and their event handlers
143                 for (j = iStart; j <= iEnd; j++) {
144                     sClass = (j == oPaging.iPage + 1) ? 'class="active"' : '';
145                     $('<li ' + sClass + '><a href="#">' + j + '</a></li>')
146                         .insertBefore($('li.next:first', an[i])[0])
147                         .bind('click', function (e) {
148                             e.preventDefault();
149                             oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
150                             fnDraw(oSettings);
151                         });
152                 }
153
154                 // Add / remove disabled classes from the static elements
155                 if (oPaging.iPage === 0) {
156                     $('a.prev', an[i]).addClass('disabled');
157                 } else {
158                     $('a.prev', an[i]).removeClass('disabled');
159                 }
160
161                 if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
162                     $('a.next', an[i]).addClass('disabled');
163                 } else {
164                     $('a.next', an[i]).removeClass('disabled');
165                 }
166             }
167         }
168     }
169 });