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