Subversion Repositories eFlore/Applications.cel

Rev

Rev 1845 | Rev 2003 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1845 Rev 1847
Line 1... Line -...
1
Ext.namespace("Ext.ux.Utils");Ext.ux.Utils.EventQueue=function(handler,scope){if(!handler){throw"Handler is required."}this.handler=handler;this.scope=scope||window;this.queue=[];this.is_processing=false;this.postEvent=function(event,data){data=data||null;this.queue.push({event:event,data:data});if(!this.is_processing){this.process()}};this.flushEventQueue=function(){this.queue=[]},this.process=function(){while(this.queue.length>0){this.is_processing=true;var event_data=this.queue.shift();this.handler.call(this.scope,event_data.event,event_data.data)}this.is_processing=false}};Ext.ux.Utils.FSA=function(initial_state,trans_table,trans_table_scope){this.current_state=initial_state;this.trans_table=trans_table||{};this.trans_table_scope=trans_table_scope||window;Ext.ux.Utils.FSA.superclass.constructor.call(this,this.processEvent,this)};Ext.extend(Ext.ux.Utils.FSA,Ext.ux.Utils.EventQueue,{current_state:null,trans_table:null,trans_table_scope:null,state:function(){return this.current_state},processEvent:function(event,data){var transitions=this.currentStateEventTransitions(event);if(!transitions){throw"State '"+this.current_state+"' has no transition for event '"+event+"'."}for(var i=0,len=transitions.length;i<len;i++){var transition=transitions[i];var predicate=transition.predicate||transition.p||true;var action=transition.action||transition.a||Ext.emptyFn;var new_state=transition.state||transition.s||this.current_state;var scope=transition.scope||this.trans_table_scope;if(this.computePredicate(predicate,scope,data,event)){this.callAction(action,scope,data,event);this.current_state=new_state;return }}throw"State '"+this.current_state+"' has no transition for event '"+event+"' in current context"},currentStateEventTransitions:function(event){return this.trans_table[this.current_state]?this.trans_table[this.current_state][event]||false:false},computePredicate:function(predicate,scope,data,event){var result=false;switch(Ext.type(predicate)){case"function":result=predicate.call(scope,data,event,this);break;case"array":result=true;for(var i=0,len=predicate.length;result&&(i<len);i++){if(Ext.type(predicate[i])=="function"){result=predicate[i].call(scope,data,event,this)}else{throw ["Predicate: ",predicate[i],' is not callable in "',this.current_state,'" state for event "',event].join("")}}break;case"boolean":result=predicate;break;default:throw ["Predicate: ",predicate,' is not callable in "',this.current_state,'" state for event "',event].join("")}return result},callAction:function(action,scope,data,event){switch(Ext.type(action)){case"array":for(var i=0,len=action.length;i<len;i++){if(Ext.type(action[i])=="function"){action[i].call(scope,data,event,this)}else{throw ["Action: ",action[i],' is not callable in "',this.current_state,'" state for event "',event].join("")}}break;case"function":action.call(scope,data,event,this);break;default:throw ["Action: ",action,' is not callable in "',this.current_state,'" state for event "',event].join("")}}});Ext.namespace("Ext.ux.UploadDialog");Ext.ux.UploadDialog.BrowseButton=Ext.extend(Ext.Button,{input_name:"file",input_file:null,original_handler:null,original_scope:null,initComponent:function(){Ext.ux.UploadDialog.BrowseButton.superclass.initComponent.call(this);this.original_handler=this.handler||null;this.original_scope=this.scope||window;this.handler=null;this.scope=null},onRender:function(ct,position){Ext.ux.UploadDialog.BrowseButton.superclass.onRender.call(this,ct,position);this.createInputFile()},createInputFile:function(){var button_container=this.el.child(".x-btn-center");button_container.position("relative");this.input_file=Ext.DomHelper.append(button_container,{tag:"input",type:"file",size:1,name:this.input_name||Ext.id(this.el),style:"position: absolute; display: block; border: none; cursor: pointer"},true);var button_box=button_container.getBox();this.input_file.setStyle("font-size",(button_box.width*0.5)+"px");var input_box=this.input_file.getBox();var adj={x:3,y:3};if(Ext.isIE){adj={x:0,y:3}}this.input_file.setLeft(button_box.width-input_box.width+adj.x+"px");this.input_file.setTop(button_box.height-input_box.height+adj.y+"px");this.input_file.setOpacity(0);if(this.handleMouseEvents){this.input_file.on("mouseover",this.onMouseOver,this);this.input_file.on("mousedown",this.onMouseDown,this)}if(this.tooltip){if(typeof this.tooltip=="object"){Ext.QuickTips.register(Ext.apply({target:this.input_file},this.tooltip))}else{this.input_file.dom[this.tooltipType]=this.tooltip}}this.input_file.on("change",this.onInputFileChange,this);this.input_file.on("click",function(e){e.stopPropagation()})},detachInputFile:function(no_create){var result=this.input_file;no_create=no_create||false;if(typeof this.tooltip=="object"){Ext.QuickTips.unregister(this.input_file)}else{this.input_file.dom[this.tooltipType]=null}this.input_file.removeAllListeners();this.input_file=null;if(!no_create){this.createInputFile()}return result},getInputFile:function(){return this.input_file},disable:function(){Ext.ux.UploadDialog.BrowseButton.superclass.disable.call(this);this.input_file.dom.disabled=true},enable:function(){Ext.ux.UploadDialog.BrowseButton.superclass.enable.call(this);this.input_file.dom.disabled=false},destroy:function(){var input_file=this.detachInputFile(true);input_file.remove();input_file=null;Ext.ux.UploadDialog.BrowseButton.superclass.destroy.call(this)},onInputFileChange:function(){if(this.original_handler){this.original_handler.call(this.original_scope,this)}}});Ext.ux.UploadDialog.TBBrowseButton=Ext.extend(Ext.ux.UploadDialog.BrowseButton,{hideParent:true,onDestroy:function(){Ext.ux.UploadDialog.TBBrowseButton.superclass.onDestroy.call(this);if(this.container){this.container.remove()}}});Ext.ux.UploadDialog.FileRecord=Ext.data.Record.create([{name:"filename"},{name:"state",type:"int"},{name:"note"},{name:"input_element"}]);Ext.ux.UploadDialog.FileRecord.STATE_QUEUE=0;Ext.ux.UploadDialog.FileRecord.STATE_FINISHED=1;Ext.ux.UploadDialog.FileRecord.STATE_FAILED=2;Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING=3;Ext.ux.UploadDialog.Dialog=function(config){var default_config={border:false,width:450,height:300,minWidth:450,minHeight:300,plain:true,constrainHeader:true,draggable:true,closable:true,maximizable:false,minimizable:false,resizable:true,autoDestroy:true,closeAction:"hide",title:this.i18n.title,cls:"ext-ux-uploaddialog-dialog",url:"",base_params:{},permitted_extensions:[],reset_on_hide:true,allow_close_on_upload:false,upload_autostart:false,post_var_name:"file"};config=Ext.applyIf(config||{},default_config);config.layout="absolute";Ext.ux.UploadDialog.Dialog.superclass.constructor.call(this,config)};Ext.extend(Ext.ux.UploadDialog.Dialog,Ext.Window,{fsa:null,state_tpl:null,form:null,grid_panel:null,progress_bar:null,is_uploading:false,initial_queued_count:0,upload_frame:null,initComponent:function(){Ext.ux.UploadDialog.Dialog.superclass.initComponent.call(this);var tt={created:{"window-render":[{action:[this.createForm,this.createProgressBar,this.createGrid],state:"rendering"}],destroy:[{action:this.flushEventQueue,state:"destroyed"}]},rendering:{"grid-render":[{action:[this.fillToolbar,this.updateToolbar],state:"ready"}],destroy:[{action:this.flushEventQueue,state:"destroyed"}]},ready:{"file-selected":[{predicate:[this.fireFileTestEvent,this.isPermittedFile],action:this.addFileToUploadQueue,state:"adding-file"},{}],"grid-selection-change":[{action:this.updateToolbar}],"remove-files":[{action:[this.removeFiles,this.fireFileRemoveEvent]}],"reset-queue":[{action:[this.resetQueue,this.fireResetQueueEvent]}],"start-upload":[{predicate:this.hasUnuploadedFiles,action:[this.setUploadingFlag,this.saveInitialQueuedCount,this.updateToolbar,this.updateProgressBar,this.prepareNextUploadTask,this.fireUploadStartEvent],state:"uploading"},{}],"stop-upload":[{}],hide:[{predicate:[this.isNotEmptyQueue,this.getResetOnHide],action:[this.resetQueue,this.fireResetQueueEvent]},{}],destroy:[{action:this.flushEventQueue,state:"destroyed"}]},"adding-file":{"file-added":[{predicate:this.isUploading,action:[this.incInitialQueuedCount,this.updateProgressBar,this.fireFileAddEvent],state:"uploading"},{predicate:this.getUploadAutostart,action:[this.startUpload,this.fireFileAddEvent],state:"ready"},{action:[this.updateToolbar,this.fireFileAddEvent],state:"ready"}]},uploading:{"file-selected":[{predicate:[this.fireFileTestEvent,this.isPermittedFile],action:this.addFileToUploadQueue,state:"adding-file"},{}],"grid-selection-change":[{}],"start-upload":[{}],"stop-upload":[{predicate:this.hasUnuploadedFiles,action:[this.resetUploadingFlag,this.abortUpload,this.updateToolbar,this.updateProgressBar,this.fireUploadStopEvent],state:"ready"},{action:[this.resetUploadingFlag,this.abortUpload,this.updateToolbar,this.updateProgressBar,this.fireUploadStopEvent,this.fireUploadCompleteEvent],state:"ready"}],"file-upload-start":[{action:[this.uploadFile,this.findUploadFrame,this.fireFileUploadStartEvent]}],"file-upload-success":[{predicate:this.hasUnuploadedFiles,action:[this.resetUploadFrame,this.updateRecordState,this.updateProgressBar,this.prepareNextUploadTask,this.fireUploadSuccessEvent]},{action:[this.resetUploadFrame,this.resetUploadingFlag,this.updateRecordState,this.updateToolbar,this.updateProgressBar,this.fireUploadSuccessEvent,this.fireUploadCompleteEvent],state:"ready"}],"file-upload-error":[{predicate:this.hasUnuploadedFiles,action:[this.resetUploadFrame,this.updateRecordState,this.updateProgressBar,this.prepareNextUploadTask,this.fireUploadErrorEvent]},{action:[this.resetUploadFrame,this.resetUploadingFlag,this.updateRecordState,this.updateToolbar,this.updateProgressBar,this.fireUploadErrorEvent,this.fireUploadCompleteEvent],state:"ready"}],"file-upload-failed":[{predicate:this.hasUnuploadedFiles,action:[this.resetUploadFrame,this.updateRecordState,this.updateProgressBar,this.prepareNextUploadTask,this.fireUploadFailedEvent]},{action:[this.resetUploadFrame,this.resetUploadingFlag,this.updateRecordState,this.updateToolbar,this.updateProgressBar,this.fireUploadFailedEvent,this.fireUploadCompleteEvent],state:"ready"}],hide:[{predicate:this.getResetOnHide,action:[this.stopUpload,this.repostHide]},{}],destroy:[{predicate:this.hasUnuploadedFiles,action:[this.resetUploadingFlag,this.abortUpload,this.fireUploadStopEvent,this.flushEventQueue],state:"destroyed"},{action:[this.resetUploadingFlag,this.abortUpload,this.fireUploadStopEvent,this.fireUploadCompleteEvent,this.flushEventQueue],state:"destroyed"}]},destroyed:{}};this.fsa=new Ext.ux.Utils.FSA("created",tt,this);this.addEvents({filetest:true,fileadd:true,fileremove:true,resetqueue:true,uploadsuccess:true,uploaderror:true,uploadfailed:true,uploadstart:true,uploadstop:true,uploadcomplete:true,fileuploadstart:true});this.on("render",this.onWindowRender,this);this.on("beforehide",this.onWindowBeforeHide,this);this.on("hide",this.onWindowHide,this);this.on("destroy",this.onWindowDestroy,this);this.state_tpl=new Ext.Template("<div class='ext-ux-uploaddialog-state ext-ux-uploaddialog-state-{state}'>&#160;</div>").compile()},createForm:function(){this.form=Ext.DomHelper.append(this.body,{tag:"form",method:"post",action:this.url,style:"position: absolute; left: -100px; top: -100px; width: 100px; height: 100px"})},createProgressBar:function(){this.progress_bar=this.add(new Ext.ProgressBar({x:0,y:0,anchor:"0",value:0,text:this.i18n.progress_waiting_text}))},createGrid:function(){var store=new Ext.data.Store({proxy:new Ext.data.MemoryProxy([]),reader:new Ext.data.JsonReader({},Ext.ux.UploadDialog.FileRecord),sortInfo:{field:"state",direction:"DESC"},pruneModifiedRecords:true});var cm=new Ext.grid.ColumnModel([{header:this.i18n.state_col_title,width:this.i18n.state_col_width,resizable:false,dataIndex:"state",sortable:true,renderer:this.renderStateCell.createDelegate(this)},{header:this.i18n.filename_col_title,width:this.i18n.filename_col_width,dataIndex:"filename",sortable:true,renderer:this.renderFilenameCell.createDelegate(this)},{header:this.i18n.note_col_title,width:this.i18n.note_col_width,dataIndex:"note",sortable:true,renderer:this.renderNoteCell.createDelegate(this)}]);this.grid_panel=new Ext.grid.GridPanel({ds:store,cm:cm,x:0,y:22,anchor:"0 -22",border:true,viewConfig:{autoFill:true,forceFit:true},bbar:new Ext.Toolbar()});this.grid_panel.on("render",this.onGridRender,this);this.add(this.grid_panel);this.grid_panel.getSelectionModel().on("selectionchange",this.onGridSelectionChange,this)},fillToolbar:function(){var tb=this.grid_panel.getBottomToolbar();tb.x_buttons={};tb.x_buttons.add=tb.addItem(new Ext.ux.UploadDialog.TBBrowseButton({input_name:this.post_var_name,text:this.i18n.add_btn_text,tooltip:this.i18n.add_btn_tip,iconCls:"ext-ux-uploaddialog-addbtn",handler:this.onAddButtonFileSelected,scope:this}));tb.x_buttons.remove=tb.addButton({text:this.i18n.remove_btn_text,tooltip:this.i18n.remove_btn_tip,iconCls:"ext-ux-uploaddialog-removebtn",handler:this.onRemoveButtonClick,scope:this});tb.x_buttons.reset=tb.addButton({text:this.i18n.reset_btn_text,tooltip:this.i18n.reset_btn_tip,iconCls:"ext-ux-uploaddialog-resetbtn",handler:this.onResetButtonClick,scope:this});tb.add("-");tb.x_buttons.upload=tb.addButton({text:this.i18n.upload_btn_start_text,tooltip:this.i18n.upload_btn_start_tip,iconCls:"ext-ux-uploaddialog-uploadstartbtn",handler:this.onUploadButtonClick,scope:this});tb.add("-");tb.x_buttons.indicator=tb.addItem(new Ext.Toolbar.Item(Ext.DomHelper.append(tb.getEl(),{tag:"div",cls:"ext-ux-uploaddialog-indicator-stoped",html:"&#160"})));tb.add("->");tb.x_buttons.close=tb.addButton({text:this.i18n.close_btn_text,tooltip:this.i18n.close_btn_tip,handler:this.onCloseButtonClick,scope:this})},renderStateCell:function(data,cell,record,row_index,column_index,store){return this.state_tpl.apply({state:data})},renderFilenameCell:function(data,cell,record,row_index,column_index,store){var view=this.grid_panel.getView();var f=function(){try{Ext.fly(view.getCell(row_index,column_index)).child(".x-grid3-cell-inner").dom.qtip=data}catch(e){}};f.defer(1000);return data},renderNoteCell:function(data,cell,record,row_index,column_index,store){var view=this.grid_panel.getView();var f=function(){try{Ext.fly(view.getCell(row_index,column_index)).child(".x-grid3-cell-inner").dom.qtip=data}catch(e){}};f.defer(1000);return data},getFileExtension:function(filename){var result=null;var parts=filename.split(".");if(parts.length>1){result=parts.pop()}return result},isPermittedFileType:function(filename){var result=true;if(this.permitted_extensions.length>0){result=this.permitted_extensions.indexOf(this.getFileExtension(filename))!=-1}return result},isPermittedFile:function(browse_btn){var result=false;var filename=browse_btn.getInputFile().dom.value;if(this.isPermittedFileType(filename)){result=true}else{Ext.Msg.alert(this.i18n.error_msgbox_title,String.format(this.i18n.err_file_type_not_permitted,filename,this.permitted_extensions.join(this.i18n.permitted_extensions_join_str)));result=false}return result},fireFileTestEvent:function(browse_btn){return this.fireEvent("filetest",this,browse_btn.getInputFile().dom.value)!==false},addFileToUploadQueue:function(browse_btn){var input_file=browse_btn.detachInputFile();input_file.appendTo(this.form);input_file.setStyle("width","100px");input_file.dom.disabled=true;var store=this.grid_panel.getStore();store.add(new Ext.ux.UploadDialog.FileRecord({state:Ext.ux.UploadDialog.FileRecord.STATE_QUEUE,filename:input_file.dom.value,note:this.i18n.note_queued_to_upload,input_element:input_file}));this.fsa.postEvent("file-added",input_file.dom.value)},fireFileAddEvent:function(filename){this.fireEvent("fileadd",this,filename)},updateProgressBar:function(){if(this.is_uploading){var queued=this.getQueuedCount(true);var value=1-queued/this.initial_queued_count;this.progress_bar.updateProgress(value,String.format(this.i18n.progress_uploading_text,this.initial_queued_count-queued,this.initial_queued_count))}else{this.progress_bar.updateProgress(0,this.i18n.progress_waiting_text)}},updateToolbar:function(){var tb=this.grid_panel.getBottomToolbar();if(this.is_uploading){tb.x_buttons.remove.disable();tb.x_buttons.reset.disable();tb.x_buttons.upload.enable();if(!this.getAllowCloseOnUpload()){tb.x_buttons.close.disable()}Ext.fly(tb.x_buttons.indicator.getEl()).replaceClass("ext-ux-uploaddialog-indicator-stoped","ext-ux-uploaddialog-indicator-processing");tb.x_buttons.upload.setIconClass("ext-ux-uploaddialog-uploadstopbtn");tb.x_buttons.upload.setText(this.i18n.upload_btn_stop_text);tb.x_buttons.upload.getEl().child(tb.x_buttons.upload.buttonSelector).dom[tb.x_buttons.upload.tooltipType]=this.i18n.upload_btn_stop_tip}else{tb.x_buttons.remove.enable();tb.x_buttons.reset.enable();tb.x_buttons.close.enable();Ext.fly(tb.x_buttons.indicator.getEl()).replaceClass("ext-ux-uploaddialog-indicator-processing","ext-ux-uploaddialog-indicator-stoped");tb.x_buttons.upload.setIconClass("ext-ux-uploaddialog-uploadstartbtn");tb.x_buttons.upload.setText(this.i18n.upload_btn_start_text);tb.x_buttons.upload.getEl().child(tb.x_buttons.upload.buttonSelector).dom[tb.x_buttons.upload.tooltipType]=this.i18n.upload_btn_start_tip;if(this.getQueuedCount()>0){tb.x_buttons.upload.enable()}else{tb.x_buttons.upload.disable()}if(this.grid_panel.getSelectionModel().hasSelection()){tb.x_buttons.remove.enable()}else{tb.x_buttons.remove.disable()}if(this.grid_panel.getStore().getCount()>0){tb.x_buttons.reset.enable()}else{tb.x_buttons.reset.disable()}}},saveInitialQueuedCount:function(){this.initial_queued_count=this.getQueuedCount()},incInitialQueuedCount:function(){this.initial_queued_count++},setUploadingFlag:function(){this.is_uploading=true},resetUploadingFlag:function(){this.is_uploading=false},prepareNextUploadTask:function(){var store=this.grid_panel.getStore();var record=null;store.each(function(r){if(!record&&r.get("state")==Ext.ux.UploadDialog.FileRecord.STATE_QUEUE){record=r}else{r.get("input_element").dom.disabled=true}});record.get("input_element").dom.disabled=false;record.set("state",Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING);record.set("note",this.i18n.note_processing);record.commit();this.fsa.postEvent("file-upload-start",record)},fireUploadStartEvent:function(){this.fireEvent("uploadstart",this)},removeFiles:function(file_records){var store=this.grid_panel.getStore();for(var i=0,len=file_records.length;i<len;i++){var r=file_records[i];r.get("input_element").remove();store.remove(r)}},fireFileRemoveEvent:function(file_records){for(var i=0,len=file_records.length;i<len;i++){this.fireEvent("fileremove",this,file_records[i].get("filename"))}},resetQueue:function(){var store=this.grid_panel.getStore();store.each(function(r){r.get("input_element").remove()});store.removeAll()},fireResetQueueEvent:function(){this.fireEvent("resetqueue",this)},uploadFile:function(record){Ext.Ajax.request({url:this.url,params:this.base_params||this.baseParams||this.params,method:"POST",form:this.form,isUpload:true,success:this.onAjaxSuccess,failure:this.onAjaxFailure,scope:this,record:record})},fireFileUploadStartEvent:function(record){this.fireEvent("fileuploadstart",this,record.get("filename"))},updateRecordState:function(data){if("success" in data.response&&data.response.success){data.record.set("state",Ext.ux.UploadDialog.FileRecord.STATE_FINISHED);data.record.set("note",data.response.message||data.response.error||this.i18n.note_upload_success)}else{data.record.set("state",Ext.ux.UploadDialog.FileRecord.STATE_FAILED);data.record.set("note",data.response.message||data.response.error||this.i18n.note_upload_error)}data.record.commit()},fireUploadSuccessEvent:function(data){this.fireEvent("uploadsuccess",this,data.record.get("filename"),data.response)},fireUploadErrorEvent:function(data){this.fireEvent("uploaderror",this,data.record.get("filename"),data.response)},fireUploadFailedEvent:function(data){this.fireEvent("uploadfailed",this,data.record.get("filename"))},fireUploadCompleteEvent:function(){this.fireEvent("uploadcomplete",this)},findUploadFrame:function(){this.upload_frame=Ext.getBody().child("iframe.x-hidden:last")},resetUploadFrame:function(){this.upload_frame=null},removeUploadFrame:function(){if(this.upload_frame){this.upload_frame.removeAllListeners();this.upload_frame.dom.src="about:blank";this.upload_frame.remove()}this.upload_frame=null},abortUpload:function(){this.removeUploadFrame();var store=this.grid_panel.getStore();var record=null;store.each(function(r){if(r.get("state")==Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING){record=r;return false}});record.set("state",Ext.ux.UploadDialog.FileRecord.STATE_FAILED);record.set("note",this.i18n.note_aborted);record.commit()},fireUploadStopEvent:function(){this.fireEvent("uploadstop",this)},repostHide:function(){this.fsa.postEvent("hide")},flushEventQueue:function(){this.fsa.flushEventQueue()},onWindowRender:function(){this.fsa.postEvent("window-render")},onWindowBeforeHide:function(){return this.isUploading()?this.getAllowCloseOnUpload():true},onWindowHide:function(){this.fsa.postEvent("hide")},onWindowDestroy:function(){this.fsa.postEvent("destroy")},onGridRender:function(){this.fsa.postEvent("grid-render")},onGridSelectionChange:function(){this.fsa.postEvent("grid-selection-change")},onAddButtonFileSelected:function(btn){this.fsa.postEvent("file-selected",btn)},onUploadButtonClick:function(){if(this.is_uploading){this.fsa.postEvent("stop-upload")}else{this.fsa.postEvent("start-upload")}},onRemoveButtonClick:function(){var selections=this.grid_panel.getSelectionModel().getSelections();this.fsa.postEvent("remove-files",selections)},onResetButtonClick:function(){this.fsa.postEvent("reset-queue")},onCloseButtonClick:function(){this[this.closeAction].call(this)},onAjaxSuccess:function(response,options){var json_response={success:false,error:this.i18n.note_upload_error};try{var rt=response.responseText;var filter=rt.match(/^<[^>]+>((?:.|\n)*)<\/[^>]+>$/);if(filter){rt=filter[1]}json_response=Ext.util.JSON.decode(rt)}catch(e){}var data={record:options.record,response:json_response};if("success" in json_response&&json_response.success){this.fsa.postEvent("file-upload-success",data)}else{this.fsa.postEvent("file-upload-error",data)}},onAjaxFailure:function(response,options){var data={record:options.record,response:{success:false,error:this.i18n.note_upload_failed}};this.fsa.postEvent("file-upload-failed",data)},startUpload:function(){this.fsa.postEvent("start-upload")},stopUpload:function(){this.fsa.postEvent("stop-upload")},getUrl:function(){return this.url},setUrl:function(url){this.url=url},getBaseParams:function(){return this.base_params},setBaseParams:function(params){this.base_params=params},getUploadAutostart:function(){return this.upload_autostart},setUploadAutostart:function(value){this.upload_autostart=value},getAllowCloseOnUpload:function(){return this.allow_close_on_upload},setAllowCloseOnUpload:function(value){this.allow_close_on_upload},getResetOnHide:function(){return this.reset_on_hide},setResetOnHide:function(value){this.reset_on_hide=value},getPermittedExtensions:function(){return this.permitted_extensions},setPermittedExtensions:function(value){this.permitted_extensions=value},isUploading:function(){return this.is_uploading},isNotEmptyQueue:function(){return this.grid_panel.getStore().getCount()>0},getQueuedCount:function(count_processing){var count=0;var store=this.grid_panel.getStore();store.each(function(r){if(r.get("state")==Ext.ux.UploadDialog.FileRecord.STATE_QUEUE){count++}if(count_processing&&r.get("state")==Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING){count++}});return count},hasUnuploadedFiles:function(){return this.getQueuedCount()>0}});var p=Ext.ux.UploadDialog.Dialog.prototype;p.i18n={title:"File upload dialog",state_col_title:"State",state_col_width:70,filename_col_title:"Filename",filename_col_width:230,note_col_title:"Note",note_col_width:150,add_btn_text:"Add",add_btn_tip:"Add file into upload queue.",remove_btn_text:"Remove",remove_btn_tip:"Remove file from upload queue.",reset_btn_text:"Reset",reset_btn_tip:"Reset queue.",upload_btn_start_text:"Upload",upload_btn_stop_text:"Abort",upload_btn_start_tip:"Upload queued files to the server.",upload_btn_stop_tip:"Stop upload.",close_btn_text:"Close",close_btn_tip:"Close the dialog.",progress_waiting_text:"Waiting...",progress_uploading_text:"Uploading: {0} of {1} files complete.",error_msgbox_title:"Error",permitted_extensions_join_str:",",err_file_type_not_permitted:"Selected file extension isn't permitted.<br/>Please select files with following extensions: {1}",note_queued_to_upload:"Queued for upload.",note_processing:"Uploading...",note_upload_failed:"Server is unavailable or internal server error occured.",note_upload_success:"OK.",note_upload_error:"Upload error.",note_aborted:"Aborted by user."};
-
 
