Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.93 KB | None | 0 0
  1. (function(){var c=YAHOO.util.Dom,r=YAHOO.util.Element,k=YAHOO.util.KeyListener,D=YAHOO.util.Event;var s=Alfresco.util.encodeHTML;Alfresco.DNDUpload=function(E){Alfresco.DNDUpload.superclass.constructor.call(this,"Alfresco.DNDUpload",E,["button","container","datatable","datasource"]);this.fileStore={};this.addedFiles={};this.defaultShowConfig={files:[],siteId:null,containerId:null,destination:null,uploadDirectory:null,updateNodeRef:null,updateFilename:null,updateVersion:"1.0",mode:this.MODE_SINGLE_UPLOAD,filter:[],onFileUploadComplete:null,overwrite:false,thumbnails:null,uploadURL:null,username:null,suppressRefreshEvent:false,maximumFileSize:0};this.suppliedConfig={};this.showConfig={};this.fileItemTemplates={};if(typeof FormData!=="undefined"){this.uploadMethod=this.FORMDATA_UPLOAD}else{this.uploadMethod=this.INMEMORY_UPLOAD}return this};YAHOO.extend(Alfresco.DNDUpload,Alfresco.component.Base,{contentReady:false,FORMDATA_UPLOAD:1,INMEMORY_UPLOAD:2,uploadMethod:2,STATE_BROWSING:1,STATE_ADDED:2,STATE_UPLOADING:3,STATE_FINISHED:4,STATE_FAILURE:5,STATE_SUCCESS:6,state:1,fileStore:null,noOfSuccessfulUploads:0,noOfFailedUploads:0,aggregateUploadTargetSize:0,aggregateUploadCurrentSize:0,addedFiles:null,MODE_SINGLE_UPLOAD:1,MODE_SINGLE_UPDATE:2,MODE_MULTI_UPLOAD:3,defaultShowConfig:null,suppliedConfig:null,showConfig:null,panel:null,dataTable:null,titleText:null,statusText:null,aggregateProgressText:null,aggregateDataWrapper:null,fileSelectionInput:null,minorVersion:null,description:null,uploadedFor:null,uploadedForLabel:null,uploadedBy:null,uploadedByLabel:null,uploadedByText:null,uploadedByDate:null,uploadedByDateLabel:null,versionSection:null,fileItemTemplates:null,_maximumFileSizeLimit:0,setMaximumFileSizeLimit:function d(E){this._maximumFileSizeLimit=E},getMaximumFileSizeLimit:function m(){return this._maximumFileSizeLimit},_inMemoryLimit:250000000,setInMemoryLimit:function t(E){if(isNaN(E)){Alfresco.logger.warn('Non-numerical value set for "in-memory-limit" in share-documentlibrary.xml: ',E);this._inMemoryLimit=25000000}else{this._inMemoryLimit=E}},getInMemoryLimit:function m(){return this._inMemoryLimit},onReady:function B(){c.removeClass(this.id+"-dialog","hidden");var E=this;this.panel=Alfresco.util.createYUIPanel(this.id+"-dialog");this.panel.hideEvent.subscribe(this.onCancelOkButtonClick,null,this);this.fileItemTemplates.left=c.get(this.id+"-left-div");this.fileItemTemplates.center=c.get(this.id+"-center-div");this.fileItemTemplates.right=c.get(this.id+"-right-div");this._createEmptyDataTable();this.titleText=c.get(this.id+"-title-span");this.statusText=c.get(this.id+"-status-span");this.aggregateProgressText=c.get(this.id+"-aggregate-status-span");this.aggregateDataWrapper=c.get(this.id+"-aggregate-data-wrapper");this.description=c.get(this.id+"-description-textarea");this.uploadedForLabel=c.get("uploadedFor-label");this.uploadedFor=c.get("uploadedFor-input");this.uploadedByLabel=c.get("uploadedBy-label");this.uploadedByText=c.get("uploadedBy-text");this.uploadedBy=c.get("uploadedBy-input");this.uploadedByDate=c.get("uploadedBy-date");this.uploadedByDateLabel=c.get("uploadedByDate-label");this.uploadedFor.addEventListener("keyup",function(){var F=E._isUploadDisabledForSiteUser();E.widgets.uploadButton.set("disabled",F)});this.minorVersion=c.get(this.id+"-minorVersion-radioButton");this.versionSection=c.get(this.id+"-versionSection-div");this.widgets.cancelOkButton=Alfresco.util.createYUIButton(this,"cancelOk-button",this.onCancelOkButtonClick);this.widgets.uploadButton=Alfresco.util.createYUIButton(this,"upload-button",this.onUploadButtonClick,{additionalClass:"alf-primary-button"});this.widgets.fileSelectionOverlayButton=Alfresco.util.createYUIButton(this,"file-selection-button-overlay",this._doNothing,{additionalClass:"alf-primary-button"});c.addClass(this.widgets.fileSelectionOverlayButton._button,"dnd-file-selection-button-overlay");c.addClass(this.widgets.fileSelectionOverlayButton._button.parentNode,"dnd-file-selection-button-overlay-wrapper");this.widgets.escapeListener=new k(document,{keys:k.KEY.ESCAPE},{fn:this.onCancelOkButtonClick,scope:this,correctScope:true})},_doNothing:function i(){},onFileSelection:function n(E){var I=E.target.files;if(I!=null){this.showConfig.files=I;if(this.dataTable!=null){this.dataTable.set("height","204px",true)}var F=true;for(var G=0;G<I.length;G++){if(I[G].size!==0){F=false;break}}if(F){this.processFilesForUpload(this.showConfig.files)}else{if(this.suppliedConfig.mode==this.MODE_SINGLE_UPDATE){var H=this._isUploadDisabledForSiteUser();this.widgets.uploadButton.set("disabled",H);c.removeClass(this.widgets.uploadButton,"hidden")}else{c.removeClass(this.id+"-filelist-table","hidden");c.removeClass(this.id+"-aggregate-data-wrapper","hidden");c.addClass(this.id+"-file-selection-controls","hidden");this.processFilesForUpload(this.showConfig.files)}}}else{}},show:function b(G){var I=this;this.suppliedConfig=G;this.showConfig=YAHOO.lang.merge(this.defaultShowConfig,G);if(this.showConfig.uploadDirectory!==null&&this.showConfig.uploadDirectory.length===0){this.showConfig.uploadDirectory="/"}if(!this.showConfig.uploadDirectory&&!this.showConfig.updateNodeRef&&!this.showConfig.destination&&!this.showConfig.uploadURL){throw new Error("An updateNodeRef, uploadDirectory, destination or uploadURL must be provided")}var J=this.showConfig.uploadDirectory;var E=this.showConfig.siteId;var L=true;if(J!=null&&E!=null){var M=Alfresco.constants.PROXY_URI+"api/safed/getNodeOfPath?path="+J+"&siteId="+E;var F=null;Alfresco.util.Ajax.jsonGet({url:M,successCallback:{fn:function H(N){F=N.json.destinationNode;var O=Alfresco.constants.PROXY_URI+"/api/safed/get-node-Properties?nodeRef=workspace://SpacesStore/"+F;Alfresco.util.Ajax.jsonGet({url:O,successCallback:{fn:function P(R){nodeType=R.json.data[0].type;if(nodeType=="sd:tmf"){L=false}if(nodeType=="sd:nonTmf"){L=false}if(nodeType=="sd:compoundLevelDocument"){L=false}if(L){Alfresco.util.PopupManager.displayPrompt({text:this.msg("Document cannot be uploaded in this directory. Please navigate to a correct folder structure and upload.")})}else{this._resetGUI();this._applyConfig();if(this.showConfig.files==null||this.showConfig.files.length==0){c.removeClass(this.id+"-file-selection-controls","hidden");c.addClass(this.id+"-filelist-table","hidden");c.addClass(this.aggregateDataWrapper,"hidden");if(YAHOO.env.ua.ie>9){if(this.fileSelectionInput&&this.fileSelectionInput.parentNode){this.fileSelectionInputParent=this.fileSelectionInput.parentNode;this.fileSelectionInput.parentNode.removeChild(this.fileSelectionInput)}else{this.fileSelectionInputParent=this.widgets.fileSelectionOverlayButton._button.parentNode;this.fileSelectionInputParent.removeChild(this.widgets.fileSelectionOverlayButton._button)}this.fileSelectionInput=document.createElement("input");c.setAttribute(this.fileSelectionInput,"type","file");if(this.suppliedConfig.mode!==this.MODE_SINGLE_UPLOAD&&this.suppliedConfig.mode!==this.MODE_SINGLE_UPDATE){c.setAttribute(this.fileSelectionInput,"multiple","")}c.setAttribute(this.fileSelectionInput,"name","files[]");c.addClass(this.fileSelectionInput,"ie10-dnd-file-selection-button");D.addListener(this.fileSelectionInput,"change",this.onFileSelection,this,true);new k(this.fileSelectionInput,{keys:k.KEY.ENTER},{fn:function Q(S){this.fileSelectionInput.click()},scope:this,correctScope:true}).enable();this.fileSelectionInputParent.appendChild(this.fileSelectionInput)}else{if(this.fileSelectionInput&&this.fileSelectionInput.parentNode){this.fileSelectionInput.parentNode.removeChild(this.fileSelectionInput)}this.fileSelectionInput=document.createElement("input");c.setAttribute(this.fileSelectionInput,"type","file");if(this.suppliedConfig.mode!==this.MODE_SINGLE_UPLOAD&&this.suppliedConfig.mode!==this.MODE_SINGLE_UPDATE){c.setAttribute(this.fileSelectionInput,"multiple","")}c.setAttribute(this.fileSelectionInput,"name","files[]");c.addClass(this.fileSelectionInput,"dnd-file-selection-button");D.addListener(this.fileSelectionInput,"change",this.onFileSelection,this,true);this.widgets.fileSelectionOverlayButton._button.parentNode.appendChild(this.fileSelectionInput)}this.widgets.escapeListener.enable();this.widgets.enterListener=new k(this.widgets.fileSelectionOverlayButton._button,{keys:k.KEY.ENTER},{fn:function Q(S){this.fileSelectionInput.click()},scope:this,correctScope:true});this.widgets.enterListener.enable();this.panel.setFirstLastFocusable();this.panel.show()}else{c.removeClass(this.id+"-filelist-table","hidden");c.removeClass(this.aggregateDataWrapper,"hidden");c.addClass(this.id+"-file-selection-controls","hidden");this.processFilesForUpload(this.showConfig.files)}}},scope:this}})},scope:this}})}else{this._resetGUI();this._applyConfig();this.updateUploadedForField();if(this.showConfig.files==null||this.showConfig.files.length==0){c.removeClass(this.id+"-file-selection-controls","hidden");c.addClass(this.id+"-filelist-table","hidden");c.addClass(this.aggregateDataWrapper,"hidden");if(YAHOO.env.ua.ie>9){if(this.fileSelectionInput&&this.fileSelectionInput.parentNode){this.fileSelectionInputParent=this.fileSelectionInput.parentNode;this.fileSelectionInput.parentNode.removeChild(this.fileSelectionInput)}else{this.fileSelectionInputParent=this.widgets.fileSelectionOverlayButton._button.parentNode;this.fileSelectionInputParent.removeChild(this.widgets.fileSelectionOverlayButton._button)}this.fileSelectionInput=document.createElement("input");c.setAttribute(this.fileSelectionInput,"type","file");if(this.suppliedConfig.mode!==this.MODE_SINGLE_UPLOAD&&this.suppliedConfig.mode!==this.MODE_SINGLE_UPDATE){c.setAttribute(this.fileSelectionInput,"multiple","")}c.setAttribute(this.fileSelectionInput,"name","files[]");c.addClass(this.fileSelectionInput,"ie10-dnd-file-selection-button");D.addListener(this.fileSelectionInput,"change",this.onFileSelection,this,true);new k(this.fileSelectionInput,{keys:k.KEY.ENTER},{fn:function K(N){this.fileSelectionInput.click()},scope:this,correctScope:true}).enable();this.fileSelectionInputParent.appendChild(this.fileSelectionInput)}else{if(this.fileSelectionInput&&this.fileSelectionInput.parentNode){this.fileSelectionInput.parentNode.removeChild(this.fileSelectionInput)}this.fileSelectionInput=document.createElement("input");c.setAttribute(this.fileSelectionInput,"type","file");if(this.suppliedConfig.mode!==this.MODE_SINGLE_UPLOAD&&this.suppliedConfig.mode!==this.MODE_SINGLE_UPDATE){c.setAttribute(this.fileSelectionInput,"multiple","")}c.setAttribute(this.fileSelectionInput,"name","files[]");c.addClass(this.fileSelectionInput,"dnd-file-selection-button");D.addListener(this.fileSelectionInput,"change",this.onFileSelection,this,true);this.widgets.fileSelectionOverlayButton._button.parentNode.appendChild(this.fileSelectionInput)}this.widgets.escapeListener.enable();this.widgets.enterListener=new k(this.widgets.fileSelectionOverlayButton._button,{keys:k.KEY.ENTER},{fn:function K(N){this.fileSelectionInput.click()},scope:this,correctScope:true});this.widgets.enterListener.enable();this.panel.setFirstLastFocusable();this.panel.show()}else{c.removeClass(this.id+"-filelist-table","hidden");c.removeClass(this.aggregateDataWrapper,"hidden");c.addClass(this.id+"-file-selection-controls","hidden");this.processFilesForUpload(this.showConfig.files)}}},updateUploadedForField:function(){var G=this.showConfig.updateNodeRef;if(G!=null){var F=Alfresco.constants.PROXY_URI+"api/metadata?nodeRef="+G+"&shortQNames=true";Alfresco.util.Ajax.jsonGet({url:F,successCallback:{fn:function E(J){var H=J.json.properties["sd:uploadedFor"];if(H!=null){this.uploadedFor=c.get("uploadedFor-input");var I=Alfresco.constants.PROXY_URI+"api/people";if(H!=null&&H!=""){I+="/"+H}Alfresco.util.Ajax.jsonGet({url:I,successCallback:{fn:function(L){var K=L.json;var M=formatFullName(K);this.uploadedFor=c.get("uploadedFor-input");this.uploadedFor.value=M},scope:this},failureCallback:{fn:function(K){},scope:this}})}}}})}},processFilesForUpload:function(E){var G=0,I=null,H=null,J;for(var F=0;F<E.length;F++){G+=E[F].size;J=E[F].name;I=this._getFileValidationErrors(E[F]);if(I){if(H){H+="<br/>"+I}else{H=I}}}this.aggregateUploadTargetSize=G;this._addFiles(0,E.length,this);this._spawnUploads();if(H){Alfresco.util.PopupManager.displayPrompt({title:this.msg("header.error"),text:H,noEscape:true})}},_getFileValidationErrors:function(E){var F=E.name;if(E.size===0){return this.msg("message.zeroByteFileSelected",s(F))}else{if(this._maximumFileSizeLimit>0&&E.size>this._maximumFileSizeLimit){return this.msg("message.maxFileFileSizeExceeded",s(F),Alfresco.util.formatFileSize(E.size),Alfresco.util.formatFileSize(this._maximumFileSizeLimit))}else{if(!Alfresco.forms.validation.nodeName({id:"file",value:F},null,null,null,true)){return this.msg("message.illegalCharacters",s(F))}else{if(E.type!="text/plain"&&E.type!="application/rtf"&&E.type!="application/pdf"&&E.type!="application/msword"&&E.type!="application/vnd.openxmlformats-officedocument.wordprocessingml.document"&&E.type!="application/vnd.ms-excel"&&E.type!="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"&&E.type!="application/vnd.ms-powerpoint"&&E.type!="application/vnd.openxmlformats-officedocument.presentationml.presentation"&&E.type!="image/jpeg"&&E.type!="image/png"&&E.type!="text/csv"&&E.type!="image/gif"&&E.type!="image/bmp"&&E.type!="audio/mp4"&&E.type!="video/mp4"&&E.type!="video/mpeg"&&E.type!="audio/mpeg"&&E.type!="image/tiff"){return this.msg("Upload not allowed for this mimetype!",s(F))}}}}return null},_addFiles:function v(O,R,U){var Q;if(O<R){var I=U.showConfig.files[O];if(!this._getFileValidationErrors(I)){var G="file"+O;try{var M=function S(Z){Alfresco.logger.debug("File upload progress update received",Z);if(Z.lengthComputable){try{var V=Math.round((Z.loaded*100)/Z.total),X=U.fileStore[G];X.progressPercentage.innerHTML=V+"%";var Y=(-400+((V/100)*400));c.setStyle(X.progress,"left",Y+"px");U._updateAggregateProgress(X,Z.loaded);X.lastProgress=Z.loaded}catch(W){Alfresco.logger.error("The following error occurred processing an upload progress event: ",W)}}else{Alfresco.logger.debug("File upload progress not computable",Z)}};var P=function H(Y){try{Alfresco.logger.debug("File upload completion notification received",Y);var W=U.fileStore[G];if(W.request.readyState!=4){W.request.onreadystatechange=function X(){if(W.request.readyState==4){U._processUploadCompletion(W)}}}else{U._processUploadCompletion(W)}}catch(V){Alfresco.logger.error("The following error occurred processing an upload completion event: ",V)}};var N=function T(X){try{var W=U.fileStore[G];if(W.state!==U.STATE_FAILURE){U._processUploadFailure(W,X.status)}}catch(V){Alfresco.logger.error("The following error occurred processing an upload failure event: ",V)}};var L=I.name;var K=new XMLHttpRequest();K.upload._fileData=G;K.upload.addEventListener("progress",M,false);K.upload.addEventListener("load",P,false);K.upload.addEventListener("error",N,false);data={id:G,name:L,size:U.showConfig.files[O].size};var J=null;if(U.suppliedConfig&&U.suppliedConfig.updateNodeRef){J=U.suppliedConfig.updateNodeRef}var E={filedata:U.showConfig.files[O],filename:L,destination:U.showConfig.destination,siteId:U.showConfig.siteId,containerId:U.showConfig.containerId,uploaddirectory:U.showConfig.uploadDirectory,majorVersion:!U.minorVersion.checked,updateNodeRef:J,description:U.description.value,uploadedFor:getUserNameValue(U.uploadedFor.value),overwrite:U.showConfig.overwrite,thumbnails:U.showConfig.thumbnails,username:U.showConfig.username};if(U&&U.uploadedBy){E.uploadedBy=U.uploadedBy.value}U.fileStore[G]={state:U.STATE_ADDED,fileName:L,nodeRef:J,uploadData:E,request:K};U.dataTable.addRow(data);U.addedFiles[Q]=U._getUniqueFileToken(data);U.widgets.escapeListener.enable();U.panel.setFirstLastFocusable();U.panel.show()}catch(F){Alfresco.logger.error("DNDUpload_show: The following exception occurred processing a file to upload: ",F)}}U._addFiles(O+1,R,U)}},getUserNameValue:function(E){return E.substring(E.lastIndexOf("(")+1,E.lastIndexOf(")"))},_processUploadCompletion:function j(F){if(F.request.status=="200"){var E=Alfresco.util.parseJSON(F.request.responseText);F.nodeRef=E.nodeRef;F.fileName=E.fileName;F.state=this.STATE_SUCCESS;c.addClass(F.progressStatusIncomplete,"hidden");c.removeClass(F.progressStatusComplete,"hidden");c.removeClass(F.progress,"fileupload-progressSuccess-span");c.addClass(F.progress,"fileupload-progressFinished-span");c.setStyle(F.progress,"left",0+"px");F.progressPercentage.innerHTML="100%";this.noOfSuccessfulUploads++;this._updateAggregateProgress(F,F.uploadData.filedata.size);this._updateStatus();this._adjustGuiIfFinished();this._spawnUploads()}else{this._processUploadFailure(F,F.request.status)}},_processUploadFailure:function w(H,E){if(E===401){var K=H.request.getResponseHeader.Location;if(K){window.location.href=window.location.protocol+"//"+window.location.host+K;return}else{window.location.reload(true);return}}H.state=this.STATE_FAILURE;var J=H.request.status+" "+H.request.statusText;try{J=JSON.parse(H.request.responseText).message;J=J.substring(J.indexOf(" ")+1)}catch(G){Alfresco.logger.error("The following error occurred parsing the upload failure message for "+J+": "+G)}var F="label.failure."+E,I=Alfresco.util.message(F,this.name);if(I==F){I=Alfresco.util.message("label.failure",this.name,J)}I="Error Uploading Document";H.fileSizeInfo.innerHTML=H.fileSizeInfo.innerHTML+" ("+I+")";H.fileSizeInfo.setAttribute("title",I);H.progressInfo.setAttribute("title",I);H.progressInfo.parentElement.setAttribute("title",I);c.addClass(H.progressStatusIncomplete,"hidden");c.removeClass(H.progressStatusFailed,"hidden");c.removeClass(H.progress,"fileupload-progressSuccess-span");c.addClass(H.progress,"fileupload-progressFailure-span");c.setStyle(H.progress,"left",0+"px");this._updateAggregateProgress(H,H.uploadData.filedata.size);this.noOfFailedUploads++;this._updateStatus();this._adjustGuiIfFinished();this._spawnUploads()},_updateAggregateProgress:function x(G,F){this.aggregateUploadCurrentSize-=G.lastProgress;this.aggregateUploadCurrentSize+=F;var E=(this.aggregateUploadCurrentSize/this.aggregateUploadTargetSize);var H=(-620+(E*620));c.setStyle(this.id+"-aggregate-progress-span","left",H+"px")},_resetGUI:function y(){if(this.statusText==null){this.onReady()}this.state=this.STATE_UPLOADING;this.noOfFailedUploads=0;this.noOfSuccessfulUploads=0;this.statusText.innerHTML="&nbsp;";this.description.value="";this.uploadedFor.value="";this.minorVersion.checked=true;this.widgets.cancelOkButton.set("label",this.msg("button.cancel"));this.widgets.cancelOkButton.set("disabled",false);c.addClass(this.widgets.uploadButton,"hidden");this.widgets.uploadButton.set("label",this.msg("button.upload"));this.widgets.uploadButton.set("disabled",true);this.aggregateUploadTargetSize=0;this.aggregateUploadCurrentSize=0;c.setStyle(this.id+"-aggregate-progress-span","left","-620px");c.removeClass(this.aggregateDataWrapper,"hidden")},onPostRenderEvent:function p(E){if(this.dataTable.getRecordSet().getLength()>0){this.panel.setFirstLastFocusable();this.panel.focusFirst()}},onRowAddEvent:function A(G){try{var H=G.record.getData();var F=this.fileStore[H.id];F.lastProgress=0;this._updateAggregateStatus()}catch(E){Alfresco.logger.error("The following error occurred initiating upload: "+E)}},_spawnUploads:function(){var I=this.dataTable.getRecordSet().getLength();for(var H=0;H<I;H++){var F=this.dataTable.getRecordSet().getRecord(H);var E=F.getData("id");var G=this.fileStore[E];if(G.state==this.STATE_ADDED){this._startUpload(G);return}}},_startUpload:function(F){F.state=this.STATE_UPLOADING;var E;if(this.showConfig.uploadURL===null){E=Alfresco.constants.PROXY_URI+"api/upload"}else{E=Alfresco.constants.PROXY_URI+this.showConfig.uploadURL}if(Alfresco.util.CSRFPolicy.isFilterEnabled()){E+="?"+Alfresco.util.CSRFPolicy.getParameter()+"="+encodeURIComponent(Alfresco.util.CSRFPolicy.getToken())}if(this.uploadMethod===this.FORMDATA_UPLOAD){Alfresco.logger.debug("Using FormData for file upload");var J=new FormData;J.append("filedata",F.uploadData.filedata);J.append("filename",F.uploadData.filename);J.append("destination",F.uploadData.destination);J.append("uploaddirectory",F.uploadData.uploaddirectory);J.append("majorVersion",F.uploadData.majorVersion?"true":"false");J.append("username",F.uploadData.username);J.append("overwrite",F.uploadData.overwrite);J.append("thumbnails",F.uploadData.thumbnails);if(F.uploadData.updateNodeRef){J.append("updateNodeRef",F.uploadData.updateNodeRef)}else{J.append("siteId",F.uploadData.siteId);J.append("containerId",F.uploadData.containerId)}if(F.uploadData.description){J.append("description",F.uploadData.description)}if(F.uploadData.uploadedFor){J.append("uploadedFor",F.uploadData.uploadedFor)}if(F.uploadData.uploadedBy){J.append("uploadedBy",F.uploadData.uploadedBy)}F.request.open("POST",E,true);F.request.send(J);F.request.onreadystatechange=function(){if(this.status===401){var K=this.getResponseHeader.Location;if(K){window.location.href=window.location.protocol+"//"+window.location.host+K;return}else{window.location.reload(true);return}}}}else{if(this.uploadMethod===this.INMEMORY_UPLOAD){Alfresco.logger.debug("Using custom multipart upload");var G="----AlfrescoCustomMultipartBoundary"+(new Date).getTime();var I="\r\n";var H="--"+G;H+=I+'Content-Disposition: form-data; name="filedata"; filename="'+unescape(encodeURIComponent(F.uploadData.filename))+'"';H+=I+"Content-Type: image/png";H+=I+I+F.uploadData.filedata.getAsBinary()+I+"--"+G;H+=I+'Content-Disposition: form-data; name="filename"';H+=I+I+unescape(encodeURIComponent(F.uploadData.filename))+I+"--"+G;H+=I+'Content-Disposition: form-data; name="destination"';if(F.uploadData.destination!==null){H+=I+I+unescape(encodeURIComponent(F.uploadData.destination))+I+"--"+G}else{H+=I+I+I+"--"+G}H+=I+'Content-Disposition: form-data; name="siteId"';H+=I+I+unescape(encodeURIComponent(F.uploadData.siteId))+I+"--"+G;H+=I+'Content-Disposition: form-data; name="containerId"';H+=I+I+unescape(encodeURIComponent(F.uploadData.containerId))+I+"--"+G;H+=I+'Content-Disposition: form-data; name="uploaddirectory"';H+=I+I+unescape(encodeURIComponent(F.uploadData.uploaddirectory))+I+"--"+G+"--";H+=I+'Content-Disposition: form-data; name="majorVersion"';H+=I+I+unescape(encodeURIComponent(F.uploadData.majorVersion))+I+"--"+G+"--";if(F.uploadData.updateNodeRef){H+=I+'Content-Disposition: form-data; name="updateNodeRef"';H+=I+I+unescape(encodeURIComponent(F.uploadData.updateNodeRef))+I+"--"+G+"--"}if(F.uploadData.description){H+=I+'Content-Disposition: form-data; name="description"';H+=I+I+unescape(encodeURIComponent(F.uploadData.description))+I+"--"+G+"--"}if(F.uploadData.uploadedFor){H+=I+'Content-Disposition: form-data; name="uploadedFor"';H+=I+I+unescape(encodeURIComponent(F.uploadData.uploadedFor))+I+"--"+G+"--"}if(F.uploadData.uploadedBy){H+=I+'Content-Disposition: form-data; name="uploadedBy"';H+=I+I+unescape(encodeURIComponent(F.uploadData.uploadedBy))+I+"--"+G+"--"}if(F.uploadData.username){H+=I+'Content-Disposition: form-data; name="username"';H+=I+I+unescape(encodeURIComponent(F.uploadData.username))+I+"--"+G+"--"}if(F.uploadData.overwrite){H+=I+'Content-Disposition: form-data; name="overwrite"';H+=I+I+unescape(encodeURIComponent(F.uploadData.overwrite))+I+"--"+G+"--"}if(F.uploadData.thumbnails){H+=I+'Content-Disposition: form-data; name="thumbnails"';H+=I+I+unescape(encodeURIComponent(F.uploadData.thumbnails))+I+"--"+G+"--"}F.request.open("POST",E,true);F.request.setRequestHeader("Content-Type","multipart/form-data; boundary="+G);F.request.sendAsBinary(H)}}},onUploadButtonClick:function l(){this.state=this.STATE_UPLOADING;c.removeClass(this.id+"-filelist-table","hidden");c.removeClass(this.id+"-aggregate-data-wrapper","hidden");c.addClass(this.id+"-file-selection-controls","hidden");c.addClass(this.versionSection,"hidden");c.addClass(this.uploadedFor,"hidden");c.addClass(this.uploadedForLabel,"hidden");if(this.uploadedBy){c.addClass(this.uploadedBy,"hidden");c.addClass(this.uploadedByLabel,"hidden");c.addClass(this.uploadedByText,"hidden")}if(this.uploadedByDate){c.addClass(this.uploadedByDate,"hidden");c.addClass(this.uploadedByDateLabel,"hidden")}this.widgets.uploadButton.set("disabled",true);this.processFilesForUpload(this.showConfig.files)},onCancelOkButtonClick:function C(){var G,F;if(this.state===this.STATE_UPLOADING){this._cancelAllUploads();var E=0;for(F in this.fileStore){if(this.fileStore[F]&&this.fileStore[F].state===this.STATE_SUCCESS){E++}}if(E>0){G=YAHOO.lang.substitute(this.msg("message.cancelStatus"),{"0":E})}if(!this.showConfig.suppressRefreshEvent){YAHOO.Bubbling.fire("metadataRefresh",{currentPath:this.showConfig.path})}}else{if(this.state===this.STATE_FINISHED){var I=null,H;for(F in this.fileStore){H=this.fileStore[F];if(H&&H.state===this.STATE_SUCCESS){I=H.fileName;break}}if(!this.showConfig.suppressRefreshEvent){if(I){YAHOO.Bubbling.fire("metadataRefresh",{currentPath:this.showConfig.path,highlightFile:I})}else{YAHOO.Bubbling.fire("metadataRefresh",{currentPath:this.showConfig.path})}}}}this._clear();this.panel.hide();this.widgets.escapeListener.disable();if(G){Alfresco.util.PopupManager.displayPrompt({text:G})}},_applyConfig:function h(){var K,I;if(this.showConfig.mode===this.MODE_SINGLE_UPLOAD){I=this.msg("header.singleUpload");this.titleText.innerHTML=I}else{if(this.showConfig.mode===this.MODE_MULTI_UPLOAD){I=this.showConfig.files.length==1?"header.multiUpload.singleFile":"header.multiUpload";var G=this.showConfig.uploadDirectoryName==""?this.msg("label.documents"):this.showConfig.uploadDirectoryName;this.titleText.innerText=this.msg(I,s(G));var H=document.createElement("img");H.setAttribute("src",Alfresco.constants.URL_RESCONTEXT+"components/documentlibrary/images/folder-open-16.png");H.setAttribute("class","title-folder");this.titleText.appendChild(H)}else{if(this.showConfig.mode===this.MODE_SINGLE_UPDATE){I=this.msg("header.singleUpdate");this.titleText.innerHTML=I;if(this.options.inRequestSiteDocumentWorkflow){this.titleText.innerHTML=this.msg("header.singleUpload")}}}}if(this.showConfig.mode===this.MODE_SINGLE_UPDATE){c.removeClass(this.uploadedForLabel,"hidden");c.removeClass(this.uploadedFor,"hidden");c.addClass(this.versionSection,"hidden");var F=(this.showConfig.updateVersion||"1.0").split("."),E=parseInt(F[0],10),J=parseInt(F[1],10);c.get(this.id+"-minorVersion").innerHTML=this.msg("label.minorVersion.more",E+"."+(1+J));c.get(this.id+"-majorVersion").innerHTML=this.msg("label.majorVersion.more",(1+E)+".0")}else{c.addClass(this.uploadedForLabel,"hidden");c.addClass(this.uploadedFor,"hidden");c.addClass(this.versionSection,"hidden")}if(this.showConfig.mode===this.MODE_MULTI_UPLOAD){c.removeClass(this.statusText,"hidden");this.dataTable.set("height","204px",true)}else{c.addClass(this.statusText,"hidden");this.dataTable.set("height","40px")}},_createEmptyDataTable:function u(){var E=this;var F=function(M,N,O,P){try{E._formatCellElements(M,N,E.fileItemTemplates.left)}catch(L){Alfresco.logger.error("DNDUpload__createEmptyDataTable (formatLeftCell): The following error occurred: ",L)}};var K=function(M,N,O,P){try{E._formatCellElements(M,N,E.fileItemTemplates.center)}catch(L){Alfresco.logger.error("DNDUpload__createEmptyDataTable (formatCenterCell): The following error occurred: ",L)}};var I=function(M,N,O,P){try{E._formatCellElements(M,N,E.fileItemTemplates.right)}catch(L){Alfresco.logger.error("DNDUpload__createEmptyDataTable (formatRightCell): The following error occurred: ",L)}};this._formatCellElements=function(M,Y,W){var T=Y.getData(),O=T.id;var X=new r(M);var Q=W.cloneNode(true);Q.setAttribute("id",Q.getAttribute("id")+O);var L=c.getElementsByClassName("fileupload-progressSuccess-span","span",Q);if(L.length==1){this.fileStore[O].progress=L[0]}var U=c.getElementsByClassName("fileupload-progressInfo-span","span",Q);if(U.length==1){var N=T.name;Q.setAttribute("title",N);U=U[0];this.fileStore[O].progressInfo=U;this.fileStore[O].progressInfo.innerHTML=N;this.fileStore[O].progressInfoCell=M}var P=c.getElementsByClassName("fileupload-filesize-span","span",Q);if(P.length==1){var N=Alfresco.util.formatFileSize(T.size);P=P[0];this.fileStore[O].fileSizeInfo=P;P.innerHTML=N}var V=c.getElementsByClassName("fileupload-contentType-select","select",Q);if(V.length==1){this.fileStore[O].contentType=V[0]}else{V=c.getElementsByClassName("fileupload-contentType-input","input",Q);if(V.length==1){this.fileStore[O].contentType=V[0]}}var S=c.getElementsByClassName("fileupload-percentage-span","span",Q);if(S.length==1){this.fileStore[O].progressPercentage=S[0]}var R=c.getElementsByClassName("fileupload-status-img","img",Q);if(R.length==3){this.fileStore[O].progressStatusIncomplete=R[0];this.fileStore[O].progressStatusComplete=R[1];this.fileStore[O].progressStatusFailed=R[2]}X.appendChild(Q)};var J=[{key:"id",className:"col-left",resizable:false,formatter:F},{key:"name",className:"col-center",resizable:false,formatter:K},{key:"created",className:"col-right",resizable:false,formatter:I}];var H=new YAHOO.util.DataSource([],{responseType:YAHOO.util.DataSource.TYPE_JSARRAY});YAHOO.widget.DataTable._bStylesheetFallback=!!YAHOO.env.ua.ie;var G=c.get(this.id+"-filelist-table");this.dataTable=new YAHOO.widget.DataTable(G,J,H,{scrollable:true,height:"100px",width:"620px",renderLoopSize:1,MSG_EMPTY:this.msg("label.noFiles")});this.dataTable.subscribe("postRenderEvent",this.onPostRenderEvent,this,true);this.dataTable.subscribe("rowAddEvent",this.onRowAddEvent,this,true)},_getUniqueFileToken:function g(E){return E.name+":"+E.size},_updateStatus:function e(){if(this.noOfFailedUploads>0){this.statusText.innerHTML=YAHOO.lang.substitute(this.msg("label.uploadStatus.withFailures"),{"0":this.noOfSuccessfulUploads,"1":this.dataTable.getRecordSet().getLength(),"2":this.noOfFailedUploads})}else{this.statusText.innerHTML=YAHOO.lang.substitute(this.msg("label.uploadStatus"),{"0":this.noOfSuccessfulUploads,"1":this.dataTable.getRecordSet().getLength()})}},_updateAggregateStatus:function q(){this.aggregateProgressText.innerHTML=YAHOO.lang.substitute(this.msg("label.aggregateUploadStatus"),{"0":this.dataTable.getRecordSet().getLength(),"1":Alfresco.util.formatFileSize(this.aggregateUploadTargetSize)})},_adjustGuiIfFinished:function f(){try{var H={successful:[],failed:[]};var G=null;for(var F in this.fileStore){G=this.fileStore[F];if(G){if(G.state==this.STATE_SUCCESS){H.successful.push({fileName:G.fileName,nodeRef:G.nodeRef})}else{if(G.state==this.STATE_FAILURE){H.failed.push({fileName:G.fileName})}else{return}}}}this.state=this.STATE_FINISHED;c.addClass(this.aggregateDataWrapper,"hidden");c.addClass(this.widgets.uploadButton,"hidden");this.widgets.cancelOkButton.set("label",this.msg("button.ok"));this.widgets.cancelOkButton.focus();var K=this.showConfig.onFileUploadComplete;if(K&&typeof K.fn=="function"){K.fn.call((typeof K.scope=="object"?K.scope:this),H,K.obj)}if(H.failed.length===0){this.onCancelOkButtonClick()}}catch(E){Alfresco.logger.error("_adjustGuiIfFinished",E)}if(this.noOfFailedUploads>0){Alfresco.util.PopupManager.displayPrompt({text:'<span class="para-text text-wrap">'+this.msg("The document you have uploaded may be a duplicate. If the document already exists please check-out the original document and upload the new document in it's place. If you believe the document is not a duplicate, ensure that all document details are correct.")+"</span>",noEscape:true,buttons:[{text:this.msg("Ok"),handler:function I(){this.destroy()}},{text:this.msg("button.cancel"),handler:function J(){this.destroy()},isDefault:true}]})}else{Alfresco.util.PopupManager.displayPrompt({text:'<span class="para-text text-wrap">'+this.msg("Document is uploaded successfully and placed in specified folder(s).")+"</span>",noEscape:true,buttons:[{text:this.msg("Ok"),handler:function I(){this.destroy();const L=dndUpload.showConfig["updateNodeRef"];if(L){YAHOO.util["Dom"].get("loading-container")["style"]["display"]="block";const M=Alfresco.constants["PROXY_URI"]+"api/safed/distribute/content-propagation-mode?nodeRef="+L;Alfresco.util["Ajax"].request({url:M,method:Alfresco.util["Ajax"]["GET"],requestContentType:Alfresco.util["Ajax"]["JSON"],successCallback:{fn:function(N){YAHOO.util["Dom"].get("loading-container")["style"]["display"]="none";const P=N.json["mode"];if(P){const O={nodeRef:dndUpload.showConfig["updateNodeRef"],jsNode:dndUpload.showConfig["jsNode"],mode:P};YAHOO.Bubbling.fire("propagateContentToNewVersions",O)}else{if(window.location.href.indexOf("documentlibrary")===-1){window.location.reload()}}},scope:this},failureCallback:{fn:function(N){YAHOO.util["Dom"].get("loading-container")["style"]["display"]="none";Alfresco.util["PopupManager"].displayPrompt({title:"ERROR",text:"Failed to retrieve content propagation mode.",buttons:[{text:"OK",handler:function(){window.location.reload()},isDefault:true}]})},scope:this}})}}}]})}},_cancelAllUploads:function o(){var I=this.dataTable.getRecordSet().getLength();for(var H=0;H<I;H++){var F=this.dataTable.getRecordSet().getRecord(H);var E=F.getData("id");var G=this.fileStore[E];if(G.state===this.STATE_UPLOADING){Alfresco.logger.debug("Aborting upload of file: "+G.fileName);G.request.abort()}}},_clear:function z(){var E=this.dataTable.getRecordSet().getLength();this.addedFiles={};this.fileStore={};this.dataTable.deleteRows(0,E)},_isUploadDisabledForSiteUser:function a(){if(this["options"]["isSiteUser"]&&this["options"]["isStudySiteLevel"]){return false}var F=false,E=c.get("uploadedFor-input");if(E&&this.options.isSiteUser&&(E.value===""||!E.value.replace(/\s/g,"").length)){F=true}return F}})})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement