cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessicaw...@apache.org
Subject git commit: updated refs/heads/4.2 to 24af02e
Date Tue, 23 Jul 2013 21:55:09 GMT
Updated Branches:
  refs/heads/4.2 8d1a67002 -> 24af02e5b


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.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/24af02e5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/24af02e5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/24af02e5

Branch: refs/heads/4.2
Commit: 24af02e5b5433e9029d5b5611e024fb0f2086f55
Parents: 8d1a670
Author: Jessica Wang <jessicawang@apache.org>
Authored: Tue Jul 23 14:52:55 2013 -0700
Committer: Jessica Wang <jessicawang@apache.org>
Committed: Tue Jul 23 14:52:55 2013 -0700

----------------------------------------------------------------------
 .../vnmcNetworkProvider/vnmcNetworkProvider.js  | 1073 ++++++++++--------
 1 file changed, 574 insertions(+), 499 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/24af02e5/ui/modules/vnmcNetworkProvider/vnmcNetworkProvider.js
----------------------------------------------------------------------
diff --git a/ui/modules/vnmcNetworkProvider/vnmcNetworkProvider.js b/ui/modules/vnmcNetworkProvider/vnmcNetworkProvider.js
index 22cff63..9764a94 100644
--- a/ui/modules/vnmcNetworkProvider/vnmcNetworkProvider.js
+++ b/ui/modules/vnmcNetworkProvider/vnmcNetworkProvider.js
@@ -14,540 +14,615 @@
 // 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 = [
-      {
-        label: 'VNMC Devices',
-        path: '_zone.vnmcDevices'
-      }
-    ];
-
-    var vnmcListView = {
-      id: 'vnmcDevices',
-      fields: {
-        resourcename: { label: 'Resource Name' },
-        provider: { label: 'Provider' }
-      },
-      dataProvider: function(args) {
-        $.ajax({
-          url: createURL('listCiscoVnmcResources'),
-          data: {
-            physicalnetworkid: args.context.physicalNetworks[0].id
-          },
-          success: function(json){
-            var items = json.listCiscoVnmcResources.CiscoVnmcResource;
-            args.response.success({
-              data: items
-            });
-          }
-        });
-      },
-      actions: {
-        add: {
-          label: 'Add VNMC device',
-
-          messages: {
-            notification: function(args) {
-              return 'Add VNMC device';
-            }
-          },
-
-          createForm: {
-            title: 'Add VNMC device',
+(function ($, cloudStack) {
+    cloudStack.modules.vnmcNetworkProvider = function (module) {
+        var vnmcDeviceViewAll = window._m = [{
+            label: 'VNMC Devices',
+            path: '_zone.vnmcDevices'
+        }];
+
+        var vnmcListView = {
+            id: 'vnmcDevices',
             fields: {
-              hostname: {
-                label: 'label.host',
-                validation: { required: true }
-              },
-              username: {
-                label: 'label.username',
-                validation: { required: true }
-              },
-              password: {
-                label: 'label.password',
-                isPassword: true,
-                validation: { required: true }
-              }
-            }
-          },
-
-          action: function(args) {
-            $.ajax({
-              url: createURL('listNetworkServiceProviders'),
-              data: {
-                name: 'CiscoVnmc',
-                physicalnetworkid: args.context.physicalNetworks[0].id
-              },
-              success: function(json){
-                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
-                if(items != null && items.length > 0) {
-                  var ciscoVnmcProvider = items[0];
-                  if(ciscoVnmcProvider.state == 'Enabled') {
-                    addCiscoVnmcResourceFn();
-                  }
-                  else {
-                    enableCiscoVnmcProviderFn(ciscoVnmcProvider);
-                  }
+                resourcename: {
+                    label: 'Resource Name'
+                },
+                provider: {
+                    label: 'Provider'
                 }
-                else {
-                  $.ajax({
-                    url: createURL("addNetworkServiceProvider"),
+            },
+            dataProvider: function (args) {
+                $.ajax({
+                    url: createURL('listCiscoVnmcResources'),
                     data: {
-                      name: 'CiscoVnmc',
-                      physicalnetworkid: args.context.physicalNetworks[0].id
+                        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
+                    success: function (json) {
+                        var items = json.listCiscoVnmcResources.CiscoVnmcResource;
+                        args.response.success({
+                            data: items
+                        });
+                    }
+                });
+            },
+            actions: {
+                add: {
+                    label: 'Add VNMC device',
+
+                    messages: {
+                        notification: function (args) {
+                            return 'Add VNMC device';
+                        }
+                    },
+
+                    createForm: {
+                        title: 'Add VNMC device',
+                        fields: {
+                            hostname: {
+                                label: 'label.host',
+                                validation: {
+                                    required: true
+                                }
+                            },
+                            username: {
+                                label: 'label.username',
+                                validation: {
+                                    required: true
+                                }
+                            },
+                            password: {
+                                label: 'label.password',
+                                isPassword: true,
+                                validation: {
+                                    required: true
+                                }
                             }
-                            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) {
-                                args.response.error(_s(result.jobresult.errortext));
-                              }
+                        }
+                    },
+
+                    action: function (args) {
+                        $.ajax({
+                            url: createURL('listNetworkServiceProviders'),
+                            data: {
+                                name: 'CiscoVnmc',
+                                physicalnetworkid: args.context.physicalNetworks[0].id
+                            },
+                            success: function (json) {
+                                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
+                                if (items != null && items.length > 0) {
+                                    var ciscoVnmcProvider = items[0];
+                                    if (ciscoVnmcProvider.state == 'Enabled') {
+                                        addCiscoVnmcResourceFn();
+                                    } else {
+                                        enableCiscoVnmcProviderFn(ciscoVnmcProvider);
+                                    }
+                                } else {
+                                    $.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) {
+                                                                //nspMap["CiscoVnmc"] = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
+                                                                var ciscoVnmcProvider = json.queryasyncjobresultresponse.jobresult.networkserviceprovider;
+                                                                enableCiscoVnmcProviderFn(ciscoVnmcProvider);
+                                                            } else if (result.jobstatus == 2) {
+                                                                args.response.error(_s(result.jobresult.errortext));
+                                                            }
+                                                        }
+                                                    },
+                                                    error: function (XMLHttpResponse) {
+                                                        args.response.error(parseXMLHttpResponse(data));
+                                                    }
+                                                });
+                                            }, g_queryAsyncJobResultInterval);
+                                        }
+                                    });
+                                }
                             }
-                          },
-                          error: function(XMLHttpResponse) {
-                            args.response.error(parseXMLHttpResponse(data));
-                          }
                         });
-                      }, g_queryAsyncJobResultInterval);
-                    }
-                  });
-                }
-              }
-            });
 
