Skip to content

Commit d79c371

Browse files
author
Jessica Wang
committed
volume-upload: UI > storage > volumes > add new action "Upload Volume from Local" in header of listView.
1 parent 818f9cf commit d79c371

1 file changed

Lines changed: 141 additions & 1 deletion

File tree

‎ui/scripts/storage.js‎

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,147 @@
376376
notification: {
377377
poll: pollAsyncJobResult
378378
}
379-
}
379+
},
380+
381+
uploadVolumefromLocal: {
382+
isHeader: true,
383+
label: 'Upload Volume from Local',
384+
preFilter: function(args) {
385+
return !args.context.instances;
386+
},
387+
messages: {
388+
notification: function() {
389+
return 'Upload Volume from Local';
390+
}
391+
},
392+
createForm: {
393+
title: 'Upload Volume from Local',
394+
fileUpload: {
395+
getURL: function(args) {
396+
args.data = args.formData;
397+
398+
var data = {
399+
name: args.data.name,
400+
zoneId: args.data.availabilityZone,
401+
format: args.data.format,
402+
url: args.data.url
403+
};
404+
405+
if (args.data.checksum != null && args.data.checksum.length > 0) {
406+
$.extend(data, {
407+
checksum: args.data.checksum
408+
});
409+
}
410+
411+
$.ajax({
412+
url: createURL('getUploadParamsForVolume'),
413+
data: data,
414+
async: false,
415+
success: function(json) {
416+
var uploadparams = json.postuploadvolumeresponse.getuploadparams; //son.postuploadvolumeresponse.getuploadparams is an object, not an array of object.
417+
var volumeId = uploadparams.id;
418+
419+
args.response.success({
420+
url: uploadparams.postURL,
421+
data: {
422+
signature: uploadparams.signature,
423+
expires: uploadparams.timeout,
424+
metadata: uploadparams.metadata
425+
}
426+
});
427+
428+
cloudStack.dialog.notice({
429+
message: "This volume file has been uploaded. Please check its status at Stroage menu > Volumes > " + args.data.name + " > Status field."
430+
});
431+
}
432+
});
433+
},
434+
postUpload: function(args) {
435+
console.log("postUpload() is hit");
436+
// Called when upload is done to do
437+
// verification checks;
438+
// i.e., poll the server to verify successful upload
439+
//
440+
// success() will close the dialog and call standard action
441+
// error() will keep dialog open if user wants to re-submit
442+
args.response.success();
443+
}
444+
},
445+
fields: {
446+
volumeFileUpload: {
447+
label: 'local file',
448+
isFileUpload: true
449+
},
450+
name: {
451+
label: 'label.name',
452+
validation: {
453+
required: true
454+
},
455+
docID: 'helpUploadVolumeName'
456+
},
457+
availabilityZone: {
458+
label: 'label.availability.zone',
459+
docID: 'helpUploadVolumeZone',
460+
select: function(args) {
461+
$.ajax({
462+
url: createURL("listZones&available=true"),
463+
dataType: "json",
464+
async: true,
465+
success: function(json) {
466+
var zoneObjs = json.listzonesresponse.zone;
467+
args.response.success({
468+
descriptionField: 'name',
469+
data: zoneObjs
470+
});
471+
}
472+
});
473+
}
474+
},
475+
format: {
476+
label: 'label.format',
477+
docID: 'helpUploadVolumeFormat',
478+
select: function(args) {
479+
var items = [];
480+
items.push({
481+
id: 'RAW',
482+
description: 'RAW'
483+
});
484+
items.push({
485+
id: 'VHD',
486+
description: 'VHD'
487+
});
488+
items.push({
489+
id: 'VHDX',
490+
description: 'VHDX'
491+
});
492+
items.push({
493+
id: 'OVA',
494+
description: 'OVA'
495+
});
496+
items.push({
497+
id: 'QCOW2',
498+
description: 'QCOW2'
499+
});
500+
args.response.success({
501+
data: items
502+
});
503+
}
504+
},
505+
checksum: {
506+
docID: 'helpUploadVolumeChecksum',
507+
label: 'label.md5.checksum'
508+
}
509+
}
510+
},
511+
512+
action: function(args) {
513+
return; //createForm.fileUpload.getURL() has executed the whole action. Therefore, nothing needs to be done here.
514+
},
515+
516+
notification: {
517+
poll: pollAsyncJobResult
518+
}
519+
}
380520
},
381521

382522
advSearchFields: {

0 commit comments

Comments
 (0)