moved code up one level to eliminate the docs subdirectory
[acontent.git] / include / jscripts / infusion / components / uploader / js / FileQueueView.js
1 var fluid_1_4=fluid_1_4||{};(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.model;var i;for(i=0;i<files.length;i++){var file=files[i];if(file.id.toString()===row.prop("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.events.onFileRemoved.fire(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(),fileName=file.name,fileSize=fluid.uploader.formatFileSize(file.size);row.removeClass(that.options.styles.hiddenTemplate);that.locate("fileName",row).text(fileName);that.locate("fileSize",row).text(fileSize);that.locate("fileIconBtn",row).addClass(that.options.styles.remove);row.prop("id",file.id);row.addClass(that.options.styles.ready);bindRowHandlers(that,row);fluid.updateAriaLabel(row,fileName+" "+fileSize);return row};var createProgressorFromTemplate=function(that,row){var rowProgressor=that.rowProgressorTemplate.clone();var rowId=row.prop("id");var progressId=rowId+"_progress";rowProgressor.prop("id",progressId);rowProgressor.css("top",row.position().top);rowProgressor.height(row.height()).width(5);that.container.after(rowProgressor);that.fileProgressors[progressId]=fluid.progress(that.options.uploaderContainer,{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.attr("title",that.options.strings.status.remove);row.fadeIn("slow");createProgressorFromTemplate(that,row);that.refreshView();that.scroller.scrollTo("100%")};var enableRows=function(rows,state){var i;for(i=0;i<rows.length;i++){fluid.enabled(rows[i],state)}};var prepareForUpload=function(that){var rowButtons=that.locate("fileIconBtn",that.locate("fileRows"));rowButtons.prop("disabled",true);rowButtons.addClass(that.options.styles.dim);enableRows(that.locate("fileRows"),false)};var refreshAfterUpload=function(that){var rowButtons=that.locate("fileIconBtn",that.locate("fileRows"));rowButtons.prop("disabled",false);rowButtons.removeClass(that.options.styles.dim);enableRows(that.locate("fileRows"),true)};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.prop("id",fileRow.prop("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 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();that.errorInfoRowTemplate=that.locate("errorInfoRowTemplate").remove();that.errorInfoRowTemplate.removeClass(that.options.styles.hiddenTemplate);that.rowProgressorTemplate=that.locate("rowProgressorTemplate",that.options.uploaderContainer).remove()};fluid.registerNamespace("fluid.uploader.fileQueueView");fluid.uploader.fileQueueView.finalInit=function(that){prepareTemplateElements(that);addKeyboardNavigation(that)};fluid.uploader.fileQueueView.preInit=function(that){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.selectableContext.refresh();that.scroller.refreshView()}};fluid.defaults("fluid.uploader.fileQueueView",{gradeNames:["fluid.viewComponent","autoInit"],preInitFunction:"fluid.uploader.fileQueueView.preInit",finalInitFunction:"fluid.uploader.fileQueueView.finalInit",components:{scroller:{type:"fluid.scrollableTable"},eventBinder:{type:"fluid.uploader.fileQueueView.eventBinder"}},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",remove:"Press Delete key to remove file"},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."}},events:{onFileRemoved:null},mergePolicy:{model:"preserve"}});fluid.defaults("fluid.uploader.fileQueueView.eventBinder",{gradeNames:["fluid.eventedComponent","autoInit"]});fluid.demands("fluid.uploader.fileQueueView.eventBinder",[],{});fluid.scrollable=function(element,options){var that=fluid.initView("fluid.scrollable",element,options);that.scrollable=that.options.makeScrollableFn(that.container,that.options);that.maxHeight=that.scrollable.css("max-height");that.scrollTo=function(){that.scrollable.scrollTo.apply(that.scrollable,arguments)};that.refreshView=function(){if($.browser.msie&&$.browser.version==="6.0"){that.scrollable.css("height","");if(that.scrollable.height()>=parseInt(that.maxHeight,10)){that.scrollable.css("height",that.maxHeight)}}};that.refreshView();return that};fluid.scrollable.makeSimple=function(element,options){return fluid.container(element)};fluid.scrollable.makeTable=function(table,options){table.wrap(options.wrapperMarkup);return table.closest(".fl-scrollable-scroller")};fluid.defaults("fluid.scrollable",{makeScrollableFn:fluid.scrollable.makeSimple});fluid.scrollableTable=function(table,options){options=$.extend({},fluid.defaults("fluid.scrollableTable"),options);return fluid.scrollable(table,options)};fluid.defaults("fluid.scrollableTable",{gradeNames:"fluid.viewComponent",makeScrollableFn:fluid.scrollable.makeTable,wrapperMarkup:"<div class='fl-scrollable-scroller'><div class='fl-scrollable-inner'></div></div>"});fluid.demands("fluid.scrollableTable","fluid.uploader.fileQueueView",{funcName:"fluid.scrollableTable",args:["{fileQueueView}.container"]})})(jQuery,fluid_1_4);