4836: side menu inline edit now properly saved after exiting edit mode.
[acontent.git] / docs / include / jscripts / infusion / components / uploader / js / Uploader.js
1 fluid_1_1=fluid_1_1||{};(function($,fluid){var rowForFile=function(that,file){return that.locate("fileQueue").find("#"+file.id)};var errorRowForFile=function(that,file){return $("#"+file.id+"_error",that.container)};var fileForRow=function(that,row){var files=that.uploadManager.queue.files;for(var i=0;i<files.length;i++){var file=files[i];if(file.id.toString()===row.attr("id")){return file}}return null};var progressorForFile=function(that,file){var progressId=file.id+"_progress";return that.fileProgressors[progressId]};var startFileProgress=function(that,file){var fileRowElm=rowForFile(that,file);that.scroller.scrollTo(fileRowElm);var fileProgressor=progressorForFile(that,file);fileProgressor.refreshView();fileProgressor.show()};var updateFileProgress=function(that,file,fileBytesComplete,fileTotalBytes){var filePercent=fluid.uploader.derivePercent(fileBytesComplete,fileTotalBytes);var filePercentStr=filePercent+"%";progressorForFile(that,file).update(filePercent,filePercentStr)};var hideFileProgress=function(that,file){var fileRowElm=rowForFile(that,file);progressorForFile(that,file).hide();if(file.filestatus===fluid.uploader.fileStatusConstants.COMPLETE){that.locate("fileIconBtn",fileRowElm).removeClass(that.options.styles.dim)}};var removeFileProgress=function(that,file){var fileProgressor=progressorForFile(that,file);if(!fileProgressor){return }var rowProgressor=fileProgressor.displayElement;rowProgressor.remove()};var animateRowRemoval=function(that,row){row.fadeOut("fast",function(){row.remove();that.refreshView()})};var removeFileErrorRow=function(that,file){if(file.filestatus===fluid.uploader.fileStatusConstants.ERROR){animateRowRemoval(that,errorRowForFile(that,file))}};var removeFileAndRow=function(that,file,row){removeFileProgress(that,file);removeFileErrorRow(that,file);that.uploadManager.removeFile(file);animateRowRemoval(that,row)};var removeFileForRow=function(that,row){var file=fileForRow(that,row);if(!file||file.filestatus===fluid.uploader.fileStatusConstants.COMPLETE){return }removeFileAndRow(that,file,row)};var removeRowForFile=function(that,file){var row=rowForFile(that,file);removeFileAndRow(that,file,row)};var bindHover=function(row,styles){var over=function(){if(row.hasClass(styles.ready)&&!row.hasClass(styles.uploading)){row.addClass(styles.hover)}};var out=function(){if(row.hasClass(styles.ready)&&!row.hasClass(styles.uploading)){row.removeClass(styles.hover)}};row.hover(over,out)};var bindDeleteKey=function(that,row){var deleteHandler=function(){removeFileForRow(that,row)};fluid.activatable(row,null,{additionalBindings:[{key:$.ui.keyCode.DELETE,activateHandler:deleteHandler}]})};var bindRowHandlers=function(that,row){if($.browser.msie&&$.browser.version<7){bindHover(row,that.options.styles)}that.locate("fileIconBtn",row).click(function(){removeFileForRow(that,row)});bindDeleteKey(that,row)};var renderRowFromTemplate=function(that,file){var row=that.rowTemplate.clone();that.locate("fileName",row).text(file.name);that.locate("fileSize",row).text(fluid.uploader.formatFileSize(file.size));that.locate("fileIconBtn",row).addClass(that.options.styles.remove);row.attr("id",file.id);row.addClass(that.options.styles.ready);bindRowHandlers(that,row);return row};var createProgressorFromTemplate=function(that,row){var rowProgressor=that.rowProgressorTemplate.clone();var rowId=row.attr("id");var progressId=rowId+"_progress";rowProgressor.attr("id",progressId);rowProgressor.css("top",row.position().top);rowProgressor.height(row.height()).width(5);that.container.after(rowProgressor);that.fileProgressors[progressId]=fluid.progress(that.uploadContainer,{selectors:{progressBar:"#"+rowId,displayElement:"#"+progressId,label:"#"+progressId+" .fl-uploader-file-progress-text",indicator:"#"+progressId}})};var addFile=function(that,file){var row=renderRowFromTemplate(that,file);if(!($.browser.msie&&($.browser.version>=8))){row.hide()}that.container.append(row);row.fadeIn("slow");that.scroller.scrollBottom();createProgressorFromTemplate(that,row);that.refreshView()};var prepareForUpload=function(that){var rowButtons=that.locate("fileIconBtn",that.locate("fileRows"));rowButtons.attr("disabled","disabled");rowButtons.addClass(that.options.styles.dim)};var refreshAfterUpload=function(that){var rowButtons=that.locate("fileIconBtn",that.locate("fileRows"));rowButtons.removeAttr("disabled");rowButtons.removeClass(that.options.styles.dim)};var changeRowState=function(that,row,newState){row.removeClass(that.options.styles.ready).removeClass(that.options.styles.error).addClass(newState)};var markRowAsComplete=function(that,file){var row=rowForFile(that,file);changeRowState(that,row,that.options.styles.uploaded);row.attr("title",that.options.strings.status.success);fluid.enabled(row,false);var removeRowBtn=that.locate("fileIconBtn",row);removeRowBtn.unbind("click");removeRowBtn.removeClass(that.options.styles.remove);removeRowBtn.attr("title",that.options.strings.status.success)};var renderErrorInfoRowFromTemplate=function(that,fileRow,error){var errorRow=that.errorInfoRowTemplate.clone();errorRow.attr("id",fileRow.attr("id")+"_error");var errorType=fluid.keyForValue(fluid.uploader.errorConstants,error);var errorMsg=that.options.strings.errors[errorType];that.locate("errorText",errorRow).text(errorMsg);fileRow.after(errorRow);that.scroller.scrollTo(errorRow)};var showErrorForFile=function(that,file,error){hideFileProgress(that,file);if(file.filestatus===fluid.uploader.fileStatusConstants.ERROR){var fileRowElm=rowForFile(that,file);changeRowState(that,fileRowElm,that.options.styles.error);renderErrorInfoRowFromTemplate(that,fileRowElm,error)}};var bindModelEvents=function(that){that.returnedOptions={listeners:{afterFileQueued:that.addFile,onUploadStart:that.prepareForUpload,onFileStart:that.showFileProgress,onFileProgress:that.updateFileProgress,onFileSuccess:that.markFileComplete,onFileError:that.showErrorForFile,afterFileComplete:that.hideFileProgress,afterUploadComplete:that.refreshAfterUpload}}};var addKeyboardNavigation=function(that){fluid.tabbable(that.container);that.selectableContext=fluid.selectable(that.container,{selectableSelector:that.options.selectors.fileRows,onSelect:function(itemToSelect){$(itemToSelect).addClass(that.options.styles.selected)},onUnselect:function(selectedItem){$(selectedItem).removeClass(that.options.styles.selected)}})};var prepareTemplateElements=function(that){that.rowTemplate=that.locate("rowTemplate").remove();if($.browser.msie&&($.browser.version>=8)){that.rowTemplate.removeClass(that.options.styles.hiddenTemplate)}that.errorInfoRowTemplate=that.locate("errorInfoRowTemplate").remove();that.errorInfoRowTemplate.removeClass(that.options.styles.hiddenTemplate);that.rowProgressorTemplate=that.locate("rowProgressorTemplate",that.uploadContainer).remove()};var setupFileQueue=function(that,uploadManager){that.uploadManager=uploadManager;that.scroller=fluid.scroller(that.container);prepareTemplateElements(that);addKeyboardNavigation(that);bindModelEvents(that)};fluid.fileQueueView=function(container,parentContainer,uploadManager,options){var that=fluid.initView("fluid.fileQueueView",container,options);that.uploadContainer=parentContainer;that.fileProgressors={};that.addFile=function(file){addFile(that,file)};that.removeFile=function(file){removeRowForFile(that,file)};that.prepareForUpload=function(){prepareForUpload(that)};that.refreshAfterUpload=function(){refreshAfterUpload(that)};that.showFileProgress=function(file){startFileProgress(that,file)};that.updateFileProgress=function(file,fileBytesComplete,fileTotalBytes){updateFileProgress(that,file,fileBytesComplete,fileTotalBytes)};that.markFileComplete=function(file){progressorForFile(that,file).update(100,"100%");markRowAsComplete(that,file)};that.showErrorForFile=function(file,error){showErrorForFile(that,file,error)};that.hideFileProgress=function(file){hideFileProgress(that,file)};that.refreshView=function(){that.scroller.refreshView();that.selectableContext.refresh()};setupFileQueue(that,uploadManager);return that};fluid.defaults("fluid.fileQueueView",{selectors:{fileRows:".flc-uploader-file",fileName:".flc-uploader-file-name",fileSize:".flc-uploader-file-size",fileIconBtn:".flc-uploader-file-action",errorText:".flc-uploader-file-error",rowTemplate:".flc-uploader-file-tmplt",errorInfoRowTemplate:".flc-uploader-file-error-tmplt",rowProgressorTemplate:".flc-uploader-file-progressor-tmplt"},styles:{hover:"fl-uploader-file-hover",selected:"fl-uploader-file-focus",ready:"fl-uploader-file-state-ready",uploading:"fl-uploader-file-state-uploading",uploaded:"fl-uploader-file-state-uploaded",error:"fl-uploader-file-state-error",remove:"fl-uploader-file-action-remove",dim:"fl-uploader-dim",hiddenTemplate:"fl-uploader-hidden-templates"},strings:{progress:{toUploadLabel:"To upload: %fileCount %fileLabel (%totalBytes)",singleFile:"file",pluralFiles:"files"},status:{success:"File Uploaded",error:"File Upload Error"},errors:{HTTP_ERROR:"File upload error: a network error occured or the file was rejected (reason unknown).",IO_ERROR:"File upload error: a network error occured.",UPLOAD_LIMIT_EXCEEDED:"File upload error: you have uploaded as many files as you are allowed during this session",UPLOAD_FAILED:"File upload error: the upload failed for an unknown reason.",QUEUE_LIMIT_EXCEEDED:"You have as many files in the queue as can be added at one time. Removing files from the queue may allow you to add different files.",FILE_EXCEEDS_SIZE_LIMIT:"One or more of the files that you attempted to add to the queue exceeded the limit of %fileSizeLimit.",ZERO_BYTE_FILE:"One or more of the files that you attempted to add contained no data.",INVALID_FILETYPE:"One or more files were not added to the queue because they were of the wrong type."}}})})(jQuery,fluid_1_1);(function($,fluid){var fileOrFiles=function(that,numFiles){return(numFiles===1)?that.options.strings.progress.singleFile:that.options.strings.progress.pluralFiles};var enableElement=function(that,elm){elm.removeAttr("disabled");elm.removeClass(that.options.styles.dim)};var disableElement=function(that,elm){elm.attr("disabled","disabled");elm.addClass(that.options.styles.dim)};var showElement=function(that,elm){elm.removeClass(that.options.styles.hidden)};var hideElement=function(that,elm){elm.addClass(that.options.styles.hidden)};var setTotalProgressStyle=function(that,didError){didError=didError||false;var indicator=that.totalProgress.indicator;indicator.toggleClass(that.options.styles.totalProgress,!didError);indicator.toggleClass(that.options.styles.totalProgressError,didError)};var setStateEmpty=function(that){disableElement(that,that.locate("uploadButton"));if(that.uploadManager.queue.files.length===0){that.locate("browseButton").text(that.options.strings.buttons.browse);showElement(that,that.locate("instructions"))}};var setStateDone=function(that){disableElement(that,that.locate("uploadButton"));enableElement(that,that.locate("browseButton"));hideElement(that,that.locate("pauseButton"));showElement(that,that.locate("uploadButton"))};var setStateLoaded=function(that){that.locate("browseButton").text(that.options.strings.buttons.addMore);hideElement(that,that.locate("pauseButton"));showElement(that,that.locate("uploadButton"));enableElement(that,that.locate("uploadButton"));enableElement(that,that.locate("browseButton"));hideElement(that,that.locate("instructions"));that.totalProgress.hide()};var setStateUploading=function(that){that.totalProgress.hide(false,false);setTotalProgressStyle(that);hideElement(that,that.locate("uploadButton"));disableElement(that,that.locate("browseButton"));enableElement(that,that.locate("pauseButton"));showElement(that,that.locate("pauseButton"));that.locate(that.options.focusWithEvent.afterUploadStart).focus()};var renderUploadTotalMessage=function(that){var numReadyFiles=that.uploadManager.queue.getReadyFiles().length;var bytesReadyFiles=that.uploadManager.queue.sizeOfReadyFiles();var fileLabelStr=fileOrFiles(that,numReadyFiles);var totalStateStr=fluid.stringTemplate(that.options.strings.progress.toUploadLabel,{fileCount:numReadyFiles,fileLabel:fileLabelStr,totalBytes:fluid.uploader.formatFileSize(bytesReadyFiles)});that.locate("totalFileStatusText").html(totalStateStr)};var updateTotalProgress=function(that){var batch=that.uploadManager.queue.currentBatch;var totalPercent=fluid.uploader.derivePercent(batch.totalBytesUploaded,batch.totalBytes);var numFilesInBatch=batch.files.length;var fileLabelStr=fileOrFiles(that,numFilesInBatch);var totalProgressStr=fluid.stringTemplate(that.options.strings.progress.totalProgressLabel,{curFileN:batch.fileIdx+1,totalFilesN:numFilesInBatch,fileLabel:fileLabelStr,currBytes:fluid.uploader.formatFileSize(batch.totalBytesUploaded),totalBytes:fluid.uploader.formatFileSize(batch.totalBytes)});that.totalProgress.update(totalPercent,totalProgressStr)};var updateTotalAtCompletion=function(that){var numErroredFiles=that.uploadManager.queue.getErroredFiles().length;var numTotalFiles=that.uploadManager.queue.files.length;var fileLabelStr=fileOrFiles(that,numTotalFiles);var errorStr="";if(numErroredFiles>0){var errorLabelString=(numErroredFiles===1)?that.options.strings.progress.singleError:that.options.strings.progress.pluralErrors;setTotalProgressStyle(that,true);errorStr=fluid.stringTemplate(that.options.strings.progress.numberOfErrors,{errorsN:numErroredFiles,errorLabel:errorLabelString})}var totalProgressStr=fluid.stringTemplate(that.options.strings.progress.completedLabel,{curFileN:that.uploadManager.queue.getUploadedFiles().length,totalFilesN:numTotalFiles,errorString:errorStr,fileLabel:fileLabelStr,totalCurrBytes:fluid.uploader.formatFileSize(that.uploadManager.queue.sizeOfUploadedFiles())});that.totalProgress.update(100,totalProgressStr)};var bindDOMEvents=function(that){that.locate("browseButton").click(function(evnt){that.uploadManager.browseForFiles();evnt.preventDefault()});that.locate("uploadButton").click(function(){that.uploadManager.start()});that.locate("pauseButton").click(function(){that.uploadManager.stop()})};var updateStateAfterFileDialog=function(that){if(that.uploadManager.queue.getReadyFiles().length>0){setStateLoaded(that);renderUploadTotalMessage(that);that.locate(that.options.focusWithEvent.afterFileDialog).focus()}};var updateStateAfterFileRemoval=function(that){if(that.uploadManager.queue.getReadyFiles().length===0){setStateEmpty(that)}renderUploadTotalMessage(that)};var updateStateAfterPause=function(that){};var updateStateAfterCompletion=function(that){var userPaused=that.uploadManager.queue.shouldStop;if(that.uploadManager.queue.getReadyFiles().length===0){setStateDone(that)}else{setStateLoaded(that)}updateTotalAtCompletion(that)};var bindModelEvents=function(that){that.events.afterFileDialog.addListener(function(){updateStateAfterFileDialog(that)});that.events.afterFileRemoved.addListener(function(){updateStateAfterFileRemoval(that)});that.events.onUploadStart.addListener(function(){setStateUploading(that)});that.events.onUploadStop.addListener(function(){that.locate(that.options.focusWithEvent.afterUploadStop).focus()});that.events.onFileProgress.addListener(function(){updateTotalProgress(that)});that.events.onFileSuccess.addListener(function(){updateTotalProgress(that)});that.events.onFileError.addListener(function(file,error,message){if(error===fluid.uploader.errorConstants.UPLOAD_STOPPED){updateStateAfterPause(that)}});that.events.afterUploadComplete.addListener(function(){updateStateAfterCompletion(that)})};var initUploadManager=function(that){var manager=fluid.initSubcomponent(that,"uploadManager",[that.events,fluid.COMPONENT_OPTIONS]);return that.options.demo?fluid.demoUploadManager(manager):manager};var setupUploader=function(that){that.decorators=fluid.initSubcomponents(that,"decorators",[that,fluid.COMPONENT_OPTIONS]);that.uploadManager=initUploadManager(that);that.fileQueueView=fluid.initSubcomponent(that,"fileQueueView",[that.locate("fileQueue"),that.container,that.uploadManager,fluid.COMPONENT_OPTIONS]);that.totalProgress=fluid.initSubcomponent(that,"totalProgressBar",[that.container,fluid.COMPONENT_OPTIONS]);disableElement(that,that.locate("uploadButton"));bindDOMEvents(that);bindModelEvents(that)};fluid.uploader=function(container,options){var that=fluid.initView("fluid.uploader",container,options);setupUploader(that);return that};fluid.progressiveEnhanceableUploader=function(container,enhanceable,options){enhanceable=fluid.container(enhanceable);container=fluid.container(container);if(swfobject.getFlashPlayerVersion().major<9){enhanceable.show()}else{container.show();return fluid.uploader(container,options)}};fluid.uploader.formatFileSize=function(bytes){if(typeof bytes==="number"){if(bytes===0){return"0.0 KB"}else{if(bytes>0){if(bytes<1048576){return(Math.ceil(bytes/1024*10)/10).toFixed(1)+" KB"}else{return(Math.ceil(bytes/1048576*10)/10).toFixed(1)+" MB"}}}}return""};fluid.uploader.derivePercent=function(num,total){return Math.round((num*100)/total)};fluid.defaults("fluid.uploader",{demo:false,decorators:[{type:"fluid.swfUploadSetupDecorator"},{type:"fluid.manuallyDegrade",options:{selectors:{enhanceable:".fl-uploader.fl-progEnhance-basic"}}}],uploadManager:{type:"fluid.swfUploadManager"},fileQueueView:{type:"fluid.fileQueueView"},totalProgressBar:{type:"fluid.progress",options:{selectors:{progressBar:".flc-uploader-queue-footer",displayElement:".flc-uploader-total-progress",label:".flc-uploader-total-progress-text",indicator:".flc-uploader-total-progress",ariaElement:".flc-uploader-total-progress"}}},selectors:{fileQueue:".flc-uploader-queue",browseButton:".flc-uploader-button-browse",uploadButton:".flc-uploader-button-upload",pauseButton:".flc-uploader-button-pause",totalFileStatusText:".flc-uploader-total-progress-text",instructions:".flc-uploader-browse-instructions"},focusWithEvent:{afterFileDialog:"uploadButton",afterUploadStart:"pauseButton",afterUploadStop:"uploadButton"},styles:{disabled:"fl-uploader-disabled",hidden:"fl-uploader-hidden",dim:"fl-uploader-dim",totalProgress:"fl-uploader-total-progress-okay",totalProgressError:"fl-uploader-total-progress-errored"},events:{afterReady:null,onFileDialog:null,afterFileQueued:null,afterFileRemoved:null,onQueueError:null,afterFileDialog:null,onUploadStart:null,onUploadStop:null,onFileStart:null,onFileProgress:null,onFileError:null,onFileSuccess:null,afterFileComplete:null,afterUploadComplete:null},strings:{progress:{toUploadLabel:"To upload: %fileCount %fileLabel (%totalBytes)",totalProgressLabel:"Uploading: %curFileN of %totalFilesN %fileLabel (%currBytes of %totalBytes)",completedLabel:"Uploaded: %curFileN of %totalFilesN %fileLabel (%totalCurrBytes)%errorString",numberOfErrors:", %errorsN %errorLabel",singleFile:"file",pluralFiles:"files",singleError:"error",pluralErrors:"errors"},buttons:{browse:"Browse Files",addMore:"Add More",stopUpload:"Stop Upload",cancelRemaning:"Cancel remaining Uploads",resumeUpload:"Resume Upload"}}});fluid.uploader.errorConstants={HTTP_ERROR:-200,MISSING_UPLOAD_URL:-210,IO_ERROR:-220,SECURITY_ERROR:-230,UPLOAD_LIMIT_EXCEEDED:-240,UPLOAD_FAILED:-250,SPECIFIED_FILE_ID_NOT_FOUND:-260,FILE_VALIDATION_FAILED:-270,FILE_CANCELLED:-280,UPLOAD_STOPPED:-290};fluid.uploader.fileStatusConstants={QUEUED:-1,IN_PROGRESS:-2,ERROR:-3,COMPLETE:-4,CANCELLED:-5};var renderLink=function(renderLocation,text,classes,appendBeside){var link=$("<a href='#'>"+text+"</a>");link.addClass(classes);if(renderLocation==="before"){appendBeside.before(link)}else{appendBeside.after(link)}return link};var toggleVisibility=function(toShow,toHide){if(window.opera){toShow.show().removeClass("hideUploaderForOpera");toHide.show().addClass("hideUploaderForOpera")}else{toShow.show();toHide.hide()}};var defaultControlRenderer=function(that){var degradeLink=renderLink(that.options.defaultRenderLocation,that.options.strings.degradeLinkText,that.options.styles.degradeLinkClass,that.enhancedContainer);degradeLink.addClass("flc-manuallyDegrade-degrade");var enhanceLink=renderLink(that.options.defaultRenderLocation,that.options.strings.enhanceLinkText,that.options.styles.enhanceLinkClass,that.degradedContainer);enhanceLink.addClass("flc-manuallyDegrade-enhance")};var fetchControls=function(that){that.degradeControl=that.locate("degradeControl");that.enhanceControl=that.locate("enhanceControl")};var setupManuallyDegrade=function(that){if(!that.degradedContainer.length){return }fetchControls(that);if(!that.degradeControl.length&&!that.enhanceControl.length){that.options.controlRenderer(that);fetchControls(that)}that.degradeControl.click(that.degrade);that.enhanceControl.click(that.enhance);that.enhanceControl.hide()};var determineContainer=function(options){var defaults=fluid.defaults("fluid.manuallyDegrade");return(options&&options.container)?options.container:defaults.container};fluid.manuallyDegrade=function(component,options){var container=determineContainer(options);var that=fluid.initView("fluid.manuallyDegrade",container,options);var isDegraded=false;that.enhancedContainer=component.container;that.degradedContainer=that.locate("enhanceable");that.degrade=function(){toggleVisibility(that.enhanceControl,that.degradeControl);toggleVisibility(that.degradedContainer,that.enhancedContainer);isDegraded=true};that.enhance=function(){toggleVisibility(that.degradeControl,that.enhanceControl);toggleVisibility(that.enhancedContainer,that.degradedContainer);isDegraded=false};that.isDegraded=function(){return isDegraded};setupManuallyDegrade(that);return that};fluid.defaults("fluid.manuallyDegrade",{container:"body",controlRenderer:defaultControlRenderer,defaultRenderLocation:"before",strings:{degradeLinkText:"Switch to the standard single-file Uploader",enhanceLinkText:"Switch to the Flash-based multi-file Uploader"},selectors:{enhanceable:".fl-ProgEnhance-basic",degradeControl:".flc-manuallyDegrade-degrade",enhanceControl:".flc-manuallyDegrade-enhance"},styles:{degradeLinkClass:"fl-uploader-manually-degrade",enhanceLinkClass:"fl-uploader-manually-enhance"}})})(jQuery,fluid_1_1);