rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / performance / src / main / webapp / performance / js / commonUtil.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 commonUtil = {};
17
18 commonUtil.sendSynRequest = function(url){
19         var response;
20         $.ajax({
21                 "type": 'get',
22                 "url": url,
23                 "dataType": "json",
24                 "async": false,
25                 success: function (resp) {
26                         response = resp;
27                          return response;
28                 },
29                 error: function(XMLHttpRequest, textStatus, errorThrown){
30                 }
31         });
32 };
33
34 commonUtil.strToJson = function(str){
35         var json = eval('(' + str + ')');
36         return json;
37 };
38
39 commonUtil.arrayRemove = function(aryInstance, index){
40         if (aryInstance == undefined || aryInstance == null) {
41                 return;
42         }
43         for (var i = 0, n = 0; i < aryInstance.length; i++) {
44                 if (aryInstance[i] != aryInstance[dx]) {
45                         aryInstance[n++] = aryInstance[i];
46                 }
47         }
48         aryInstance.length -= 1;
49 };
50
51 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
52 // (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
53 commonUtil.parseDate = function(dateObj, format){
54         var o = {
55                 "M+": dateObj.getMonth() + 1,
56                 "d+": dateObj.getDate(),
57                 "h+": dateObj.getHours(),
58                 "m+": dateObj.getMinutes(),
59                 "s+": dateObj.getSeconds(),
60                 "q+": Math.floor((dateObj.getMonth() + 3) / 3),
61                 "S": dateObj.getMilliseconds()
62         }
63         if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
64                 (dateObj.getFullYear() + "").substr(4 - RegExp.$1.length));
65         for (var k in o)
66                 if (new RegExp("(" + k + ")").test(format))
67                         format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] :
68                                 ("00" + o[k]).substr(("" + o[k]).length));
69         return format;
70 };
71
72 commonUtil.strToJson = function(str){
73         var json = eval('(' + str + ')');
74         return json;
75 };