2
1
/**
-
 
2
 * This namespace should be in another file but I dicided to put it here for consistancy.
-
 
3
 */
-
 
4
Ext.namespace('Ext.ux.Utils');
-
 
5
 
-
 
6
/**
-
 
7
 * This class implements event queue behaviour.
-
 
8
 *
-
 
9
 * @class Ext.ux.Utils.EventQueue
-
 
10
 * @param function  handler  Event handler.
-
 
11
 * @param object    scope    Handler scope.
-
 
12
 */
-
 
13
Ext.ux.Utils.EventQueue = function(handler, scope)
-
 
14
{
-
 
15
  if (!handler) {
-
 
16
    throw 'Handler is required.';
-
 
17
  }
-
 
18
  this.handler = handler;
-
 
19
  this.scope = scope || window;
-
 
20
  this.queue = [];
-
 
21
  this.is_processing = false;
-
 
22
  
-
 
23
  /**
-
 
24
   * Posts event into the queue.
-
 
25
   * 
-
 
26
   * @access public
-
 
27
   * @param mixed event Event identificator.
-
 
28
   * @param mixed data  Event data.
-
 
29
   */
-
 
30
  this.postEvent = function(event, data)
-
 
31
  {
-
 
32
    data = data || null;
-
 
33
    this.queue.push({event: event, data: data});
-
 
34
    if (!this.is_processing) {
-
 
35
      this.process();
-
 
36
    }
-
 
37
  }
-
 
38
  
-
 
39
  this.flushEventQueue = function()
-
 
40
  {
-
 
41
    this.queue = [];
-
 
42
  },
-
 
43
  
-
 
44
  /**
-
 
45
   * @access private
-
 
46
   */
-
 
47
  this.process = function()
-
 
48
  {
-
 
49
    while (this.queue.length > 0) {
-
 
50
      this.is_processing = true;
-
 
51
      var event_data = this.queue.shift();
-
 
52
      this.handler.call(this.scope, event_data.event, event_data.data);
-
 
53
    }
-
 
54
    this.is_processing = false;
-
 
55
  }
-
 
56
}
-
 
