cronapp-framework-js
Version:
Javascript library for CronApp's projects
1 lines • 2.06 kB
JavaScript
app,angular.module("upload.services",[]).service("UploadService",["$http","$compile","$modal","Upload",function(e,o,t,a){var n=$("body");angular.element(n.get(0)).scope(),this.ensureProps=e=>(!e.filter||(e.filter=e.filter.replace(/\s/g,"")),e),this.upload=function(e){let o=this.ensureProps(e);t.open({templateUrl:"node_modules/cronapp-framework-js/components/upload/upload.html",controller:"UploadController",resolve:{data:function(){return o}}})}.bind(this)}]),angular.module("custom.controllers").controller("UploadController",["$scope","$http","$translate","$stateParams","$location","$http","$modalInstance","data",function(e,o,t,a,n,o,l,r){app.registerEventsCronapi(e,t),e.params=a,e.$http=o;var i=n.search();for(var s in i)i.hasOwnProperty(s)&&(e.params[s]=i[s]);e.files=[],e.uploading=!1,e.uploaded=!0,e.progress=0,e.data=r,e.message=t.instant("Upload.oneFile"),"true"==r.multiple&&(e.message=t.instant("Upload.multipleFile")),r.description&&(e.message=r.description),e.safeApply=safeApply,e.uploadFile=function(a){var n=e.data.scope,l="api/cronapi/upload/"+r.id,i=new FormData;if(0==a.length)this.Notification.error(function(e){var o=[].slice.call(arguments,1),t=0;return e.replace(/%s/g,(function(){return o[t++]}))}(t.instant("Upload.errorValidation"),r.maxSize,r.filter));else{for(var s=0;s<a.length;s++)i.append("file",a[s]),console.log(a[s].$valid);var p=JSON.parse(localStorage.getItem("_u"));let t=window.isUsingCookie()?{"Content-Type":void 0}:{"Content-Type":void 0,"X-AUTH-TOKEN":p?p.token:""};this.$promise=o({method:"POST",url:(window.hostApp||"")+l,data:i,headers:t,onProgress:function(o){this.safeApply((function(){if(o.lengthComputable){var t=o.loaded/o.total*100|0;e.progress=t}e.uploading=!0,console.log(t)}))}.bind(this)}).then(function(o,t,a,l){n.cronapi.evalInContext(JSON.stringify(o)).then((o=>{e.uploaded=!0,e.uploading=!1,e.close()}))}.bind(this)).catch(function(o,t,a){let n=o.error;o&&o.data&&(n=o.data.error),this.Notification.error(n),e.uploading=!1,e.close()}.bind(this))}}.bind(e),e.close=function(){l.dismiss("cancel")}}]);