|
33 | 33 | 'Disabled': 'off' |
34 | 34 | }} |
35 | 35 | }, |
36 | | - dataProvider: function(args) { |
37 | | - args.response.success({ |
38 | | - data: [ |
39 | | - { name: 'device1', ipaddress: '192.168.1.12', state: 'Enabled' }, |
40 | | - { name: 'device2', ipaddress: '192.168.1.13', state: 'Disabled' }, |
41 | | - { name: 'device3', ipaddress: '192.168.1.14', state: 'Enabled' } |
42 | | - ] |
43 | | - }); |
| 36 | + |
| 37 | + actions: { |
| 38 | + add: { |
| 39 | + label: 'Add VNMC device', |
| 40 | + |
| 41 | + messages: { |
| 42 | + /* |
| 43 | + confirm: function(args) { |
| 44 | + return 'Add VNMC device'; |
| 45 | + }, |
| 46 | + */ |
| 47 | + notification: function(args) { |
| 48 | + return 'Add VNMC device'; |
| 49 | + } |
| 50 | + }, |
| 51 | + |
| 52 | + createForm: { |
| 53 | + title: 'Add VNMC device', |
| 54 | + fields: { |
| 55 | + hostname: { |
| 56 | + label: 'label.host', |
| 57 | + validation: { required: true } |
| 58 | + }, |
| 59 | + username: { |
| 60 | + label: 'label.username', |
| 61 | + validation: { required: true } |
| 62 | + }, |
| 63 | + password: { |
| 64 | + label: 'label.password', |
| 65 | + isPassword: true, |
| 66 | + validation: { required: true } |
| 67 | + } |
| 68 | + } |
| 69 | + }, |
| 70 | + |
| 71 | + action: function(args) { |
| 72 | + //debugger; |
| 73 | + $.ajax({ |
| 74 | + url: createURL('listNetworkServiceProviders'), |
| 75 | + data: { |
| 76 | + name: 'CiscoVnmc', |
| 77 | + physicalnetworkid: args.context.physicalNetworks[0].id |
| 78 | + }, |
| 79 | + success: function(json){ |
| 80 | + //debugger; |
| 81 | + var items = json.listnetworkserviceprovidersresponse.networkserviceprovider; |
| 82 | + if(items != null && items.length > 0) { |
| 83 | + var ciscoVnmcProvider = items[0]; |
| 84 | + if(ciscoVnmcProvider.state == 'Enabled') { |
| 85 | + addCiscoVnmcResourceFn(); |
| 86 | + } |
| 87 | + else { |
| 88 | + enableCiscoVnmcProviderFn(ciscoVnmcProvider); |
| 89 | + } |
| 90 | + } |
| 91 | + else { |
| 92 | + $.ajax({ |
| 93 | + url: createURL("addNetworkServiceProvider"), |
| 94 | + data: { |
| 95 | + name: 'CiscoVnmc', |
| 96 | + physicalnetworkid: args.context.physicalNetworks[0].id |
| 97 | + }, |
| 98 | + success: function(json) { |
| 99 | + var jobId = json.addnetworkserviceproviderresponse.jobid; |
| 100 | + var addVnmcProviderIntervalID = setInterval(function() { |
| 101 | + $.ajax({ |
| 102 | + url: createURL("queryAsyncJobResult&jobId="+jobId), |
| 103 | + dataType: "json", |
| 104 | + success: function(json) { |
| 105 | + var result = json.queryasyncjobresultresponse; |
| 106 | + //debugger; |
| 107 | + if (result.jobstatus == 0) { |
| 108 | + return; //Job has not completed |
| 109 | + } |
| 110 | + else { |
| 111 | + clearInterval(addVnmcProviderIntervalID ); |
| 112 | + if (result.jobstatus == 1) { |
| 113 | + //nspMap["CiscoVnmc"] = json.queryasyncjobresultresponse.jobresult.networkserviceprovider; |
| 114 | + var ciscoVnmcProvider = json.queryasyncjobresultresponse.jobresult.networkserviceprovider; |
| 115 | + enableCiscoVnmcProviderFn(ciscoVnmcProvider); |
| 116 | + } |
| 117 | + else if (result.jobstatus == 2) { |
| 118 | + args.response.error(_s(result.jobresult.errortext)); |
| 119 | + } |
| 120 | + } |
| 121 | + }, |
| 122 | + error: function(XMLHttpResponse) { |
| 123 | + args.response.error(parseXMLHttpResponse(data)); |
| 124 | + } |
| 125 | + }); |
| 126 | + }, g_queryAsyncJobResultInterval); |
| 127 | + } |
| 128 | + }); |
| 129 | + } |
| 130 | + } |
| 131 | + }); |
| 132 | + //debugger; |
| 133 | + |
| 134 | + var enableCiscoVnmcProviderFn = function(ciscoVnmcProvider){ |
| 135 | + $.ajax({ |
| 136 | + url: createURL('updateNetworkServiceProvider'), |
| 137 | + data: { |
| 138 | + id: ciscoVnmcProvider.id, |
| 139 | + state: 'Enabled' |
| 140 | + }, |
| 141 | + success: function(json) { |
| 142 | + var jid = json.updatenetworkserviceproviderresponse.jobid; |
| 143 | + var enableVnmcProviderIntervalID = setInterval(function(){ |
| 144 | + $.ajax({ |
| 145 | + url: createURL('queryAsyncJobResult'), |
| 146 | + data: { |
| 147 | + jobid: jid |
| 148 | + }, |
| 149 | + success: function(json){ |
| 150 | + var result = json.queryasyncjobresultresponse; |
| 151 | + if (result.jobstatus == 0) { |
| 152 | + return; //Job has not completed |
| 153 | + } |
| 154 | + else { |
| 155 | + clearInterval(enableVnmcProviderIntervalID); |
| 156 | + if (result.jobstatus == 1) { |
| 157 | + addCiscoVnmcResourceFn(); |
| 158 | + } |
| 159 | + else if (result.jobstatus == 2) { |
| 160 | + args.response.error(_s(result.jobresult.errortext)); |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + }); |
| 165 | + }, g_queryAsyncJobResultInterval); |
| 166 | + } |
| 167 | + }); |
| 168 | + } |
| 169 | + |
| 170 | + var addCiscoVnmcResourceFn = function(){ |
| 171 | + //debugger; |
| 172 | + var data = { |
| 173 | + physicalnetworkid: args.context.physicalNetworks[0].id, |
| 174 | + hostname: args.data.hostname, |
| 175 | + username: args.data.username, |
| 176 | + password: args.data.password |
| 177 | + }; |
| 178 | + |
| 179 | + $.ajax({ |
| 180 | + url: createURL('addCiscoVnmcResource'), |
| 181 | + data: data, |
| 182 | + success: function(json) { |
| 183 | + //debugger; |
| 184 | + var item = json.addciscovnmcresourceresponse.ciscovnmcresource; |
| 185 | + args.response.success({data: item}); |
| 186 | + }, |
| 187 | + error: function(data) { |
| 188 | + args.response.error(parseXMLHttpResponse(data)); |
| 189 | + } |
| 190 | + }); |
| 191 | + } |
| 192 | + }, |
| 193 | + |
| 194 | + notification: { |
| 195 | + poll: function(args) { |
| 196 | + args.complete(); |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + }, |
| 201 | + |
| 202 | + dataProvider: function(args) { |
| 203 | + $.ajax({ |
| 204 | + url: createURL('listCiscoVnmcResources'), |
| 205 | + data: { |
| 206 | + physicalnetworkid: args.context.physicalNetworks[0].id |
| 207 | + }, |
| 208 | + success: function(json){ |
| 209 | + args.response.success({ |
| 210 | + data: [ |
| 211 | + { name: 'device1', ipaddress: '192.168.1.12', state: 'Enabled' }, |
| 212 | + { name: 'device2', ipaddress: '192.168.1.13', state: 'Disabled' }, |
| 213 | + { name: 'device3', ipaddress: '192.168.1.14', state: 'Enabled' } |
| 214 | + ] |
| 215 | + }); |
| 216 | + } |
| 217 | + }); |
44 | 218 | } |
45 | 219 | }; |
46 | 220 |
|
|
0 commit comments