+function(n,t){var i=n.ERFx=n.ERFx||{};i.Controls=i.Controls||{};n.ERFx.Controls.FileUploader=function(i,r,u,f,e,o,s,h,c,l,a,v,y,p,w,b,k,d){this._containerId=r;this.container=jQuery("#"+this._containerId);this.maxUploadCount=k.Get("MaxUploadCount");this.Init=function(){u.FileUploadStart.AddHandler(jQuery.proxy(this,"OnUploadStart"));u.FileUploadComplete.AddHandler(jQuery.proxy(this,"OnUploadComplete"));u.UploadingProgressChanged.AddHandler(jQuery.proxy(this,"OnProgressChanged"));o.Click.AddHandler(jQuery.proxy(this,"OnUploadClick"));w.Click.AddHandler(jQuery.proxy(this,"OnCancelClick"));b.CallbackComplete.AddHandler(jQuery.proxy(this,"OnRemoved"));s.Click.AddHandler(jQuery.proxy(this,"Preview"));this.BindDOMHandlers();this.DataBindControls()};this.BindDOMHandlers=function(){var n=this;this.container=jQuery("#"+this._containerId);this.container.find(".js--fileinfo-item-remove-btn").click(function(){n.MultipleModeFileRemove(this)})};this.AddHandler=function(n,t){this.events[n]=t};this.OnProgressChanged=function(n,t){y.SetPosition(t.progress);var i=t.currentFileName+"&emsp; "+this.BytesToString(t.uploadedContentLength)+" / "+this.BytesToString(t.totalContentLength);p.SetContentHtml(i)};this.OnUploadClick=function(){if(typeof u!="undefuned"&&!u.GetText())return k12PopupEFX.Alert("Upload file is required!"),!1;if(typeof f!="undefined"&&!f.GetText()&&e)return k12PopupEFX.Alert("Description to uploaded file is required!"),!1;if(this.maxUploadCount>0&&this.maxUploadCount<=this.container.find(".fileinfo-item").length){k12PopupEFX.Alert("You cannot upload more than "+this.maxUploadCount+" item(s)!");return}u.UploadFile()};this.OnCancelClick=function(){u.Cancel();v.Hide()};this.Preview=function(){n.open(k.Get("Link"),"_blank","location=0,status=0,scrollbars=1,resizable=0, fullscreen=1")};this.OnUploadStart=function(){o.SetEnabled(!1);v.Show();y.SetPosition(0);p.SetContentHtml("");k.Set("Description",f.GetText())};this.OnUploadComplete=function(n,t){if(v.Hide(),t.isValid){var i=t.callbackData.split("|");k.Set("Link",i[0]);k.Set("Size",i[2]);k.Set("Ext",i[1]);k.Set("UploadedAttachmentID",i[3]);k.Set("FileName",i[4]);k.Get("IsMultipleUpload")&&this.AddUploadedAttachment();this.DataBindControls()}else o.SetEnabled(!0)};this.isFileUploaded=function(){return!o.GetEnabled()};this.DataBindControls=function(){var n=k.Get("IsMultipleUpload");l.SetNavigateUrl(k.Get("Link"));a.SetNavigateUrl("javascript:"+i+".Remove();");f.SetText(k.Get("Description"));s.SetImageUrl(this.GetIconByExt());h.SetVisible(this.GetFileExists());a.SetVisible(k.Get("IsEditable"));n?(this.maxUploadCount>0?this.maxUploadCount<=this.container.find(".fileinfo-item").length?(console.log("Cant upload again!"),u.SetEnabled(!1),f.SetEnabled(!1),o.SetEnabled(!0)):(u.SetEnabled(!0),f.SetEnabled(!0),o.SetEnabled(!0)):(u.SetEnabled(!0),f.SetEnabled(!0),o.SetEnabled(!0)),this.container.find(".fileinfo-item").length>0&&this.container.find(".fileinfo-items-wrapper")):(u.SetEnabled(!this.GetFileExists()),f.SetEnabled(!this.GetFileExists()),o.SetEnabled(!this.GetFileExists()));c.SetText(String.format("(.{0}, {1})",k.Get("Ext").toUpperCase(),this.BytesToString(k.Get("Size"))));this.ShowHideMultipleFilesInfo();typeof d=="function"&&d();typeof f!="undefined"&&f.SetText("")};this.Clear=function(){k.Set("Link","");k.Set("Size","");k.Set("Ext","");k.Set("Description",k.Get("DefaultDescription"));k.Set("UploadedAttachmentID","");k.Set("FileName","");this.DataBindControls()};this.ShowHideMultipleFilesInfo=function(){this.container.find(".js--pnl-multiple-files-info .fileinfo-item").length<=0?this.container.find(".js--pnl-multiple-files-info").hide():this.container.find(".js--pnl-multiple-files-info").show()};this.Remove=function(){this.ShowHideMultipleFilesInfo();b.PerformCallback();loading.Show()};this.OnRemoved=function(n,t){loading.Hide();t.result=="completed"?this.Clear():t.result=="failed"&&k12PopupEFX.Alert("Could not remove file")};this.GetIconByExt=function(){var n=k.Get("Ext");if(k.Get("ContentType")==1)return n!=null&&n!=""?k.Get("Link"):t.JsGlobal.ResolveUrl("~/images/not_uploaded.gif");if(n!=null&&n!="")switch(n){case"pdf":return t.JsGlobal.ResolveUrl("~/images/pdf_icon_100.jpg");case"xls":return t.JsGlobal.ResolveUrl("~/images/excel_icon_100.jpg");default:return t.JsGlobal.ResolveUrl("~/images/document_fan_100.jpg")}else return t.JsGlobal.ResolveUrl("~/images/not_uploaded.gif")};this.GetFileExists=function(){return k.Get("Link")!=""};this.SetDescription=function(n){k.Set("Description",n);f.SetText(n)};this.GetDescription=function(){return k.Get("Description")};this.BytesToString=function(n){return n==1?"1 byte":n<1024?String.format("{0} bytes",n):n<1048576?String.format("{0:N1} KB",n/1024):n<1073741824?String.format("{0:N2} MB",n/1048576):String.format("{0:N2} GB",n/1073741824)};this.MultipleModeFileRemove=function(n){var t=jQuery(n),i=t.data("att-id"),r=t.closest(".fileinfo-item");r.remove();b.PerformCallback(i)};this.AddUploadedAttachment=function(){var t=this.container.find(".fileinfo-items-container"),n=t.find(".fileinfo-item-empty").first().clone(),i=n.find(".fileinfo-item-name");i.attr("href",k.Get("Link"));i.text(k.Get("FileName"));n.find(".js--fileinfo-item-remove-btn").attr("data-att-id",k.Get("UploadedAttachmentID"));n.attr("class","fileinfo-item");t.append(n);this.container.find(".js--pnl-multiple-files-info").show();this.BindDOMHandlers()};this.Init()}}(window,K12Api)