CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-resmgr / src / main / webapp / resmgr-nfv / js / resmgr.js
1 /* Copyright 2016-2017, Huawei Technologies Co., Ltd.\r
2  *\r
3  * Licensed under the Apache License, Version 2.0 (the "License");\r
4  * you may not use this file except in compliance with the License.\r
5  * You may obtain a copy of the License at\r
6  *\r
7  *    http://www.apache.org/licenses/LICENSE-2.0\r
8  *\r
9  * Unless required by applicable law or agreed to in writing, software\r
10  * distributed under the License is distributed on an "AS IS" BASIS,\r
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12  * See the License for the specific language governing permissions and\r
13  * limitations under the License.\r
14  */\r
15 function hideFirstCol() {\r
16 //      $('table tr').find('th:eq(0)').hide();\r
17 //      $('table tr').find('td:eq(0)').hide();\r
18 }\r
19 function deleteLocation(objectId) {\r
20     var requestUrl = app_url+"/openoapi/resmgr/v1/locations/" + objectId;\r
21     $.ajax({\r
22         type: "DELETE",\r
23         url: requestUrl,\r
24         contentType: "application/json",\r
25         success: function (jsonobj) {\r
26             $('#location_table').bootstrapTable('remove', {\r
27                 field: 'id',\r
28                 values: [objectId]\r
29             });\r
30             bootbox.alert("Delete  successfull !!!");\r
31         },\r
32         error: function (xhr, ajaxOptions, thrownError) {\r
33             bootbox.alert("Error on deleting data: " + xhr.responseText);\r
34         }\r
35     });\r
36 }\r
37 \r
38 function editLocation(row) {\r
39     $('#vmAppDialog').addClass('in').css({\r
40         'display': 'block'\r
41     });\r
42     $('#id').val(row.id);\r
43     $('#country').val(row.country);\r
44     $('#location').val(row.location);\r
45     $('#description').val(row.description);\r
46     $('#latitude').val(row.latitude);\r
47     $('#longitude').val(row.longitude);\r
48 }\r
49 \r
50 function loadLocationData() {\r
51     var requestUrl = app_url+"/openoapi/resmgr/v1/locations";\r
52     $.ajax({\r
53         type: "GET",\r
54         url: requestUrl,\r
55         contentType: "application/json",\r
56         success: function (jsonobj) {\r
57             $('#location_table').bootstrapTable({\r
58                 pageSize: 50,\r
59                 striped: true,\r
60                 data: jsonobj.locations\r
61             });\r
62             $('#location_table').bootstrapTable('refresh');\r
63 \r
64         },\r
65         error: function (xhr, ajaxOptions, thrownError) {\r
66             bootbox.alert("Error on getting site data : " + xhr.responseText);\r
67         }\r
68     });\r
69 \r
70 }\r
71 \r
72 $(function () {\r
73     $("#vmAppForm").validate({\r
74         rules: {\r
75             country: "required",\r
76             location: "required",\r
77             latitude: {\r
78                 required: true,\r
79                 number: true\r
80             },\r
81             longitude: {\r
82                 required: true,\r
83                 number: true\r
84             }\r
85         }\r
86     });\r
87 \r
88     $('.close,.button-previous').click(function () {\r
89         $('#vmAppDialog').removeClass('in').css('display', 'none');\r
90     });\r
91     $('.detail-top ul li').click(function () {\r
92         $(this).addClass('current').siblings().removeClass('current');\r
93     });\r
94     $('.para').click(function () {\r
95         if ($('#serviceTemplateName').val() == '') {\r
96             alert('Please choose the service templet!');\r
97             $('#flavorTab').css('display', 'none');\r
98         } else {\r
99             $('#flavorTab').css('display', 'block');\r
100         }\r
101         $('#basicTab').css('display', 'block');\r
102     });\r
103     $('.basic').click(function () {\r
104         $('#flavorTab').css('display', 'none');\r
105     });\r
106 \r
107     $('.table tbody tr').click(\r
108         function () {\r
109             $(this).addClass('openoTable_row_selected').siblings()\r
110                 .removeClass('openoTable_row_selected');\r
111         });\r
112     $('.table tr:odd').addClass('active');\r
113     $('#false').click(function () {\r
114         $('#vmAppForm')[0].reset();\r
115         $('#vmAppDialog').addClass('in').css({\r
116             'display': 'block'\r
117         });\r
118     });\r
119     $('.close,.button-previous').click(function () {\r
120         $('#vmAppDialog').removeClass('in').css('display', 'none');\r
121     });\r
122     $('#filterTpLogicalType').click(\r
123         function () {\r
124             $('#filterTpLogicalType_select_popupcontainer').toggleClass(\r
125                 'openo-hide');\r
126             $('#filterTpLogicalType').toggleClass('openo-focus');\r
127             var oLeft = $('#open_base_tpL_td6').offset().left;\r
128             var oTop = $('#open_base_tpL_td6').offset().top;\r
129             var oHeight = $('#open_base_tpL_td6').height();\r
130             $('#filterTpLogicalType_select_popupcontainer').css({\r
131                 'left': oLeft,\r
132                 'top': oTop + oHeight + 10\r
133             });\r
134         });\r
135     $('div.openo-select-popup-container>div.openo-select-item>label').click(\r
136         function () {\r
137             var Lvalue = $(this).html();\r
138             $('#filterTpLogicalType_select_input').attr('value', Lvalue);\r
139             $('#filterTpLogicalType_select_popupcontainer').addClass(\r
140                 'openo-hide');\r
141             $('#filterTpLogicalType').removeClass('openo-focus');\r
142         });\r
143     $.fn.serializeObject = function () {\r
144         var o = {};\r
145         var a = this.serializeArray();\r
146         $.each(a, function () {\r
147             if (o[this.name] !== undefined) {\r
148                 if (!o[this.name].push) {\r
149                     o[this.name] = [o[this.name]];\r
150                 }\r
151                 o[this.name].push(this.value || '');\r
152             } else {\r
153                 o[this.name] = this.value || '';\r
154             }\r
155         });\r
156         return o;\r
157     };\r
158     $('#createLocation')\r
159         .click(\r
160             function () {\r
161                 var formData = JSON.stringify($("#vmAppForm").serializeObject());\r
162                 var jsonobj = JSON.parse(formData);\r
163                 var requestUrl = app_url+"/openoapi/resmgr/v1/locations";\r
164                 var requestUrl_query = app_url+"/openoapi/resmgr/v1/locations";\r
165                 if ($('#id').val().length === 0) {//create\r
166 \r
167 \r
168                     $.ajax({\r
169                         type: "POST",\r
170                         url: requestUrl,\r
171                         contentType: "application/json",\r
172                         dataType: "json",\r
173                         data: formData,\r
174                         success: function (jsonResp) {\r
175                             loadLocationData();\r
176                             bootbox.alert(jsonResp.msg);\r
177                             $('#vmAppDialog').removeClass('in').css({\r
178                                 'display': 'none'\r
179                             });\r
180 \r
181                         },\r
182                         error: function (xhr, ajaxOptions, thrownError) {\r
183                             bootbox.alert("Error on page : " + xhr.responseText);\r
184                         }\r
185                     });\r
186                 } else {//put\r
187 \r
188 \r
189                     $.ajax({\r
190                         type: "PUT",\r
191                         url: requestUrl,\r
192                         contentType: "application/json",\r
193                         dataType: "json",\r
194                         data: formData,\r
195                         success: function (jsonResp) {\r
196                             loadLocationData();\r
197                             bootbox.alert(jsonResp.msg);\r
198                             $('#vmAppDialog').removeClass('in').css({\r
199                                 'display': 'none'\r
200                             });\r
201 \r
202                         },\r
203                         error: function (xhr, ajaxOptions, thrownError) {\r
204                             bootbox.alert("Error on page : " + xhr.responseText);\r
205                         }\r
206                     });\r
207                 }\r
208 \r
209             });\r
210 \r
211 \r
212 })