Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3BC0810AF0 for ; Mon, 10 Jun 2013 14:33:21 +0000 (UTC) Received: (qmail 70235 invoked by uid 500); 10 Jun 2013 14:33:21 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 70168 invoked by uid 500); 10 Jun 2013 14:33:20 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 70157 invoked by uid 99); 10 Jun 2013 14:33:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jun 2013 14:33:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5E97E8A27C2; Mon, 10 Jun 2013 14:33:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Message-Id: <9474688ec180491cb8031f120e592837@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/1811-fauxton-attachment-upload to 3556216 Date: Mon, 10 Jun 2013 14:33:20 +0000 (UTC) Updated Branches: refs/heads/1811-fauxton-attachment-upload 7f8d35eaf -> 355621632 (forced update) Fauxton: Upload attachments Can upload an attachment along with progress bar and view it in the code and field editor. Resolves COUCHDB-1811 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/35562163 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/35562163 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/35562163 Branch: refs/heads/1811-fauxton-attachment-upload Commit: 3556216323059d832199c5ed59c7e799dfe2827c Parents: 7cb6442 Author: Garren Smith Authored: Wed Jun 5 17:21:35 2013 +0200 Committer: Garren Smith Committed: Mon Jun 10 16:33:05 2013 +0200 ---------------------------------------------------------------------- LICENSE | 1 + NOTICE | 6 + src/fauxton/app/app.js | 3 +- src/fauxton/app/config.js | 4 +- src/fauxton/app/helpers.js | 14 + src/fauxton/app/modules/documents/routes.js | 9 + src/fauxton/app/modules/documents/views.js | 135 +- src/fauxton/app/templates/documents/doc.html | 19 +- .../templates/documents/doc_field_editor.html | 16 +- .../documents/doc_field_editor_tabs.html | 3 + .../app/templates/documents/upload_modal.html | 42 + src/fauxton/assets/js/plugins/jquery.form.js | 1190 ++++++++++++++++++ src/fauxton/package.json | 2 +- 13 files changed, 1434 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/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/35562163/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 + + * jquery.form.js (https://github.com/malsup/form/) + + Copyright 2006-2013 (c) M. Alsup + + http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/src/fauxton/app/app.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js index e754c5f..be0136d 100644 --- a/src/fauxton/app/app.js +++ b/src/fauxton/app/app.js @@ -7,7 +7,8 @@ define([ "helpers", // Plugins. - "plugins/backbone.layoutmanager" + "plugins/backbone.layoutmanager", + "plugins/jquery.form" ], function($, _, Backbone, Helpers) { http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/src/fauxton/app/config.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/config.js b/src/fauxton/app/config.js index 5bf1f87..c7ae1d6 100644 --- a/src/fauxton/app/config.js +++ b/src/fauxton/app/config.js @@ -47,7 +47,9 @@ require.config({ "plugins/codemirror-javascript": ["codemirror"], - "plugins/prettify": [] + "plugins/prettify": [], + + "plugins/jquery.form": ["jquery"] } }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/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/35562163/src/fauxton/app/modules/documents/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js index 5a44c0e..a49fa91 100644 --- a/src/fauxton/app/modules/documents/routes.js +++ b/src/fauxton/app/modules/documents/routes.js @@ -51,6 +51,10 @@ function(app, FauxtonAPI, Documents, Databases) { "database/:database/:doc": "code_editor" }, + events: { + "route:reRenderDoc": "reRenderDoc" + }, + crumbs: function() { return [ {"name": "Databases", "link": "/_all_dbs"}, @@ -67,6 +71,11 @@ function(app, FauxtonAPI, Documents, Databases) { })); }, + reRenderDoc: function () { + this.docView.forceRender(); + console.log('rerender'); + }, + field_editor: function(events) { this.tabsView.updateSelected('field_editor'); this.docView = this.setView("#dashboard-content", new Documents.Views.DocFieldEditor({ http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/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 93f06f1..b9a278d 100644 --- a/src/fauxton/app/modules/documents/views.js +++ b/src/fauxton/app/modules/documents/views.js @@ -128,6 +128,85 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) { } }); + Views.UploadModal = FauxtonAPI.View.extend({ + template: "templates/documents/upload_modal", + + events: { + "click a#upload-btn": "uploadFile" + }, + + uploadFile: function (event) { + event.preventDefault(); + + var that = this, + docRev = this.model.get('_rev'), + $form = this.$('#file-upload'); + + 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(), + type: 'POST', + beforeSend: function () { + that.$('.progress').removeClass('hide'); + }, + uploadProgress: function(event, position, total, percentComplete) { + that.$('.bar').css({width: percentComplete + '%'}); + }, + 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); + } + }); + }, + + showModal: function () { + this.$('.bar').css({width: '0%'}); + this.$('.progress').addClass('hide'); + this.clear_error_msg(); + this.$('.modal').modal(); + // hack to get modal visible + $('.modal-backdrop').css('z-index',1025); + }, + + hideModal: function () { + this.$('.modal').modal('hide'); + }, + + set_error_msg: function (msg) { + var text; + if (typeof(msg) == 'string') { + text = msg; + } else { + text = JSON.parse(msg.responseText).reason; + } + + this.$('#modal-error').text(text).removeClass('hide'); + }, + + clear_error_msg: function () { + this.$('#modal-error').text(' ').addClass('hide'); + }, + + serialize: function () { + return this.model.toJSON(); + + } + + }); + Views.FieldEditorTabs = FauxtonAPI.View.extend({ template: "templates/documents/doc_field_editor_tabs", @@ -137,7 +216,8 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) { events: { "click button.delete": "destroy", - "click button.duplicate": "duplicate" + "click button.duplicate": "duplicate", + "click button.upload": "upload" }, destroy: function(event) { @@ -160,6 +240,16 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) { }); }, + beforeRender: function () { + this.uploadModal = this.setView('#upload-modal', new Views.UploadModal({model: this.model})); + this.uploadModal.render(); + }, + + upload: function (event) { + event.preventDefault(); + this.uploadModal.showModal(); + }, + duplicate: function(event) { FauxtonAPI.addNotification({ type: "warning", @@ -462,11 +552,28 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) { }, serialize: function() { + console.log('att', this.getAttachments()); return { - doc: this.model + doc: this.model, + attachments: this.getAttachments() }; }, + getAttachments: function () { + var attachments = this.model.get('_attachments'); + + if (!attachments) { return false; } + + return _.map(attachments, function (att, key) { + return { + fileName: key, + size: att.length, + contentType: att.content_type, + url: this.model.url() + '/' + key + }; + }, this); + }, + afterRender: function() { this.model.on("sync", this.updateValues, this); var that = this; @@ -507,12 +614,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/35562163/src/fauxton/app/templates/documents/doc.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/templates/documents/doc.html b/src/fauxton/app/templates/documents/doc.html index 044866b..969bf06 100644 --- a/src/fauxton/app/templates/documents/doc.html +++ b/src/fauxton/app/templates/documents/doc.html @@ -14,11 +14,28 @@ the License.
+ <% if (attachments) { %> +
+ + View Attachments + + + +
+ <% } %>

- +

http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/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. - <% _.each(doc.attributes, function(value, key) { %> + <% _.each(doc, function(value, key) { %> @@ -53,6 +53,20 @@ the License. <% }); %> + + + Attachments + + + <%_.each(attachments, function (att) { %> + + + + <%= att.fileName %> + <%= att.contentType %>, <%= formatSize(att.size)%> + + + <% }) %> New field http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/src/fauxton/app/templates/documents/doc_field_editor_tabs.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html index 41bbe40..01cb8a9 100644 --- a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html +++ b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html @@ -18,9 +18,12 @@ the License. + +
http://git-wip-us.apache.org/repos/asf/couchdb/blob/35562163/src/fauxton/app/templates/documents/upload_modal.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/templates/documents/upload_modal.html b/src/fauxton/app/templates/documents/upload_modal.html new file mode 100644 index 0000000..d9cdbb0 --- /dev/null +++ b/src/fauxton/app/templates/documents/upload_modal.html @@ -0,0 +1,42 @@ + + +