57
 
-
 
58
/**
-
 
59
 * This class implements Mili's finite state automata behaviour.
-
 
60
 *  
-
 
61
 *  Transition / output table format:
-
 
62
 *  {
-
 
63
 *    'state_1' : {
-
 
64
 *      'event_1' : [
-
 
65
 *        {
-
 
66
 *          p|predicate: function,    // Transition predicate, optional, default to true.
-
 
67
 *                                    // If array then conjunction will be applyed to the operands.
-
 
68
 *                                    // Predicate signature is (data, event, this).
-
 
69
 *          a|action: function|array, // Transition action, optional, default to Ext.emptyFn.
-
 
70
 *                                    // If array then methods will be called sequentially.
-
 
71
 *                                    // Action signature is (data, event, this).
-
 
72
 *          s|state: 'state_x',       // New state - transition destination, optional, default to 
-
 
73
 *                                    // current state.
-
 
74
 *          scope: object             // Predicate and action scope, optional, default to 
-
 
75
 *                                    // trans_table_scope or window.
-
 
76
 *        }
-
 
77
 *      ]
-
 
78
 *    },
-
 
79
 *
-
 
80
 *    'state_2' : {
-
 
81
 *      ...
-
 
82
 *    }
-
 
83
 *    ...
-
 
84
 *  }
-
 
85
 *
-
 
86
 *  @param  mixed initial_state Initial state.
-
 
87
 *  @param  object trans_table Transition / output table.
-
 
88
 *  @param  trans_table_scope Transition / output table's methods scope.
-
 
89
 */
-
 
90
Ext.ux.Utils.FSA = function(initial_state, trans_table, trans_table_scope)
-
 
91
{
-
 
92
  this.current_state = initial_state;
-
 
93
  this.trans_table = trans_table || {};
-
 
94
  this.trans_table_scope = trans_table_scope || window;
-
 
95
  Ext.ux.Utils.FSA.superclass.constructor.call(this, this.processEvent, this);
-
 
96
}
-
 
97
 
-
 
