(function(){"use strict";u8.Base.Widgets.FileUpload=function(t,e){this.Widget(t,$.extend({},u8.Base.Widgets.FileUpload.defaults,e));this._isCreated=false;this._create()};u8.Base.Widgets.FileUpload.defaults={};$.extend(u8.Base.Widgets.FileUpload.prototype,{startUpload:function(t){var e={params:this.params,progress:this._onUploadProgress.bind(this),form:t||this.form,file:this.file,url:this.url};this._displayMessage($t("TXT_file_text_1"));this._upload=u8.services.files.uploadForm(e,this._onUploadFinished.bind(this))},cancel:function(t){this._cancelUpload(t)},_create:function(){Function.chain(this._using,this._createView).call(this,u8.tools.created.curry(this))},dispose:function(){if(this._isDisposed){return}if(this._upload){this._upload.abort()}this.Widget_dispose()},_using:function(t){u8.using({templates:[{name:"fileupload-uploading-template",url:"~/crm/fileUpload/FileUpload.utml.htm"}],texts:["file_text","button_text"]},t)},_createView:function(t){var e=this;this.$(this.element).utml({name:"fileupload-uploading-template",itemOptions:{parent:this},data:{id:this.id,statusLabel:{id:this.id+"_status",visible:false},cancelButton:{id:this.id+"_cancelButton",command:"CancelUpload",text:"TXT_button_text_13"}}},function(){e._$progress=e.$(e.element).find("#"+e.id+"_progress");t()})},_onUploadProgress:function(t){if(this._isDisposed||t.indeterminate){return}if(t.percentComplete>0){this._$progress.val(Math.floor(t.percentComplete))}this.raise("Progress",{percentComplete:t.percentComplete})},_onUploadFinished:function(t,e){if(e.aborted){return}if(!e.error){this._$progress.val(100)}else{this._$progress.val(0)}this._showOkButton();this._displayMessage(e.error?$t("TXT_file_text_2"):$t("TXT_file_text_3"));this._result={error:e.error,response:e.response};this.raise("Finished",this._result)},"Command.CancelUpload":function(){this._cancelUpload()},"Command.Ok":function(){this.raise("Done",this._result)},_cancelUpload:function(t){if(this._upload&&!this._upload.isDone){this._upload.abort()}this._showOkButton();this._displayMessage(t||$t("TXT_file_text_0"));this._result={error:{canceled:true}};this.raise("Canceled",this._result)},_displayMessage:function(t){var e=this.getWidget("status");e.setText(t);e.update({reason:"text"});e.setVisible(true)},_showOkButton:function(){var t=this.getWidget("cancelButton");t.setVisible(false);var e=this.$(this.element).find("#"+this.id+"_okButton");e.show();u8.create("Button",e,{parent:this,command:"Ok",textId:"TXT_button_text_11",timeout:this.okTimeout})}});u8.Base.Widgets.FileUpload.makeClass({name:"FileUpload",deriveFrom:u8.Base.Widgets.Widget,events:["Canceled","Created","Done","Finished","Progress"]})})();