rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / lifecyclemgr / src / main / webapp / lifecyclemgr / js / rest.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
16 var url = "";
17 $(function () {
18
19     $.getJSON("./conf/dataconfig.json", function (jsonData){
20         url = jsonData.url +":"+ jsonData.port;
21         console.log("URL = " + url);
22     });
23
24     $('.creat-btn').click(function () {
25         /*$('#vmAppDialog').addClass('in').css({'display': 'block'});*/
26         $('#vmAppDialog').modal();
27
28     });
29     $('.close,.button-previous').click(function () {
30         $('#vmAppDialog').removeClass('in').css('display', 'none');
31     });
32     $('.detail-top ul li').click(function () {
33         $(this).addClass('current').siblings().removeClass('current');
34     });
35     $('.para').click(function () {
36         if ($('#serviceTemplateName').val() == '') {
37             alert('Please choose the service templateļ¼');
38             $('#flavorTab').css('display', 'none');
39         } else {
40             $('#flavorTab').css('display', 'block');
41         }
42         $('#basicTab').css('display', 'block');
43     });
44     $('.basic').click(function () {
45         $('#flavorTab').css('display', 'none');
46     });
47 /*
48     $('.table tbody tr').click(function(){
49         $(this).addClass('openoTable_row_selected').siblings().removeClass('openoTable_row_selected');
50     });*/
51     $('.table tr:odd').addClass('active');
52     $('#false').click(function () {
53         /*$('#vmAppDialog').addClass('in').css({'display': 'block'});*/
54     $('#vmAppDialog').modal();
55     });
56     $('.close,.button-previous').click(function () {
57         $('#vmAppDialog').removeClass('in').css('display', 'none');
58     });
59     $('#filterTpLogicalType').click(function () {
60         $('#filterTpLogicalType_select_popupcontainer').toggleClass('openo-hide');
61         $('#filterTpLogicalType').toggleClass('openo-focus');
62         var oLeft = $('#open_base_tpL_td6').offset().left;
63         var oTop = $('#open_base_tpL_td6').offset().top;
64         var oHeight = $('#open_base_tpL_td6').height();
65         $('#filterTpLogicalType_select_popupcontainer').css({'left': oLeft, 'top': oTop + oHeight + 10});
66     });
67     $('div.openo-select-popup-container>div.openo-select-item>label').click(function () {
68         var Lvalue = $(this).html();
69         $('#filterTpLogicalType_select_input').attr('value', Lvalue);
70         $('#filterTpLogicalType_select_popupcontainer').addClass('openo-hide');
71         $('#filterTpLogicalType').removeClass('openo-focus');
72     });
73     $.fn.serializeObject = function () {
74         var o = {};
75         var a = this.serializeArray();
76         $.each(a, function () {
77             if (o[this.name] !== undefined) {
78                 if (!o[this.name].push) {
79                     o[this.name] = [o[this.name]];
80                 }
81                 o[this.name].push(this.value || '');
82             } else {
83                 o[this.name] = this.value || '';
84             }
85         });
86         return o;
87     };
88     /*
89     $('#createNS').click(function(){
90         var formData = JSON.stringify($("#neForm").serializeObject());
91         var jsonobj = JSON.parse(formData);
92         var newJson = {"managedElement": jsonobj};
93         formData = JSON.stringify(newJson);
94         var requestUrl = url + "/openoapi/sdnobrs/v1/managed-elements";
95         $
96             .ajax({
97                 type : "POST",
98                 url : requestUrl,
99                 contentType : "application/json",
100                 dataType : "json",
101                 data : formData,
102                 success : function(jsonResp) {
103                     alert("NS saved successfully!!!");
104                     jsonobj["id"]= jsonResp.managedElement.id;
105                     $('#ne').bootstrapTable("append", jsonobj);
106                     $('#vmAppDialog').removeClass('in').css('display','none');
107
108                 },
109                 error : function(xhr, ajaxOptions, thrownError) {
110                     alert("Error on page : " + xhr.responseText);
111                 }
112             });
113     });*/
114     //init the templates combo
115     $.when(
116             generateTemplatesComponent()
117         ).then(
118             function (templates) {
119                 document.getElementById("svcTempl").innerHTML = templates;
120             }
121         );
122 })
123
124 /**
125  * generate the templates Component
126  * @returns
127  */
128 function generateTemplatesComponent(){
129     var defer = $.Deferred();
130     $.when(
131             queryTemplates()
132         ).then(
133             function (tmplatesResponse) {
134                 var templatesInfo = translateToTemplatesInfo(tmplatesResponse);
135                 defer.resolve(templatesInfo);
136             }
137         )
138     return defer;
139 }
140
141 /**
142  * query templates
143  * @returns
144  */
145 function queryTemplates() {
146     var queryTemplatesUrl = '/openoapi/catalog/v1/servicetemplates';
147     return $.ajax({
148         type : "GET",
149         url : queryTemplatesUrl
150     });
151 }
152
153 /**
154  * generate templates html string
155  * @param templates
156  * @returns
157  */
158 function translateToTemplatesInfo(templates) {
159     var options = '<option value="select">--select--</option>';
160     var i;
161     for (i = 0; i < templates.length; i += 1) {
162         var option = '<option value="' + templates[i].serviceTemplateId + '">' + templates[i].templateName
163                 + '</option>';
164         options = options + option;
165     }
166     return options;
167 }
168
169 /*******************************************Get Service**********************************************/
170 function loadGetServiceData(){
171
172     var returnVal = [];
173     var requestUrl = "/openoapi/inventory/v1/services";
174     var parameter = {
175             'sort': [],
176             'pagination': 0,
177             'pagesize': 10000,
178             'condition': {},
179             'serviceId': ""
180         };
181     $
182         .ajax({
183             type : "POST",
184             url : requestUrl,
185             async: false,
186             contentType : "application/json",
187             dataType: "json",
188             data: JSON.stringify(parameter),
189             success : function(jsonobj) {
190                 // TODO return according to the json data received.
191                 returnVal =  jsonobj;
192             },
193             error : function(xhr, ajaxOptions, thrownError) {
194                 alert("Error on getting link data : " + xhr.responseText);
195             }
196         });
197     return returnVal;
198 }
199
200 /*********************************************Get Service Details********************************************/
201 function loadServiceDetails(serviceId){
202    
203    // TODO re-confirm the latest url.
204     var requestUrl ="/openoapi/gso/v1/services/toposequence/" + serviceId;
205     var returnObj;
206     $
207         .ajax({
208             type : "GET",
209             async: false,
210             url : requestUrl,
211             contentType : "application/json",
212             success : function(jsonobj) {
213                 // TODO return according to the json data received.
214                 returnObj = jsonobj;
215             },
216             error : function(xhr, ajaxOptions, thrownError) {
217                 alert("Error on getting link data : " + xhr.responseText);
218             }
219         });
220     return returnObj;
221 }
222
223
224 function anchorClick(serviceId){
225     var jsonData = loadServiceDetails(serviceId);
226     //TODO populate the modal according to json response
227     return true;
228 }