You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2015/01/14 20:27:11 UTC
git commit: updated refs/heads/volume-upload to f243ae1
Repository: cloudstack
Updated Branches:
refs/heads/volume-upload 627f5a62d -> f243ae135
Add front-end file uploader
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f243ae13
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f243ae13
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f243ae13
Branch: refs/heads/volume-upload
Commit: f243ae135b802d09077dde7bf20256f28c9e6287
Parents: 627f5a6
Author: Brian Federle <br...@citrix.com>
Authored: Wed Jan 14 11:26:38 2015 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Wed Jan 14 11:26:38 2015 -0800
----------------------------------------------------------------------
ui/scripts/templates.js | 20 +++++++++++
ui/scripts/ui/dialog.js | 83 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 97 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f243ae13/ui/scripts/templates.js
----------------------------------------------------------------------
diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js
index b8b8534..1b6400a 100644
--- a/ui/scripts/templates.js
+++ b/ui/scripts/templates.js
@@ -107,6 +107,22 @@
title: 'label.action.register.template',
docID: 'helpNetworkOfferingName',
preFilter: cloudStack.preFilter.createTemplate,
+ fileUpload: {
+ getURL: function(args) {
+ args.response.success({
+ url: 'http://10.223.183.3/test-upload.php'
+ });
+ },
+ postUpload: function(args) {
+ // Called when upload is done to do
+ // verification checks;
+ // i.e., poll the server to verify successful upload
+ //
+ // success() will close the dialog and call standard action
+ // error() will keep dialog open if user wants to re-submit
+ args.response.success();
+ }
+ },
fields: {
name: {
label: 'label.name',
@@ -115,6 +131,10 @@
required: true
}
},
+ templateFileUpload: {
+ label: 'Select a file',
+ isFileUpload: true
+ },
description: {
label: 'label.description',
docID: 'helpRegisterTemplateDescription',
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f243ae13/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index 332b78f..f3f5dae 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -473,6 +473,16 @@
if (field.defaultValue) {
$input.val(strOrFunc(field.defaultValue));
}
+ } else if (field.isFileUpload) {
+ $input = $('<input>').attr({
+ type: 'file',
+ name: 'files[]'
+ }).appendTo($value);
+
+ // Add events
+ $input.change(function(event) {
+ $form.data('files', event.target.files);
+ });
} else if (field.isTokenInput) { // jquery.tokeninput.js
isAsync = true;
@@ -672,12 +682,73 @@
}
}
- args.after({
- data: data,
- ref: args.ref, // For backwards compatibility; use context
- context: args.context,
- $form: $form
- });
+ var uploadFiles = function() {
+ $form.prepend($('<div>').addClass('loading-overlay'));
+ args.form.fileUpload.getURL({
+ formData: data,
+ context: args.context,
+ response: {
+ success: function(successArgs) {
+ //
+ // Move file field into iframe; keep visible for consistency
+ //
+ var $uploadFrame = $('<iframe>');
+ var $frameForm = $('<form>').attr({
+ method: 'POST',
+ action: successArgs.url,
+ enctype: 'multipart/form-data'
+ });
+ var $file = $form.find('input[type=file]');
+ var $field = $file.closest('.form-item .value');
+
+ $uploadFrame.css({ width: $field.outerWidth(), height: $field.height() }).show();
+ $frameForm.append($file);
+ $field.append($uploadFrame);
+ $uploadFrame.contents().find('html body').append($frameForm);
+ $frameForm.submit(function() {
+ $uploadFrame.load(function() {
+ args.form.fileUpload.postUpload({
+ formData: data,
+ context: args.context,
+ response: {
+ success: function() {
+ args.after({
+ data: data,
+ ref: args.ref, // For backwards compatibility; use context
+ context: args.context,
+ $form: $form
+ });
+ },
+ error: function(msg) {
+ $form.find('.loading-overlay').remove();
+ cloudStack.dialog.error({ message: msg });
+ }
+ }
+ });
+ });
+ return true;
+ });
+ $frameForm.submit();
+ },
+ error: function(msg) {
+ cloudStack.dialog.error({ message: msg });
+ }
+ }
+ });
+ };
+
+ if ($form.data('files')) {
+ uploadFiles();
+
+ return false;
+ } else {
+ args.after({
+ data: data,
+ ref: args.ref, // For backwards compatibility; use context
+ context: args.context,
+ $form: $form
+ });
+ }
return true;
};