/* * Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var vm = avalon .define({ $id : "vimController", vimInfo : [], //vimStatusTime:$.i18n.prop('com_zte_ums_eco_roc_vim_getting_info'), // ifSearch : 0, // server_rtn:{ // info_block:false, // warning_block:false, // rtn_info:"", // $RTN_SUCCESS:"RTN_SUCCESS", // $RTN_FAILED:"RTN_FAILED", // wait : $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status') // }, executeWait : {clazz : 'alert-info', visible : true, text : $.i18n.prop('com_zte_ums_eco_roc_vim_checking_status')}, executeError : {clazz : 'alert-danger', visible : true, text : 'error'}, $Status :{ success:"active", failed:"inactive", displayActive: $.i18n.prop('com_zte_ums_eco_roc_vim_normal'), displayInactive: $.i18n.prop('com_zte_ums_eco_roc_vim_abnormal') }, isSave : true, action : {ADD : 'add', UPDATE : 'update'}, $queryVimInfoUrl : '../../openoapi/extsys/v1/vims', $addVimInfoUrl : '../../openoapi/extsys/v1/vims/', $updateVimInfoUrl : '../../openoapi/extsys/v1/vims/', $delVimInfoUrl : '../../openoapi/extsys/v1/vims/{vim_id}', $initTable : function() { $.ajax({ "type": 'get', "url": vm.$queryVimInfoUrl, //"dataType": "json", "success": function (resp,statusText,jqXHR) { if(jqXHR.status=="200") { vm.vimInfo = resp; } else{ vm.vimInfo=[]; bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed")); return; } }, error: function(XMLHttpRequest, textStatus, errorThrown) { bootbox.alert($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_query_failed") + textStatus+":"+errorThrown); return; }, complete: function() { resUtil.tooltipVimStatus(); } }); }, $vimType: { condName : $.i18n.prop("com_zte_ums_eco_roc_vim_type"), component_type : 'select', selectItems : [ { cond_value : 'vmware', name : "vmware", value : true }, { cond_value : 'openstack', name :"openstack", value : true } ] }, addVim : { titleName: $.i18n.prop("com_zte_ums_eco_roc_vim_register_info"), vimId : "", vimName : "", domain : '', userName : "", tenant : "", password : "", url : "", saveType :"add", description : "", vimType :"openstack", vendor :"" }, $showVimTable : function(el, action) { vm.isSave = false; if(vm.action.ADD == action){ vm.addVim.vimId = ""; vm.addVim.vimName = ""; vm.addVim.userName = ""; vm.addVim.password = ""; vm.addVim.url = ""; vm.addVim.domain = ""; vm.addVim.description = ""; vm.addVim.tenant = ""; vm.addVim.vendor = ""; vm.addVim.saveType = "add"; vm.addVim.vimType = "openstack"; vm.addVim.titleName = $.i18n.prop("com_zte_ums_eco_roc_vim_register_info"); } else { vm.addVim.vimId = el.vimId; vm.addVim.vimName = el.name; vm.addVim.url = el.url; vm.addVim.description = el.description; vm.addVim.userName = el.userName; vm.addVim.password = el.password; vm.addVim.tenant = el.tenant; vm.addVim.domain = el.domain; vm.addVim.saveType = "update"; vm.addVim.titleName = $.i18n.prop('com_zte_ums_eco_roc_vim_modify_info'); vm.addVim.vimType = el.type; vm.addVim.vendor = el.vendor; } vm.executeError.visible=false; vm.executeWait.visible=false; $(".form-group").each(function () { $(this).removeClass('has-success'); $(this).removeClass('has-error'); $(this).find(".help-block[id]").remove(); }); $("#addVimDlg").modal("show"); }, $saveVimTable : function() { vm.isSave = true; success.hide(); error.hide(); if (form.valid() == false) { vm.isSave = false; return false; } vm.executeWait.visible = true; vm.executeError.visible = false; if(vm.addVim.saveType=="add") { //不能重复添加 /* for( var i = 0; i < vm.vimInfo.length; i ++ ){ if(vm.addVim.url == vm.vimInfo[i].url){ resUtil.growl($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_title") + 'already exists',"info"); $('#addVimDlg').modal('hide'); return; } } */ vm.persistVim(); } else if( vm.addVim.saveType == "update" ){ vm.updateVim(); } }, //新增vim persistVim : function(){ $.ajax({ type : "Post", url : vm.$addVimInfoUrl, data : JSON.stringify({ name : vm.addVim.vimName, url : vm.addVim.url, userName : vm.addVim.userName, password : vm.addVim.password, tenant : vm.addVim.tenant, domain : vm.addVim.domain, vendor : vm.addVim.vendor, version : vm.addVim.version, description: vm.addVim.description, type : vm.addVim.vimType, }), async : false, dataType : "json", contentType : 'application/json', success : function(data,statusText,jqXHR) { vm.executeWait.visible=false; vm.executeError.visible=false; if ( jqXHR.status=="201" ) { vm.addVim.vimId = data.vimId; vm.addVim.name = data.name; vm.addVim.tenant = data.tenant; vm.addVim.type = data.type; var newVim=jQuery.extend({}, vm.addVim); vm.vimInfo.push(newVim); $('#addVimDlg').modal('hide'); resUtil.growl($.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_title") + $.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_save_success"),"success"); } else{ vm.executeError.visible=true; vm.executeError.text = $.i18n.prop("com_zte_ums_eco_roc_vim_growl_msg_save_failed"); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { vm.executeError.visible = true; vm.executeError.text = textStatus+":"+errorThrown; vm.executeWait.visible = false; vm.isSave = false; } }); }, //更新vim updateVim : function(){ $.ajax({ type : "Put", url : vm.$updateVimInfoUrl+vm.addVim.vimId, contentType : 'application/json', data : JSON.stringify({ name : vm.addVim.vimName, userName : vm.addVim.userName, password : vm.addVim.password, domain : vm.addVim.domain, version : vm.addVim.version, description : vm.addVim.description, url : vm.addVim.url, tenant:vm.addVim.tenant, type : vm.addVim.vimType, vendor : vm.addVim.vendor, }), dataType : "json", async : false, success : function(data,statusText,jqXHR) { vm.executeWait.visible=false; vm.executeError.visible=false; if (jqXHR.status=="200") { for(var i=0;i