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