98
Ext.extend(Ext.ux.Utils.FSA, Ext.ux.Utils.EventQueue, {
-
 
99
 
-
 
100
  current_state : null,
-
 
101
  trans_table : null,  
-
 
102
  trans_table_scope : null,
-
 
103
  
-
 
104
  /**
-
 
105
   * Returns current state
-
 
106
   * 
-
 
107
   * @access public
-
 
108
   * @return mixed Current state.
-
 
109
   */
-
 
110
  state : function()
-
 
111
  {
-
 
112
    return this.current_state;
-
 
113
  },
-
 
114
  
-
 
115
  /**
-
 
116
   * @access public
-
 
117
   */
-
 
118
  processEvent : function(event, data)
-
 
119
  {
-
 
120
    var transitions = this.currentStateEventTransitions(event);
-
 
121
    if (!transitions) {
-
 
122
      throw "State '" + this.current_state + "' has no transition for event '" + event + "'.";
-
 
123
    }
-
 
124
    for (var i = 0, len = transitions.length; i < len; i++) {
-
 
125
      var transition = transitions[i];
-
 
126
 
-
 
127
      var predicate = transition.predicate || transition.p || true;
-
 
128
      var action = transition.action || transition.a || Ext.emptyFn;
-
 
129
      var new_state = transition.state || transition.s || this.current_state;
-
 
130
      var scope = transition.scope || this.trans_table_scope;
-
 
131
      
-
 
132
      if (this.computePredicate(predicate, scope, data, event)) {
-
 
133
        this.callAction(action, scope, data, event);
-
 
134
        this.current_state = new_state; 
-
 
135
        return;
-
 
136
      }
-
 
137
    }
-
 
138
    
-
 
139
    throw "State '" + this.current_state + "' has no transition for event '" + event + "' in current context";
-
 
140
  },
-
 
141
  
-
 
142
  /**
-
 
143
   * @access private
-
 
144
   */
-
 
145
  currentStateEventTransitions : function(event)
-
 
146
  {
-
 
147
    return this.trans_table[this.current_state] ? 
-
 
148
      this.trans_table[this.current_state][event] || false
-
 
149
      :
-
 
150
      false;
-
 
151
  },
-
 
152
  
-
 
153
  /**
-
 
154
   * @access private
-
 
155
   */
-
 
156
  computePredicate : function(predicate, scope, data, event)
-
 
157
  {
-
 
158
    var result = false; 
-
 
159
    
-
 
160
    switch (Ext.type(predicate)) {
-
 
161
     case 'function':
-
 
162
       result = predicate.call(scope, data, event, this);
-
 
163
       break;
-
 
164
     case 'array':
-
 
165
       result = true;
-
 
166
       for (var i = 0, len = predicate.length; result && (i < len); i++) {
-
 
167
         if (Ext.type(predicate[i]) == 'function') {
-
 
168
           result = predicate[i].call(scope, data, event, this);
-
 
169
         }
-
 
170
         else {
-
 
171
           throw [
-
 
172
             'Predicate: ',
-
 
173
             predicate[i],
-
 
174
             ' is not callable in "',
-
 
175
             this.current_state,
-
 
176
             '" state for event "',
-
 
177
             event
-
 
178
           ].join('');
-
 
179
         }
-
 
180
       }
-
 
181
       break;
-
 
182
     case 'boolean':
-
 
183
       result = predicate;
-
 
184
       break;
-
 
185
     default:
-
 
186
       throw [
-
 
187
         'Predicate: ',
-
 
188
         predicate,
-
 
189
         ' is not callable in "',
-
 
190
         this.current_state,
-
 
191
         '" state for event "',
-
 
192
         event
-
 
193
       ].join('');
-
 
194
    }
-
 
195
    return result;
-
 
196
  },
-
 
197
  
-
 
198
  /**
-
 
199
   * @access private
-
 
200
   */
-
 
201
  callAction : function(action, scope, data, event)
-
 
202
  {
-
 
203
    switch (Ext.type(action)) {
-
 
204
       case 'array':
-
 
205
       for (var i = 0, len = action.length; i < len; i++) {
-
 
206
         if (Ext.type(action[i]) == 'function') {
-
 
207
           action[i].call(scope, data, event, this);
-
 
208
         }
-
 
209
         else {
-
 
210
           throw [
-
 
211
             'Action: ',
-
 
212
             action[i],
-
 
213
             ' is not callable in "',
-
 
214
             this.current_state,
-
 
215
             '" state for event "',
-
 
216
             event
-
 
217
           ].join('');
-
 
218
         }
-
 
219
       }
-
 
220
         break;
-
 
221
     case 'function':
-
 
222
       action.call(scope, data, event, this);
-
 
223
       break;
-
 
224
     default:
-
 
225
       throw [
-
 
226
         'Action: ',
-
 
227
         action,
-
 
228
         ' is not callable in "',
-
 
229
         this.current_state,
-
 
230
         '" state for event "',
-
 
231
         event
-
 
232
       ].join('');
-
 
233
    }
-
 
234
  }
-
 
235
});
-
 
236
 
-
 
237
// ---------------------------------------------------------------------------------------------- //
-
 
238
 
-
 
239
/**
-
 
240
 * Ext.ux.UploadDialog namespace.
-
 
241
 */
-
 
242
Ext.namespace('Ext.ux.UploadDialog');
-
 
243
 
-
 
244
/**
-
 
245
 * File upload browse button.
-
 
246
 *
-
 
247
 * @class Ext.ux.UploadDialog.BrowseButton
-
 
248
 */ 
-
 
249
Ext.ux.UploadDialog.BrowseButton = Ext.extend(Ext.Button, 
-
 
250
{
-
 
251
  input_name : 'file',
-
 
252
  
-
 
253
  input_file : null,
-
 
254
  
-
 
255
  original_handler : null,
-
 
256
  
-
 
257
  original_scope : null,
-
 
258
  
-
 
259
  /**
-
 
260
   * @access private
-
 
261
   */
-
 
262
  initComponent : function()
-
 
263
  {
-
 
264
    Ext.ux.UploadDialog.BrowseButton.superclass.initComponent.call(this);
-
 
265
    this.original_handler = this.handler || null;
-
 
266
    this.original_scope = this.scope || window;
-
 
267
    this.handler = null;
-
 
268
    this.scope = null;
-
 
269
  },
-
 
270
  
-
 
271
  /**
-
 
272
   * @access private
-
 
273
   */
-
 
274
  onRender : function(ct, position)
-
 
275
  {
-
 
276
    Ext.ux.UploadDialog.BrowseButton.superclass.onRender.call(this, ct, position);
-
 
277
    this.createInputFile();
-
 
278
  },
-
 
279
  
-
 
280
  /**
-
 
281
   * @access private
-
 
282
   */
-
 
283
  createInputFile : function()
-
 
284
  {
-
 
285
    var button_container = this.el.child('.x-btn-center');
-
 
286
    button_container.position('relative');
-
 
287
    this.input_file = Ext.DomHelper.append(
-
 
288
      button_container, 
-
 
289
      {
-
 
290
        tag: 'input',
-
 
291
        type: 'file',
-
 
292
        size: 1,
-
 
293
        name: this.input_name || Ext.id(this.el),
-
 
294
        style: 'position: absolute; display: block; border: none; cursor: pointer'
-
 
295
      },
-
 
296
      true
-
 
297
    );
-
 
298
    
-
 
299
    var button_box = button_container.getBox();
-
 
300
    this.input_file.setStyle('font-size', (button_box.width * 0.5) + 'px');
-
 
301
 
-
 
302
    var input_box = this.input_file.getBox();
-
 
303
    var adj = {x: 3, y: 3}
-
 
304
    if (Ext.isIE) {
-
 
305
      adj = {x: 0, y: 3}
-
 
306
    }
-
 
307
    
-
 
308
    this.input_file.setLeft(button_box.width - input_box.width + adj.x + 'px');
-
 
309
    this.input_file.setTop(button_box.height - input_box.height + adj.y + 'px');
-
 
310
    this.input_file.setOpacity(0.0);
-
 
311
        
-
 
312
    if (this.handleMouseEvents) {
-
 
313
      this.input_file.on('mouseover', this.onMouseOver, this);
-
 
314
        this.input_file.on('mousedown', this.onMouseDown, this);
-
 
315
    }
-
 
316
    
-
 
317
    if(this.tooltip){
-
 
318
      if(typeof this.tooltip == 'object'){
-
 
319
        Ext.QuickTips.register(Ext.apply({target: this.input_file}, this.tooltip));
-
 
320
      } 
-
 
321
      else {
-
 
322
        this.input_file.dom[this.tooltipType] = this.tooltip;
-
 
323
        }
-
 
324
      }
-
 
325
    
-
 
326
    this.input_file.on('change', this.onInputFileChange, this);
-
 
327
    this.input_file.on('click', function(e) { e.stopPropagation(); }); 
-
 
328
  },
-
 
329
  
-
 
330
  /**
-
 
331
   * @access public
-
 
332
   */
-
 
333
  detachInputFile : function(no_create)
-
 
334
  {
-
 
335
    var result = this.input_file;
-
 
336
    
-
 
337
    no_create = no_create || false;
-
 
338
    
-
 
339
    if (typeof this.tooltip == 'object') {
-
 
340
      Ext.QuickTips.unregister(this.input_file);
-
 
341
    }
-
 
342
    else {
-
 
343
      this.input_file.dom[this.tooltipType] = null;
-
 
344
    }
-
 
345
    this.input_file.removeAllListeners();
-
 
346
    this.input_file = null;
-
 
347
    
-
 
348
    if (!no_create) {
-
 
349
      this.createInputFile();
-
 
350
    }
-
 
351
    return result;
-
 
352
  },
-
 
353
  
-
 
354
  /**
-
 
355
   * @access public
-
 
356
   */
-
 
357
  getInputFile : function()
-
 
358
  {
-
 
359
    return this.input_file;
-
 
360
  },
-
 
361
  
-
 
362
  /**
-
 
363
   * @access public
-
 
364
   */
-
 
365
  disable : function()
-
 
366
  {
-
 
367
    Ext.ux.UploadDialog.BrowseButton.superclass.disable.call(this);  
-
 
368
    this.input_file.dom.disabled = true;
-
 
369
  },
-
 
370
  
-
 
371
  /**
-
 
372
   * @access public
-
 
373
   */
-
 
374
  enable : function()
-
 
375
  {
-
 
376
    Ext.ux.UploadDialog.BrowseButton.superclass.enable.call(this);
-
 
377
    this.input_file.dom.disabled = false;
-
 
378
  },
-
 
379
  
-
 
380
  /**
-
 
381
   * @access public
-
 
382
   */
-
 
383
  destroy : function()
-
 
384
  {
-
 
385
    var input_file = this.detachInputFile(true);
-
 
386
    input_file.remove();
-
 
387
    input_file = null;
-
 
388
    Ext.ux.UploadDialog.BrowseButton.superclass.destroy.call(this);      
-
 
389
  },
-
 
390
  
-
 
391
  /**
-
 
392
   * @access private
-
 
393
   */
-
 
394
  onInputFileChange : function()
-
 
395
  {
-
 
396
    if (this.original_handler) {
-
 
397
      this.original_handler.call(this.original_scope, this);
-
 
398
    }
-
 
399
  }  
-
 
400
});
-
 
401
 
-
 
402
/**
-
 
403
 * Toolbar file upload browse button.
-
 
404
 *
-
 
405
 * @class Ext.ux.UploadDialog.TBBrowseButton
-
 
406
 */
-
 
407
Ext.ux.UploadDialog.TBBrowseButton = Ext.extend(Ext.ux.UploadDialog.BrowseButton, 
-
 
408
{
-
 
409
  hideParent : true,
-
 
410
 
-
 
411
  onDestroy : function()
-
 
412
  {
-
 
413
    Ext.ux.UploadDialog.TBBrowseButton.superclass.onDestroy.call(this);
-
 
414
    if(this.container) {
-
 
415
      this.container.remove();
-
 
416
      }
-
 
417
  }
-
 
418
});
-
 
419
 
-
 
420
/**
-
 
421
 * Record type for dialogs grid.
-
 
422
 *
-
 
423
 * @class Ext.ux.UploadDialog.FileRecord 
-
 
424
 */
-
 
425
Ext.ux.UploadDialog.FileRecord = Ext.data.Record.create([
-
 
426
  {name: 'filename'},
-
 
427
  {name: 'state', type: 'int'},
-
 
428
  {name: 'note'},
-
 
429
  {name: 'input_element'}
-
 
430
]);
-
 
431
 
-
 
432
Ext.ux.UploadDialog.FileRecord.STATE_QUEUE = 0;
-
 
433
Ext.ux.UploadDialog.FileRecord.STATE_FINISHED = 1;
-
 
434
Ext.ux.UploadDialog.FileRecord.STATE_FAILED = 2;
-
 
435
Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING = 3;
-
 
436
 
-
 
437
/**
-
 
438
 * Dialog class.
-
 
439
 *
-
 
440
 * @class Ext.ux.UploadDialog.Dialog
-
 
441
 */
-
 
442
Ext.ux.UploadDialog.Dialog = function(config)
-
 
