fng-jq-upload 0.12.0-beta.261 → 0.12.0-beta.263

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,7 +83,8 @@
83
83
  $scope.dataField = function (initialise) {
84
84
  var retVal;
85
85
  if ($scope.info.name.indexOf('.') === -1) {
86
- var record = $scope.formScope.record;
86
+ const model = $scope.options.model || 'record';
87
+ const record = $scope.formScope[model];
87
88
  if (record) {
88
89
  retVal = record[$scope.info.name];
89
90
  }
@@ -94,6 +95,7 @@
94
95
  retVal = record[$scope.info.name] = [];
95
96
  }
96
97
  } else if ($scope.options.subschema) {
98
+ // not supporting $scope.options?.model here yet
97
99
  var modelBase = $scope.formScope.record;
98
100
  var compoundName = $scope.info.name;
99
101
  var root = $scope.options.subschemaroot;
@@ -233,28 +235,52 @@
233
235
  assignQueueToFormScope();
234
236
  }
235
237
 
238
+ // this function is assigned to a property of the scope so any directive making use of this controller
239
+ // can call it itself in situations where the watch on formScope.watch will not do
240
+ $scope.initialiseJqUpload = function () {
241
+ $scope.$$childHead.queue = $scope.$$childHead.queue || [];
242
+ setUpAttachments();
243
+ $scope.$on('fngCancel', function () {
244
+ $scope.$$childHead.queue = [];
245
+ setUpAttachments();
246
+ });
247
+ };
248
+
236
249
  if (!$scope.formScope.newRecord) {
237
250
  var watchDeregister = $scope.formScope.$watch('phase', function (newVal) {
238
251
  if (newVal === 'ready') {
239
- $scope.$$childHead.queue = $scope.$$childHead.queue || [];
240
- setUpAttachments();
241
- $scope.$on('fngCancel', function () {
242
- $scope.$$childHead.queue = [];
243
- setUpAttachments();
244
- });
245
-
252
+ $scope.initialiseJqUpload();
246
253
  watchDeregister();
247
254
  }
248
255
  });
249
256
  }
250
257
 
258
+ $scope.$on('jqUpload:reinitialise', function () {
259
+ $scope.$$childHead.queue = [];
260
+ $scope.initialiseJqUpload();
261
+ });
262
+
251
263
  $scope.$on('fileuploadstart', function () {
252
264
  delete $scope.uploadError;
253
265
  });
254
266
 
267
+ // if the user clicks on the "Cancel" button at the top of the page while an upload is in progress, cancel it.
268
+ // failing to do this will not only result in wasted storage, but if the user (without switching to another page /
269
+ // record first) then uploads another file, the data field array will end up containing more than 1 element (when -
270
+ // except when multi is true - it should only ever contain one)
271
+ $scope.$on('fngCancel', () => {
272
+ const jqScope = $scope.$$childHead;
273
+ if (!jqScope) {
274
+ return;
275
+ }
276
+ if (typeof jqScope.active === 'function' && jqScope.active() && typeof jqScope.cancel === 'function') {
277
+ jqScope.cancel();
278
+ }
279
+ });
280
+
255
281
  $scope.$on('fileuploadfail', function (event, data) {
256
282
  // clear out the failed queue item so another upload can be attempted
257
- $scope.$$childHead.queue = [];
283
+ $scope.$$childHead.queue.pop();
258
284
  let error;
259
285
  if (data.xhr) {
260
286
  const xhr = data.xhr();
@@ -269,7 +295,15 @@
269
295
  if (!error) {
270
296
  error = data.errorThrown || 'an unexpected error occurred';
271
297
  }
272
- $scope.uploadError = error;
298
+ // "abort" is what we'll receive if the user clicks on our red Cancel button while the upload is in progress
299
+ // (you'd probably need to introduce a fake server-side delay to reproduce that, otherwise the cancel button
300
+ // isn't visible for long enough to click on)
301
+ if (error !== 'abort') {
302
+ $scope.uploadError = error;
303
+ }
304
+ if (error.includes('ENOTFOUND')) {
305
+ error = 'Failed to connect to storage service to upload file. Have you gone offline?';
306
+ }
273
307
  });
274
308
 
275
309
  $scope.$on('fileuploaddone', function (event, data) {
@@ -286,11 +320,12 @@
286
320
  location,
287
321
  thumbnailId,
288
322
  });
289
- // at the point of fileuploaddone being fired, $scope.$$childHead.queue[0] will have already been populated
290
- // with the details of the file provided by the server. we just need to decorate this now with the
323
+ // at the point of fileuploaddone being fired, the last item in $scope.$$childHead.queue will have already been
324
+ // populated with the details of the file provided by the server. we just need to decorate this now with the
291
325
  // urls for downloading, deleting and retrieving a thumbnail for this item as setUpAttachments() isn't
292
326
  // called again here
293
- addAttachmentUrls($scope.$$childHead.queue[0], location, _id, filename, thumbnailId);
327
+ const queue = $scope.$$childHead.queue;
328
+ addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
294
329
  $scope.ngModel.$setDirty();
295
330
  assignQueueToFormScope();
296
331
  });
@@ -83,7 +83,8 @@
83
83
  $scope.dataField = function (initialise) {
84
84
  var retVal;
85
85
  if ($scope.info.name.indexOf('.') === -1) {
86
- var record = $scope.formScope.record;
86
+ const model = $scope.options.model || 'record';
87
+ const record = $scope.formScope[model];
87
88
  if (record) {
88
89
  retVal = record[$scope.info.name];
89
90
  }
@@ -94,6 +95,7 @@
94
95
  retVal = record[$scope.info.name] = [];
95
96
  }
96
97
  } else if ($scope.options.subschema) {
98
+ // not supporting $scope.options?.model here yet
97
99
  var modelBase = $scope.formScope.record;
98
100
  var compoundName = $scope.info.name;
99
101
  var root = $scope.options.subschemaroot;
@@ -233,28 +235,52 @@
233
235
  assignQueueToFormScope();
234
236
  }
235
237
 
