couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [6/6] git commit: updated refs/heads/1811-fauxton-attachment-upload to 3d408fe
Date Thu, 06 Jun 2013 16:03:10 GMT
Finish upload files, get attachments working with the field editor


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/3d408fe3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3d408fe3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3d408fe3

Branch: refs/heads/1811-fauxton-attachment-upload
Commit: 3d408fe304eac9be8714692c99e6e27bc099e808
Parents: 34b5487
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Jun 6 15:26:53 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu Jun 6 18:02:44 2013 +0200

----------------------------------------------------------------------
 LICENSE                                            |    1 +
 NOTICE                                             |    6 ++
 src/fauxton/Gruntfile.js                           |    4 +-
 src/fauxton/app/helpers.js                         |   14 +++++
 src/fauxton/app/modules/documents/views.js         |   44 +++++++++++----
 .../app/templates/documents/doc_field_editor.html  |   16 +++++-
 6 files changed, 71 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index 418b918..d488036 100644
--- a/LICENSE
+++ b/LICENSE
@@ -369,6 +369,7 @@ For the share/www/script/jquery-ui-* components:
   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 For the share/www/script/jquery.form.js component:
+For the src/fauxton/assets/js/plugins/jquery.form.js component:
 
   http://malsup.com/jquery/form/
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
index 2010ba6..8379f97 100644
--- a/NOTICE
+++ b/NOTICE
@@ -137,3 +137,9 @@ This product also includes the following third-party components:
  * codemirror-javascript.js (https://github.com/marijnh/CodeMirror)
 
    Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com>
+
+ * jquery.form.js (https://github.com/malsup/form/)
+
+   Copyright 2006-2013 (c) M. Alsup
+
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/src/fauxton/Gruntfile.js
----------------------------------------------------------------------
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index b76ae24..292385f 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -198,10 +198,10 @@ module.exports = function(grunt) {
           host: 'localhost',
           port: 5984,
           https: false
-        },
+        }
         // This sets the Host header in the proxy so that you can use external
         // CouchDB instances and not have the Host set to 'localhost'
-        changeOrigin: true
+        //changeOrigin: true
       }
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/src/fauxton/app/helpers.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/helpers.js b/src/fauxton/app/helpers.js
index 6b3a7cd..2ffe2fd 100644
--- a/src/fauxton/app/helpers.js
+++ b/src/fauxton/app/helpers.js
@@ -30,6 +30,20 @@ function() {
     return path;
   };
 
+  // File size pretty printing, taken from futon.format.js
+  Helpers.formatSize = function(size) {
+      var jump = 512;
+      if (size < jump) return size + " bytes";
+      var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+      var i = 0;
+      while (size >= jump && i < units.length) {
+        i += 1;
+        size /= 1024;
+      }
+      return size.toFixed(1) + ' ' + units[i - 1];
+    };
+
+
   return Helpers;
 });
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index ae87c82..d4754b0 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -131,11 +131,6 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
   Views.UploadModal = FauxtonAPI.View.extend({
     template: "templates/documents/upload_modal",
 
-    initialize: function (options) {
-      console.log('model', this.model, this.model.toJSON());
-
-    },
-
     events: {
       "click a#upload-btn": "uploadFile"
     },
@@ -144,9 +139,18 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
       event.preventDefault();
 
       var that = this,
+          docRev = this.model.get('_rev'),
           $form = this.$('#file-upload');
 
-      this.$('#_rev').val(this.model.get('_rev'));
+      if (!docRev) {
+        return this.set_error_msg('The document needs to be saved before adding an attachment.');
+      }
+
+      if ($('input[type="file"]')[0].files.length === 0) {
+        return this.set_error_msg('Selected a file to be uploaded.');
+      }
+
+      this.$('#_rev').val(docRev);
 
       $form.ajaxSubmit({
         url: this.model.url(),
@@ -159,7 +163,9 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
         },
         success: function (resp) {
           FauxtonAPI.triggerRouteEvent('reRenderDoc');
+          //slight delay to make this transistion a little more fluid and less jumpy
           setTimeout(function () {
+            $form.clearForm();
             that.hideModal();
           }, 1000);
         }
@@ -177,8 +183,6 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
 
     hideModal: function () {
       this.$('.modal').modal('hide');
-      // force this removal as the navbar
-      //$('.modal-backdrop').remove();
     },
 
     set_error_msg: function (msg) {
@@ -593,12 +597,30 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
 
     serialize: function() {
       return {
-        doc: this.getModel()
+        doc: this.getModelWithoutAttachments(),
+        attachments: this.getAttachments()
       };
     },
 
-    getModel: function() {
-      return this.model;
+    getModelWithoutAttachments: function() {
+      var model = this.model.toJSON();
+      delete model._attachments;
+      return model;
+    },
+
+    getAttachments: function () {
+      var attachments = this.model.get('_attachments');
+
+      if (!attachments) { return []; }
+
+      return _.map(attachments, function (att, key) {
+        return {
+          fileName: key,
+          size: att.length,
+          contentType: att.content_type,
+          url: this.model.url() + '/' + key
+        };
+      }, this);
     },
 
     establish: function() {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3d408fe3/src/fauxton/app/templates/documents/doc_field_editor.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/doc_field_editor.html b/src/fauxton/app/templates/documents/doc_field_editor.html
index 494e721..c9ce32b 100644
--- a/src/fauxton/app/templates/documents/doc_field_editor.html
+++ b/src/fauxton/app/templates/documents/doc_field_editor.html
@@ -44,7 +44,7 @@ the License.
         <td class="key"><input type="text" class="input-large" value='' /></td>
         <td class="value"><input type="text" class="input-xxlarge" value='' /></td>
       </tr>
-      <% _.each(doc.attributes, function(value, key) { %>
+      <% _.each(doc, function(value, key) { %>
         <tr>
           <td class="select"><input type="checkbox" /></td>
           <td class="key">
@@ -53,6 +53,20 @@ the License.
           <td class="value"><input type="text" class="input-xxlarge" value='<%=
JSON.stringify(value) %>' /></td>
         </tr>
       <% }); %>
+        <tr>
+          <th colspan="3">
+            Attachments
+          </th>
+        </tr>
+      <%_.each(attachments, function (att) { %>
+        <tr>
+          <td class="select"><input type="checkbox" /></td>
+          <td colspan="2">
+            <a href="<%= att.url %>" target="_blank"> <%= att.fileName %>
</a>
+            <span> <%= att.contentType %>, <%= formatSize(att.size)%> </span>
+          </td>
+        </tr>
+      <% }) %>
     </tbody>
   </table>
   <a class="btn btn-small new" style="margin-left: 64px"><i class="icon-plus"></i>
New field</a>


Mime
View raw message