443
{
-
 
444
  var default_config = {
-
 
445
    border: false,
-
 
446
    width: 450,
-
 
447
    height: 300,
-
 
448
    minWidth: 450,
-
 
449
    minHeight: 300,
-
 
450
    plain: true,
-
 
451
    constrainHeader: true,
-
 
452
    draggable: true,
-
 
453
    closable: true,
-
 
454
    maximizable: false,
-
 
455
    minimizable: false,
-
 
456
    resizable: true,
-
 
457
    autoDestroy: true,
-
 
458
    closeAction: 'hide',
-
 
459
    title: this.i18n.title,
-
 
460
    cls: 'ext-ux-uploaddialog-dialog',
-
 
461
    // --------
-
 
462
    url: '',
-
 
463
    base_params: {},
-
 
464
    permitted_extensions: [],
-
 
465
    reset_on_hide: true,
-
 
466
    allow_close_on_upload: false,
-
 
467
    upload_autostart: false,
-
 
468
    post_var_name: 'file'
-
 
469
  }
-
 
470
  config = Ext.applyIf(config || {}, default_config);
-
 
471
  config.layout = 'absolute';
-
 
472
  
-
 
473
  Ext.ux.UploadDialog.Dialog.superclass.constructor.call(this, config);
-
 
474
}
-
 
475
 
-
 
