You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/07/18 18:34:55 UTC
[20/39] Format JS
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/storage.js
----------------------------------------------------------------------
diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js
index ad0965a..348ba7b 100644
--- a/ui/scripts/storage.js
+++ b/ui/scripts/storage.js
@@ -16,1712 +16,1900 @@
// under the License.
(function(cloudStack) {
- var diskofferingObjs, selectedDiskOfferingObj;
-
- cloudStack.sections.storage = {
- title: 'label.storage',
- id: 'storage',
- sectionSelect: {
- label: 'label.select-view'
- },
- sections: {
- /**
- * Volumes
- */
- volumes: {
- type: 'select',
- title: 'label.volumes',
- listView: {
- id: 'volumes',
- label: 'label.volumes',
- preFilter: function(args) {
- var hiddenFields = [];
- if(isAdmin() != true)
- hiddenFields.push('hypervisor');
- return hiddenFields;
- },
- fields: {
- name: { label: 'label.name' },
- type: { label: 'label.type' },
- hypervisor: { label: 'label.hypervisor' },
- vmdisplayname: { label: 'label.vm.display.name' }
-
- /*
- state: {
+ var diskofferingObjs, selectedDiskOfferingObj;
+
+ cloudStack.sections.storage = {
+ title: 'label.storage',
+ id: 'storage',
+ sectionSelect: {
+ label: 'label.select-view'
+ },
+ sections: {
+ /**
+ * Volumes
+ */
+ volumes: {
+ type: 'select',
+ title: 'label.volumes',
+ listView: {
+ id: 'volumes',
+ label: 'label.volumes',
+ preFilter: function(args) {
+ var hiddenFields = [];
+ if (isAdmin() != true)
+ hiddenFields.push('hypervisor');
+ return hiddenFields;
+ },
+ fields: {
+ name: {
+ label: 'label.name'
+ },
+ type: {
+ label: 'label.type'
+ },
+ hypervisor: {
+ label: 'label.hypervisor'
+ },
+ vmdisplayname: {
+ label: 'label.vm.display.name'
+ }
+
+ /*
+ state: {
label: 'State',
- indicator: {
+ indicator: {
'Ready': 'on'
}
}
*/
- },
-
- // List view actions
- actions: {
- // Add volume
- add: {
- label: 'label.add.volume',
-
- messages: {
- confirm: function(args) {
- return 'message.add.volume';
- },
- notification: function(args) {
- return 'label.add.volume';
- }
- },
-
- createForm: {
- title: 'label.add.volume',
- desc: 'message.add.volume',
- fields: {
- name: {
- docID: 'helpVolumeName',
- label: 'label.name',
- validation: { required: true }
- },
- availabilityZone: {
- label: 'label.availability.zone',
- docID: 'helpVolumeAvailabilityZone',
- select: function(args) {
- $.ajax({
- url: createURL("listZones&available=true"),
- dataType: "json",
- async: true,
- success: function(json) {
- var zoneObjs = json.listzonesresponse.zone;
- args.response.success({descriptionField: 'name', data: zoneObjs});
- }
- });
- }
- },
- diskOffering: {
- label: 'label.disk.offering',
- docID: 'helpVolumeDiskOffering',
- select: function(args) {
- $.ajax({
- url: createURL("listDiskOfferings"),
- dataType: "json",
- async: false,
- success: function(json) {
- diskofferingObjs = json.listdiskofferingsresponse.diskoffering;
- var items = [];
- $(diskofferingObjs).each(function(){
- items.push({id: this.id, description: this.displaytext});
- });
- args.response.success({data: items});
- }
- });
-
- args.$select.change(function() {
- var diskOfferingId = $(this).val();
- $(diskofferingObjs).each(function(){
- if(this.id == diskOfferingId) {
- selectedDiskOfferingObj = this;
- return false; //break the $.each() loop
- }
- });
- if(selectedDiskOfferingObj == null)
- return;
+ },
- var $form = $(this).closest('form');
- var $diskSize = $form.find('.form-item[rel=diskSize]');
- if (selectedDiskOfferingObj.iscustomized == true) {
- $diskSize.css('display', 'inline-block');
- }
- else {
- $diskSize.hide();
- }
- var $minIops = $form.find('.form-item[rel=minIops]');
- var $maxIops = $form.find('.form-item[rel=maxIops]');
- if (selectedDiskOfferingObj.iscustomizediops == true) {
- $minIops.css('display', 'inline-block');
- $maxIops.css('display', 'inline-block');
- }
- else {
- $minIops.hide();
- $maxIops.hide();
- }
- });
- }
- }
-
- ,
- diskSize: {
- label: 'label.disk.size.gb',
- validation: { required: true, number: true },
- isHidden: true
- },
-
- minIops: {
- label: 'label.disk.iops.min',
- validation: { required: false, number: true },
- isHidden: true
- },
-
- maxIops: {
- label: 'label.disk.iops.max',
- validation: { required: false, number: true },
- isHidden: true
- },
+ // List view actions
+ actions: {
+ // Add volume
+ add: {
+ label: 'label.add.volume',
+
+ messages: {
+ confirm: function(args) {
+ return 'message.add.volume';
+ },
+ notification: function(args) {
+ return 'label.add.volume';
+ }
+ },
- }
- },
-
- action: function(args) {
- var data = {
- name: args.data.name,
- zoneId: args.data.availabilityZone,
- diskOfferingId: args.data.diskOffering
- };
-
- // if(thisDialog.find("#size_container").css("display") != "none") { //wait for Brian to include $form in args
- if (selectedDiskOfferingObj.iscustomized == true) {
- $.extend(data, {
- size: args.data.diskSize
- });
- }
-
- if (selectedDiskOfferingObj.iscustomizediops == true) {
- if (args.data.minIops != "" && args.data.minIops > 0) {
- $.extend(data, {
- miniops: args.data.minIops
- });
- }
-
- if (args.data.maxIops != "" && args.data.maxIops > 0) {
- $.extend(data, {
- maxiops: args.data.maxIops
- });
- }
- }
+ createForm: {
+ title: 'label.add.volume',
+ desc: 'message.add.volume',
+ fields: {
+ name: {
+ docID: 'helpVolumeName',
+ label: 'label.name',
+ validation: {
+ required: true
+ }
+ },
+ availabilityZone: {
+ label: 'label.availability.zone',
+ docID: 'helpVolumeAvailabilityZone',
+ select: function(args) {
+ $.ajax({
+ url: createURL("listZones&available=true"),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var zoneObjs = json.listzonesresponse.zone;
+ args.response.success({
+ descriptionField: 'name',
+ data: zoneObjs
+ });
+ }
+ });
+ }
+ },
+ diskOffering: {
+ label: 'label.disk.offering',
+ docID: 'helpVolumeDiskOffering',
+ select: function(args) {
+ $.ajax({
+ url: createURL("listDiskOfferings"),
+ dataType: "json",
+ async: false,
+ success: function(json) {
+ diskofferingObjs = json.listdiskofferingsresponse.diskoffering;
+ var items = [];
+ $(diskofferingObjs).each(function() {
+ items.push({
+ id: this.id,
+ description: this.displaytext
+ });
+ });
+ args.response.success({
+ data: items
+ });
+ }
+ });
+
+ args.$select.change(function() {
+ var diskOfferingId = $(this).val();
+ $(diskofferingObjs).each(function() {
+ if (this.id == diskOfferingId) {
+ selectedDiskOfferingObj = this;
+ return false; //break the $.each() loop
+ }
+ });
+ if (selectedDiskOfferingObj == null)
+ return;
+
+ var $form = $(this).closest('form');
+ var $diskSize = $form.find('.form-item[rel=diskSize]');
+ if (selectedDiskOfferingObj.iscustomized == true) {
+ $diskSize.css('display', 'inline-block');
+ } else {
+ $diskSize.hide();
+ }
+ var $minIops = $form.find('.form-item[rel=minIops]');
+ var $maxIops = $form.find('.form-item[rel=maxIops]');
+ if (selectedDiskOfferingObj.iscustomizediops == true) {
+ $minIops.css('display', 'inline-block');
+ $maxIops.css('display', 'inline-block');
+ } else {
+ $minIops.hide();
+ $maxIops.hide();
+ }
+ });
+ }
+ }
+
+ ,
+ diskSize: {
+ label: 'label.disk.size.gb',
+ validation: {
+ required: true,
+ number: true
+ },
+ isHidden: true
+ },
+
+ minIops: {
+ label: 'label.disk.iops.min',
+ validation: {
+ required: false,
+ number: true
+ },
+ isHidden: true
+ },
+
+ maxIops: {
+ label: 'label.disk.iops.max',
+ validation: {
+ required: false,
+ number: true
+ },
+ isHidden: true
+ },
+
+ }
+ },
+
+ action: function(args) {
+ var data = {
+ name: args.data.name,
+ zoneId: args.data.availabilityZone,
+ diskOfferingId: args.data.diskOffering
+ };
+
+ // if(thisDialog.find("#size_container").css("display") != "none") { //wait for Brian to include $form in args
+ if (selectedDiskOfferingObj.iscustomized == true) {
+ $.extend(data, {
+ size: args.data.diskSize
+ });
+ }
+
+ if (selectedDiskOfferingObj.iscustomizediops == true) {
+ if (args.data.minIops != "" && args.data.minIops > 0) {
+ $.extend(data, {
+ miniops: args.data.minIops
+ });
+ }
+
+ if (args.data.maxIops != "" && args.data.maxIops > 0) {
+ $.extend(data, {
+ maxiops: args.data.maxIops
+ });
+ }
+ }
+
+ $.ajax({
+ url: createURL('createVolume'),
+ data: data,
+ success: function(json) {
+ var jid = json.createvolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function(json) {
+ return json.queryasyncjobresultresponse.jobresult.volume;
+ },
+ getActionFilter: function() {
+ return volumeActionfilter;
+ }
+ }
+ });
+ },
+ error: function(json) {
+ args.response.error(parseXMLHttpResponse(json));
+ }
+ });
+ },
- $.ajax({
- url: createURL('createVolume'),
- data: data,
- success: function(json) {
- var jid = json.createvolumeresponse.jobid;
- args.response.success(
- {_custom:
- {jobId: jid,
- getUpdatedItem: function(json) {
- return json.queryasyncjobresultresponse.jobresult.volume;
+ notification: {
+ poll: pollAsyncJobResult
+ }
},
- getActionFilter: function() {
- return volumeActionfilter;
- }
- }
- }
- );
- },
- error: function(json) {
- args.response.error(parseXMLHttpResponse(json));
- }
- });
- },
-
- notification: {
- poll: pollAsyncJobResult
- }
- },
-
- uploadVolume: {
- isHeader: true,
- label: 'label.upload.volume',
- messages: {
- notification: function() {
- return 'label.upload.volume';
- }
- },
- createForm: {
- title: 'label.upload.volume',
- fields: {
- name: {
- label: 'label.name',
- validation: { required: true },
- docID: 'helpUploadVolumeName'
- },
- availabilityZone: {
- label: 'label.availability.zone',
- docID: 'helpUploadVolumeZone',
- select: function(args) {
- $.ajax({
- url: createURL("listZones&available=true"),
- dataType: "json",
- async: true,
- success: function(json) {
- var zoneObjs = json.listzonesresponse.zone;
- args.response.success({descriptionField: 'name', data: zoneObjs});
- }
- });
- }
- },
- format: {
- label: 'label.format',
- docID: 'helpUploadVolumeFormat',
- select: function(args) {
- var items = [];
- items.push({ id: 'RAW', description: 'RAW' });
- items.push({ id: 'VHD', description: 'VHD' });
- items.push({ id: 'OVA', description: 'OVA' });
- items.push({ id: 'QCOW2', description: 'QCOW2' });
- args.response.success({ data: items });
- }
- },
- url: {
- label: 'label.url',
- docID: 'helpUploadVolumeURL',
- validation: { required: true }
- },
- checksum : {
- docID: 'helpUploadVolumeChecksum',
- label: 'label.checksum'
- }
- }
- },
-
- action: function(args) {
- var data = {
- name: args.data.name,
- zoneId: args.data.availabilityZone,
- format: args.data.format,
- url: args.data.url
- };
-
- if(args.data.checksum != null && args.data.checksum.length > 0) {
- $.extend(data, {
- checksum: args.data.checksum
- });
- }
-
- $.ajax({
- url: createURL('uploadVolume'),
- data: data,
- success: function(json) {
- var jid = json.uploadvolumeresponse.jobid;
- args.response.success(
- {_custom:
- {jobId: jid,
- getUpdatedItem: function(json) {
- return json.queryasyncjobresultresponse.jobresult.volume;
- },
- getActionFilter: function() {
- return volumeActionfilter;
- }
- }
- }
- );
- },
- error: function(json) {
- args.response.error(parseXMLHttpResponse(json));
- }
- });
- },
-
- notification: {
- poll: pollAsyncJobResult
- }
- }
- },
-
- advSearchFields: {
- name: { label: 'Name' },
- zoneid: {
- label: 'Zone',
- select: function(args) {
- $.ajax({
- url: createURL('listZones'),
- data: {
- listAll: true
- },
- success: function(json) {
- var zones = json.listzonesresponse.zone ? json.listzonesresponse.zone : [];
-
- args.response.success({
- data: $.map(zones, function(zone) {
- return {
- id: zone.id,
- description: zone.name
- };
- })
- });
- }
- });
- }
- },
-
- domainid: {
- label: 'Domain',
- select: function(args) {
- if(isAdmin() || isDomainAdmin()) {
- $.ajax({
- url: createURL('listDomains'),
- data: {
- listAll: true,
- details: 'min'
- },
- success: function(json) {
- var array1 = [{id: '', description: ''}];
- var domains = json.listdomainsresponse.domain;
- if(domains != null && domains.length > 0) {
- for(var i = 0; i < domains.length; i++) {
- array1.push({id: domains[i].id, description: domains[i].path});
- }
- }
- args.response.success({
- data: array1
- });
- }
- });
- }
- else {
- args.response.success({
- data: null
- });
- }
- },
- isHidden: function(args) {
- if(isAdmin() || isDomainAdmin())
- return false;
- else
- return true;
- }
- },
-
- account: {
- label: 'Account',
- isHidden: function(args) {
- if(isAdmin() || isDomainAdmin())
- return false;
- else
- return true;
- }
- },
-
- tagKey: { label: 'Tag Key' },
- tagValue: { label: 'Tag Value' }
- },
-
- dataProvider: function(args) {
- var data = {};
- listViewDataProvider(args, data);
-
- if(args.context != null) {
- if("instances" in args.context) {
- $.extend(data, {
- virtualMachineId: args.context.instances[0].id
- });
- }
- }
-
- $.ajax({
- url: createURL('listVolumes'),
- data: data,
- success: function(json) {
- var items = json.listvolumesresponse.volume;
- args.response.success({
- actionFilter: volumeActionfilter,
- data: items
- });
- }
- });
- },
-
- detailView: {
- name: 'Volume details',
- viewAll: { path: 'storage.snapshots', label: 'label.snapshots' },
- actions: {
-
- migrateVolume:{
- label:'Migrate Volume',
- messages: {
- confirm: function(args) {
- return 'Do you want to migrate this volume ?' ;
- },
- notification: function(args) {
- return 'Volume migrated';
- }
- },
-
- createForm: {
- title: 'Migrate Volume',
- desc: '',
- fields: {
- storagePool: {
- label: 'Storage Pool',
- validation: { required: true },
- select: function(args) {
- $.ajax({
- url: createURL("findStoragePoolsForMigration&id=" + args.context.volumes[0].id),
- dataType: "json",
- async: true,
- success: function(json) {
- var pools = json.findstoragepoolsformigrationresponse.storagepool;
- var items = [];
- $(pools).each(function() {
- items.push({id: this.id, description: this.name + " (" + (this.suitableformigration? "Suitable": "Not Suitable")+")" });
- });
- args.response.success({data: items});
-
- }
- });
- }
- }
- }
-
- },
- action: function(args) {
- $.ajax({
- url: createURL("migrateVolume&livemigrate=true&storageid=" + args.data.storagePool + "&volumeid=" + args.context.volumes[0].id ),
- dataType: "json",
- async: true,
- success: function(json) {
- var jid = json.migratevolumeresponse.jobid;
- args.response.success(
- {_custom:
- {
- jobId: jid
- }
- }
- );
- }
- });
- },
- notification: {
- poll: pollAsyncJobResult
- }
+ uploadVolume: {
+ isHeader: true,
+ label: 'label.upload.volume',
+ messages: {
+ notification: function() {
+ return 'label.upload.volume';
+ }
+ },
+ createForm: {
+ title: 'label.upload.volume',
+ fields: {
+ name: {
+ label: 'label.name',
+ validation: {
+ required: true
+ },
+ docID: 'helpUploadVolumeName'
+ },
+ availabilityZone: {
+ label: 'label.availability.zone',
+ docID: 'helpUploadVolumeZone',
+ select: function(args) {
+ $.ajax({
+ url: createURL("listZones&available=true"),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var zoneObjs = json.listzonesresponse.zone;
+ args.response.success({
+ descriptionField: 'name',
+ data: zoneObjs
+ });
+ }
+ });
+ }
+ },
+ format: {
+ label: 'label.format',
+ docID: 'helpUploadVolumeFormat',
+ select: function(args) {
+ var items = [];
+ items.push({
+ id: 'RAW',
+ description: 'RAW'
+ });
+ items.push({
+ id: 'VHD',
+ description: 'VHD'
+ });
+ items.push({
+ id: 'OVA',
+ description: 'OVA'
+ });
+ items.push({
+ id: 'QCOW2',
+ description: 'QCOW2'
+ });
+ args.response.success({
+ data: items
+ });
+ }
+ },
+ url: {
+ label: 'label.url',
+ docID: 'helpUploadVolumeURL',
+ validation: {
+ required: true
+ }
+ },
+ checksum: {
+ docID: 'helpUploadVolumeChecksum',
+ label: 'label.checksum'
+ }
+ }
+ },
- },
-
- takeSnapshot: {
- label: 'label.action.take.snapshot',
- messages: {
- confirm: function(args) {
- return 'message.action.take.snapshot' ;
- },
- notification: function(args) {
- return 'label.action.take.snapshot';
- }
- },
- action: function(args) {
- $.ajax({
- url: createURL("createSnapshot&volumeid=" + args.context.volumes[0].id),
- dataType: "json",
- async: true,
- success: function(json) {
- var jid = json.createsnapshotresponse.jobid;
- args.response.success(
- {_custom:
- {
- jobId: jid //take snapshot from a volume doesn't change any property in this volume. So, don't need to specify getUpdatedItem() to return updated volume. Besides, createSnapshot API doesn't return updated volume.
- }
+ action: function(args) {
+ var data = {
+ name: args.data.name,
+ zoneId: args.data.availabilityZone,
+ format: args.data.format,
+ url: args.data.url
+ };
+
+ if (args.data.checksum != null && args.data.checksum.length > 0) {
+ $.extend(data, {
+ checksum: args.data.checksum
+ });
+ }
+
+ $.ajax({
+ url: createURL('uploadVolume'),
+ data: data,
+ success: function(json) {
+ var jid = json.uploadvolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function(json) {
+ return json.queryasyncjobresultresponse.jobresult.volume;
+ },
+ getActionFilter: function() {
+ return volumeActionfilter;
+ }
+ }
+ });
+ },
+ error: function(json) {
+ args.response.error(parseXMLHttpResponse(json));
+ }
+ });
+ },
+
+ notification: {
+ poll: pollAsyncJobResult
+ }
}
- );
- }
- });
- },
- notification: {
- poll: pollAsyncJobResult
- }
- },
+ },
- recurringSnapshot: {
- label: 'label.snapshot.schedule',
- action: {
- custom: cloudStack.uiCustom.recurringSnapshots({
- desc: 'message.snapshot.schedule',
- dataProvider: function(args) {
- $.ajax({
- url: createURL('listSnapshotPolicies'),
- data: {
- volumeid: args.context.volumes[0].id
+ advSearchFields: {
+ name: {
+ label: 'Name'
},
- async: true,
- dataType: 'json',
- success: function(data) {
- args.response.success({
- data: $.map(
- data.listsnapshotpoliciesresponse.snapshotpolicy ? data.listsnapshotpoliciesresponse.snapshotpolicy : [],
- function(snapshot, index) {
- return {
- id: snapshot.id,
- type: snapshot.intervaltype,
- time: snapshot.intervaltype > 0 ?
- snapshot.schedule.split(':')[1] + ':' + snapshot.schedule.split(':')[0] :
- snapshot.schedule,
- timezone: snapshot.timezone,
- keep: snapshot.maxsnaps,
- 'day-of-week': snapshot.intervaltype == 2 ?
- snapshot.schedule.split(':')[2] : null,
- 'day-of-month': snapshot.intervaltype == 3 ?
- snapshot.schedule.split(':')[2] : null
- };
- }
- )
- });
+ zoneid: {
+ label: 'Zone',
+ select: function(args) {
+ $.ajax({
+ url: createURL('listZones'),
+ data: {
+ listAll: true
+ },
+ success: function(json) {
+ var zones = json.listzonesresponse.zone ? json.listzonesresponse.zone : [];
+
+ args.response.success({
+ data: $.map(zones, function(zone) {
+ return {
+ id: zone.id,
+ description: zone.name
+ };
+ })
+ });
+ }
+ });
+ }
+ },
+
+ domainid: {
+ label: 'Domain',
+ select: function(args) {
+ if (isAdmin() || isDomainAdmin()) {
+ $.ajax({
+ url: createURL('listDomains'),
+ data: {
+ listAll: true,
+ details: 'min'
+ },
+ success: function(json) {
+ var array1 = [{
+ id: '',
+ description: ''
+ }];
+ var domains = json.listdomainsresponse.domain;
+ if (domains != null && domains.length > 0) {
+ for (var i = 0; i < domains.length; i++) {
+ array1.push({
+ id: domains[i].id,
+ description: domains[i].path
+ });
+ }
+ }
+ args.response.success({
+ data: array1
+ });
+ }
+ });
+ } else {
+ args.response.success({
+ data: null
+ });
+ }
+ },
+ isHidden: function(args) {
+ if (isAdmin() || isDomainAdmin())
+ return false;
+ else
+ return true;
+ }
+ },
+
+ account: {
+ label: 'Account',
+ isHidden: function(args) {
+ if (isAdmin() || isDomainAdmin())
+ return false;
+ else
+ return true;
+ }
+ },
+
+ tagKey: {
+ label: 'Tag Key'
+ },
+ tagValue: {
+ label: 'Tag Value'
}
- });
},
- actions: {
- add: function(args) {
- var snap = args.snapshot;
-
- var data = {
- keep: snap.maxsnaps,
- timezone: snap.timezone
- };
-
- var convertTime = function(minute, hour, meridiem, extra) {
- var convertedHour = meridiem == 'PM' ?
- (hour != 12 ? parseInt(hour) + 12 : 12) : (hour != 12 ? hour : '00');
- var time = minute + ':' + convertedHour;
- if (extra) time += ':' + extra;
-
- return time;
- };
-
- switch (snap['snapshot-type']) {
- case 'hourly': // Hourly
- $.extend(data, {
- schedule: snap.schedule
- }); break;
-
- case 'daily': // Daily
- $.extend(data, {
- schedule: convertTime(
- snap['time-minute'],
- snap['time-hour'],
- snap['time-meridiem']
- )
- }); break;
-
- case 'weekly': // Weekly
- $.extend(data, {
- schedule: convertTime(
- snap['time-minute'],
- snap['time-hour'],
- snap['time-meridiem'],
- snap['day-of-week']
- )
- }); break;
-
- case 'monthly': // Monthly
- $.extend(data, {
- schedule: convertTime(
- snap['time-minute'],
- snap['time-hour'],
- snap['time-meridiem'],
- snap['day-of-month']
- )
- }); break;
+
+ dataProvider: function(args) {
+ var data = {};
+ listViewDataProvider(args, data);
+
+ if (args.context != null) {
+ if ("instances" in args.context) {
+ $.extend(data, {
+ virtualMachineId: args.context.instances[0].id
+ });
+ }
}
$.ajax({
- url: createURL('createSnapshotPolicy'),
- data: {
- volumeid: args.context.volumes[0].id,
- intervaltype: snap['snapshot-type'],
- maxsnaps: snap.maxsnaps,
- schedule: data.schedule,
- timezone: snap.timezone
- },
- dataType: 'json',
- async: true,
- success: function(successData) {
- var snapshot = successData.createsnapshotpolicyresponse.snapshotpolicy;
-
- args.response.success({
- data: {
- id: snapshot.id,
- type: snapshot.intervaltype,
- time: snapshot.intervaltype > 0 ?
- snapshot.schedule.split(':')[1] + ':' + snapshot.schedule.split(':')[0] :
- snapshot.schedule,
- timezone: snapshot.timezone,
- keep: snapshot.maxsnaps,
- 'day-of-week': snapshot.intervaltype == 2 ?
- snapshot.schedule.split(':')[2] : null,
- 'day-of-month': snapshot.intervaltype == 3 ?
- snapshot.schedule.split(':')[2] : null
- }
- });
- }
- });
- },
- remove: function(args) {
- $.ajax({
- url: createURL('deleteSnapshotPolicies'),
- data: {
- id: args.snapshot.id
- },
- dataType: 'json',
- async: true,
- success: function(data) {
- args.response.success();
- }
+ url: createURL('listVolumes'),
+ data: data,
+ success: function(json) {
+ var items = json.listvolumesresponse.volume;
+ args.response.success({
+ actionFilter: volumeActionfilter,
+ data: items
+ });
+ }
});
- }
},
- // Select data
- selects: {
- schedule: function(args) {
- var time = [];
-
- for (var i = 1; i <= 59; i++) {
- time.push({
- id: i,
- name: i
- });
- }
+ detailView: {
+ name: 'Volume details',
+ viewAll: {
+ path: 'storage.snapshots',
+ label: 'label.snapshots'
+ },
+ actions: {
+
+ migrateVolume: {
+ label: 'Migrate Volume',
+ messages: {
+ confirm: function(args) {
+ return 'Do you want to migrate this volume ?';
+ },
+ notification: function(args) {
+ return 'Volume migrated';
+ }
+ },
+
+ createForm: {
+ title: 'Migrate Volume',
+ desc: '',
+ fields: {
+ storagePool: {
+ label: 'Storage Pool',
+ validation: {
+ required: true
+ },
+ select: function(args) {
+ $.ajax({
+ url: createURL("findStoragePoolsForMigration&id=" + args.context.volumes[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var pools = json.findstoragepoolsformigrationresponse.storagepool;
+ var items = [];
+ $(pools).each(function() {
+ items.push({
+ id: this.id,
+ description: this.name + " (" + (this.suitableformigration ? "Suitable" : "Not Suitable") + ")"
+ });
+ });
+ args.response.success({
+ data: items
+ });
+
+ }
+ });
+ }
+ }
+ }
+
+ },
+
+ action: function(args) {
+ $.ajax({
+ url: createURL("migrateVolume&livemigrate=true&storageid=" + args.data.storagePool + "&volumeid=" + args.context.volumes[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.migratevolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
- args.response.success({
- data: time
- });
- },
- timezone: function(args) {
- args.response.success({
- data: $.map(timezoneMap, function(value, key) {
- return {
- id: key,
- name: value
- };
- })
- });
- },
- 'day-of-week': function(args) {
- args.response.success({
- data: [
- { id: 1, name: 'label.sunday' },
- { id: 2, name: 'label.monday' },
- { id: 3, name: 'label.tuesday' },
- { id: 4, name: 'label.wednesday' },
- { id: 5, name: 'label.thursday' },
- { id: 6, name: 'label.friday' },
- { id: 7, name: 'label.saturday' }
- ]
- });
- },
+ },
- 'day-of-month': function(args) {
- var time = [];
+ takeSnapshot: {
+ label: 'label.action.take.snapshot',
+ messages: {
+ confirm: function(args) {
+ return 'message.action.take.snapshot';
+ },
+ notification: function(args) {
+ return 'label.action.take.snapshot';
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("createSnapshot&volumeid=" + args.context.volumes[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.createsnapshotresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid //take snapshot from a volume doesn't change any property in this volume. So, don't need to specify getUpdatedItem() to return updated volume. Besides, createSnapshot API doesn't return updated volume.
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
- for (var i = 1; i <= 31; i++) {
- time.push({
- id: i,
- name: i
- });
- }
+ recurringSnapshot: {
+ label: 'label.snapshot.schedule',
+ action: {
+ custom: cloudStack.uiCustom.recurringSnapshots({
+ desc: 'message.snapshot.schedule',
+ dataProvider: function(args) {
+ $.ajax({
+ url: createURL('listSnapshotPolicies'),
+ data: {
+ volumeid: args.context.volumes[0].id
+ },
+ async: true,
+ dataType: 'json',
+ success: function(data) {
+ args.response.success({
+ data: $.map(
+ data.listsnapshotpoliciesresponse.snapshotpolicy ? data.listsnapshotpoliciesresponse.snapshotpolicy : [],
+ function(snapshot, index) {
+ return {
+ id: snapshot.id,
+ type: snapshot.intervaltype,
+ time: snapshot.intervaltype > 0 ? snapshot.schedule.split(':')[1] + ':' + snapshot.schedule.split(':')[0] : snapshot.schedule,
+ timezone: snapshot.timezone,
+ keep: snapshot.maxsnaps,
+ 'day-of-week': snapshot.intervaltype == 2 ? snapshot.schedule.split(':')[2] : null,
+ 'day-of-month': snapshot.intervaltype == 3 ? snapshot.schedule.split(':')[2] : null
+ };
+ }
+ )
+ });
+ }
+ });
+ },
+ actions: {
+ add: function(args) {
+ var snap = args.snapshot;
+
+ var data = {
+ keep: snap.maxsnaps,
+ timezone: snap.timezone
+ };
+
+ var convertTime = function(minute, hour, meridiem, extra) {
+ var convertedHour = meridiem == 'PM' ?
+ (hour != 12 ? parseInt(hour) + 12 : 12) : (hour != 12 ? hour : '00');
+ var time = minute + ':' + convertedHour;
+ if (extra) time += ':' + extra;
+
+ return time;
+ };
+
+ switch (snap['snapshot-type']) {
+ case 'hourly': // Hourly
+ $.extend(data, {
+ schedule: snap.schedule
+ });
+ break;
+
+ case 'daily': // Daily
+ $.extend(data, {
+ schedule: convertTime(
+ snap['time-minute'],
+ snap['time-hour'],
+ snap['time-meridiem']
+ )
+ });
+ break;
+
+ case 'weekly': // Weekly
+ $.extend(data, {
+ schedule: convertTime(
+ snap['time-minute'],
+ snap['time-hour'],
+ snap['time-meridiem'],
+ snap['day-of-week']
+ )
+ });
+ break;
+
+ case 'monthly': // Monthly
+ $.extend(data, {
+ schedule: convertTime(
+ snap['time-minute'],
+ snap['time-hour'],
+ snap['time-meridiem'],
+ snap['day-of-month']
+ )
+ });
+ break;
+ }
+
+ $.ajax({
+ url: createURL('createSnapshotPolicy'),
+ data: {
+ volumeid: args.context.volumes[0].id,
+ intervaltype: snap['snapshot-type'],
+ maxsnaps: snap.maxsnaps,
+ schedule: data.schedule,
+ timezone: snap.timezone
+ },
+ dataType: 'json',
+ async: true,
+ success: function(successData) {
+ var snapshot = successData.createsnapshotpolicyresponse.snapshotpolicy;
+
+ args.response.success({
+ data: {
+ id: snapshot.id,
+ type: snapshot.intervaltype,
+ time: snapshot.intervaltype > 0 ? snapshot.schedule.split(':')[1] + ':' + snapshot.schedule.split(':')[0] : snapshot.schedule,
+ timezone: snapshot.timezone,
+ keep: snapshot.maxsnaps,
+ 'day-of-week': snapshot.intervaltype == 2 ? snapshot.schedule.split(':')[2] : null,
+ 'day-of-month': snapshot.intervaltype == 3 ? snapshot.schedule.split(':')[2] : null
+ }
+ });
+ }
+ });
+ },
+ remove: function(args) {
+ $.ajax({
+ url: createURL('deleteSnapshotPolicies'),
+ data: {
+ id: args.snapshot.id
+ },
+ dataType: 'json',
+ async: true,
+ success: function(data) {
+ args.response.success();
+ }
+ });
+ }
+ },
+
+ // Select data
+ selects: {
+ schedule: function(args) {
+ var time = [];
+
+ for (var i = 1; i <= 59; i++) {
+ time.push({
+ id: i,
+ name: i
+ });
+ }
+
+ args.response.success({
+ data: time
+ });
+ },
+ timezone: function(args) {
+ args.response.success({
+ data: $.map(timezoneMap, function(value, key) {
+ return {
+ id: key,
+ name: value
+ };
+ })
+ });
+ },
+ 'day-of-week': function(args) {
+ args.response.success({
+ data: [{
+ id: 1,
+ name: 'label.sunday'
+ }, {
+ id: 2,
+ name: 'label.monday'
+ }, {
+ id: 3,
+ name: 'label.tuesday'
+ }, {
+ id: 4,
+ name: 'label.wednesday'
+ }, {
+ id: 5,
+ name: 'label.thursday'
+ }, {
+ id: 6,
+ name: 'label.friday'
+ }, {
+ id: 7,
+ name: 'label.saturday'
+ }]
+ });
+ },
+
+ 'day-of-month': function(args) {
+ var time = [];
+
+ for (var i = 1; i <= 31; i++) {
+ time.push({
+ id: i,
+ name: i
+ });
+ }
+
+ args.response.success({
+ data: time
+ });
+ },
+
+ 'time-hour': function(args) {
+ var time = [];
+
+ for (var i = 1; i <= 12; i++) {
+ time.push({
+ id: i,
+ name: i
+ });
+ }
+
+ args.response.success({
+ data: time
+ });
+ },
+
+ 'time-minute': function(args) {
+ var time = [];
+
+ for (var i = 0; i <= 59; i++) {
+ time.push({
+ id: i < 10 ? '0' + i : i,
+ name: i < 10 ? '0' + i : i
+ });
+ }
+
+ args.response.success({
+ data: time
+ });
+ },
+
+ 'time-meridiem': function(args) {
+ args.response.success({
+ data: [{
+ id: 'AM',
+ name: 'AM'
+ }, {
+ id: 'PM',
+ name: 'PM'
+ }]
+ });
+ }
+ }
+ })
+ },
+ messages: {
+ notification: function(args) {
+ return 'label.snapshot.schedule';
+ }
+ }
+ },
- args.response.success({
- data: time
- });
- },
+ attachDisk: {
+ addRow: 'false',
+ label: 'label.action.attach.disk',
+ messages: {
+ confirm: function(args) {
+ return 'Are you sure you want to attach disk?';
+ },
+ notification: function(args) {
+ return 'label.action.attach.disk';
+ }
+ },
+ createForm: {
+ title: 'label.action.attach.disk',
+ desc: 'label.action.attach.disk',
+ fields: {
+ virtualMachineId: {
+ label: 'label.instance',
+ select: function(args) {
+ var zoneid = args.context.volumes[0].zoneid;
+ var items = [];
+ var data;
+
+ if (!args.context.projects) {
+ data = {
+ zoneid: zoneid,
+ domainid: args.context.volumes[0].domainid,
+ account: args.context.volumes[0].account
+ };
+ } else {
+ data = {
+ zoneid: zoneid,
+ projectid: args.context.projects[0].id
+ };
+ }
+
+ if (args.context.volumes[0].hypervisor != null && args.context.volumes[0].hypervisor.length > 0 && args.context.volumes[0].hypervisor != 'None') {
+ data = $.extend(data, {
+ hypervisor: args.context.volumes[0].hypervisor
+ });
+ }
+
+ $(['Running', 'Stopped']).each(function() {
+ $.ajax({
+ url: createURL('listVirtualMachines'),
+ data: $.extend(data, {
+ state: this.toString()
+ }),
+ async: false,
+ success: function(json) {
+ var instanceObjs = json.listvirtualmachinesresponse.virtualmachine;
+ $(instanceObjs).each(function() {
+ items.push({
+ id: this.id,
+ description: this.displayname ? this.displayname : this.name
+ });
+ });
+ }
+ });
+ });
+
+ args.response.success({
+ data: items
+ });
+ }
+ }
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("attachVolume&id=" + args.context.volumes[0].id + '&virtualMachineId=' + args.data.virtualMachineId),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.attachvolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function(json) {
+ return json.queryasyncjobresultresponse.jobresult.volume;
+ },
+ getActionFilter: function() {
+ return volumeActionfilter;
+ }
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
+ detachDisk: {
+ label: 'label.action.detach.disk',
+ messages: {
+ confirm: function(args) {
+ return 'message.detach.disk';
+ },
+ notification: function(args) {
+ return 'label.action.detach.disk';
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("detachVolume&id=" + args.context.volumes[0].id),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.detachvolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function(json) {
+ return {
+ virtualmachineid: null,
+ vmname: null
+ };
+ },
+ getActionFilter: function() {
+ return volumeActionfilter;
+ }
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
- 'time-hour': function(args) {
- var time = [];
+ downloadVolume: {
+ label: 'label.action.download.volume',
+ messages: {
+ confirm: function(args) {
+ return 'message.download.volume.confirm';
+ },
+ notification: function(args) {
+ return 'label.action.download.volume';
+ },
+ complete: function(args) {
+ var url = decodeURIComponent(args.url);
+ var htmlMsg = _l('message.download.volume');
+ var htmlMsg2 = htmlMsg.replace(/#/, url).replace(/00000/, url);
+ //$infoContainer.find("#info").html(htmlMsg2);
+ return htmlMsg2;
+ }
+ },
+ action: function(args) {
+ $.ajax({
+ url: createURL("extractVolume&id=" + args.context.volumes[0].id + "&zoneid=" + args.context.volumes[0].zoneid + "&mode=HTTP_DOWNLOAD"),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var jid = json.extractvolumeresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function(json) {
+ return json.queryasyncjobresultresponse.jobresult.volume;
+ },
+ getActionFilter: function() {
+ return volumeActionfilter;
+ }
+ }
+ });
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult
+ }
+ },
- for (var i = 1; i <= 12; i++) {
- time.push({
- id: i,
- name: i
- });
- }
+ createTemplate: {
+ label: 'label.create.template',
+ messages: {
+ confirm: function(args) {
+ return 'message.create.template';
+ },
+ notification: function(args) {
+ return 'label.create.template';
+ }
+ },
+ createForm: {
+ title: 'label.create.template',
+ preFilter: cloudStack.preFilter.createTemplate,
+ desc: '',
+ fields: {
+ name: {
+ label: 'label.name',
+ validation: {
+ required: true
+ }
+ },
+ displayText: {
+ label: 'label.description',
+ validation: {
+ required: true
+ }
+ },
+ osTypeId: {
+ label: 'label.os.type',
+ select: function(args) {
+ $.ajax({
+ url: createURL("listOsTypes"),
+ dataType: "json",
+ async: true,
+ success: function(json) {
+ var ostypes = json.listostypesresponse.ostype;
+ var items = [];
+ $(ostypes).each(function() {
+ items.push({
+ id: this.id,
+ description: this.description
+ });
+ });
+ args.response.success({
+ data: items
+ });
+ }
+ });
+ }
+ },
+ isPublic: {
+ label: 'label.public',
+ isBoolean: true
+ },
+ isPasswordEnabled: {
+ label: 'label.password.enabled',
+ isBoolean: true
+ },
+ isFeatured: {
+ label: "label.featured",
+ isBoolean: true
+ }
+ }
+ },
+ action: function(args) {
+ var data = {
+ volumeId: args.context.volumes[0].id,
+ name: args.data.name,
+ displayText: args.data.displayText,
+ osTypeId: args.data.osTypeId,
+ isPublic: (args.data.isPublic == "on"),
+ passwordEnabled: (args.data.isPasswordEnabled == "on")
+ };
+
+ if (args.$form.find('.form-item[rel=isFeatured]').css("display") != "none") {
+ $.extend(data, {
+ isfeatured: (args.data.isFeatured == "on")
+ });
+ }
+
+ $.ajax({
+ url: createURL('createTemplate'),
+ data: data,
+ success: function(json) {
+ var jid = json.createtemplateresponse.jobid;
+
<TRUNCATED>