238
+ // this function is assigned to a property of the scope so any directive making use of this controller
239
+ // can call it itself in situations where the watch on formScope.watch will not do
240
+ $scope.initialiseJqUpload = function () {
241
+ $scope.$$childHead.queue = $scope.$$childHead.queue || [];
242
+ setUpAttachments();
243
+ $scope.$on('fngCancel', function () {
244
+ $scope.$$childHead.queue = [];
245
+ setUpAttachments();
246
+ });
247
+ };
248
+
236
249
  if (!$scope.formScope.newRecord) {
237
250
  var watchDeregister = $scope.formScope.$watch('phase', function (newVal) {
238
251
  if (newVal === 'ready') {
239
- $scope.$$childHead.queue = $scope.$$childHead.queue || [];
240
- setUpAttachments();
241
- $scope.$on('fngCancel', function () {
242
- $scope.$$childHead.queue = [];
243
- setUpAttachments();
244
- });
245
-
252
+ $scope.initialiseJqUpload();
246
253
  watchDeregister();
247
254
  }
248
255
  });
249
256
  }
250
257
 
258
+ $scope.$on('jqUpload:reinitialise', function () {
259
+ $scope.$$childHead.queue = [];
260
+ $scope.initialiseJqUpload();
261
+ });
262
+
251
263
  $scope.$on('fileuploadstart', function () {
252
264
  delete $scope.uploadError;
253
265
  });
254
266
 
267
+ // if the user clicks on the "Cancel" button at the top of the page while an upload is in progress, cancel it.
268
+ // failing to do this will not only result in wasted storage, but if the user (without switching to another page /
269
+ // record first) then uploads another file, the data field array will end up containing more than 1 element (when -
270
+ // except when multi is true - it should only ever contain one)
271
+ $scope.$on('fngCancel', () => {
272
+ const jqScope = $scope.$$childHead;
273
+ if (!jqScope) {
274
+ return;
275
+ }
276
+ if (typeof jqScope.active === 'function' && jqScope.active() && typeof jqScope.cancel === 'function') {
277
+ jqScope.cancel();
278
+ }
279
+ });
280
+
255
281
  $scope.$on('fileuploadfail', function (event, data) {
256
282
  // clear out the failed queue item so another upload can be attempted
257
- $scope.$$childHead.queue = [];
283
+ $scope.$$childHead.queue.pop();
258
284
  let error;
259
285
  if (data.xhr) {
260
286
  const xhr = data.xhr();
@@ -269,7 +295,15 @@
269
295
  if (!error) {
270
296
  error = data.errorThrown || 'an unexpected error occurred';
271
297
  }
272
- $scope.uploadError = error;
298
+ // "abort" is what we'll receive if the user clicks on our red Cancel button while the upload is in progress
299
+ // (you'd probably need to introduce a fake server-side delay to reproduce that, otherwise the cancel button
300
+ // isn't visible for long enough to click on)
301
+ if (error !== 'abort') {
302
+ $scope.uploadError = error;
303
+ }
304
+ if (error.includes('ENOTFOUND')) {
305
+ error = 'Failed to connect to storage service to upload file. Have you gone offline?';
306
+ }
273
307
  });
274
308
 
275
309
  $scope.$on('fileuploaddone', function (event, data) {
@@ -286,11 +320,12 @@
286
320
  location,
287
321
  thumbnailId,
288
322
  });
289
- // at the point of fileuploaddone being fired, $scope.$$childHead.queue[0] will have already been populated
290
- // with the details of the file provided by the server. we just need to decorate this now with the
323
+ // at the point of fileuploaddone being fired, the last item in $scope.$$childHead.queue will have already been
324
+ // populated with the details of the file provided by the server. we just need to decorate this now with the
291
325
  // urls for downloading, deleting and retrieving a thumbnail for this item as setUpAttachments() isn't
292
326
  // called again here
293
- addAttachmentUrls($scope.$$childHead.queue[0], location, _id, filename, thumbnailId);
327
+ const queue = $scope.$$childHead.queue;
328
+ addAttachmentUrls(queue[queue.length - 1], location, _id, filename, thumbnailId);
294
329
  $scope.ngModel.$setDirty();
295
330
  assignQueueToFormScope();
296
331
  });