476
Ext.extend(Ext.ux.UploadDialog.Dialog, Ext.Window, {
-
 
477
 
-
 
478
  fsa : null,
-
 
479
  
-
 
480
  state_tpl : null,
-
 
481
  
-
 
482
  form : null,
-
 
483
  
-
 
484
  grid_panel : null,
-
 
485
  
-
 
486
  progress_bar : null,
-
 
487
  
-
 
488
  is_uploading : false,
-
 
489
  
-
 
490
  initial_queued_count : 0,
-
 
491
  
-
 
492
  upload_frame : null,
-
 
493
  
-
 
494
  /**
-
 
495
   * @access private
-
 
496
   */
-
 
497
  //--------------------------------------------------------------------------------------------- //
-
 
498
  initComponent : function()
-
 
499
  {
-
 
500
    Ext.ux.UploadDialog.Dialog.superclass.initComponent.call(this);
-
 
501
    
-
 
502
    // Setting automata protocol
-
 
503
    var tt = {
-
 
504
      // --------------
-
 
505
      'created' : {
-
 
506
      // --------------
-
 
507
        'window-render' : [
-
 
508
          {
-
 
509
            action: [this.createForm, this.createProgressBar, this.createGrid],
-
 
510
            state: 'rendering'
-
 
511
          }
-
 
512
        ],
-
 
513
        'destroy' : [
-
 
514
          {
-
 
515
            action: this.flushEventQueue,
-
 
516
            state: 'destroyed'
-
 
517
          }
-
 
518
        ]
-
 
519
      },
-
 
520
      // --------------
-
 
521
      'rendering' : {
-
 
522
      // --------------
-
 
523
        'grid-render' : [
-
 
524
          {
-
 
525
            action: [this.fillToolbar, this.updateToolbar],
-
 
526
            state: 'ready'
-
 
527
          }
-
 
528
        ],
-
 
529
        'destroy' : [
-
 
530
          {
-
 
531
            action: this.flushEventQueue,
-
 
532
            state: 'destroyed'
-
 
533
          }
-
 
534
        ]
-
 
535
      },
-
 
536
      // --------------
-
 
537
      'ready' : {
-
 
538
      // --------------
-
 
539
        'file-selected' : [
-
 
540
          {
-
 
541
            predicate: [this.fireFileTestEvent, this.isPermittedFile],
-
 
542
            action: this.addFileToUploadQueue,
-
 
543
            state: 'adding-file'
-
 
544
          },
-
 
545
          {
-
 
546
            // If file is not permitted then do nothing.
-
 
547
          }
-
 
548
        ],
-
 
549
        'grid-selection-change' : [
-
 
550
          {
-
 
551
            action: this.updateToolbar
-
 
552
          }
-
 
553
        ],
-
 
554
        'remove-files' : [
-
 
555
          {
-
 
556
            action: [this.removeFiles, this.fireFileRemoveEvent]
-
 
557
          }
-
 
558
        ],
-
 
559
        'reset-queue' : [
-
 
560
          {
-
 
561
            action: [this.resetQueue, this.fireResetQueueEvent]
-
 
562
          }
-
 
563
        ],
-
 
564
        'start-upload' : [
-
 
565
          {
-
 
566
            predicate: this.hasUnuploadedFiles,
-
 
567
            action: [
-
 
568
              this.setUploadingFlag, this.saveInitialQueuedCount, this.updateToolbar, 
-
 
569
              this.updateProgressBar, this.prepareNextUploadTask, this.fireUploadStartEvent
-
 
570
            ],
-
 
571
            state: 'uploading'
-
 
572
          },
-
 
573
          {
-
 
574
            // Has nothing to upload, do nothing.
-
 
575
          }
-
 
576
        ],
-
 
577
        'stop-upload' : [
-
 
578
          {
-
 
579
            // We are not uploading, do nothing. Can be posted by user only at this state. 
-
 
580
          }
-
 
581
        ],
-
 
582
        'hide' : [
-
 
583
          {
-
 
584
            predicate: [this.isNotEmptyQueue, this.getResetOnHide],
-
 
585
            action: [this.resetQueue, this.fireResetQueueEvent]
-
 
586
          },
-
 
587
          {
-
 
588
            // Do nothing
-
 
589
          }
-
 
590
        ],
-
 
591
        'destroy' : [
-
 
592
          {
-
 
593
            action: this.flushEventQueue,
-
 
594
            state: 'destroyed'
-
 
595
          }
-
 
596
        ]
-
 
597
      },
-
 
598
      // --------------
-
 
599
      'adding-file' : {
-
 
600
      // --------------
-
 
601
        'file-added' : [
-
 
602
          {
-
 
603
            predicate: this.isUploading,
-
 
604
            action: [this.incInitialQueuedCount, this.updateProgressBar, this.fireFileAddEvent],
-
 
605
            state: 'uploading' 
-
 
606
          },
-
 
607
          {
-
 
608
            predicate: this.getUploadAutostart,
-
 
609
            action: [this.startUpload, this.fireFileAddEvent],
-
 
610
            state: 'ready'
-
 
611
          },
-
 
612
          {
-
 
613
            action: [this.updateToolbar, this.fireFileAddEvent],
-
 
614
            state: 'ready'
-
 
615
          }
-
 
616
        ]
-
 
617
      },
-
 
618
      // --------------
-
 
619
      'uploading' : {
-
 
620
      // --------------
-
 
621
        'file-selected' : [
-
 
622
          {
-
 
623
            predicate: [this.fireFileTestEvent, this.isPermittedFile],
-
 
624
            action: this.addFileToUploadQueue,
-
 
625
            state: 'adding-file'
-
 
626
          },
-
 
627
          {
-
 
628
            // If file is not permitted then do nothing.
-
 
629
          }
-
 
630
        ],
-
 
631
        'grid-selection-change' : [
-
 
632
          {
-
 
633
            // Do nothing.
-
 
634
          }
-
 
635
        ],
-
 
636
        'start-upload' : [
-
 
637
          {
-
 
638
            // Can be posted only by user in this state. 
-
 
639
          }
-
 
640
        ],
-
 
641
        'stop-upload' : [
-
 
642
          {
-
 
643
            predicate: this.hasUnuploadedFiles,
-
 
644
            action: [
-
 
645
              this.resetUploadingFlag, this.abortUpload, this.updateToolbar, 
-
 
646
              this.updateProgressBar, this.fireUploadStopEvent
-
 
647
            ],
-
 
648
            state: 'ready'
-
 
649
          },
-
 
650
          {
-
 
651
            action: [
-
 
652
              this.resetUploadingFlag, this.abortUpload, this.updateToolbar, 
-
 
653
              this.updateProgressBar, this.fireUploadStopEvent, this.fireUploadCompleteEvent
-
 
654
            ],
-
 
655
            state: 'ready'
-
 
656
          }
-
 
657
        ],
-
 
658
        'file-upload-start' : [
-
 
659
          {
-
 
660
            action: [this.uploadFile, this.findUploadFrame, this.fireFileUploadStartEvent]
-
 
661
          }
-
 
662
        ],
-
 
663
        'file-upload-success' : [
-
 
664
          {
-
 
665
            predicate: this.hasUnuploadedFiles,
-
 
666
            action: [
-
 
667
              this.resetUploadFrame, this.updateRecordState, this.updateProgressBar, 
-
 
668
              this.prepareNextUploadTask, this.fireUploadSuccessEvent
-
 
669
            ]
-
 
670
          },
-
 
671
          {
-
 
672
            action: [
-
 
673
              this.resetUploadFrame, this.resetUploadingFlag, this.updateRecordState, 
-
 
674
              this.updateToolbar, this.updateProgressBar, this.fireUploadSuccessEvent, 
-
 
675
              this.fireUploadCompleteEvent
-
 
676
            ],
-
 
677
            state: 'ready'
-
 
678
          }
-
 
679
        ],
-
 
680
        'file-upload-error' : [
-
 
681
          {
-
 
682
            predicate: this.hasUnuploadedFiles,
-
 
683
            action: [
-
 
684
              this.resetUploadFrame, this.updateRecordState, this.updateProgressBar, 
-
 
685
              this.prepareNextUploadTask, this.fireUploadErrorEvent
-
 
686
            ]
-
 
687
          },
-
 
688
          {
-
 
689
            action: [
-
 
690
              this.resetUploadFrame, this.resetUploadingFlag, this.updateRecordState, 
-
 
691
              this.updateToolbar, this.updateProgressBar, this.fireUploadErrorEvent, 
-
 
692
              this.fireUploadCompleteEvent
-
 
693
            ],
-
 
694
            state: 'ready'
-
 
695
          }
-
 
696
        ],
-
 
697
        'file-upload-failed' : [
-
 
698
          {
-
 
699
            predicate: this.hasUnuploadedFiles,
-
 
700
            action: [
-
 
701
              this.resetUploadFrame, this.updateRecordState, this.updateProgressBar, 
-
 
702
              this.prepareNextUploadTask, this.fireUploadFailedEvent
-
 
703
            ]
-
 
704
          },
-
 
705
          {
-
 
706
            action: [
-
 
707
              this.resetUploadFrame, this.resetUploadingFlag, this.updateRecordState, 
-
 
708
              this.updateToolbar, this.updateProgressBar, this.fireUploadFailedEvent, 
-
 
709
              this.fireUploadCompleteEvent
-
 
710
            ],
-
 
711
            state: 'ready'
-
 
712
          }
-
 
713
        ],
-
 
714
        'hide' : [
-
 
715
          {
-
 
716
            predicate: this.getResetOnHide,
-
 
717
            action: [this.stopUpload, this.repostHide]
-
 
718
          },
-
 
719
          {
-
 
720
            // Do nothing.
-
 
721
          }
-
 
722
        ],
-
 
723
        'destroy' : [
-
 
724
          {
-
 
725
            predicate: this.hasUnuploadedFiles,
-
 
726
            action: [
-
 
727
              this.resetUploadingFlag, this.abortUpload,
-
 
728
              this.fireUploadStopEvent, this.flushEventQueue
-
 
729
            ],
-
 
730
            state: 'destroyed'
-
 
731
          },
-
 
732
          {
-
 
733
            action: [
-
 
734
              this.resetUploadingFlag, this.abortUpload,
-
 
735
              this.fireUploadStopEvent, this.fireUploadCompleteEvent, this.flushEventQueue
-
 
736
            ], 
-
 
737
            state: 'destroyed'
-
 
738
          }
-
 
739
        ]
-
 
740
      },
-
 
741
      // --------------
-
 
742
      'destroyed' : {
-
 
743
      // --------------
-
 
744
      }
-
 
745
    }
-
 
746
    this.fsa = new Ext.ux.Utils.FSA('created', tt, this);
-
 
747
    
-
 
748
    // Registering dialog events.
-
 
749
    this.addEvents({
-
 
750
      'filetest': true,
-
 
751
      'fileadd' : true,
-
 
752
      'fileremove' : true,
-
 
753
      'resetqueue' : true,
-
 
754
      'uploadsuccess' : true,
-
 
755
      'uploaderror' : true,
-
 
756
      'uploadfailed' : true,
-
 
757
      'uploadstart' : true,
-
 
758
      'uploadstop' : true,
-
 
759
      'uploadcomplete' : true,
-
 
760
      'fileuploadstart' : true
-
 
761
    });
-
 
762
    
-
 
763
    // Attaching to window events.
-
 
764
    this.on('render', this.onWindowRender, this);
-
 
765
    this.on('beforehide', this.onWindowBeforeHide, this);
-
 
766
    this.on('hide', this.onWindowHide, this);
-
 
767
    this.on('destroy', this.onWindowDestroy, this);
-
 
768
    
-
 
769
    // Compiling state template.
-
 
770
    this.state_tpl = new Ext.Template(
-
 
771
      "<div class='ext-ux-uploaddialog-state ext-ux-uploaddialog-state-{state}'>&#160;</div>"
-
 
772
    ).compile();
-
 
773
  },
-
 
774
  
-
 
775
  createForm : function()
-
 
776
  {
-
 
777
    this.form = Ext.DomHelper.append(this.body, {
-
 
778
      tag: 'form',
-
 
779
      method: 'post',
-
 
780
      action: this.url,
-
 
781
      style: 'position: absolute; left: -100px; top: -100px; width: 100px; height: 100px'
-
 
782
    });
-
 
783
  },
-
 
784
  
-
 
785
  createProgressBar : function()
-
 
786
  {
-
 
787
    this.progress_bar = this.add(
-
 
788
      new Ext.ProgressBar({
-
 
789
        x: 0,
-
 
790
        y: 0,
-
 
791
        anchor: '0',
-
 
792
        value: 0.0,
-
 
793
        text: this.i18n.progress_waiting_text
-
 
794
      })
-
 
795
    );
-
 
796
  },
-
 
797
  
-
 
798
  createGrid : function()
-
 
799
  {
-
 
800
    var store = new Ext.data.Store({
-
 
801
      proxy: new Ext.data.MemoryProxy([]),
-
 
802
      reader: new Ext.data.JsonReader({}, Ext.ux.UploadDialog.FileRecord),
-
 
803
      sortInfo: {field: 'state', direction: 'DESC'},
-
 
804
      pruneModifiedRecords: true
-
 
805
    });
-
 
806
    
-
 
807
    var cm = new Ext.grid.ColumnModel([
-
 
808
      {
-
 
809
        header: this.i18n.state_col_title,
-
 
810
        width: this.i18n.state_col_width,
-
 
811
        resizable: false,
-
 
812
        dataIndex: 'state',
-
 
813
        sortable: true,
-
 
814
        renderer: this.renderStateCell.createDelegate(this)
-
 
815
      },
-
 
816
      {
-
 
817
        header: this.i18n.filename_col_title,
-
 
818
        width: this.i18n.filename_col_width,
-
 
819
        dataIndex: 'filename',
-
 
820
        sortable: true,
-
 
821
        renderer: this.renderFilenameCell.createDelegate(this)
-
 
822
      },
-
 
823
      {
-
 
824
        header: this.i18n.note_col_title,
-
 
825
        width: this.i18n.note_col_width, 
-
 
826
        dataIndex: 'note',
-
 
827
        sortable: true,
-
 
828
        renderer: this.renderNoteCell.createDelegate(this)
-
 
829
      }
-
 
830
    ]);
-
 
831
  
-
 
832
      this.grid_panel = new Ext.grid.GridPanel({
-
 
833
      ds: store,
-
 
834
      cm: cm,
-
 
835
    
-
 
836
      x: 0,
-
 
837
      y: 22,
-
 
838
      anchor: '0 -22',
-
 
839
      border: true,
-
 
840
      
-
 
841
        viewConfig: {
-
 
842
        autoFill: true,
-
 
843
          forceFit: true
-
 
844
        },
-
 
845
      
-
 
846
      bbar : new Ext.Toolbar()
-
 
847
    });
-
 
848
    this.grid_panel.on('render', this.onGridRender, this);
-
 
849
    
-
 
850
    this.add(this.grid_panel);
-
 
851
    
-
 
852
    this.grid_panel.getSelectionModel().on('selectionchange', this.onGridSelectionChange, this);
-
 
853
  },
-
 
854
  
-
 
855
  fillToolbar : function()
-
 
856
  {
-
 
857
    var tb = this.grid_panel.getBottomToolbar();
-
 
858
    tb.x_buttons = {}
-
 
859
    
-
 
860
    tb.x_buttons.add = tb.addItem(new Ext.ux.UploadDialog.TBBrowseButton({
-
 
861
      input_name: this.post_var_name,
-
 
862
      text: this.i18n.add_btn_text,
-
 
863
      tooltip: this.i18n.add_btn_tip,
-
 
864
      iconCls: 'ext-ux-uploaddialog-addbtn',
-
 
865
      handler: this.onAddButtonFileSelected,
-
 
866
      scope: this
-
 
867
    }));
-
 
868
    
-
 
869
    tb.x_buttons.remove = tb.addButton({
-
 
870
      text: this.i18n.remove_btn_text,
-
 
871
      tooltip: this.i18n.remove_btn_tip,
-
 
872
      iconCls: 'ext-ux-uploaddialog-removebtn',
-
 
873
      handler: this.onRemoveButtonClick,
-
 
874
      scope: this
-
 
875
    });
-
 
876
    
-
 
877
    tb.x_buttons.reset = tb.addButton({
-
 
878
      text: this.i18n.reset_btn_text,
-
 
879
      tooltip: this.i18n.reset_btn_tip,
-
 
880
      iconCls: 'ext-ux-uploaddialog-resetbtn',
-
 
881
      handler: this.onResetButtonClick,
-
 
882
      scope: this
-
 
883
    });
-
 
884
    
-
 
885
    tb.add('-');
-
 
886
    
-
 
887
    tb.x_buttons.upload = tb.addButton({
-
 
888
      text: this.i18n.upload_btn_start_text,
-
 
889
      tooltip: this.i18n.upload_btn_start_tip,
-
 
890
      iconCls: 'ext-ux-uploaddialog-uploadstartbtn',
-
 
891
      handler: this.onUploadButtonClick,
-
 
892
      scope: this
-
 
893
    });
-
 
894
    
-
 
895
    tb.add('-');
-
 
896
    
-
 
897
    tb.x_buttons.indicator = tb.addItem(
-
 
898
      new Ext.Toolbar.Item(
-
 
899
        Ext.DomHelper.append(tb.getEl(), {
-
 
900
          tag: 'div',
-
 
901
          cls: 'ext-ux-uploaddialog-indicator-stoped',
-
 
902
          html: '&#160'
-
 
903
        })
-
 
904
      )
-
 
905
    );
-
 
906
    
-
 
907
    tb.add('->');
-
 
908
    
-
 
909
    tb.x_buttons.close = tb.addButton({
-
 
910
      text: this.i18n.close_btn_text,
-
 
911
      tooltip: this.i18n.close_btn_tip,
-
 
912
      handler: this.onCloseButtonClick,
-
 
913
      scope: this
-
 
914
    });
-
 
915
  },
-
 
916
  
-
 
917
  renderStateCell : function(data, cell, record, row_index, column_index, store)
-
 
918
  {
-
 
919
    return this.state_tpl.apply({state: data});
-
 
920
  },
-
 
921
  
-
 
922
  renderFilenameCell : function(data, cell, record, row_index, column_index, store)
-
 
923
  {
-
 
924
    var view = this.grid_panel.getView();
-
 
925
    var f = function() {
-
 
926
      try {
-
 
927
        Ext.fly(
-
 
928
          view.getCell(row_index, column_index)
-
 
929
        ).child('.x-grid3-cell-inner').dom['qtip'] = data;
-
 
930
      }
-
 
931
      catch (e)
-
 
932
      {}
-
 
933
    }
-
 
934
    f.defer(1000);
-
 
935
    return data;
-
 
936
  },
-
 
937
  
-
 
938
  renderNoteCell : function(data, cell, record, row_index, column_index, store)
-
 
939
  {
-
 
940
    var view = this.grid_panel.getView();
-
 
941
    var f = function() {
-
 
942
      try {
-
 
943
        Ext.fly(
-
 
944
          view.getCell(row_index, column_index)
-
 
945
        ).child('.x-grid3-cell-inner').dom['qtip'] = data;
-
 
946
      }
-
 
947
      catch (e)
-
 
948
      {}
-
 
949
      }
-
 
950
    f.defer(1000);
-
 
951
    return data;
-
 
952
  },
-
 
953
  
-
 
954
  getFileExtension : function(filename)
-
 
955
  {
-
 
956
    var result = null;
-
 
957
    var parts = filename.split('.');
-
 
958
    if (parts.length > 1) {
-
 
959
      result = parts.pop();
-
 
960
    }
-
 
961
    return result;
-
 
962
  },
-
 
963
  
-
 
964
  isPermittedFileType : function(filename)
-
 
965
  {
-
 
966
    var result = true;
-
 
967
    if (this.permitted_extensions.length > 0) {
-
 
968
      result = this.permitted_extensions.indexOf(this.getFileExtension(filename)) != -1;
-
 
969
    }
-
 
970
    return result;
-
 
971
  },
-
 
972
 
-
 
973
  isPermittedFile : function(browse_btn)
-
 
974
  {
-
 
975
    var result = false;
-
 
976
    var filename = browse_btn.getInputFile().dom.value;
-
 
977
    
-
 
978
    if (this.isPermittedFileType(filename)) {
-
 
979
      result = true;
-
 
980
    }
-
 
981
    else {
-
 
982
      Ext.Msg.alert(
-
 
983
        this.i18n.error_msgbox_title, 
-
 
984
        String.format(
-
 
985
          this.i18n.err_file_type_not_permitted,
-
 
986
          filename,
-
 
987
          this.permitted_extensions.join(this.i18n.permitted_extensions_join_str)
-
 
988
        )
-
 
989
      );
-
 
990
      result = false;
-
 
991
    }
-
 
992
    
-
 
993
    return result;
-
 
994
  },
-
 
995
  
-
 
996
  fireFileTestEvent : function(browse_btn)
-
 
997
  {
-
 
998
    return this.fireEvent('filetest', this, browse_btn.getInputFile().dom.value) !== false;
-
 
999
  },
-
 
1000
  
-
 
1001
  addFileToUploadQueue : function(browse_btn)
-
 
1002
  {
-
 
1003
    var input_file = browse_btn.detachInputFile();
-
 
1004
    
-
 
1005
    input_file.appendTo(this.form);
-
 
1006
    input_file.setStyle('width', '100px');
-
 
1007
    input_file.dom.disabled = true;
-
 
1008
    
-
 
1009
    var store = this.grid_panel.getStore();
-
 
1010
    store.add(
-
 
1011
      new Ext.ux.UploadDialog.FileRecord({
-
 
1012
          state: Ext.ux.UploadDialog.FileRecord.STATE_QUEUE,
-
 
1013
          filename: input_file.dom.value,
-
 
1014
          note: this.i18n.note_queued_to_upload,
-
 
1015
          input_element: input_file
-
 
1016
        })
-
 
1017
      );
-
 
1018
    this.fsa.postEvent('file-added', input_file.dom.value);
-
 
1019
  },
-
 
1020
  
-
 
1021
  fireFileAddEvent : function(filename)
-
 
1022
  {
-
 
1023
    this.fireEvent('fileadd', this, filename);
-
 
1024
  },
-
 
1025
  
-
 
1026
  updateProgressBar : function()
-
 
1027
  {
-
 
1028
    if (this.is_uploading) {
-
 
1029
      var queued = this.getQueuedCount(true);
-
 
1030
      var value = 1 - queued / this.initial_queued_count;
-
 
1031
      this.progress_bar.updateProgress(
-
 
1032
        value,
-
 
1033
        String.format(
-
 
1034
          this.i18n.progress_uploading_text, 
-
 
1035
          this.initial_queued_count - queued,
-
 
1036
          this.initial_queued_count
-
 
1037
        )
-
 
1038
      );
-
 
1039
    }
-
 
1040
    else {
-
 
1041
      this.progress_bar.updateProgress(0, this.i18n.progress_waiting_text);
-
 
1042
    }
-
 
1043
  },
-
 
1044
  
-
 
1045
  updateToolbar : function()
-
 
1046
  {
-
 
1047
    var tb = this.grid_panel.getBottomToolbar();
-
 
1048
    if (this.is_uploading) {
-
 
1049
      tb.x_buttons.remove.disable();
-
 
1050
      tb.x_buttons.reset.disable();
-
 
1051
      tb.x_buttons.upload.enable();
-
 
1052
      if (!this.getAllowCloseOnUpload()) {
-
 
1053
        tb.x_buttons.close.disable();
-
 
1054
      }
-
 
1055
      Ext.fly(tb.x_buttons.indicator.getEl()).replaceClass(
-
 
1056
        'ext-ux-uploaddialog-indicator-stoped',
-
 
1057
        'ext-ux-uploaddialog-indicator-processing'
-
 
1058
      );
-
 
1059
      tb.x_buttons.upload.setIconClass('ext-ux-uploaddialog-uploadstopbtn');
-
 
1060
      tb.x_buttons.upload.setText(this.i18n.upload_btn_stop_text);
-
 
1061
      tb.x_buttons.upload.getEl()
-
 
1062
        .child(tb.x_buttons.upload.buttonSelector)
-
 
1063
        .dom[tb.x_buttons.upload.tooltipType] = this.i18n.upload_btn_stop_tip;
-
 
1064
    }
-
 
1065
    else {
-
 
1066
      tb.x_buttons.remove.enable();
-
 
1067
      tb.x_buttons.reset.enable();
-
 
1068
      tb.x_buttons.close.enable();
-
 
1069
      Ext.fly(tb.x_buttons.indicator.getEl()).replaceClass(
-
 
1070
        'ext-ux-uploaddialog-indicator-processing',
-
 
1071
        'ext-ux-uploaddialog-indicator-stoped'
-
 
1072
      );
-
 
1073
      tb.x_buttons.upload.setIconClass('ext-ux-uploaddialog-uploadstartbtn');
-
 
1074
      tb.x_buttons.upload.setText(this.i18n.upload_btn_start_text);
-
 
1075
      tb.x_buttons.upload.getEl()
-
 
1076
        .child(tb.x_buttons.upload.buttonSelector)
-
 
1077
        .dom[tb.x_buttons.upload.tooltipType] = this.i18n.upload_btn_start_tip;
-
 
1078
      
-
 
1079
      if (this.getQueuedCount() > 0) {
-
 
1080
        tb.x_buttons.upload.enable();
-
 
1081
      }
-
 
1082
      else {
-
 
1083
        tb.x_buttons.upload.disable();      
-
 
1084
      }
-
 
1085
      
-
 
1086
      if (this.grid_panel.getSelectionModel().hasSelection()) {
-
 
1087
        tb.x_buttons.remove.enable();
-
 
1088
      }
-
 
1089
      else {
-
 
1090
        tb.x_buttons.remove.disable();
-
 
1091
      }
-
 
1092
      
-
 
1093
      if (this.grid_panel.getStore().getCount() > 0) {
-
 
1094
        tb.x_buttons.reset.enable();
-
 
1095
      }
-
 
1096
      else {
-
 
1097
        tb.x_buttons.reset.disable();
-
 
1098
      }
-
 
1099
    }
-
 
1100
  },
-
 
1101
  
-
 
1102
  saveInitialQueuedCount : function()
-
 
1103
  {
-
 
1104
    this.initial_queued_count = this.getQueuedCount();
-
 
1105
  },
-
 
1106
  
-
 
1107
  incInitialQueuedCount : function()
-
 
1108
  {
-
 
1109
    this.initial_queued_count++;
-
 
1110
  },
-
 
1111
  
-
 
1112
  setUploadingFlag : function()
-
 
1113
  {
-
 
1114
    this.is_uploading = true;
-
 
1115
  }, 
-
 
1116
  
-
 
1117
  resetUploadingFlag : function()
-
 
1118
  {
-
 
1119
    this.is_uploading = false;
-
 
1120
  },
-
 
1121
 
-
 
1122
  prepareNextUploadTask : function()
-
 
1123
  {
-
 
1124
    // Searching for first unuploaded file.
-
 
1125
    var store = this.grid_panel.getStore();
-
 
1126
    var record = null;
-
 
1127
    
-
 
1128
    store.each(function(r) {
-
 
1129
      if (!record && r.get('state') == Ext.ux.UploadDialog.FileRecord.STATE_QUEUE) {
-
 
1130
        record = r;
-
 
1131
      }
-
 
1132
      else {
-
 
1133
        r.get('input_element').dom.disabled = true;
-
 
1134
      }
-
 
1135
    });
-
 
1136
    
-
 
1137
    record.get('input_element').dom.disabled = false;
-
 
1138
    record.set('state', Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING);
-
 
1139
    record.set('note', this.i18n.note_processing);
-
 
1140
    record.commit();
-
 
1141
    
-
 
1142
    this.fsa.postEvent('file-upload-start', record);
-
 
1143
  },
-
 
1144
   
-
 
1145
  fireUploadStartEvent : function()
-
 
1146
  {
-
 
1147
    this.fireEvent('uploadstart', this);
-
 
1148
  },
-
 
1149
  
-
 
1150
  removeFiles : function(file_records)
-
 
1151
  {
-
 
1152
    var store = this.grid_panel.getStore();
-
 
1153
    for (var i = 0, len = file_records.length; i < len; i++) {
-
 
1154
      var r = file_records[i];
-
 
1155
      r.get('input_element').remove();
-
 
1156
      store.remove(r);
-
 
1157
    }
-
 
1158
  },
-
 
1159
  
-
 
1160
  fireFileRemoveEvent : function(file_records)
-
 
1161
  {
-
 
1162
    for (var i = 0, len = file_records.length; i < len; i++) {
-
 
1163
      this.fireEvent('fileremove', this, file_records[i].get('filename'));
-
 
1164
    }
-
 
1165
  },
-
 
1166
  
-
 
1167
  resetQueue : function()
-
 
1168
  {
-
 
1169
    var store = this.grid_panel.getStore();
-
 
1170
    store.each(
-
 
1171
      function(r) {
-
 
1172
        r.get('input_element').remove();
-
 
1173
      }
-
 
1174
    );
-
 
1175
    store.removeAll();
-
 
1176
  },
-
 
1177
  
-
 
1178
  fireResetQueueEvent : function()
-
 
1179
  {
-
 
1180
    this.fireEvent('resetqueue', this);
-
 
1181
  },
-
 
1182
  
-
 
1183
  uploadFile : function(record)
-
 
1184
  {
-
 
1185
    Ext.Ajax.request({
-
 
1186
      url : this.url,
-
 
1187
      params : this.base_params || this.baseParams || this.params,
-
 
1188
      method : 'POST',
-
 
1189
      form : this.form,
-
 
1190
      isUpload : true,
-
 
1191
      success : this.onAjaxSuccess,
-
 
1192
      failure : this.onAjaxFailure,
-
 
1193
      scope : this,
-
 
1194
      record: record
-
 
1195
    });
-
 
1196
  },
-
 
1197
   
-
 
1198
  fireFileUploadStartEvent : function(record)
-
 
1199
  {
-
 
1200
    this.fireEvent('fileuploadstart', this, record.get('filename'));
-
 
1201
  },
-
 
1202
  
-
 
1203
  updateRecordState : function(data)
-
 
1204
  {
-
 
1205
    if ('success' in data.response && data.response.success) {
-
 
1206
      data.record.set('state', Ext.ux.UploadDialog.FileRecord.STATE_FINISHED);
-
 
1207
      data.record.set(
-
 
1208
        'note', data.response.message || data.response.error || this.i18n.note_upload_success
-
 
1209
      );
-
 
1210
    }
-
 
1211
    else {
-
 
1212
      data.record.set('state', Ext.ux.UploadDialog.FileRecord.STATE_FAILED);
-
 
1213
      data.record.set(
-
 
1214
        'note', data.response.message || data.response.error || this.i18n.note_upload_error
-
 
1215
      );
-
 
1216
    }
-
 
1217
    
-
 
1218
    data.record.commit();
-
 
1219
  },
-
 
1220
  
-
 
1221
  fireUploadSuccessEvent : function(data)
-
 
1222
  {
-
 
1223
    this.fireEvent('uploadsuccess', this, data.record.get('filename'), data.response);
-
 
1224
  },
-
 
1225
  
-
 
1226
  fireUploadErrorEvent : function(data)
-
 
1227
  {
-
 
1228
    this.fireEvent('uploaderror', this, data.record.get('filename'), data.response);
-
 
1229
  },
-
 
1230
  
-
 
1231
  fireUploadFailedEvent : function(data)
-
 
1232
  {
-
 
1233
    this.fireEvent('uploadfailed', this, data.record.get('filename'));
-
 
1234
  },
-
 
1235
  
-
 
1236
  fireUploadCompleteEvent : function()
-
 
1237
  {
-
 
1238
    this.fireEvent('uploadcomplete', this);
-
 
1239
  },
-
 
1240
  
-
 
1241
  findUploadFrame : function() 
-
 
1242
  {
-
 
1243
    this.upload_frame = Ext.getBody().child('iframe.x-hidden:last');
-
 
1244
  },
-
 
1245
  
-
 
1246
  resetUploadFrame : function()
-
 
1247
  {
-
 
1248
    this.upload_frame = null;
-
 
1249
  },
-
 
1250
  
-
 
1251
  removeUploadFrame : function()
-
 
1252
  {
-
 
1253
    if (this.upload_frame) {
-
 
1254
      this.upload_frame.removeAllListeners();
-
 
1255
      this.upload_frame.dom.src = 'about:blank';
-
 
1256
      this.upload_frame.remove();
-
 
1257
    }
-
 
1258
    this.upload_frame = null;
-
 
1259
  },
-
 
1260
  
-
 
1261
  abortUpload : function()
-
 
1262
  {
-
 
1263
    this.removeUploadFrame();
-
 
1264
    
-
 
1265
    var store = this.grid_panel.getStore();
-
 
1266
    var record = null;
-
 
1267
    store.each(function(r) {
-
 
1268
      if (r.get('state') == Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING) {
-
 
1269
        record = r;
-
 
1270
        return false;
-
 
1271
      }
-
 
1272
    });
-
 
1273
    
-
 
1274
    record.set('state', Ext.ux.UploadDialog.FileRecord.STATE_FAILED);
-
 
1275
    record.set('note', this.i18n.note_aborted);
-
 
1276
    record.commit();
-
 
1277
  },
-
 
1278
  
-
 
1279
  fireUploadStopEvent : function()
-
 
1280
  {
-
 
1281
    this.fireEvent('uploadstop', this);
-
 
1282
  },
-
 
1283
  
-
 
1284
  repostHide : function()
-
 
1285
  {
-
 
1286
    this.fsa.postEvent('hide');
-
 
1287
  },
-
 
1288
  
-
 
1289
  flushEventQueue : function()
-
 
1290
  {
-
 
1291
    this.fsa.flushEventQueue();
-
 
1292
  },
-
 
1293
  
-
 
1294
  /**
-
 
1295
   * @access private
-
 
1296
   */
-
 
1297
  // -------------------------------------------------------------------------------------------- //
-
 
1298
  onWindowRender : function()
-
 
1299
  {
-
 
1300
    this.fsa.postEvent('window-render');
-
 
1301
  },
-
 
1302
  
-
 
1303
  onWindowBeforeHide : function()
-
 
1304
  {
-
 
1305
    return this.isUploading() ? this.getAllowCloseOnUpload() : true;
-
 
1306
  },
-
 
1307
  
-
 
1308
  onWindowHide : function()
-
 
1309
  {
-
 
1310
    this.fsa.postEvent('hide');
-
 
1311
  },
-
 
1312
  
-
 
1313
  onWindowDestroy : function()
-
 
1314
  {
-
 
1315
    this.fsa.postEvent('destroy');
-
 
1316
  },
-
 
1317
  
-
 
1318
  onGridRender : function()
-
 
1319
  {
-
 
1320
    this.fsa.postEvent('grid-render');
-
 
1321
  },
-
 
1322
  
-
 
1323
  onGridSelectionChange : function()
-
 
1324
  {
-
 
1325
    this.fsa.postEvent('grid-selection-change');
-
 
1326
  },
-
 
1327
  
-
 
1328
  onAddButtonFileSelected : function(btn)
-
 
1329
  {
-
 
1330
    this.fsa.postEvent('file-selected', btn);
-
 
1331
  },
-
 
1332
  
-
 
1333
  onUploadButtonClick : function()
-
 
1334
  {
-
 
1335
    if (this.is_uploading) {
-
 
1336
      this.fsa.postEvent('stop-upload');
-
 
1337
    }
-
 
1338
    else {
-
 
1339
      this.fsa.postEvent('start-upload');
-
 
1340
    }
-
 
1341
  },
-
 
1342
  
-
 
1343
  onRemoveButtonClick : function()
-
 
1344
  {
-
 
1345
    var selections = this.grid_panel.getSelectionModel().getSelections();
-
 
1346
    this.fsa.postEvent('remove-files', selections);
-
 
1347
  },
-
 
1348
  
-
 
1349
  onResetButtonClick : function()
-
 
1350
  {
-
 
1351
    this.fsa.postEvent('reset-queue');
-
 
1352
  },
-
 
1353
  
-
 
1354
  onCloseButtonClick : function()
-
 
1355
  {
-
 
1356
    this[this.closeAction].call(this);
-
 
1357
  },
-
 
1358
  
-
 
1359
  onAjaxSuccess : function(response, options)
-
 
1360
  {
-
 
1361
    var json_response = {
-
 
1362
      'success' : false,
-
 
1363
      'message' : this.response
-
 
1364
    }
-
 
1365
    
-
 
1366
    if(response.responseText == "OK" )
-
 
1367
    {
-
 
1368
    	var data = {
-
 
1369
		      record : options.record,
-
 
1370
		      response : {
-
 
1371
	          'success' : true,
-
 
1372
		      'message' : this.response
-
 
1373
    		}
-
 
1374
		}
-
 
1375
      this.fsa.postEvent('file-upload-success', data);
-
 
1376
    }
-
 
1377
    else {
-
 
1378
      this.fsa.postEvent('file-upload-error', data);
-
 
1379
    }
-
 
1380
  },
-
 
1381
  
-
 
1382
  onAjaxFailure : function(response, options)
-
 
1383
  {
-
 
1384
    var data = {
-
 
1385
      record : options.record,
-
 
1386
      response : {
-
 
1387
        'success' : false,
-
 
1388
       	'error' : this.i18n.note_upload_error
-
 
1389
      }
-
 
1390
    }
-
 
1391
 
-
 
1392
    this.fsa.postEvent('file-upload-failed', data);
-
 
1393
  },
-
 
1394
  
-
 
1395
  /**
-
 
1396
   * @access public
-
 
1397
   */
-
 
1398
  // -------------------------------------------------------------------------------------------- //
-
 
1399
  startUpload : function()
-
 
1400
  {
-
 
1401
    this.fsa.postEvent('start-upload');
-
 
1402
  },
-
 
1403
  
-
 
1404
  stopUpload : function()
-
 
1405
  {
-
 
1406
    this.fsa.postEvent('stop-upload');
-
 
1407
  },
-
 
1408
  
-
 
1409
  getUrl : function()
-
 
1410
  {
-
 
1411
    return this.url;
-
 
1412
  },
-
 
1413
  
-
 
1414
  setUrl : function(url)
-
 
1415
  {
-
 
1416
    this.url = url;
-
 
1417
  },
-
 
1418
  
-
 
1419
  getBaseParams : function()
-
 
1420
  {
-
 
1421
    return this.base_params;
-
 
1422
  },
-
 
1423
  
-
 
1424
  setBaseParams : function(params)
-
 
1425
  {
-
 
1426
    this.base_params = params;
-
 
1427
  },
-
 
1428
  
-
 
1429
  getUploadAutostart : function()
-
 
1430
  {
-
 
1431
    return this.upload_autostart;
-
 
1432
  },
-
 
1433
  
-
 
1434
  setUploadAutostart : function(value)
-
 
1435
  {
-
 
1436
    this.upload_autostart = value;
-
 
1437
  },
-
 
1438
  
-
 
1439
  getAllowCloseOnUpload : function()
-
 
1440
  {
-
 
1441
    return this.allow_close_on_upload;
-
 
1442
  },
-
 
1443
  
-
 
1444
  setAllowCloseOnUpload : function(value)
-
 
1445
  {
-
 
1446
    this.allow_close_on_upload;
-
 
1447
  },
-
 
1448
  
-
 
1449
  getResetOnHide : function()
-
 
1450
  {
-
 
1451
    return this.reset_on_hide;
-
 
1452
  },
-
 
1453
  
-
 
1454
  setResetOnHide : function(value)
-
 
1455
  {
-
 
1456
    this.reset_on_hide = value;
-
 
1457
  },
-
 
1458
  
-
 
1459
  getPermittedExtensions : function()
-
 
1460
  {
-
 
1461
    return this.permitted_extensions;
-
 
1462
  },
-
 
1463
  
-
 
1464
  setPermittedExtensions : function(value)
-
 
1465
  {
-
 
1466
    this.permitted_extensions = value;
-
 
1467
  },
-
 
1468
  
-
 
1469
  isUploading : function()
-
 
1470
  {
-
 
1471
    return this.is_uploading;
-
 
1472
  },
-
 
1473
  
-
 
1474
  isNotEmptyQueue : function()
-
 
1475
  {
-
 
1476
    return this.grid_panel.getStore().getCount() > 0;
-
 
1477
  },
-
 
1478
  
-
 
1479
  getQueuedCount : function(count_processing)
-
 
1480
  {
-
 
1481
    var count = 0;
-
 
1482
    var store = this.grid_panel.getStore();
-
 
1483
    store.each(function(r) {
-
 
1484
      if (r.get('state') == Ext.ux.UploadDialog.FileRecord.STATE_QUEUE) {
-
 
1485
        count++;
-
 
1486
      }
-
 
1487
      if (count_processing && r.get('state') == Ext.ux.UploadDialog.FileRecord.STATE_PROCESSING) {
-
 
1488
        count++;
-
 
1489
      }
-
 
1490
    });
-
 
1491
    return count;
-
 
1492
  },
-
 
1493
  
-
 
1494
  hasUnuploadedFiles : function()
-
 
1495
  {
-
 
1496
    return this.getQueuedCount() > 0;
-
 
1497
  }
-
 
1498
});
-
 