-            var enableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
-              $.ajax({
-                url: createURL('updateNetworkServiceProvider'),
-                data: {
-                  id: ciscoVnmcProvider.id,
-                  state: 'Enabled'
-                },
-                success: function(json) {
-                  var jid = json.updatenetworkserviceproviderresponse.jobid;
-                  var enableVnmcProviderIntervalID = setInterval(function(){
-                    $.ajax({
-                      url: createURL('queryAsyncJobResult'),
-                      data: {
-                        jobid: jid
-                      },
-                      success: function(json){
-                        var result = json.queryasyncjobresultresponse;
-                        if (result.jobstatus == 0) {
-                          return; //Job has not completed
+                        var enableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
+                            $.ajax({
+                                url: createURL('updateNetworkServiceProvider'),
+                                data: {
+                                    id: ciscoVnmcProvider.id,
+                                    state: 'Enabled'
+                                },
+                                success: function (json) {
+                                    var jid = json.updatenetworkserviceproviderresponse.jobid;
+                                    var enableVnmcProviderIntervalID = setInterval(function () {
+                                        $.ajax({
+                                            url: createURL('queryAsyncJobResult'),
+                                            data: {
+                                                jobid: jid
+                                            },
+                                            success: function (json) {
+                                                var result = json.queryasyncjobresultresponse;
+                                                if (result.jobstatus == 0) {
+                                                    return; //Job has not completed
+                                                } else {
+                                                    clearInterval(enableVnmcProviderIntervalID);
+                                                    if (result.jobstatus == 1) {
+                                                        addCiscoVnmcResourceFn();
+                                                    } else if (result.jobstatus == 2) {
+                                                        args.response.error(_s(result.jobresult.errortext));
+                                                    }
+                                                }
+                                            }
+                                        });
+                                    }, g_queryAsyncJobResultInterval);
+                                }
+                            });
+                        };
+
+                        var addCiscoVnmcResourceFn = function () {
+                            var data = {
+                                physicalnetworkid: args.context.physicalNetworks[0].id,
+                                hostname: args.data.hostname,
+                                username: args.data.username,
+                                password: args.data.password
+                            };
+
+                            $.ajax({
+                                url: createURL('addCiscoVnmcResource'),
+                                data: data,
+                                success: function (json) {
+                                    var item = json.addCiscoVnmcResource.CiscoVnmcResource;
+                                    args.response.success({
+                                        data: item
+                                    });
+                                },
+                                error: function (data) {
+                                    args.response.error(parseXMLHttpResponse(data));
+                                }
+                            });
                         }
-                        else {
-                          clearInterval(enableVnmcProviderIntervalID);
-                          if (result.jobstatus == 1) {
-                            addCiscoVnmcResourceFn();
-                          }
-                          else if (result.jobstatus == 2) {
-                            args.response.error(_s(result.jobresult.errortext));
-                          }
+                    },
+
+                    notification: {
+                        poll: function (args) {
+                            args.complete();
                         }
-                      }
-                    });
-                  }, g_queryAsyncJobResultInterval);
-                }
-              });
-            };
-
-            var addCiscoVnmcResourceFn = function(){
-              var data = {
-                physicalnetworkid: args.context.physicalNetworks[0].id,
-                hostname: args.data.hostname,
-                username: args.data.username,
-                password: args.data.password
-              };
-
-              $.ajax({
-                url: createURL('addCiscoVnmcResource'),
-                data: data,
-                success: function(json) {
-                  var item = json.addCiscoVnmcResource.CiscoVnmcResource;
-                  args.response.success({data: item});
-                },
-                error: function(data) {
-                  args.response.error(parseXMLHttpResponse(data));
+                    }
                 }
-              });
-            }
-          },
-
-          notification: {
-            poll: function(args) {
-              args.complete();
-            }
-          }
-        }
-      },
-
-      detailView: {
-        name: 'CiscoVNMC resource details',
-        actions: {
-          remove: {
-            label: 'delete CiscoVNMC resource',
-            messages: {
-              confirm: function(args) {
-                return 'Please confirm you want to delete CiscoVNMC resource';
-              },
-              notification: function(args) {
-                return 'delete CiscoVNMC resource';
-              }
             },
-            action: function(args) {
-              $.ajax({
-                url: createURL('deleteCiscoVnmcResource'),
-                data: {
-                  resourceid: args.context.vnmcDevices[0].resourceid
-                },
-                success: function(json) {
-                  args.response.success();
+
+            detailView: {
+                name: 'CiscoVNMC resource details',
+                actions: {
+                    remove: {
+                        label: 'delete CiscoVNMC resource',
+                        messages: {
+                            confirm: function (args) {
+                                return 'Please confirm you want to delete CiscoVNMC resource';
+                            },
+                            notification: function (args) {
+                                return 'delete CiscoVNMC resource';
+                            }
+                        },
+                        action: function (args) {
+                            $.ajax({
+                                url: createURL('deleteCiscoVnmcResource'),
+                                data: {
+                                    resourceid: args.context.vnmcDevices[0].resourceid
+                                },
+                                success: function (json) {
+                                    args.response.success();
+                                },
+                                error: function (data) {
+                                    args.response.error(parseXMLHttpResponse(data));
+                                }
+                            });
+                        },
+                        notification: {
+                            poll: function (args) {
+                                args.complete();
+                            }
+                        }
+                    }
                 },
-                error: function(data) {
-                  args.response.error(parseXMLHttpResponse(data));
+
+                tabs: {
+                    details: {
+                        title: 'label.details',
+                        fields: [{
+                            resourcename: {
+                                label: 'Resource Name'
+                            }
+                        }, {
+                            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) {
+                                    var item = json.listCiscoVnmcResources.CiscoVnmcResource[0];
+                                    args.response.success({
+                                        data: item
+                                    });
+                                }
+                            });
+                        }
+                    }
                 }
-              });
-            },
-            notification: {
-              poll: function(args) {
-                args.complete();
-              }
-            }
-          }
-        },
-
-        tabs: {
-          details: {
-            title: 'label.details',
-            fields: [
-             {
-               resourcename: { label: 'Resource Name' }
-             },
-             {
-               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){
-                 var item = json.listCiscoVnmcResources.CiscoVnmcResource[0];
-                 args.response.success({
-                   data: item
-                 });
-               }
-             });
             }
-          }
-        }
-      }
-    };
+        };
+
+        var vnmcProviderDetailView = {
+            id: 'vnmcProvider',
+            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';
+                        }
+                    },
 
