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/06 23:02:38 UTC
[2/2] git commit: updated refs/heads/ui-template-uploader to a36d219
Test custom file upload
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a36d2191
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a36d2191
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a36d2191
Branch: refs/heads/ui-template-uploader
Commit: a36d2191ec69c8bafed2c2d98e3776f4a48c61c4
Parents: 70fe283
Author: Brian Federle <br...@citrix.com>
Authored: Tue Jan 6 13:51:37 2015 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Tue Jan 6 13:51:37 2015 -0800
----------------------------------------------------------------------
ui/scripts/ui/dialog.js | 65 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 57 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a36d2191/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index a510be9..ca5ce8b 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -476,9 +476,13 @@
} else if (field.isFileUpload) {
$input = $('<input>').attr({
type: 'file',
- name: 'files[]',
- 'data-url': '/upload.jsp'
+ 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;
@@ -678,12 +682,57 @@
}
}
- args.after({
- data: data,
- ref: args.ref, // For backwards compatibility; use context
- context: args.context,
- $form: $form
- });
+ var uploadFiles = function() {
+ // START A LOADING SPINNER HERE
+
+ // Create a formdata object and add the files
+ var data = new FormData();
+ $.each($form.data('files'), function(key, value)
+ {
+ data.append(key, value);
+ });
+
+ $.ajax({
+ url: '/client/upload.json',
+ type: 'POST',
+ data: data,
+ cache: false,
+ dataType: 'json',
+ processData: false, // Don't process the files
+ contentType: false, // Set content type to false as jQuery will tell the server its a query string request
+ success: function(data, textStatus, jqXHR)
+ {
+ if(typeof data.error === 'undefined')
+ {
+ // Success so call function to process the form
+ debugger;
+ //submitForm(event, data);
+ }
+ else
+ {
+ // Handle errors here
+ console.log('ERRORS: ' + data.error);
+ }
+ },
+ error: function(jqXHR, textStatus, errorThrown)
+ {
+ // Handle errors here
+ console.log('ERRORS: ' + textStatus);
+ // STOP LOADING SPINNER
+ }
+ });
+ };
+
+ if ($form.data('files')) {
+ uploadFiles();
+ } else {
+ args.after({
+ data: data,
+ ref: args.ref, // For backwards compatibility; use context
+ context: args.context,
+ $form: $form
+ });
+ }
return true;
};