1499
 
-
 
1500
// ---------------------------------------------------------------------------------------------- //
-
 
1501
 
-
 
1502
var p = Ext.ux.UploadDialog.Dialog.prototype;
-
 
1503
p.i18n = {
-
 
1504
  title: 'Ajout simple de fichiers',
-
 
1505
  state_col_title: 'Etat',
-
 
1506
  state_col_width: 70,
-
 
1507
  filename_col_title: 'Fichier',
-
 
1508
  filename_col_width: 230,  
-
 
1509
  note_col_title: 'Note',
-
 
1510
  note_col_width: 150,
-
 
1511
  add_btn_text: 'Ajouter',
-
 
1512
  add_btn_tip: 'Ajoute un fichier à la liste.',
-
 
1513
  remove_btn_text: 'Supprimer',
-
 
1514
  remove_btn_tip: 'Supprime un fichier de la liste.',
-
 
1515
  reset_btn_text: 'Vider',
-
 
1516
  reset_btn_tip: 'Vider la liste.',
-
 
1517
  upload_btn_start_text: 'Envoyer',
-
 
1518
  upload_btn_stop_text: 'Annuler',
-
 
1519
  upload_btn_start_tip: 'Envoie les fichiers de la liste sur le serveur.',
-
 
1520
  upload_btn_stop_tip: 'Stopper l\'envoi.',
-
 
1521
  close_btn_text: 'Fermer',
-
 
1522
  close_btn_tip: 'Ferme la fenêtre.',
-
 
1523
  progress_waiting_text: 'En attente...',
-
 
1524
  progress_uploading_text: 'Envoi de: {0} sur {1} fichiers terminé.',
-
 
1525
  error_msgbox_title: 'Erreur',
-
 
1526
  permitted_extensions_join_str: ',',
-
 
1527
  err_file_type_not_permitted: 'Cette extension de fichier n\'est pas permise.<br/>Selectionnez un fichier portant une des extensions suivantes: {1}',
-
 
1528
  note_queued_to_upload: 'Prêt à être envoyé.',
-
 
1529
  note_processing: 'Envoi...',
-
 
1530
  note_upload_failed: 'Le serveur est inaccessible ou bien une erreur serveur s\'est produite.',
-
 
1531
  note_upload_success: 'OK.',
-
 
1532
  note_upload_error: 'Erreur d\'envoi.',
-
 
1533
  note_aborted: 'Annulé par l\'utilisateur.'
-
 
1534
}
-
 
1535
3
1536