2 * Copyright 2016-2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 $id: "vnfmController",
21 //mocSelectItems : [],
27 $RTN_SUCCESS: "RTN_SUCCESS",
28 $RTN_FAILED: "RTN_FAILED"
35 queryVnfmInfoUrl: '/openoapi/extsys/v1/vnfms',
36 addVnfmInfoUrl: '/openoapi/extsys/v1/vnfms',
37 updateVnfmInfoUrl: '/openoapi/extsys/v1/vnfms/',
38 delVnfmInfoUrl: '/openoapi/extsys/v1/vnfms/',
40 queryVimUrl: '/openoapi/extsys/v1/vims'
43 saveSuccess: $.i18n.prop("nfv-vnfm-iui-message-save-success"),
44 saveFail: $.i18n.prop("nfv-vnfm-iui-message-save-fail"),
45 alreadyExist: $.i18n.prop("nfv-vnfm-iui-message-vnfm-already-exists"),
46 updateSuccess: $.i18n.prop("nfv-vnfm-iui-message-update-success"),
47 updateFail: $.i18n.prop("nfv-vnfm-iui-message-update-fail")
49 $initTable: function () {
52 "url": vm.$restUrl.queryVnfmInfoUrl,
54 "success": function (resp) {
55 for (var i = 0; i < resp.length; i++) {
56 resp[i].status = vm.$Status.success;
60 error: function (XMLHttpRequest, textStatus, errorThrown) {
61 bootbox.alert($.i18n.prop("nfv-vnfm-iui-message-query-fail") + ":" + textStatus + ":" + errorThrown);
64 complete: function () {
65 vnfmUtil.tooltipVnfmStatus();
69 // $initMoc : function() {
70 // /*var url = vm.$restUrl.queryMocUrl;
71 // commonUtil.get(url, null, function(resp) {
73 // vm.addVnfm.moc = resp.data;
77 // { id : "nfv.vnfm.eco", name : "VNFM(ECO)"},
78 // { id : "nfv.vnfm.tacker", name : "VNFM(Tacker)"},
79 // { id : "nfv.vnfm.cmcc", name : "VNFM(CMCC)"},
80 // { id : "nfv.vnfm.etsi", name : "VNFM(ETSI)"}
82 // vm.mocSelectItems = resp;
84 $initVim: function () {
87 url: vm.$restUrl.queryVimUrl,
89 success: function (resp) {
91 vm.vimSelectItems = resp;
93 vm.vimSelectItems.push({"vimId": "", "name": ""});
98 title: $.i18n.prop("nfv-vnfm-iui-text-register"),
103 nameReadonly : false,
105 //vimVisiable : false,
111 urlTip: $.i18n.prop("nfv-vnfm-iui-text-url-tip"),
117 $showVnfmTable: function () {
118 vm.addVnfm.title = $.i18n.prop("nfv-vnfm-iui-text-register"),
119 vm.addVnfm.vnfmId = "";
120 vm.addVnfm.name = "";
121 vm.addVnfm.type = "";
122 //vm.addVnfm.moc = "";
123 vm.addVnfm.nameReadonly = false;
124 vm.addVnfm.vimId = "";
125 //vm.addVnfm.vimVisiable = false;
126 vm.addVnfm.vendor = "";
127 vm.addVnfm.version = "";
128 vm.addVnfm.description = "";
129 vm.addVnfm.certificateUrl = "";
131 vm.addVnfm.userName = "";
132 vm.addVnfm.password = "";
133 vm.addVnfm.saveType = "add";
134 vm.server_rtn.warning_block = false;
135 vm.server_rtn.info_block = false;
140 $(".form-group").each(function () {
141 $(this).removeClass('has-success');
142 $(this).removeClass('has-error');
143 $(this).find(".help-block[id]").remove();
145 $("#addVnfmDlg").modal("show");
147 // $getMocName : function(mocId) {
148 // var items = vm.mocSelectItems;
149 // for(var i=0;i<items.length;i++) {
150 // if(items[i].id == mocId) {
151 // return items[i].name;
156 $saveVnfm: function () {
157 var form = $('#vnfm_form');
158 if (form.valid() == false) {
161 vm.server_rtn.info_block = true;
162 vm.server_rtn.warning_block = false;
163 vm.addVnfm.status = vm.$Status.success;
166 name: vm.addVnfm.name,
167 //status : vm.addVnfm.status,
168 //moc : $("#moc").val(),
169 //vimId : vm.$getVimId($("#moc").val()),
170 vimId: $("#vimId").val(),
171 vendor: vm.addVnfm.vendor,
172 version: vm.addVnfm.version,
173 type: vm.addVnfm.type,
174 description: vm.addVnfm.description,
175 certificateUrl: vm.addVnfm.certificateUrl,
177 userName: vm.addVnfm.userName,
178 password: vm.addVnfm.password
181 if (vm.addVnfm.saveType == "add") {
182 // for( var i = 0; i < vm.vnfmInfo.length; i ++ ){
183 // if(vm.addVnfm.name == vm.vnfmInfo[i].name){
184 // vm.server_rtn.warning_block = true;
185 // vm.server_rtn.rtn_info = vm.$htmlText.alreadyExist;
186 // commonUtil.showMessage(vm.$htmlText.alreadyExist, "failed");
192 url: vm.$restUrl.addVnfmInfoUrl,
193 data: JSON.stringify(param),
195 contentType: "application/json",
196 success: function (data) {
197 vm.server_rtn.info_block = false;
198 vm.server_rtn.warning_block = false;
203 $('#addVnfmDlg').modal('hide');
204 commonUtil.showMessage(vm.$htmlText.saveSuccess, "success");
206 vm.server_rtn.warning_block = true;
207 vm.server_rtn.rtn_info = vm.$htmlText.saveFail;
208 commonUtil.showMessage(vm.$htmlText.saveFail, "failed");
211 error: function (XMLHttpRequest, textStatus, errorThrown) {
212 vm.server_rtn.warning_block = true;
213 vm.server_rtn.rtn_info = textStatus + ":" + errorThrown;
214 vm.server_rtn.info_block = false;
220 url: vm.$restUrl.updateVnfmInfoUrl + vm.addVnfm.vnfmId,
221 data: JSON.stringify(param),
223 contentType: "application/json",
224 success: function (data) {
225 vm.server_rtn.info_block = false;
226 vm.server_rtn.warning_block = false;
228 for (var i = 0; i < vm.vnfmInfo.length; i++) {
229 if (vm.vnfmInfo[i].vnfmId == vm.addVnfm.vnfmId) {
230 vm.vnfmInfo[i].name = vm.addVnfm.name;
231 vm.vnfmInfo[i].vimId = $("#vimId").val();
232 vm.vnfmInfo[i].vendor = vm.addVnfm.vendor;
233 vm.vnfmInfo[i].version = vm.addVnfm.version;
234 vm.vnfmInfo[i].certificateUrl = vm.addVnfm.certificateUrl;
235 vm.vnfmInfo[i].description = vm.addVnfm.description;
236 vm.vnfmInfo[i].url = vm.addVnfm.url;
237 vm.vnfmInfo[i].userName = vm.addVnfm.userName;
238 vm.vnfmInfo[i].password = vm.addVnfm.password;
241 $('#addVnfmDlg').modal('hide');
242 commonUtil.showMessage(vm.$htmlText.updateSuccess, "success");
244 vm.server_rtn.warning_block = true;
245 vm.server_rtn.rtn_info = vm.$htmlText.updateFail;
246 commonUtil.showMessage(vm.$htmlText.updateFail, "failed");
249 error: function (XMLHttpRequest, textStatus, errorThrown) {
250 vm.server_rtn.warning_block = true;
251 vm.server_rtn.rtn_info = textStatus + ":" + errorThrown;
252 vm.server_rtn.info_block = false;
257 // mocRendered : function(action) {
258 // if(vm.addVnfm.saveType === "update" && vm.addVnfm.moc) {
259 // var items = vm.mocSelectItems;
260 // for(var i=0;i<items.length;i++) {
261 // if(items[i].id == vm.addVnfm.moc) {
262 // $("#moc")[0].selectedIndex = i;
268 // $("#moc")[0].selectedIndex = 0;
271 vimRendered: function (action) {
272 var items = vm.vimSelectItems;
273 if (vm.addVnfm.saveType === "update") {
274 for (var i = 0; i < items.length; i++) {
275 if (items[i].vimId == vm.addVnfm.vimId) {
276 $("#vimId")[0].selectedIndex = i;
281 $("#vimId")[0].selectedIndex = items.length - 1;
284 // $mocChange : function() {
285 // var mocId = $('#moc').val();
286 // if(mocId == "nfv.vnfm.tacker") {
287 // vm.addVnfm.vimVisiable = true;
289 // vm.addVnfm.vimVisiable = false;
292 // $getVimId : function(mocId) {
293 // if(vm.addVnfm.vimVisiable) {
294 // return $("#vimId").val();