CLOUDSTACK-2569: UI > Infrastructure menu > zone > physical network > network service providers > Cisco VNMC > If Cisco VNMC provider doesn't exist, show Add action and hide enable, disable action.

This commit is contained in:
Jessica Wang 2013-07-23 14:47:14 -07:00
parent 57623832b0
commit 9fb71c30a8

View File

@ -14,28 +14,30 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack) {
cloudStack.modules.vnmcNetworkProvider = function(module) {
var vnmcDeviceViewAll = window._m = [
{
(function ($, cloudStack) {
cloudStack.modules.vnmcNetworkProvider = function (module) {
var vnmcDeviceViewAll = window._m = [{
label: 'VNMC Devices',
path: '_zone.vnmcDevices'
}
];
}];
var vnmcListView = {
id: 'vnmcDevices',
fields: {
resourcename: { label: 'Resource Name' },
provider: { label: 'Provider' }
resourcename: {
label: 'Resource Name'
},
dataProvider: function(args) {
provider: {
label: 'Provider'
}
},
dataProvider: function (args) {
$.ajax({
url: createURL('listCiscoVnmcResources'),
data: {
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
success: function (json) {
var items = json.listCiscoVnmcResources.CiscoVnmcResource;
args.response.success({
data: items
@ -48,7 +50,7 @@
label: 'Add VNMC device',
messages: {
notification: function(args) {
notification: function (args) {
return 'Add VNMC device';
}
},
@ -58,69 +60,71 @@
fields: {
hostname: {
label: 'label.host',
validation: { required: true }
validation: {
required: true
}
},
username: {
label: 'label.username',
validation: { required: true }
validation: {
required: true
}
},
password: {
label: 'label.password',
isPassword: true,
validation: { required: true }
validation: {
required: true
}
}
}
},
action: function(args) {
action: function (args) {
$.ajax({
url: createURL('listNetworkServiceProviders'),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
success: function (json) {
var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
if(items != null && items.length > 0) {
if (items != null && items.length > 0) {
var ciscoVnmcProvider = items[0];
if(ciscoVnmcProvider.state == 'Enabled') {
if (ciscoVnmcProvider.state == 'Enabled') {
addCiscoVnmcResourceFn();
}
else {
} else {
enableCiscoVnmcProviderFn(ciscoVnmcProvider);
}
}
else {
} else {
$.ajax({
url: createURL("addNetworkServiceProvider"),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json) {
success: function (json) {
var jobId = json.addnetworkserviceproviderresponse.jobid;
var addVnmcProviderIntervalID = setInterval(function() {
var addVnmcProviderIntervalID = setInterval(function () {
$.ajax({
url: createURL("queryAsyncJobResult&jobId="+jobId),
url: createURL("queryAsyncJobResult&jobId=" + jobId),
dataType: "json",
success: function(json) {
success: function (json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
}
else {
clearInterval(addVnmcProviderIntervalID );
} else {
clearInterval(addVnmcProviderIntervalID);
if (result.jobstatus == 1) {
//nspMap["CiscoVnmc"] = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
var ciscoVnmcProvider = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
enableCiscoVnmcProviderFn(ciscoVnmcProvider);
}
else if (result.jobstatus == 2) {
} else if (result.jobstatus == 2) {
args.response.error(_s(result.jobresult.errortext));
}
}
},
error: function(XMLHttpResponse) {
error: function (XMLHttpResponse) {
args.response.error(parseXMLHttpResponse(data));
}
});
@ -131,32 +135,30 @@
}
});
var enableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
var enableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
$.ajax({
url: createURL('updateNetworkServiceProvider'),
data: {
id: ciscoVnmcProvider.id,
state: 'Enabled'
},
success: function(json) {
success: function (json) {
var jid = json.updatenetworkserviceproviderresponse.jobid;
var enableVnmcProviderIntervalID = setInterval(function(){
var enableVnmcProviderIntervalID = setInterval(function () {
$.ajax({
url: createURL('queryAsyncJobResult'),
data: {
jobid: jid
},
success: function(json){
success: function (json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
}
else {
} else {
clearInterval(enableVnmcProviderIntervalID);
if (result.jobstatus == 1) {
addCiscoVnmcResourceFn();
}
else if (result.jobstatus == 2) {
} else if (result.jobstatus == 2) {
args.response.error(_s(result.jobresult.errortext));
}
}
@ -167,7 +169,7 @@
});
};
var addCiscoVnmcResourceFn = function(){
var addCiscoVnmcResourceFn = function () {
var data = {
physicalnetworkid: args.context.physicalNetworks[0].id,
hostname: args.data.hostname,
@ -178,11 +180,13 @@
$.ajax({
url: createURL('addCiscoVnmcResource'),
data: data,
success: function(json) {
success: function (json) {
var item = json.addCiscoVnmcResource.CiscoVnmcResource;
args.response.success({data: item});
args.response.success({
data: item
});
},
error: function(data) {
error: function (data) {
args.response.error(parseXMLHttpResponse(data));
}
});
@ -190,7 +194,7 @@
},
notification: {
poll: function(args) {
poll: function (args) {
args.complete();
}
}
@ -203,29 +207,29 @@
remove: {
label: 'delete CiscoVNMC resource',
messages: {
confirm: function(args) {
confirm: function (args) {
return 'Please confirm you want to delete CiscoVNMC resource';
},
notification: function(args) {
notification: function (args) {
return 'delete CiscoVNMC resource';
}
},
action: function(args) {
action: function (args) {
$.ajax({
url: createURL('deleteCiscoVnmcResource'),
data: {
resourceid: args.context.vnmcDevices[0].resourceid
},
success: function(json) {
success: function (json) {
args.response.success();
},
error: function(data) {
error: function (data) {
args.response.error(parseXMLHttpResponse(data));
}
});
},
notification: {
poll: function(args) {
poll: function (args) {
args.complete();
}
}
@ -235,23 +239,28 @@
tabs: {
details: {
title: 'label.details',
fields: [
{
resourcename: { label: 'Resource Name' }
},
{
resourceid: { label: 'Resource ID'},
provider: { label: 'Provider' },
RESOURCE_NAME: { label: 'Resource Name'}
fields: [{
resourcename: {
label: 'Resource Name'
}
],
dataProvider: function(args) {
}, {
resourceid: {
label: 'Resource ID'
},
provider: {
label: 'Provider'
},
RESOURCE_NAME: {
label: 'Resource Name'
}
}],
dataProvider: function (args) {
$.ajax({
url: createURL('listCiscoVnmcResources'),
data: {
resourceid: args.context.vnmcDevices[0].resourceid
},
success: function(json){
success: function (json) {
var item = json.listCiscoVnmcResources.CiscoVnmcResource[0];
args.response.success({
data: item
@ -269,28 +278,78 @@
label: 'VNMC',
viewAll: vnmcDeviceViewAll,
actions: {
add: {
label: 'Add VNMC provider',
messages: {
confirm: function (args) {
return 'Please confirm you would like to add the VNMC provider.';
},
notification: function (args) {
return 'Add VNMC device';
}
},
action: function (args) {
$.ajax({
url: createURL("addNetworkServiceProvider"),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function (json) {
var jobId = json.addnetworkserviceproviderresponse.jobid;
var addVnmcProviderIntervalID = setInterval(function () {
$.ajax({
url: createURL("queryAsyncJobResult&jobId=" + jobId),
dataType: "json",
success: function (json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
} else {
clearInterval(addVnmcProviderIntervalID);
if (result.jobstatus == 1) {
var item = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
args.response.success({
data: item
});
} else if (result.jobstatus == 2) {
args.response.error(_s(result.jobresult.errortext));
}
}
},
error: function (XMLHttpResponse) {
args.response.error(parseXMLHttpResponse(data));
}
});
}, g_queryAsyncJobResultInterval);
}
});
}
},
enable: {
label: 'Enable VNMC provider',
messages: {
confirm: function(args) {
confirm: function (args) {
return 'Please confirm you would like to enable the VNMC provider.';
},
notification: function(args) {
notification: function (args) {
return 'Enable VNMC device';
}
},
action: function(args) {
action: function (args) {
$.ajax({
url: createURL('listNetworkServiceProviders'),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
success: function (json) {
var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
if(items != null && items.length > 0) {
if (items != null && items.length > 0) {
var ciscoVnmcProvider = items[0];
enableCiscoVnmcProviderFn(ciscoVnmcProvider);
@ -300,31 +359,33 @@
}
});
var enableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
var enableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
$.ajax({
url: createURL('updateNetworkServiceProvider'),
data: {
id: ciscoVnmcProvider.id,
state: 'Enabled'
},
success: function(json) {
success: function (json) {
var jid = json.updatenetworkserviceproviderresponse.jobid;
var enableVnmcProviderIntervalID = setInterval(function(){
var enableVnmcProviderIntervalID = setInterval(function () {
$.ajax({
url: createURL('queryAsyncJobResult'),
data: {
jobid: jid
},
success: function(json){
success: function (json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
}
else {
} else {
if (result.jobstatus == 1) {
args.response.success({ data: { state: 'Enabled' } });
args.response.success({
data: {
state: 'Enabled'
}
else if (result.jobstatus == 2) {
});
} else if (result.jobstatus == 2) {
args.response.error(_s(result.jobresult.errortext));
}
}
@ -335,7 +396,7 @@
});
}
var addCiscoVnmcResourceFn = function(){
var addCiscoVnmcResourceFn = function () {
var data = {
physicalnetworkid: args.context.physicalNetworks[0].id,
hostname: args.data.hostname,
@ -346,11 +407,13 @@
$.ajax({
url: createURL('addCiscoVnmcResource'),
data: data,
success: function(json) {
success: function (json) {
var item = json.addCiscoVnmcResource.CiscoVnmcResource;
args.response.success({data: item});
args.response.success({
data: item
});
},
error: function(data) {
error: function (data) {
args.response.error(parseXMLHttpResponse(data));
}
});
@ -358,7 +421,7 @@
},
notification: {
poll: function(args) {
poll: function (args) {
args.complete();
}
}
@ -368,24 +431,24 @@
label: 'Disable VNMC provider',
messages: {
confirm: function(args) {
confirm: function (args) {
return 'Please confirm you would like to disable the VNMC provider.';
},
notification: function(args) {
notification: function (args) {
return 'Disable VNMC device';
}
},
action: function(args) {
action: function (args) {
$.ajax({
url: createURL('listNetworkServiceProviders'),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
success: function (json) {
var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
if(items != null && items.length > 0) {
if (items != null && items.length > 0) {
var ciscoVnmcProvider = items[0];
disableCiscoVnmcProviderFn(ciscoVnmcProvider);
@ -395,32 +458,34 @@
}
});
var disableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
var disableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
$.ajax({
url: createURL('updateNetworkServiceProvider'),
data: {
id: ciscoVnmcProvider.id,
state: 'Disabled'
},
success: function(json) {
success: function (json) {
var jid = json.updatenetworkserviceproviderresponse.jobid;
var disableVnmcProviderIntervalID = setInterval(function(){
var disableVnmcProviderIntervalID = setInterval(function () {
$.ajax({
url: createURL('queryAsyncJobResult'),
data: {
jobid: jid
},
success: function(json){
success: function (json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
}
else {
} else {
clearInterval(disableVnmcProviderIntervalID);
if (result.jobstatus == 1) {
args.response.success({ data: { state: 'Disabled' } });
args.response.success({
data: {
state: 'Disabled'
}
else if (result.jobstatus == 2) {
});
} else if (result.jobstatus == 2) {
args.response.error(_s(result.jobresult.errortext));
}
}
@ -431,7 +496,7 @@
});
};
var addCiscoVnmcResourceFn = function(){
var addCiscoVnmcResourceFn = function () {
var data = {
physicalnetworkid: args.context.physicalNetworks[0].id,
hostname: args.data.hostname,
@ -442,11 +507,13 @@
$.ajax({
url: createURL('addCiscoVnmcResource'),
data: data,
success: function(json) {
success: function (json) {
var item = json.addCiscoVnmcResource.CiscoVnmcResource;
args.response.success({data: item});
args.response.success({
data: item
});
},
error: function(data) {
error: function (data) {
args.response.error(parseXMLHttpResponse(data));
}
});
@ -454,7 +521,7 @@
},
notification: {
poll: function(args) {
poll: function (args) {
args.complete();
}
}
@ -463,37 +530,41 @@
tabs: {
details: {
title: 'label.details',
fields: [
{
name: { label: 'label.name' }
fields: [{
name: {
label: 'label.name'
}
}, {
state: {
label: 'label.state'
},
id: {
label: 'label.id'
},
{
state: { label: 'label.state' },
id: { label: 'label.id' },
servicelist: {
label: 'Services',
converter: function(args){
if(args)
converter: function (args) {
if (args)
return args.join(', ');
else
return '';
}
}
}
],
dataProvider: function(args) {
}],
dataProvider: function (args) {
$.ajax({
url: createURL('listNetworkServiceProviders'),
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
success: function (json) {
var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
if(items != null && items.length > 0) {
args.response.success({ data: items[0] });
}
else {
if (items != null && items.length > 0) {
args.response.success({
data: items[0]
});
} else {
args.response.success({
data: {
name: 'CiscoVnmc',
@ -509,35 +580,39 @@
}
};
var vnmcActionFilter = function(args) {
var enabledActions = ['enable'];
var vnmcActionFilter = function (args) {
var allowedActions = [];
$.ajax({
url: createURL('listNetworkServiceProviders'),
async: false,
data: {
name: 'CiscoVnmc',
physicalnetworkid: args.context.physicalNetworks[0].id
},
success: function(json){
async: false,
success: function (json) {
var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
if(items != null && items.length > 0) {
if (items != null && items.length > 0) {
var ciscoVnmcProvider = items[0];
if (ciscoVnmcProvider.state === 'Enabled') {
enabledActions = ['disable'];
if (ciscoVnmcProvider.state == 'Enabled') {
allowedActions.push('disable');
} else if (ciscoVnmcProvider.state == 'Disabled') {
allowedActions.push('enable');
}
} else {
allowedActions.push('add');
}
}
});
return enabledActions;
return allowedActions;
};
module.pluginAPI.extend({
addDevice: function(device) {
addDevice: function (device) {
cloudStack.sections.system.subsections[device.id] = device;
vnmcDeviceViewAll.push({ label: device.title, path: '_zone.' + device.id });
vnmcDeviceViewAll.push({
label: device.title,
path: '_zone.' + device.id
});
}
});