-    var vnmcProviderDetailView = {
-      id: 'vnmcProvider',
-      label: 'VNMC',
-      viewAll: vnmcDeviceViewAll,
-      actions: {
-        enable: {
-          label: 'Enable VNMC provider',
-
-          messages: {
-            confirm: function(args) {
-              return 'Please confirm you would like to enable the VNMC provider.';
-            },
-            notification: function(args) {
-              return 'Enable 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) {
+                            return 'Please confirm you would like to enable the VNMC provider.';
+                        },
+                        notification: function (args) {
+                            return 'Enable VNMC device';
+                        }
+                    },
 
-          action: function(args) {
-            $.ajax({
-              url: createURL('listNetworkServiceProviders'),
-              data: {
-                name: 'CiscoVnmc',
-                physicalnetworkid: args.context.physicalNetworks[0].id
-              },
-              success: function(json){
-                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
-                if(items != null && items.length > 0) {
-                  var ciscoVnmcProvider = items[0];
-
-                  enableCiscoVnmcProviderFn(ciscoVnmcProvider);
-                } else {
-                  args.response.error('VNMC is not available from provider list.');
-                }
-              }
-            });
+                    action: function (args) {
+                        $.ajax({
+                            url: createURL('listNetworkServiceProviders'),
+                            data: {
+                                name: 'CiscoVnmc',
+                                physicalnetworkid: args.context.physicalNetworks[0].id
+                            },
+                            success: function (json) {
+                                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
+                                if (items != null && items.length > 0) {
+                                    var ciscoVnmcProvider = items[0];
+
+                                    enableCiscoVnmcProviderFn(ciscoVnmcProvider);
+                                } else {
+                                    args.response.error('VNMC is not available from provider list.');
+                                }
+                            }
+                        });
 
-            var enableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
-              $.ajax({
-                url: createURL('updateNetworkServiceProvider'),
-                data: {
-                  id: ciscoVnmcProvider.id,
-                  state: 'Enabled'
-                },
-                success: function(json) {
-                  var jid = json.updatenetworkserviceproviderresponse.jobid;
-                  var enableVnmcProviderIntervalID = setInterval(function(){
-                    $.ajax({
-                      url: createURL('queryAsyncJobResult'),
-                      data: {
-                        jobid: jid
-                      },
-                      success: function(json){
-                        var result = json.queryasyncjobresultresponse;
-                        if (result.jobstatus == 0) {
-                          return; //Job has not completed
+                        var enableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
+                            $.ajax({
+                                url: createURL('updateNetworkServiceProvider'),
+                                data: {
+                                    id: ciscoVnmcProvider.id,
+                                    state: 'Enabled'
+                                },
+                                success: function (json) {
+                                    var jid = json.updatenetworkserviceproviderresponse.jobid;
+                                    var enableVnmcProviderIntervalID = setInterval(function () {
+                                        $.ajax({
+                                            url: createURL('queryAsyncJobResult'),
+                                            data: {
+                                                jobid: jid
+                                            },
+                                            success: function (json) {
+                                                var result = json.queryasyncjobresultresponse;
+                                                if (result.jobstatus == 0) {
+                                                    return; //Job has not completed
+                                                } else {
+                                                    if (result.jobstatus == 1) {
+                                                        args.response.success({
+                                                            data: {
+                                                                state: 'Enabled'
+                                                            }
+                                                        });
+                                                    } else if (result.jobstatus == 2) {
+                                                        args.response.error(_s(result.jobresult.errortext));
+                                                    }
+                                                }
+                                            }
+                                        });
+                                    }, g_queryAsyncJobResultInterval);
+                                }
+                            });
                         }
-                        else {
-                          if (result.jobstatus == 1) {
-                            args.response.success({ data: { state: 'Enabled' } });
-                          }
-                          else if (result.jobstatus == 2) {
-                            args.response.error(_s(result.jobresult.errortext));
-                          }
+
+                        var addCiscoVnmcResourceFn = function () {
+                            var data = {
+                                physicalnetworkid: args.context.physicalNetworks[0].id,
+                                hostname: args.data.hostname,
+                                username: args.data.username,
+                                password: args.data.password
+                            };
+
+                            $.ajax({
+                                url: createURL('addCiscoVnmcResource'),
+                                data: data,
+                                success: function (json) {
+                                    var item = json.addCiscoVnmcResource.CiscoVnmcResource;
+                                    args.response.success({
+                                        data: item
+                                    });
+                                },
+                                error: function (data) {
+                                    args.response.error(parseXMLHttpResponse(data));
+                                }
+                            });
                         }
-                      }
-                    });
-                  }, g_queryAsyncJobResultInterval);
-                }
-              });
-            }
+                    },
 
-            var addCiscoVnmcResourceFn = function(){
-              var data = {
-                physicalnetworkid: args.context.physicalNetworks[0].id,
-                hostname: args.data.hostname,
-                username: args.data.username,
-                password: args.data.password
-              };
-
-              $.ajax({
-                url: createURL('addCiscoVnmcResource'),
-                data: data,
-                success: function(json) {
-                  var item = json.addCiscoVnmcResource.CiscoVnmcResource;
-                  args.response.success({data: item});
+                    notification: {
+                        poll: function (args) {
+                            args.complete();
+                        }
+                    }
                 },
-                error: function(data) {
-                  args.response.error(parseXMLHttpResponse(data));
-                }
-              });
-            }
-          },
 
-          notification: {
-            poll: function(args) {
-              args.complete();
-            }
-          }
-        },
-
-        disable: {
-          label: 'Disable VNMC provider',
+                disable: {
+                    label: 'Disable VNMC provider',
 
-          messages: {
-            confirm: function(args) {
-              return 'Please confirm you would like to disable the VNMC provider.';
-            },
-            notification: function(args) {
-              return 'Disable VNMC device';
-            }
-          },
+                    messages: {
+                        confirm: function (args) {
+                            return 'Please confirm you would like to disable the VNMC provider.';
+                        },
+                        notification: function (args) {
+                            return 'Disable VNMC device';
+                        }
+                    },
 
-          action: function(args) {
-            $.ajax({
-              url: createURL('listNetworkServiceProviders'),
-              data: {
-                name: 'CiscoVnmc',
-                physicalnetworkid: args.context.physicalNetworks[0].id
-              },
-              success: function(json){
-                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
-                if(items != null && items.length > 0) {
-                  var ciscoVnmcProvider = items[0];
-
-                  disableCiscoVnmcProviderFn(ciscoVnmcProvider);
-                } else {
-                  args.response.error('VNMC is not available from provider list.');
-                }
-              }
-            });
+                    action: function (args) {
+                        $.ajax({
+                            url: createURL('listNetworkServiceProviders'),
+                            data: {
+                                name: 'CiscoVnmc',
+                                physicalnetworkid: args.context.physicalNetworks[0].id
+                            },
+                            success: function (json) {
+                                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
+                                if (items != null && items.length > 0) {
+                                    var ciscoVnmcProvider = items[0];
+
+                                    disableCiscoVnmcProviderFn(ciscoVnmcProvider);
+                                } else {
+                                    args.response.error('VNMC is not available from provider list.');
+                                }
+                            }
+                        });
 
-            var disableCiscoVnmcProviderFn = function(ciscoVnmcProvider){
-              $.ajax({
-                url: createURL('updateNetworkServiceProvider'),
-                data: {
-                  id: ciscoVnmcProvider.id,
-                  state: 'Disabled'
-                },
-                success: function(json) {
-                  var jid = json.updatenetworkserviceproviderresponse.jobid;
-                  var disableVnmcProviderIntervalID = setInterval(function(){
-                    $.ajax({
-                      url: createURL('queryAsyncJobResult'),
-                      data: {
-                        jobid: jid
-                      },
-                      success: function(json){
-                        var result = json.queryasyncjobresultresponse;
-                        if (result.jobstatus == 0) {
-                          return; //Job has not completed
+                        var disableCiscoVnmcProviderFn = function (ciscoVnmcProvider) {
+                            $.ajax({
+                                url: createURL('updateNetworkServiceProvider'),
+                                data: {
+                                    id: ciscoVnmcProvider.id,
+                                    state: 'Disabled'
+                                },
+                                success: function (json) {
+                                    var jid = json.updatenetworkserviceproviderresponse.jobid;
+                                    var disableVnmcProviderIntervalID = setInterval(function () {
+                                        $.ajax({
+                                            url: createURL('queryAsyncJobResult'),
+                                            data: {
+                                                jobid: jid
+                                            },
+                                            success: function (json) {
+                                                var result = json.queryasyncjobresultresponse;
+                                                if (result.jobstatus == 0) {
+                                                    return; //Job has not completed
+                                                } else {
+                                                    clearInterval(disableVnmcProviderIntervalID);
+                                                    if (result.jobstatus == 1) {
+                                                        args.response.success({
+                                                            data: {
+                                                                state: 'Disabled'
+                                                            }
+                                                        });
+                                                    } else if (result.jobstatus == 2) {
+                                                        args.response.error(_s(result.jobresult.errortext));
+                                                    }
+                                                }
+                                            }
+                                        });
+                                    }, g_queryAsyncJobResultInterval);
+                                }
+                            });
+                        };
+
+                        var addCiscoVnmcResourceFn = function () {
+                            var data = {
+                                physicalnetworkid: args.context.physicalNetworks[0].id,
+                                hostname: args.data.hostname,
+                                username: args.data.username,
+                                password: args.data.password
+                            };
+
+                            $.ajax({
+                                url: createURL('addCiscoVnmcResource'),
+                                data: data,
+                                success: function (json) {
+                                    var item = json.addCiscoVnmcResource.CiscoVnmcResource;
+                                    args.response.success({
+                                        data: item
+                                    });
+                                },
+                                error: function (data) {
+                                    args.response.error(parseXMLHttpResponse(data));
+                                }
+                            });
                         }
-                        else {
-                          clearInterval(disableVnmcProviderIntervalID);
-                          if (result.jobstatus == 1) {
-                            args.response.success({ data: { state: 'Disabled' } });
-                          }
-                          else if (result.jobstatus == 2) {
-                            args.response.error(_s(result.jobresult.errortext));
-                          }
+                    },
+
+                    notification: {
+                        poll: function (args) {
+                            args.complete();
                         }
-                      }
-                    });
-                  }, g_queryAsyncJobResultInterval);
-                }
-              });
-            };
-
-            var addCiscoVnmcResourceFn = function(){
-              var data = {
-                physicalnetworkid: args.context.physicalNetworks[0].id,
-                hostname: args.data.hostname,
-                username: args.data.username,
-                password: args.data.password
-              };
-
-              $.ajax({
-                url: createURL('addCiscoVnmcResource'),
-                data: data,
-                success: function(json) {
-                  var item = json.addCiscoVnmcResource.CiscoVnmcResource;
-                  args.response.success({data: item});
-                },
-                error: function(data) {
-                  args.response.error(parseXMLHttpResponse(data));
+                    }
                 }
-              });
-            }
-          },
-
-          notification: {
-            poll: function(args) {
-              args.complete();
-            }
-          }
-        }
-      },
-      tabs: {
-        details: {
-          title: 'label.details',
-          fields: [
-            {
-              name: { label: 'label.name' }
             },
-            {
-              state: { label: 'label.state' },
-              id: { label: 'label.id' },
-              servicelist: {
-                label: 'Services',
-                converter: function(args){
-                  if(args)
-                    return args.join(', ');
-                  else
-                    return '';
+            tabs: {
+                details: {
+                    title: 'label.details',
+                    fields: [{
+                        name: {
+                            label: 'label.name'
+                        }
+                    }, {
+                        state: {
+                            label: 'label.state'
+                        },
+                        id: {
+                            label: 'label.id'
+                        },
+                        servicelist: {
+                            label: 'Services',
+                            converter: function (args) {
+                                if (args)
+                                    return args.join(', ');
+                                else
+                                    return '';
+                            }
+                        }
+                    }],
+                    dataProvider: function (args) {
+                        $.ajax({
+                            url: createURL('listNetworkServiceProviders'),
+                            data: {
+                                name: 'CiscoVnmc',
+                                physicalnetworkid: args.context.physicalNetworks[0].id
+                            },
+                            success: function (json) {
+                                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
+                                if (items != null && items.length > 0) {
+                                    args.response.success({
+                                        data: items[0]
+                                    });
+                                } else {
+                                    args.response.success({
+                                        data: {
+                                            name: 'CiscoVnmc',
+                                            state: 'Disabled'
+                                        },
+                                        actionFilter: vnmcActionFilter
+                                    });
+                                }
+                            }
+                        });
+                    }
                 }
-              }
             }
-          ],
-          dataProvider: function(args) {
+        };
+
+        var vnmcActionFilter = function (args) {
+        	var allowedActions = [];
             $.ajax({
-              url: createURL('listNetworkServiceProviders'),
-              data: {
-                name: 'CiscoVnmc',
-                physicalnetworkid: args.context.physicalNetworks[0].id
-              },
-              success: function(json){
-                var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
-                if(items != null && items.length > 0) {
-                  args.response.success({ data: items[0] });
-                }
-                else {
-                  args.response.success({
-                    data: {
-                      name: 'CiscoVnmc',
-                      state: 'Disabled'
-                    },
-                    actionFilter: vnmcActionFilter
-                  });
+                url: createURL('listNetworkServiceProviders'),                
+                data: {
+                    name: 'CiscoVnmc',
+                    physicalnetworkid: args.context.physicalNetworks[0].id
+                },
+                async: false,
+                success: function (json) {
+                    var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;                    
+                    if (items != null && items.length > 0) {
+                        var ciscoVnmcProvider = items[0];
+                        if (ciscoVnmcProvider.state == 'Enabled') {
+                        	allowedActions.push('disable');
+                        } else if (ciscoVnmcProvider.state == 'Disabled') {
+                        	allowedActions.push('enable');
+                        }
+                    } else {
+                    	allowedActions.push('add');
+                    }
                 }
-              }
             });
-          }
-        }
-      }
-    };
-
-    var vnmcActionFilter = function(args) {
-      var enabledActions = ['enable'];
-      
-      $.ajax({
-        url: createURL('listNetworkServiceProviders'),
-        async: false,
-        data: {
-          name: 'CiscoVnmc',
-          physicalnetworkid: args.context.physicalNetworks[0].id
-        },
-        success: function(json){
-          var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
-          if(items != null && items.length > 0) {
-            var ciscoVnmcProvider = items[0];
-
-            if (ciscoVnmcProvider.state === 'Enabled') {
-              enabledActions = ['disable'];
+            return allowedActions;
+        };
+
+        module.pluginAPI.extend({
+            addDevice: function (device) {
+                cloudStack.sections.system.subsections[device.id] = device;
+                vnmcDeviceViewAll.push({
+                    label: device.title,
+                    path: '_zone.' + device.id
+                });
             }
-          }
-        }
-      });
+        });
 
-      return enabledActions;
-    };
+        module.infrastructure.networkServiceProvider({
+            id: 'CiscoVnmc',
+            name: 'Cisco VNMC',
+            //state: 'Disabled', //don't know state until log in and visit Infrastructure menu > zone detail > physical network > network service providers
+            listView: vnmcListView,
 
-    module.pluginAPI.extend({
-      addDevice: function(device) {
-        cloudStack.sections.system.subsections[device.id] = device;
-        vnmcDeviceViewAll.push({ label: device.title, path: '_zone.' + device.id });
-      }
-    });
-
-    module.infrastructure.networkServiceProvider({
-      id: 'CiscoVnmc',
-      name: 'Cisco VNMC',
-      //state: 'Disabled', //don't know state until log in and visit Infrastructure menu > zone detail > physical network > network service providers
-      listView: vnmcListView,
-
-      detailView: vnmcProviderDetailView
-    });
-  };
-}(jQuery, cloudStack));
+            detailView: vnmcProviderDetailView
+        });
+    };
+}(jQuery, cloudStack));
\ No newline at end of file


Mime
View raw message