diff --git a/app/fng-jq-upload.js b/app/fng-jq-upload.js index 8901055..92455bb 100644 --- a/app/fng-jq-upload.js +++ b/app/fng-jq-upload.js @@ -83,7 +83,7 @@ $scope.dataField = function (initialise) { var retVal; if ($scope.info.name.indexOf('.') === -1) { - const model = $scope.options?.model || "record"; + const model = $scope.options.model || 'record'; const record = $scope.formScope[model]; if (record) { retVal = record[$scope.info.name]; diff --git a/dist/fng-jq-upload.js b/dist/fng-jq-upload.js index 132a43b..2f8d81f 100644 --- a/dist/fng-jq-upload.js +++ b/dist/fng-jq-upload.js @@ -83,7 +83,7 @@ $scope.dataField = function (initialise) { var retVal; if ($scope.info.name.indexOf('.') === -1) { - const model = $scope.options?.model || "record"; + const model = $scope.options.model || 'record'; const record = $scope.formScope[model]; if (record) { retVal = record[$scope.info.name]; diff --git a/dist/fng-jq-upload.min.js b/dist/fng-jq-upload.min.js index 4802408..abeb9ab 100644 --- a/dist/fng-jq-upload.min.js +++ b/dist/fng-jq-upload.min.js @@ -1 +1 @@ -!function(){"use strict";var e=angular.module("uploadModule",["blueimp.fileupload"]);e.controller("FngUploadAdditFieldsCtrl",["$scope","$timeout",function(i,e){function t(){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&&(t(),i.$on("fngCancel",function(){t()}),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:''}}).controller("FngJqUploadCtrl",["$scope","$http",function(r,i){function c(e,a){return 1{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,t,n){var l=r.formScope.modelName+"/"+e;let o="/api/file/"+l+"/"+i;if(c(e,o).then(e=>{a.url=e}),a.deleteUrl=o,n&&(a.deleteUrl+=","+n),a.deleteType="DELETE",a.thumbnailUrl="https://upload.wikimedia.org/wikipedia/commons/6/6c/Iconoir_journal-page.svg",t&&!r.options.defaultThumbnail){var s=t.toLowerCase();for(const d of[".gif",".png",".jpg",".jpeg"])if(s.endsWith(d)){if(n){const o="/api/file/"+l+"/"+n;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 n of e){var a=void 0===n.location?1:n.location,i=n.filename,t={name:i,size:n.size,location:a};s(t,a,n._id,i,n.thumbnailId),r.$$childHead.queue||(r.$$childHead.queue=[]),r.$$childHead.queue.push(t)}d()}}var t;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),t=(o=e,i.split(".")),n=0,l=t.length;n{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 t,n=a.xhr();try{t=JSON.parse(n.responseText),i=t.error||t}catch(e){i=n.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],t=a.id,n=a.name,l=a.location,o=a.thumbnailId,i=(i.push({_id:t,filename:n,size:a.size,location:l,thumbnailId:o}),r.$$childHead.queue);s(i[i.length-1],l,t,n,o),r.ngModel.$setDirty(),d()})}]).directive("fngJqUploadForm",["PluginHelperService","$rootScope",function(n,l){return{link:function(e,a,i,t){angular.extend(e,n.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=t},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],t=l.uploadScope.dataField(),n=t.length-1;0<=n;n--)t[n]._id===i&&t.splice(n,1);l.clear(e),l.ngModel.$setDirty()}var t,n=l.file;l.uploadScope=l.$parent.$parent.$parent;n.deleteUrl?(n.$state=function(){return t},n.$destroy=function(e){if(!e||!e.target.className.includes("ng-hide"))return l.$parent.$parent.mouseIn=!1,t="pending",a({url:n.deleteUrl,method:n.deleteType}).then(function(){t="resolved",i(n)},function(){t="rejected",i(n)})}):n.$cancel||n._index||(n.$cancel=function(){i(n)})}])}(),angular.module("uploadModule").run(["$templateCache",function(e){"use strict";e.put("templates/fileform.html",'
Upload {{label ? label() : (info.label || (info.name | titleCase))}}
Add files...
{{ uploadError }}
 

{{file.name}} {{file.name}} {{file.name}}

{{file.error}}

{{file.size | formatFileSize}}

')}]); \ No newline at end of file +!function(){"use strict";var e=angular.module("uploadModule",["blueimp.fileupload"]);e.controller("FngUploadAdditFieldsCtrl",["$scope","$timeout",function(i,e){function t(){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&&(t(),i.$on("fngCancel",function(){t()}),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:''}}).controller("FngJqUploadCtrl",["$scope","$http",function(r,i){function c(e,a){return 1{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,t,n){var l=r.formScope.modelName+"/"+e;let o="/api/file/"+l+"/"+i;if(c(e,o).then(e=>{a.url=e}),a.deleteUrl=o,n&&(a.deleteUrl+=","+n),a.deleteType="DELETE",a.thumbnailUrl="https://upload.wikimedia.org/wikipedia/commons/6/6c/Iconoir_journal-page.svg",t&&!r.options.defaultThumbnail){var s=t.toLowerCase();for(const d of[".gif",".png",".jpg",".jpeg"])if(s.endsWith(d)){if(n){const o="/api/file/"+l+"/"+n;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 n of e){var a=void 0===n.location?1:n.location,i=n.filename,t={name:i,size:n.size,location:a};s(t,a,n._id,i,n.thumbnailId),r.$$childHead.queue||(r.$$childHead.queue=[]),r.$$childHead.queue.push(t)}d()}}var t;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),t=(o=e,i.split(".")),n=0,l=t.length;n{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 t,n=a.xhr();try{t=JSON.parse(n.responseText),i=t.error||t}catch(e){i=n.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],t=a.id,n=a.name,l=a.location,o=a.thumbnailId,i=(i.push({_id:t,filename:n,size:a.size,location:l,thumbnailId:o}),r.$$childHead.queue);s(i[i.length-1],l,t,n,o),r.ngModel.$setDirty(),d()})}]).directive("fngJqUploadForm",["PluginHelperService","$rootScope",function(n,l){return{link:function(e,a,i,t){angular.extend(e,n.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=t},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],t=l.uploadScope.dataField(),n=t.length-1;0<=n;n--)t[n]._id===i&&t.splice(n,1);l.clear(e),l.ngModel.$setDirty()}var t,n=l.file;l.uploadScope=l.$parent.$parent.$parent;n.deleteUrl?(n.$state=function(){return t},n.$destroy=function(e){if(!e||!e.target.className.includes("ng-hide"))return l.$parent.$parent.mouseIn=!1,t="pending",a({url:n.deleteUrl,method:n.deleteType}).then(function(){t="resolved",i(n)},function(){t="rejected",i(n)})}):n.$cancel||n._index||(n.$cancel=function(){i(n)})}])}(),angular.module("uploadModule").run(["$templateCache",function(e){"use strict";e.put("templates/fileform.html",'
Upload {{label ? label() : (info.label || (info.name | titleCase))}}
Add files...
{{ uploadError }}
 

{{file.name}} {{file.name}} {{file.name}}

{{file.error}}

{{file.size | formatFileSize}}

')}]); \ No newline at end of file