@@ -394,7 +429,7 @@ angular.module('uploadModule').run(['$templateCache', function($templateCache) {
394
429
  'use strict';
395
430
 
396
431
  $templateCache.put('templates/fileform.html',
397
- "<div class=\"form-group control-group\" id=cg_f_{{info.name}} {{info.add}}><label for=f_{{info.name}} id={{info.name}}-label class=\"col-sm-3 control-label\">{{label ? label() : (info.label || (info.name | titleCase))}}</label><div class=\"bs3-input col-sm-9 row-fluid\"><div class=\"col-xs-12 span12 fileupload-form\"><div class=fileupload method=POST enctype=multipart/form-data data-ng-app=demo data-file-upload=directiveOptions data-ng-class=\"{'fileupload-processing': processing() || loadingFiles}\"><div class=controls><div class=\"row fileupload-buttonbar\"><div class=\"col-md-12 span7\" style=\"min-height: 60px;\"><div data-ng-show=\"directiveOptions.single && queue.length === 0\" class=pull-left><span class=\"btn btn-success fileinput-button\" ng-class=\"{disabled: isDisabled}\"><i class=\"glyphicon glyphicon-plus icon icon-plus\"></i> <span>Upload {{label ? label() : (info.label || (info.name | titleCase))}}</span> <input type=file name=files ng-disabled=isDisabled placeholder=\"Upload {{ label ? label() : (info.label || (info.name | titleCase))}}\"></span></div><div data-ng-show=directiveOptions.single class=pull-left><div class=preview ng-show=!!queue[0].thumbnailUrl><a data-ng-href={{queue[0].url}} title={{queue[0].name}} download={{queue[0].name}} target=_blank data-gallery ng-mouseover=\"mouseIn=1\" ng-mouseout=\"mouseIn=0\"><img data-ng-src={{queue[0].thumbnailUrl}} alt=\"\"></a></div></div><div data-ng-show=directiveOptions.single class=\"pull-left file-delete-div\"><button ng-show=\"mouseIn && !isDisabled\" class=\"file-delete overlay-btn\" aria-label=Delete ng-mouseover=\"mouseIn=1\" data-ng-click=queue[0].$destroy($event)><i class=\"glyphicon glyphicon-trash icon icon-trash\"></i></button></div><span data-ng-hide=directiveOptions.single><span class=\"btn btn-success fileinput-button\" ng-class=\"{disabled: isDisabled}\"><i class=\"glyphicon glyphicon-plus icon icon-plus\"></i> <span>Add files...</span> <input type=file name=files multiple ng-disabled=isDisabled placeholder=\"Upload {{info.label || (info.name | titleCase)}}\"> </span></span><button type=button data-ng-hide=directiveOptions.autoupload class=\"btn btn-primary start\" data-ng-click=submit()><i class=\"glyphicon glyphicon-upload icon icon-upload\"></i> <span>Start upload</span></button> <button data-ng-show=active() type=button class=\"btn btn-warning cancel\" data-ng-click=cancel()><i class=\"glyphicon glyphicon-ban icon-circle icon-ban-circle\"></i> <span>Cancel upload</span></button><div data-ng-show=uploadError style=\"padding-top: 5px;\"><span class=\"error text-danger\">{{ uploadError }}</span></div><span class=fileupload-process></span></div><div class=\"col-md-5 span5 fade\" data-ng-class=\"{in: active()}\"><div class=\"progress progress-striped active\" data-file-upload-progress=progress()><div class=\"progress-bar progress-bar-success\" data-ng-style=\"{width: num + '%'}\"></div></div><div class=progress-extended>&nbsp;</div></div></div><table data-ng-hide=directiveOptions.single class=\"table table-striped files ng-cloak\"><tr data-ng-repeat=\"file in queue\"><td data-ng-switch data-on=!!file.thumbnailUrl><div class=preview data-ng-switch-when=true><a data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery><img data-ng-src={{file.thumbnailUrl}} alt=\"\" width=80 height=60></a></div><div class=preview data-ng-switch-default data-file-upload-preview=file></div></td><td><p class=name data-ng-switch data-on=!!file.url><span data-ng-switch-when=true data-ng-switch data-on=!!file.thumbnailUrl><a data-ng-switch-when=true data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery>{{file.name}}</a> <a data-ng-switch-default data-ng-href={{file.url}} title={{file.name}} download={{file.name}}>{{file.name}}</a> </span><span data-ng-switch-default>{{file.name}}</span></p><strong data-ng-show=file.error class=\"error text-danger\">{{file.error}}</strong></td><td><p class=size>{{file.size | formatFileSize}}</p><div class=\"progress progress-striped active fade\" data-ng-class=\"{pending: 'in'}[file.$state()]\" data-file-upload-progress=file.$progress()><div class=\"progress-bar progress-bar-success\" data-ng-style=\"{width: num + '%'}\"></div></div></td><td ng-show=directiveOptions.additFields><fng-upload-addit-fields file={{$index}}></fng-upload-addit-fields></td><td><button type=button class=\"btn btn-primary start\" data-ng-click=file.$submit() data-ng-hide=\"!file.$submit || directiveOptions.autoupload\" data-ng-disabled=\"file.$state() == 'pending' || file.$state() == 'rejected'\"><i class=\"glyphicon glyphicon-upload icon icon-upload\"></i> <span>Start</span></button> <button type=button class=\"btn btn-warning cancel\" data-ng-click=file.$cancel() data-ng-hide=!file.$cancel><i class=\"glyphicon glyphicon-ban-circle icon icon-ban-circle\"></i> <span>Cancel</span></button> <button type=button class=\"btn btn-danger destroy\" data-ng-click=file.$destroy() data-ng-hide=\"!file.$destroy || isDisabled\" data-ng-controller=FileDestroyController><i class=\"glyphicon glyphicon-trash icon icon-trash\"></i> <span>Delete</span></button></td></tr></table></div></div></div></div></div>"
432
+ "<div class=\"form-group control-group\" id=cg_f_{{info.name}} {{info.add}}><label for=f_{{info.name}} id={{info.name}}-label class=\"col-sm-3 control-label\">{{label ? label() : (info.label || (info.name | titleCase))}}</label><div class=\"bs3-input col-sm-9 row-fluid\"><div class=\"col-xs-12 span12 fileupload-form\"><div class=fileupload method=POST enctype=multipart/form-data data-ng-app=demo data-file-upload=directiveOptions data-ng-class=\"{'fileupload-processing': processing() || loadingFiles}\"><div class=controls><div class=\"row fileupload-buttonbar\"><div class=\"col-md-12 span7\" style=\"min-height: 60px;\"><div data-ng-show=\"directiveOptions.single && queue.length === 0\" class=pull-left><span class=\"btn btn-success fileinput-button\" ng-class=\"{disabled: isDisabled}\"><i class=\"glyphicon glyphicon-plus icon icon-plus\"></i> <span>Upload {{label ? label() : (info.label || (info.name | titleCase))}}</span> <input type=file name=files ng-disabled=isDisabled placeholder=\"Upload {{ label ? label() : (info.label || (info.name | titleCase))}}\"></span></div><div data-ng-show=directiveOptions.single class=pull-left><div class=preview ng-show=!!queue[0].thumbnailUrl><a data-ng-href={{queue[0].url}} title={{queue[0].name}} download={{queue[0].name}} target=_blank data-gallery ng-mouseover=\"mouseIn=1\" ng-mouseout=\"mouseIn=0\"><img data-ng-src={{queue[0].thumbnailUrl}} alt=\"\" width=\"{{ options.width || 80 }}\" height=\"{{ options.height || 60 }}\"></a></div></div><div data-ng-show=\"directiveOptions.single && !active()\" class=\"pull-left file-delete-div\"><button ng-show=\"mouseIn && !isDisabled\" class=\"file-delete overlay-btn\" aria-label=Delete ng-mouseover=\"mouseIn=1\" data-ng-click=queue[0].$destroy($event)><i class=\"glyphicon glyphicon-trash icon icon-trash\"></i></button></div><span data-ng-hide=directiveOptions.single><span class=\"btn btn-success fileinput-button\" ng-class=\"{disabled: isDisabled}\"><i class=\"glyphicon glyphicon-plus icon icon-plus\"></i> <span>Add files...</span> <input type=file name=files multiple ng-disabled=isDisabled placeholder=\"Upload {{info.label || (info.name | titleCase)}}\"> </span></span><button type=button data-ng-hide=directiveOptions.autoupload class=\"btn btn-primary start\" data-ng-click=submit()><i class=\"glyphicon glyphicon-upload icon icon-upload\"></i> <span>Start upload</span></button> <button data-ng-show=active() type=button class=\"btn btn-warning cancel\" data-ng-click=cancel()><i class=\"glyphicon glyphicon-ban icon-circle icon-ban-circle\"></i> <span>Cancel upload</span></button><div data-ng-show=uploadError style=\"padding-top: 5px;\"><span class=\"error text-danger\">{{ uploadError }}</span></div><span class=fileupload-process></span></div><div class=\"col-md-5 span5 fade\" data-ng-class=\"{in: active()}\"><div class=\"progress progress-striped active\" data-file-upload-progress=progress()><div class=\"progress-bar progress-bar-success\" data-ng-style=\"{width: num + '%'}\"></div></div><div class=progress-extended>&nbsp;</div></div></div><table data-ng-hide=directiveOptions.single class=\"table table-striped files ng-cloak\"><tr data-ng-repeat=\"file in queue\"><td data-ng-switch data-on=!!file.thumbnailUrl><div class=preview data-ng-switch-when=true><a data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery><img data-ng-src={{file.thumbnailUrl}} alt=\"\" width=80 height=60></a></div><div class=preview data-ng-switch-default data-file-upload-preview=file></div></td><td><p class=name data-ng-switch data-on=!!file.url><span data-ng-switch-when=true data-ng-switch data-on=!!file.thumbnailUrl><a data-ng-switch-when=true data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery>{{file.name}}</a> <a data-ng-switch-default data-ng-href={{file.url}} title={{file.name}} download={{file.name}}>{{file.name}}</a> </span><span data-ng-switch-default>{{file.name}}</span></p><strong data-ng-show=file.error class=\"error text-danger\">{{file.error}}</strong></td><td><p class=size>{{file.size | formatFileSize}}</p><div class=\"progress progress-striped active fade\" data-ng-class=\"{pending: 'in'}[file.$state()]\" data-file-upload-progress=file.$progress()><div class=\"progress-bar progress-bar-success\" data-ng-style=\"{width: num + '%'}\"></div></div></td><td ng-show=directiveOptions.additFields><fng-upload-addit-fields file={{$index}}></fng-upload-addit-fields></td><td><button type=button class=\"btn btn-primary start\" data-ng-click=file.$submit() data-ng-hide=\"!file.$submit || directiveOptions.autoupload\" data-ng-disabled=\"file.$state() == 'pending' || file.$state() == 'rejected'\"><i class=\"glyphicon glyphicon-upload icon icon-upload\"></i> <span>Start</span></button> <button type=button class=\"btn btn-warning cancel\" data-ng-click=file.$cancel() data-ng-hide=!file.$cancel><i class=\"glyphicon glyphicon-ban-circle icon icon-ban-circle\"></i> <span>Cancel</span></button> <button type=button class=\"btn btn-danger destroy\" data-ng-click=file.$destroy() data-ng-hide=\"!file.$destroy || isDisabled\" data-ng-controller=FileDestroyController><i class=\"glyphicon glyphicon-trash icon icon-trash\"></i> <span>Delete</span></button></td></tr></table></div></div></div></div></div>"
398
433
  );
399
434
 
400
435
  }]);
