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