!function(a,b){"use strict";function c(){return{previewsContainer:!1,maxFiles:null,previewTemplate:a.Dropzone.prototype.defaultOptions.previewTemplate,clickable:!1}}function d(){null!==i&&(i.destroy(),i=null)}function e(e){d();var h={},l=c();Object.keys(l).forEach(function(a){h[a]=e.hasOwnProperty(a)?e[a]:l[a]});var m=h.previewsContainer===!1;b.extend(h,{method:"POST",url:a.CCM_DISPATCHER_FILENAME+"/ccm/system/file/upload",sending:function(a,b,c){m&&NProgress.start(),c.append("responseFormat","dropzone");var d=j[j.length-1];d.originalPageID&&c.append("ocID",g(d.originalPageID)?d.originalPageID():d.originalPageID),d.replacingFileID&&c.append("fID",g(d.replacingFileID)?d.replacingFileID():d.replacingFileID),d.folderID&&c.append("currentFolder",g(d.folderID)?d.folderID():d.folderID),d.uploadStarted&&d.uploadStarted(a,b,c)},success:function(a,b){f(b)},chunksUploaded:function(a,b){a.xhr.response&&f(JSON.parse(a.xhr.response)),b()},error:function(a,b,c){this.defaultOptions.error.apply(this,arguments),1===this.options.maxFiles&&a&&(a instanceof Array||(a=[a]),a.forEach(function(a){a&&a.accepted&&(a.accepted=!1)})),j[j.length-1].uploadFailed?j[j.length-1].uploadFailed(b):ConcreteAlert.error({message:b,appendTo:document.body})},queuecomplete:function(){m&&NProgress.done(),j.length&&j[j.length-1].uploadQueueCompleted&&j[j.length-1].uploadQueueCompleted(),0!==k.length&&(ConcreteEvent.publish("FileManagerAddFilesComplete",{files:k}),k=[])}}),i=new a.Dropzone(window.document.body,h)}function f(a){a&&ConcreteAjaxRequest.validateResponse(a,function(b){var c=j[j.length-1];if(b){if(a.files&&a.files.length)if(c.uploadCompleted)c.uploadCompleted(a.files);else{var d=g(c.replacingFileID)?c.replacingFileID():c.replacingFileID;d?ConcreteEvent.publish("FileManagerReplaceFileComplete",{files:a.files}):a.files.forEach(function(a){k.push(a)})}}else a.message&&(c.uploadFailed&&c.uploadFailed(a.message),ConcreteAlert.notify({title:a.title,message:a.message,appendTo:document.body}))})}function g(a){return!!(a&&a.constructor&&a.call&&a.apply)}if("undefined"==typeof a.ccm_fileUploader){var h=!1,i=null,j=[],k=[];b(document).ready(function(){h=!0,0!==j.length&&e(j[j.length-1])});var l={};Object.defineProperties(l,{start:{writable:!1,value:function(a){a=a||{},j.push(a),h&&e(a)}},stop:{writable:!1,value:function(b){var c=j.indexOf(b);if(c<0)return void a.console.error("Invalid options passed to ccm_fileUploader.stop()");var f=c===j.length-1;j.splice(c,1),f&&(d(),h&&j.length>0&&e(j[j.length-1]))}}}),Object.defineProperties(a,{ccm_fileUploader:{writable:!1,value:l}})}}(this,jQuery);