2 * Copyright 2016-2017 ZTE Corporation.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
16 var commonUtil = {};
\r
17 commonUtil.arrayRemove = function( aryInstance , index ){
\r
18 if(aryInstance == undefined || aryInstance == null){
\r
21 for(var i=0,n=0;i<aryInstance.length;i++) {
\r
22 if(aryInstance[i]!=aryInstance[dx]) {
\r
23 aryInstance[n++]=aryInstance[i];
\r
26 aryInstance.length-=1;
\r
29 //For the expansion of the Date, convert the Date to specify the format String
\r
31 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
\r
32 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
\r
33 commonUtil.parseDate = function( dateObj , format){
\r
35 "M+" : dateObj.getMonth()+1, //month
\r
36 "d+" : dateObj.getDate(), //day
\r
37 "h+" : dateObj.getHours(), //hour
\r
38 "m+" : dateObj.getMinutes(), //minute
\r
39 "s+" : dateObj.getSeconds(), //second
\r
40 "q+" : Math.floor((dateObj.getMonth()+3)/3), //quarter
\r
41 "S" : dateObj.getMilliseconds() //millisecond
\r
43 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
\r
44 (dateObj.getFullYear()+"").substr(4 - RegExp.$1.length));
\r
46 if(new RegExp("("+ k +")").test(format))
\r
47 format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] :
\r
48 ("00"+ o[k]).substr((""+ o[k]).length));
\r
53 commonUtil.showMessage = function(message, type) {
\r
55 icon: "fa fa-envelope-o fa-lg",
\r
56 title: " " + $.i18n.prop("nfv-nso-iui-common-tip"),
\r
63 commonUtil.registerCometdMessage = function(url, channel, callback) {
\r
64 var cometd = new $.Cometd();
\r
65 var cometdURL = location.protocol + "//" + location.host + url;
\r
70 // unregister websocket transport, use long-polling transport
\r
71 cometd.unregisterTransport('websocket');
\r
72 // store channel object parameters(this object include channel and callback function), start from arguments[1]
\r
73 var _args = arguments;
\r
75 cometd.addListener("/meta/handshake", function(handshake){
\r
76 if(handshake.successful === true) {
\r
77 cometd.batch(function() {
\r
79 cometd.subscribe(channel, function(message){
\r
80 callback.call(this, message.data);
\r
88 commonUtil.format = function() {
\r
89 if(arguments.length == 0) {
\r
92 var str = arguments[0];
\r
93 for(var i=0; i<arguments.length; i++) {
\r
94 var reg = new RegExp("\\{" + (i - 1) + "\\}" , "gm");
\r
95 str = str.replace(reg, arguments[i]);
\r
100 commonUtil.get = function(url, params, callback) {
\r
104 //contentType : contentType || "application/x-www-form-urlencoded; charset=UTF-8",
\r
106 data : params || {},
\r
111 commonUtil.post = function(url, params, callback, contentType) {
\r
115 contentType : contentType || "application/x-www-form-urlencoded; charset=UTF-8",
\r
116 data : params || {},
\r
121 commonUtil.delete = function(url, callback, contentType) {
\r
125 contentType : contentType || "application/x-www-form-urlencoded; charset=UTF-8",
\r