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:37 UTC

[1/2] git commit: updated refs/heads/ui-template-uploader to a36d219

Repository: cloudstack
Updated Branches:
  refs/heads/ui-template-uploader 6d9542ff3 -> a36d2191e


Add file upload field


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/70fe283b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/70fe283b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/70fe283b

Branch: refs/heads/ui-template-uploader
Commit: 70fe283b670e6f12d1b3ea05b7d41e6f81571ad1
Parents: 6d9542f
Author: Brian Federle <br...@citrix.com>
Authored: Tue Jan 6 11:38:00 2015 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Tue Jan 6 11:38:00 2015 -0800

----------------------------------------------------------------------
 ui/scripts/ui/dialog.js | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70fe283b/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index e5ac14b..a510be9 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -473,6 +473,12 @@
                     if (field.defaultValue) {
                         $input.val(strOrFunc(field.defaultValue));
                     }
+                } else if (field.isFileUpload) {
+                    $input = $('<input>').attr({
+                        type: 'file',
+                        name: 'files[]',
+                        'data-url': '/upload.jsp'
+                    }).appendTo($value);
                 } else if (field.isTokenInput) { // jquery.tokeninput.js
                     isAsync = true;
 


[2/2] git commit: updated refs/heads/ui-template-uploader to a36d219

Posted by bf...@apache.org.
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;
             };