From c7dc4223c197a0f77f1696210c74e006fd08bcd8 Mon Sep 17 00:00:00 2001 From: "Dmitriy A. Golev" Date: Sun, 21 Aug 2016 06:00:08 +0300 Subject: [PATCH] v1.0.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Progress-bar aside to percentage - Reset file’s fields after form is successfully submitted - Compatibility with `Meteor@1.4.1` - Upgrade `ostrio:files@1.7.0` --- .versions | 4 ++-- lib/client/autoform.js | 6 ++++++ lib/client/fileUpload.html | 7 +++++-- lib/client/fileUpload.js | 23 +++++++++++++++++------ package.js | 4 ++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.versions b/.versions index e394426..745ea05 100644 --- a/.versions +++ b/.versions @@ -41,9 +41,9 @@ mongo-id@1.0.5 npm-mongo@1.5.45 observe-sequence@1.0.12 ordered-dict@1.0.8 -ostrio:autoform-files@1.0.2 +ostrio:autoform-files@1.0.4 ostrio:cookies@2.0.5 -ostrio:files@1.6.9 +ostrio:files@1.7.0 promise@0.8.3 random@1.0.10 reactive-dict@1.1.3 diff --git a/lib/client/autoform.js b/lib/client/autoform.js index 2d37954..dfee70e 100644 --- a/lib/client/autoform.js +++ b/lib/client/autoform.js @@ -2,6 +2,12 @@ AutoForm.addInputType("fileUpload", { template: "afFileUpload" }); +AutoForm._globalHooks.onSuccess.push(function (type) { + if (type === 'insert') { + this.template.$('[data-reset-file]').click(); + } +}); + SimpleSchema.messages({ uploadError: '[value]' }); diff --git a/lib/client/fileUpload.html b/lib/client/fileUpload.html index 6880cea..916100a 100644 --- a/lib/client/fileUpload.html +++ b/lib/client/fileUpload.html @@ -8,11 +8,14 @@ {{> uploadFileDemo}} {{/if}} - Remove + Reset + Remove {{else}} {{#with currentUpload}} Uploading {{file.name}}: - {{progress}}% + +   + {{progress.get}}% {{else}} {{/with}} diff --git a/lib/client/fileUpload.js b/lib/client/fileUpload.js index 296a4a1..c2ecfd5 100644 --- a/lib/client/fileUpload.js +++ b/lib/client/fileUpload.js @@ -1,14 +1,19 @@ Template.afFileUpload.onCreated(function () { - this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection] + if (!this.data) { + this.data = { + atts: {} + }; + } + + this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection]; if (!this.collection) { throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"'); } - this.collectionName = () => this.data.atts.collection - + this.collectionName = () => this.data.atts.collection; this.currentUpload = new ReactiveVar(false); this.inputName = this.data.name; - this.fileId = new ReactiveVar(this.data.value); + this.fileId = new ReactiveVar(this.data.value || false); return; }); @@ -27,12 +32,18 @@ Template.afFileUpload.helpers({ }); Template.afFileUpload.events({ + 'click [data-reset-file]'(e, template) { + e.preventDefault(); + template.fileId.set(false); + return false; + }, 'click [data-remove-file]'(e, template) { + e.preventDefault(); template.fileId.set(false); try { this.remove(); - } catch (e) {} - return; + } catch (error) {} + return false; }, 'change [data-files-collection-upload]'(e, template) { if (e.currentTarget.files && e.currentTarget.files[0]) { diff --git a/package.js b/package.js index 104541a..e8bc60a 100644 --- a/package.js +++ b/package.js @@ -2,7 +2,7 @@ Package.describe({ name: "ostrio:autoform-files", summary: "File upload for AutoForm using ostrio:files", description: "File upload for AutoForm using ostrio:files", - version: "1.0.2", + version: "1.0.4", git: "https://github.com/VeliovGroup/meteor-autoform-file.git" }); @@ -15,7 +15,7 @@ Package.onUse(function(api) { 'reactive-var', 'templating', 'aldeed:autoform@5.8.0', - 'ostrio:files@1.6.9' + 'ostrio:files@1.7.0' ]); api.addFiles([