@@ -1 +1 @@
1
- !function(){"use strict";var e=angular.module("uploadModule",["blueimp.fileupload"]);e.controller("FngUploadAdditFieldsCtrl",["$scope","$timeout",function(i,e){function n(){i.schema&&i.schema.forEach(function(e){var a=i.uploadForm.dataField()[i.file];i.record[e.name]=a?a[e.name]:void 0})}i.record={},i.$watch("record",function(e,a){e!==a&&(i.uploadForm.formScope[i.uploadForm.formScope.topLevelFormName].$setDirty(),angular.extend(i.uploadForm.dataField()[i.file],e))},!0),e(function(){var a;i.formScope.newRecord?i.record={}:a=i.formScope.$watch("phase",function(e){"ready"===e&&(n(),i.$on("fngCancel",function(){n()}),a())})})}]).directive("fngUploadAdditFields",function(){return{link:function(e,a,i){e.uploadForm=e.$parent.$parent.$parent,e.formScope=e.uploadForm.formScope,e.schema=e.uploadForm.directiveOptions.additFields,e.file=parseInt(i.file)},scope:{},controller:"FngUploadAdditFieldsCtrl",template:'<form-input formstyle="inline" schema="schema" model="record" forceform="true"></form-input>'}}).controller("FngJqUploadCtrl",["$scope","$http",function(r,i){function c(e,a){return 1<e?i.get(a).then(e=>{if(201===e.status)return e.data.clientUrl;throw e="Unexpected response to getPresignedUrl (status"+e.status+")",new Error(e)}):Promise.resolve(a)}function s(a,e,i,n,t){var l=r.formScope.modelName+"/"+e;let o="/api/file/"+l+"/"+i;if(c(e,o).then(e=>{a.url=e}),a.deleteUrl=o,t&&(a.deleteUrl+=","+t),a.deleteType="DELETE",a.thumbnailUrl="https://upload.wikimedia.org/wikipedia/commons/6/6c/Iconoir_journal-page.svg",n&&!r.options.defaultThumbnail){var s=n.toLowerCase();for(const d of[".gif",".png",".jpg",".jpeg"])if(s.endsWith(d)){if(t){const o="/api/file/"+l+"/"+t;c(e,o).then(e=>{a.thumbnailUrl=e})}else a.thumbnailUrl="/api/file/"+l+"/thumbnail/"+i;break}}}function d(){r.formScope.fngJqUploadFileQueue=r.$$childHead.queue}function a(){var e=r.dataField();if(e){for(const t of e){var a=void 0===t.location?1:t.location,i=t.filename,n={name:i,size:t.size,location:a};s(n,a,t._id,i,t.thumbnailId),r.$$childHead.queue||(r.$$childHead.queue=[]),r.$$childHead.queue.push(n)}d()}}var n;r.loadingFiles=!1,r.formScope=r.$parent,r.dataField=function(e){if(-1===r.info.name.indexOf(".")){var a=r.formScope.record;if(!(o=a?a[r.info.name]:o)&&e){if(!a)throw new Error(`Cannot initialise record. ${r.info.name} - record is not defined`);o=a[r.info.name]=[]}}else if(r.options.subschema){for(var e=r.formScope.record,a=r.info.name,i=r.options.subschemaroot,a=a.slice(i.length+1),n=(o=e,i.split(".")),t=0,l=n.length;t<l;t++)o=o[n[t]];var o,e=r.options.index;if(void 0!==(e=void 0===e?r.$parent.$index:e)){if(!o[e])return;o[e][a]||(o[e][a]=[]),o=o[e][a]}else r.options.subkey?o=null!=(e=r.formScope["$_arrayOffset_"+i.replace(/\./g,"_")+"_"+r.options.subkeyno])&&void 0!==e&&-1!==e?o[e][a]:void 0:console.log("No support for this yet")}else console.log("No support for this yet either");return o},r.formScope.newRecord||(n=r.formScope.$watch("phase",function(e){"ready"===e&&(r.$$childHead.queue=r.$$childHead.queue||[],a(),r.$on("fngCancel",function(){r.$$childHead.queue=[],a()}),n())})),r.$on("fileuploadstart",function(){delete r.uploadError}),r.$on("fileuploadfail",function(e,a){r.$$childHead.queue=[];let i;if(a.xhr){var n,t=a.xhr();try{n=JSON.parse(t.responseText),i=n.error||n}catch(e){i=t.responseText}}i=i||a.errorThrown||"an unexpected error occurred",r.uploadError=i}),r.$on("fileuploaddone",function(e,a){var i=r.dataField(!0),a=a.result.files[0],n=a.id,t=a.name,l=a.location,o=a.thumbnailId;i.push({_id:n,filename:t,size:a.size,location:l,thumbnailId:o}),s(r.$$childHead.queue[0],l,n,t,o),r.ngModel.$setDirty(),d()})}]).directive("fngJqUploadForm",["PluginHelperService","$rootScope",function(t,l){return{link:function(e,a,i,n){angular.extend(e,t.extractFromAttr(i,"fngJqUploadForm",e.formScope,{setUpDynamicLabelFunc:!0})),e.label=e.formScope.label,e.passedParams=e.formScope[i.schema],angular.extend(e.options,e.passedParams.fngJqUploadForm),e.options.additFields&&(e.directiveOptions.additFields=JSON.parse(e.options.additFields)),e.directiveOptions.url="/api/file/upload/"+e.formScope.modelName+"/"+encodeURIComponent(e.info.name),e.directiveOptions.autoUpload=e.directiveOptions.autoupload,e.passedParams.readonly?e.isDisabled=!0:e.isDisabled="function"==typeof l.isSecurelyDisabled&&l.isSecurelyDisabled(e.info.id),e.name=e.passedParams.name,e.ngModel=n},restrict:"E",require:"?ngModel",templateUrl:"templates/fileform.html",scope:{},controller:"FngJqUploadCtrl"}}]).controller("FileDestroyController",["$scope","$http",function(l,a){function i(e){a=e.deleteUrl;for(var a,i=/\/file\/(.+?)\/([0-9a-f]{24})/.exec(a)[2],n=l.uploadScope.dataField(),t=n.length-1;0<=t;t--)n[t]._id===i&&n.splice(t,1);l.clear(e),l.ngModel.$setDirty()}var n,t=l.file;l.uploadScope=l.$parent.$parent.$parent;t.deleteUrl?(t.$state=function(){return n},t.$destroy=function(e){if(!e||!e.target.className.includes("ng-hide"))return l.$parent.$parent.mouseIn=!1,n="pending",a({url:t.deleteUrl,method:t.deleteType}).then(function(){n="resolved",i(t)},function(){n="rejected",i(t)})}):t.$cancel||t._index||(t.$cancel=function(){i(t)})}])}(),angular.module("uploadModule").run(["$templateCache",function(e){"use strict";e.put("templates/fileform.html",'<div class="form-group control-group" id=cg_f_{{info.name}} {{info.add}}><label for=f_{{info.name}} id={{info.name}}-label class="col-sm-3 control-label">{{label ? label() : (info.label || (info.name | titleCase))}}</label><div class="bs3-input col-sm-9 row-fluid"><div class="col-xs-12 span12 fileupload-form"><div class=fileupload method=POST enctype=multipart/form-data data-ng-app=demo data-file-upload=directiveOptions data-ng-class="{\'fileupload-processing\': processing() || loadingFiles}"><div class=controls><div class="row fileupload-buttonbar"><div class="col-md-12 span7" style="min-height: 60px;"><div data-ng-show="directiveOptions.single && queue.length === 0" class=pull-left><span class="btn btn-success fileinput-button" ng-class="{disabled: isDisabled}"><i class="glyphicon glyphicon-plus icon icon-plus"></i> <span>Upload {{label ? label() : (info.label || (info.name | titleCase))}}</span> <input type=file name=files ng-disabled=isDisabled placeholder="Upload {{ label ? label() : (info.label || (info.name | titleCase))}}"></span></div><div data-ng-show=directiveOptions.single class=pull-left><div class=preview ng-show=!!queue[0].thumbnailUrl><a data-ng-href={{queue[0].url}} title={{queue[0].name}} download={{queue[0].name}} target=_blank data-gallery ng-mouseover="mouseIn=1" ng-mouseout="mouseIn=0"><img data-ng-src={{queue[0].thumbnailUrl}} alt=""></a></div></div><div data-ng-show=directiveOptions.single class="pull-left file-delete-div"><button ng-show="mouseIn && !isDisabled" class="file-delete overlay-btn" aria-label=Delete ng-mouseover="mouseIn=1" data-ng-click=queue[0].$destroy($event)><i class="glyphicon glyphicon-trash icon icon-trash"></i></button></div><span data-ng-hide=directiveOptions.single><span class="btn btn-success fileinput-button" ng-class="{disabled: isDisabled}"><i class="glyphicon glyphicon-plus icon icon-plus"></i> <span>Add files...</span> <input type=file name=files multiple ng-disabled=isDisabled placeholder="Upload {{info.label || (info.name | titleCase)}}"> </span></span><button type=button data-ng-hide=directiveOptions.autoupload class="btn btn-primary start" data-ng-click=submit()><i class="glyphicon glyphicon-upload icon icon-upload"></i> <span>Start upload</span></button> <button data-ng-show=active() type=button class="btn btn-warning cancel" data-ng-click=cancel()><i class="glyphicon glyphicon-ban icon-circle icon-ban-circle"></i> <span>Cancel upload</span></button><div data-ng-show=uploadError style="padding-top: 5px;"><span class="error text-danger">{{ uploadError }}</span></div><span class=fileupload-process></span></div><div class="col-md-5 span5 fade" data-ng-class="{in: active()}"><div class="progress progress-striped active" data-file-upload-progress=progress()><div class="progress-bar progress-bar-success" data-ng-style="{width: num + \'%\'}"></div></div><div class=progress-extended>&nbsp;</div></div></div><table data-ng-hide=directiveOptions.single class="table table-striped files ng-cloak"><tr data-ng-repeat="file in queue"><td data-ng-switch data-on=!!file.thumbnailUrl><div class=preview data-ng-switch-when=true><a data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery><img data-ng-src={{file.thumbnailUrl}} alt="" width=80 height=60></a></div><div class=preview data-ng-switch-default data-file-upload-preview=file></div></td><td><p class=name data-ng-switch data-on=!!file.url><span data-ng-switch-when=true data-ng-switch data-on=!!file.thumbnailUrl><a data-ng-switch-when=true data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery>{{file.name}}</a> <a data-ng-switch-default data-ng-href={{file.url}} title={{file.name}} download={{file.name}}>{{file.name}}</a> </span><span data-ng-switch-default>{{file.name}}</span></p><strong data-ng-show=file.error class="error text-danger">{{file.error}}</strong></td><td><p class=size>{{file.size | formatFileSize}}</p><div class="progress progress-striped active fade" data-ng-class="{pending: \'in\'}[file.$state()]" data-file-upload-progress=file.$progress()><div class="progress-bar progress-bar-success" data-ng-style="{width: num + \'%\'}"></div></div></td><td ng-show=directiveOptions.additFields><fng-upload-addit-fields file={{$index}}></fng-upload-addit-fields></td><td><button type=button class="btn btn-primary start" data-ng-click=file.$submit() data-ng-hide="!file.$submit || directiveOptions.autoupload" data-ng-disabled="file.$state() == \'pending\' || file.$state() == \'rejected\'"><i class="glyphicon glyphicon-upload icon icon-upload"></i> <span>Start</span></button> <button type=button class="btn btn-warning cancel" data-ng-click=file.$cancel() data-ng-hide=!file.$cancel><i class="glyphicon glyphicon-ban-circle icon icon-ban-circle"></i> <span>Cancel</span></button> <button type=button class="btn btn-danger destroy" data-ng-click=file.$destroy() data-ng-hide="!file.$destroy || isDisabled" data-ng-controller=FileDestroyController><i class="glyphicon glyphicon-trash icon icon-trash"></i> <span>Delete</span></button></td></tr></table></div></div></div></div></div>')}]);
1
+ !function(){"use strict";var e=angular.module("uploadModule",["blueimp.fileupload"]);e.controller("FngUploadAdditFieldsCtrl",["$scope","$timeout",function(i,e){function n(){i.schema&&i.schema.forEach(function(e){var a=i.uploadForm.dataField()[i.file];i.record[e.name]=a?a[e.name]:void 0})}i.record={},i.$watch("record",function(e,a){e!==a&&(i.uploadForm.formScope[i.uploadForm.formScope.topLevelFormName].$setDirty(),angular.extend(i.uploadForm.dataField()[i.file],e))},!0),e(function(){var a;i.formScope.newRecord?i.record={}:a=i.formScope.$watch("phase",function(e){"ready"===e&&(n(),i.$on("fngCancel",function(){n()}),a())})})}]).directive("fngUploadAdditFields",function(){return{link:function(e,a,i){e.uploadForm=e.$parent.$parent.$parent,e.formScope=e.uploadForm.formScope,e.schema=e.uploadForm.directiveOptions.additFields,e.file=parseInt(i.file)},scope:{},controller:"FngUploadAdditFieldsCtrl",template:'<form-input formstyle="inline" schema="schema" model="record" forceform="true"></form-input>'}}).controller("FngJqUploadCtrl",["$scope","$http",function(r,i){function c(e,a){return 1<e?i.get(a).then(e=>{if(201===e.status)return e.data.clientUrl;throw e="Unexpected response to getPresignedUrl (status"+e.status+")",new Error(e)}):Promise.resolve(a)}function s(a,e,i,n,t){var l=r.formScope.modelName+"/"+e;let o="/api/file/"+l+"/"+i;if(c(e,o).then(e=>{a.url=e}),a.deleteUrl=o,t&&(a.deleteUrl+=","+t),a.deleteType="DELETE",a.thumbnailUrl="https://upload.wikimedia.org/wikipedia/commons/6/6c/Iconoir_journal-page.svg",n&&!r.options.defaultThumbnail){var s=n.toLowerCase();for(const d of[".gif",".png",".jpg",".jpeg"])if(s.endsWith(d)){if(t){const o="/api/file/"+l+"/"+t;c(e,o).then(e=>{a.thumbnailUrl=e})}else a.thumbnailUrl="/api/file/"+l+"/thumbnail/"+i;break}}}function d(){r.formScope.fngJqUploadFileQueue=r.$$childHead.queue}function e(){var e=r.dataField();if(e){for(const t of e){var a=void 0===t.location?1:t.location,i=t.filename,n={name:i,size:t.size,location:a};s(n,a,t._id,i,t.thumbnailId),r.$$childHead.queue||(r.$$childHead.queue=[]),r.$$childHead.queue.push(n)}d()}}var a;r.loadingFiles=!1,r.formScope=r.$parent,r.dataField=function(e){if(-1===r.info.name.indexOf(".")){var a=r.options.model||"record",a=r.formScope[a];if(!(o=a?a[r.info.name]:o)&&e){if(!a)throw new Error(`Cannot initialise record. ${r.info.name} - record is not defined`);o=a[r.info.name]=[]}}else if(r.options.subschema){for(var e=r.formScope.record,a=r.info.name,i=r.options.subschemaroot,a=a.slice(i.length+1),n=(o=e,i.split(".")),t=0,l=n.length;t<l;t++)o=o[n[t]];var o,e=r.options.index;if(void 0!==(e=void 0===e?r.$parent.$index:e)){if(!o[e])return;o[e][a]||(o[e][a]=[]),o=o[e][a]}else r.options.subkey?o=null!=(e=r.formScope["$_arrayOffset_"+i.replace(/\./g,"_")+"_"+r.options.subkeyno])&&void 0!==e&&-1!==e?o[e][a]:void 0:console.log("No support for this yet")}else console.log("No support for this yet either");return o},r.initialiseJqUpload=function(){r.$$childHead.queue=r.$$childHead.queue||[],e(),r.$on("fngCancel",function(){r.$$childHead.queue=[],e()})},r.formScope.newRecord||(a=r.formScope.$watch("phase",function(e){"ready"===e&&(r.initialiseJqUpload(),a())})),r.$on("jqUpload:reinitialise",function(){r.$$childHead.queue=[],r.initialiseJqUpload()}),r.$on("fileuploadstart",function(){delete r.uploadError}),r.$on("fngCancel",()=>{var e=r.$$childHead;e&&"function"==typeof e.active&&e.active()&&"function"==typeof e.cancel&&e.cancel()}),r.$on("fileuploadfail",function(e,a){r.$$childHead.queue.pop();let i;if(a.xhr){var n,t=a.xhr();try{n=JSON.parse(t.responseText),i=n.error||n}catch(e){i=t.responseText}}"abort"!==(i=i||a.errorThrown||"an unexpected error occurred")&&(r.uploadError=i),i.includes("ENOTFOUND")&&(i="Failed to connect to storage service to upload file. Have you gone offline?")}),r.$on("fileuploaddone",function(e,a){var i=r.dataField(!0),a=a.result.files[0],n=a.id,t=a.name,l=a.location,o=a.thumbnailId,i=(i.push({_id:n,filename:t,size:a.size,location:l,thumbnailId:o}),r.$$childHead.queue);s(i[i.length-1],l,n,t,o),r.ngModel.$setDirty(),d()})}]).directive("fngJqUploadForm",["PluginHelperService","$rootScope",function(t,l){return{link:function(e,a,i,n){angular.extend(e,t.extractFromAttr(i,"fngJqUploadForm",e.formScope,{setUpDynamicLabelFunc:!0})),e.label=e.formScope.label,e.passedParams=e.formScope[i.schema],angular.extend(e.options,e.passedParams.fngJqUploadForm),e.options.additFields&&(e.directiveOptions.additFields=JSON.parse(e.options.additFields)),e.directiveOptions.url="/api/file/upload/"+e.formScope.modelName+"/"+encodeURIComponent(e.info.name),e.directiveOptions.autoUpload=e.directiveOptions.autoupload,e.passedParams.readonly?e.isDisabled=!0:e.isDisabled="function"==typeof l.isSecurelyDisabled&&l.isSecurelyDisabled(e.info.id),e.name=e.passedParams.name,e.ngModel=n},restrict:"E",require:"?ngModel",templateUrl:"templates/fileform.html",scope:{},controller:"FngJqUploadCtrl"}}]).controller("FileDestroyController",["$scope","$http",function(l,a){function i(e){a=e.deleteUrl;for(var a,i=/\/file\/(.+?)\/([0-9a-f]{24})/.exec(a)[2],n=l.uploadScope.dataField(),t=n.length-1;0<=t;t--)n[t]._id===i&&n.splice(t,1);l.clear(e),l.ngModel.$setDirty()}var n,t=l.file;l.uploadScope=l.$parent.$parent.$parent;t.deleteUrl?(t.$state=function(){return n},t.$destroy=function(e){if(!e||!e.target.className.includes("ng-hide"))return l.$parent.$parent.mouseIn=!1,n="pending",a({url:t.deleteUrl,method:t.deleteType}).then(function(){n="resolved",i(t)},function(){n="rejected",i(t)})}):t.$cancel||t._index||(t.$cancel=function(){i(t)})}])}(),angular.module("uploadModule").run(["$templateCache",function(e){"use strict";e.put("templates/fileform.html",'<div class="form-group control-group" id=cg_f_{{info.name}} {{info.add}}><label for=f_{{info.name}} id={{info.name}}-label class="col-sm-3 control-label">{{label ? label() : (info.label || (info.name | titleCase))}}</label><div class="bs3-input col-sm-9 row-fluid"><div class="col-xs-12 span12 fileupload-form"><div class=fileupload method=POST enctype=multipart/form-data data-ng-app=demo data-file-upload=directiveOptions data-ng-class="{\'fileupload-processing\': processing() || loadingFiles}"><div class=controls><div class="row fileupload-buttonbar"><div class="col-md-12 span7" style="min-height: 60px;"><div data-ng-show="directiveOptions.single && queue.length === 0" class=pull-left><span class="btn btn-success fileinput-button" ng-class="{disabled: isDisabled}"><i class="glyphicon glyphicon-plus icon icon-plus"></i> <span>Upload {{label ? label() : (info.label || (info.name | titleCase))}}</span> <input type=file name=files ng-disabled=isDisabled placeholder="Upload {{ label ? label() : (info.label || (info.name | titleCase))}}"></span></div><div data-ng-show=directiveOptions.single class=pull-left><div class=preview ng-show=!!queue[0].thumbnailUrl><a data-ng-href={{queue[0].url}} title={{queue[0].name}} download={{queue[0].name}} target=_blank data-gallery ng-mouseover="mouseIn=1" ng-mouseout="mouseIn=0"><img data-ng-src={{queue[0].thumbnailUrl}} alt="" width="{{ options.width || 80 }}" height="{{ options.height || 60 }}"></a></div></div><div data-ng-show="directiveOptions.single && !active()" class="pull-left file-delete-div"><button ng-show="mouseIn && !isDisabled" class="file-delete overlay-btn" aria-label=Delete ng-mouseover="mouseIn=1" data-ng-click=queue[0].$destroy($event)><i class="glyphicon glyphicon-trash icon icon-trash"></i></button></div><span data-ng-hide=directiveOptions.single><span class="btn btn-success fileinput-button" ng-class="{disabled: isDisabled}"><i class="glyphicon glyphicon-plus icon icon-plus"></i> <span>Add files...</span> <input type=file name=files multiple ng-disabled=isDisabled placeholder="Upload {{info.label || (info.name | titleCase)}}"> </span></span><button type=button data-ng-hide=directiveOptions.autoupload class="btn btn-primary start" data-ng-click=submit()><i class="glyphicon glyphicon-upload icon icon-upload"></i> <span>Start upload</span></button> <button data-ng-show=active() type=button class="btn btn-warning cancel" data-ng-click=cancel()><i class="glyphicon glyphicon-ban icon-circle icon-ban-circle"></i> <span>Cancel upload</span></button><div data-ng-show=uploadError style="padding-top: 5px;"><span class="error text-danger">{{ uploadError }}</span></div><span class=fileupload-process></span></div><div class="col-md-5 span5 fade" data-ng-class="{in: active()}"><div class="progress progress-striped active" data-file-upload-progress=progress()><div class="progress-bar progress-bar-success" data-ng-style="{width: num + \'%\'}"></div></div><div class=progress-extended>&nbsp;</div></div></div><table data-ng-hide=directiveOptions.single class="table table-striped files ng-cloak"><tr data-ng-repeat="file in queue"><td data-ng-switch data-on=!!file.thumbnailUrl><div class=preview data-ng-switch-when=true><a data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery><img data-ng-src={{file.thumbnailUrl}} alt="" width=80 height=60></a></div><div class=preview data-ng-switch-default data-file-upload-preview=file></div></td><td><p class=name data-ng-switch data-on=!!file.url><span data-ng-switch-when=true data-ng-switch data-on=!!file.thumbnailUrl><a data-ng-switch-when=true data-ng-href={{file.url}} title={{file.name}} download={{file.name}} target=_blank data-gallery>{{file.name}}</a> <a data-ng-switch-default data-ng-href={{file.url}} title={{file.name}} download={{file.name}}>{{file.name}}</a> </span><span data-ng-switch-default>{{file.name}}</span></p><strong data-ng-show=file.error class="error text-danger">{{file.error}}</strong></td><td><p class=size>{{file.size | formatFileSize}}</p><div class="progress progress-striped active fade" data-ng-class="{pending: \'in\'}[file.$state()]" data-file-upload-progress=file.$progress()><div class="progress-bar progress-bar-success" data-ng-style="{width: num + \'%\'}"></div></div></td><td ng-show=directiveOptions.additFields><fng-upload-addit-fields file={{$index}}></fng-upload-addit-fields></td><td><button type=button class="btn btn-primary start" data-ng-click=file.$submit() data-ng-hide="!file.$submit || directiveOptions.autoupload" data-ng-disabled="file.$state() == \'pending\' || file.$state() == \'rejected\'"><i class="glyphicon glyphicon-upload icon icon-upload"></i> <span>Start</span></button> <button type=button class="btn btn-warning cancel" data-ng-click=file.$cancel() data-ng-hide=!file.$cancel><i class="glyphicon glyphicon-ban-circle icon icon-ban-circle"></i> <span>Cancel</span></button> <button type=button class="btn btn-danger destroy" data-ng-click=file.$destroy() data-ng-hide="!file.$destroy || isDisabled" data-ng-controller=FileDestroyController><i class="glyphicon glyphicon-trash icon icon-trash"></i> <span>Delete</span></button></td></tr></table></div></div></div></div></div>')}]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-jq-upload",
3
- "version": "0.12.0-beta.261",
3
+ "version": "0.12.0-beta.263",
4
4
  "author": "Mark Chapman <support@forms-angular.org>",
5
5
  "description": "jQuery file upload plugin for forms-angular, storing data in Mongo. Pretty much a wrapper for BlueImp jquery-file-upload",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "async": "3.2.4",
28
28
  "body-parser": "1.20.1",
29
29
  "express": "4.18.2",
30
- "forms-angular": "0.12.0-beta.261",
30
+ "forms-angular": "0.12.0-beta.263",
31
31
  "grunt": "^1.5.3",
32
32
  "grunt-angular-templates": "^1.2.0",
33
33
  "grunt-contrib-concat": "2.1.0",
@@ -23,7 +23,7 @@
23
23
  </a>
24
24
  </div>
25
25
  </div>
26
- <div data-ng-show="directiveOptions.single" class="pull-left file-delete-div">
26
+ <div data-ng-show="directiveOptions.single && !active()" class="pull-left file-delete-div">
27
27
  <button ng-show="mouseIn && !isDisabled" class="file-delete overlay-btn" aria-label="Delete" ng-mouseover="mouseIn=1" data-ng-click="queue[0].$destroy($event)">
28
28
  <i class="glyphicon glyphicon-trash icon icon-trash"></i>
29
29
  </button>