Type.registerNamespace("Telerik.Sitefinity.Modules.Forms.Web.UI.Fields"); Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload=function(element){Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload.initializeBase(this,[element]); this._handlePageLoadDelegate=null; this._documentServiceUrl=null; this._errorLabelId=null; this._rangeViolationMessage=null; this._cantUploadFilesFormat=null; this._maxFileSize=null; this._minFileSize=null; this._allowedExtensions=null; this._allowMultipleAttachments=null; this._selector=null; this._selectorDialog=null; this._selectorInsertDelegate=null; this._selectFileButton=null; this._selectedFilesList=null; this._selectedFiles=[]; this._documentTypeFullName=null; this._dataItem=null; this._entriesTypeName=null; this._providerName=null; this._contentLinksApplicationName=null; this.thisElement=null; this._selectedFilesHiddenElement=null; this._radUpload=null; this._radUploadAddedDelegate=null; this._radUploadDeletingDelegate=null; this._removeButtonsSelector="input[name='RemoveRow']"; }; Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload.prototype={initialize:function(){Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload.callBaseMethod(this,"initialize"); this.thisElement=jQuery(this._element); if(this._selector){this._selectorDialog=jQuery(this._selector.get_element()).dialog({autoOpen:false,modal:true,width:655,height:"auto",closeOnEscape:true,resizable:false,draggable:false,classes:{"ui-dialog":"sfSelectorDialog sfZIndexL"}}); this._selectorInsertDelegate=Function.createDelegate(this,this._selectorInsertHandler); this._selector.set_customInsertDelegate(this._selectorInsertDelegate); this._selector.set_maxFileSize(this._maxFileSize); this._selector.set_allowedExtensions(this._allowedExtensions); }if(this.get_selectFileButton()){var that=this; jQuery(this.get_selectFileButton()).click(function(){that._selectorDialog.dialog("open"); that._dialogScrollToTop(that._selectorDialog); }); }if(this.get_radUpload()){this._radUploadAddedDelegate=Function.createDelegate(this,this._radUploadAddedHandler); this.get_radUpload().add_added(this._radUploadAddedDelegate); this._radUploadDeletingDelegate=Function.createDelegate(this,this._radUploadDeletingHandler); this.get_radUpload().add_deleting(this._radUploadDeletingDelegate); if(this.get_radUpload().getFileInputs().length<=1){jQuery(this.get_radUpload().get_element()).find(this._removeButtonsSelector).hide(); }}this._handlePageLoadDelegate=Function.createDelegate(this,this._handlePageLoad); Sys.Application.add_load(this._handlePageLoadDelegate); },dispose:function(){Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload.callBaseMethod(this,"dispose"); if(this._selectorInsertDelegate){delete this._selectorInsertDelegate; }if(this._handlePageLoadDelegate){Sys.Application.remove_load(this._handlePageLoadDelegate); delete this._handlePageLoadDelegate; }if(this.get_radUpload()){if(this._radUploadAddedDelegate){this.get_radUpload().remove_added(this._radUploadAddedDelegate); delete this._radUploadAddedDelegate; }if(this._radUploadDeletingDelegate){this.get_radUpload().remove_deleting(this._radUploadDeletingDelegate); delete this._radUploadDeletingDelegate; }}},validate:function(){var baseValid=Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormFileUpload.callBaseMethod(this,"validate"); if(!baseValid){return false; }var errorText=$("#"+this.get_errorLabelId()); var that=this; var allValid=true; if(window.File&&window.Blob&&this.get_radUpload()){$.each(this.get_radUpload().getFileInputs(),function(i,uploadControl){var valid=true; $.each(uploadControl.files,function(i,file){var extensionIndex=file.name.lastIndexOf("."); var extension=file.name.substring(extensionIndex+1,file.name.length).toLowerCase().trim(); if(that.get_allowedExtensions()!==null&&$.inArray(extension,that.get_allowedExtensions())===-1){var errorMessage=String.format(that.get_cantUploadFilesFormat(),"."+extension,that.get_allowedExtensions().join(", .")); errorText.html(errorMessage); errorText.show(); valid=false; return false; }if(that.get_minFileSize()>0&&file.size0&&file.size>that.get_maxFileSize()){errorText.html(that.get_rangeViolationMessage()); errorText.show(); valid=false; return false; }}); if(!valid){allValid=false; return false; }}); }if(allValid){errorText.hide(); }return allValid; },reset:function(){this._selectedFiles.length=0; $(this._selectedFilesList).empty(); this._resetHandler(); },_handlePageLoad:function(){if(this._selector){this._selector.get_uploaderView().get_parentLibrarySelector().get_createLibraryControl().get_createLibraryTxt().set_validator(undefined); }},_selectorInsertHandler:function(selectedItem){if(!this._allowMultipleAttachments){this._selectedFiles.length=0; $(this._selectedFilesList).empty(); }this._addDocument(selectedItem,this); this._selectedFiles.push({ParentItemId:this._dataItem.Id?this._dataItem.Id:this._emptyGuid,ParentItemProviderName:this._providerName,ParentItemType:this._entriesTypeName,ComponentPropertyName:this._dataFieldName,ChildItemId:selectedItem.Id,ChildItemType:this._documentTypeFullName,ChildItemProviderName:selectedItem.ProviderName,ChildItemAdditionalInfo:selectedItem.Title+selectedItem.Extension+"|"+selectedItem.MediaUrl,ApplicationName:this._contentLinksApplicationName,Ordinal:this._selectedFiles.length}); this._selectorDialog.dialog("close"); $(this._selectedFilesHiddenElement).val(JSON.stringify($sitefinity.fixObjectForSerialization(this._selectedFiles))); },_radUploadAddedHandler:function(sender,args){if(sender.getFileInputs().length>1){jQuery(sender.get_element()).find(this._removeButtonsSelector).show(); }},_radUploadDeletingHandler:function(sender,args){if(sender.getFileInputs().length<=2){jQuery(sender.get_element()).find(this._removeButtonsSelector).hide(); }},_loadItems:function(items){$("#filesPlaceholder").html(""); $("#selectedFiles").html(""); if(items){var that=this; for(var i=0; i'; documentMarkup+=''+title+""; documentMarkup+=' '+Math.round(document.TotalSize/1024)+" KB"; documentMarkup+=' [DELETE]'; documentMarkup+=""; $(this._selectedFilesList).append(documentMarkup); this._bindDelete(); },_addReadModeDocument:function(document){var title=document.Title.PersistedValue+document.Extension; var documentMarkup='
  • '; documentMarkup+=''+title+""; documentMarkup+=' '+Math.round(document.TotalSize/1024)+" KB"; documentMarkup+="
  • "; $(this._selectedFilesList).append(documentMarkup); },_bindDelete:function(){var that=this; this.thisElement.find(".sfAsset").find("[data-command=delete]").unbind(); this.thisElement.find(".sfAsset").find("[data-command=delete]").bind("click",function(){that._removeItem($(this).attr("data-id")); }); },_removeItem:function(id){this.thisElement.find("#asset"+id).remove(); for(var i=this._selectedFiles.length-1; i>=0; i--){if(this._selectedFiles[i].ChildItemId==id){this._selectedFiles.splice(i,1); }}$(this._selectedFilesHiddenElement).val(JSON.stringify($sitefinity.fixObjectForSerialization(this._selectedFiles))); },_dialogScrollToTop:function(dlg){var scrollTopHtml=jQuery("html").eq(0).scrollTop(); var scrollTopBody=jQuery("body").eq(0).scrollTop(); var scrollTop=((scrollTopHtml>scrollTopBody)?scrollTopHtml:scrollTopBody)+50; jQuery(dlg).parent().css({top:scrollTop}); },get_value:function(){if(this.get_radUpload()){return jQuery(this.get_radUpload().getFileInputs()).val(); }else{return this._selectedFiles; }},set_value:function(value){this._selectedFiles.length=0; $(this._selectedFilesList).empty(); if(value){for(var i=0; i