function FABridge(target,bridgeName) {this.target=target;this.remoteTypeCache={};this.remoteInstanceCache={};this.remoteFunctionCache={};this.localFunctionCache={};this.bridgeID=FABridge.nextBridgeID++;this.name=bridgeName;this.nextLocalFuncID=0;FABridge.instances[this.name]=this;FABridge.idMap[this.bridgeID]=this;return this;} FABridge.TYPE_ASINSTANCE=1;FABridge.TYPE_ASFUNCTION=2;FABridge.TYPE_JSFUNCTION=3;FABridge.TYPE_ANONYMOUS=4;FABridge.initCallbacks={};FABridge.userTypes={};FABridge.addToUserTypes=function() {for(var i=0;i0){for(var i=0;i0){for(var j=0;j1){for(var k=0;k=0){FABridge.attachBridge(activeObjects[k],bridgeName);flash_found=true;break;}} if(flash_found){break;}}} if(!flash_found&&ael>1){for(var m=0;m=0){FABridge.attachBridge(activeEmbeds[m],bridgeName);break;}}}} return true;} FABridge.nextBridgeID=0;FABridge.instances={};FABridge.idMap={};FABridge.refCount=0;FABridge.extractBridgeFromID=function(id) {var bridgeID=(id>>16);return FABridge.idMap[bridgeID];} FABridge.attachBridge=function(instance,bridgeName) {if(typeof FABridge[bridgeName]=='undefined'){FABridge[bridgeName]=new FABridge(instance,bridgeName);} var callbacks=FABridge.initCallbacks[bridgeName];if(callbacks==null) {return;} for(var i=0;i0) {throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");} else {FABridge.refCount++;retVal=this.target.getPropFromAS(objRef,propName);retVal=this.handleError(retVal);FABridge.refCount--;return retVal;}},setPropertyInAS:function(objRef,propName,value) {if(FABridge.refCount>0) {throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");} else {FABridge.refCount++;retVal=this.target.setPropInAS(objRef,propName,this.serialize(value));retVal=this.handleError(retVal);FABridge.refCount--;return retVal;}},callASFunction:function(funcID,args) {if(FABridge.refCount>0) {throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");} else {FABridge.refCount++;retVal=this.target.invokeASFunction(funcID,this.serialize(args));retVal=this.handleError(retVal);FABridge.refCount--;return retVal;}},callASMethod:function(objID,funcName,args) {if(FABridge.refCount>0) {throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");} else {FABridge.refCount++;args=this.serialize(args);retVal=this.target.invokeASMethod(objID,funcName,args);retVal=this.handleError(retVal);FABridge.refCount--;return retVal;}},invokeLocalFunction:function(funcID,args) {var result;var func=this.localFunctionCache[funcID];if(func!=undefined) {result=this.serialize(func.apply(null,this.deserialize(args)));} return result;},getTypeFromName:function(objTypeName) {return this.remoteTypeCache[objTypeName];},createProxy:function(objID,typeName) {var objType=this.getTypeFromName(typeName);instanceFactory.prototype=objType;var instance=new instanceFactory(objID);this.remoteInstanceCache[objID]=instance;return instance;},getProxy:function(objID) {return this.remoteInstanceCache[objID];},addTypeDataToCache:function(typeData) {newType=new ASProxy(this,typeData.name);var accessors=typeData.accessors;for(var i=0;i="a"&&c<="z") {getterName="get"+c.toUpperCase()+propName.substr(1);setterName="set"+c.toUpperCase()+propName.substr(1);} else {getterName="get"+propName;setterName="set"+propName;} ty[setterName]=function(val) {this.bridge.setPropertyInAS(this.fb_instance_id,propName,val);} ty[getterName]=function() {return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id,propName));}},addMethodToType:function(ty,methodName) {ty[methodName]=function() {return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id,methodName,FABridge.argsToArray(arguments)));}},getFunctionProxy:function(funcID) {var bridge=this;if(this.remoteFunctionCache[funcID]==null) {this.remoteFunctionCache[funcID]=function() {bridge.callASFunction(funcID,FABridge.argsToArray(arguments));}} return this.remoteFunctionCache[funcID];},getFunctionID:function(func) {if(func.__bridge_id__==undefined) {func.__bridge_id__=this.makeID(this.nextLocalFuncID++);this.localFunctionCache[func.__bridge_id__]=func;} return func.__bridge_id__;},serialize:function(value) {var result={};var t=typeof(value);if(t=="number"||t=="string"||t=="boolean"||t==null||t==undefined) {result=value;} else if(value instanceof Array) {result=[];for(var i=0;i0) {FABridge.refCount--;} throw new Error(myErrorMessage[1]);return value;} else {return value;}}};ASProxy=function(bridge,typeName) {this.bridge=bridge;this.typeName=typeName;return this;};ASProxy.prototype={get:function(propName) {return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id,propName));},set:function(propName,value) {this.bridge.setPropertyInAS(this.fb_instance_id,propName,value);},call:function(funcName,args) {this.bridge.callASMethod(this.fb_instance_id,funcName,args);},addRef:function(){this.bridge.addRef(this);},release:function(){this.bridge.release(this);}};;if(!window.Flex){alert('Flex library not loaded');}else{Flex.Uploader=Class.create();Flex.Uploader.prototype={flex:null,uploader:null,filters:null,containerId:null,flexContainerId:null,container:null,files:null,fileRowTemplate:null,fileProgressTemplate:null,templatesPattern:/(^|.|\r|\n)(\{\{(.*?)\}\})/,onFilesComplete:false,onFileProgress:true,onFileRemove:false,onContainerHideBefore:null,initialize:function(containerId,uploaderSrc,config){this.containerId=containerId;this.container=$(containerId);this.container.controller=this;this.config=config;this.flexContainerId=this.containerId+'-flash';Element.insert(this.containerId,{'before':'
'});flexWidth=230;if(this.config.width){flexWidth=this.config.width;} this.flex=new Flex.Object({left:100,top:300,width:flexWidth,height:20,src:uploaderSrc});this.fileRowTemplate=new Template(this.getInnerElement('template').innerHTML,this.templatesPattern);this.fileProgressTemplate=new Template(this.getInnerElement('template-progress').innerHTML,this.templatesPattern);this.flex.onBridgeInit=this.handleBridgeInit.bind(this);if(this.flex.detectFlashVersion(9,0,28)){this.flex.apply(this.flexContainerId);}else{this.getInnerElement('install-flash').show();} this.onContainerHideBefore=this.handleContainerHideBefore.bind(this);},getInnerElement:function(elementName){return $(this.containerId+'-'+elementName);},getFileId:function(file){var id;if(typeof file=='object'){id=file.id;}else{id=file;} return this.containerId+'-file-'+id;},getDeleteButton:function(file){return $(this.getFileId(file)+'-delete');},handleBridgeInit:function(){this.uploader=this.flex.getBridge().getUpload();if(this.config.filters){$H(this.config.filters).each(function(pair){this.uploader.addTypeFilter(pair.key,pair.value.label,pair.value.files);}.bind(this));delete(this.config.filters);this.uploader.setUseTypeFilter(true);} this.uploader.setConfig(this.config);this.uploader.addEventListener('select',this.handleSelect.bind(this));this.uploader.addEventListener('complete',this.handleComplete.bind(this));this.uploader.addEventListener('progress',this.handleProgress.bind(this));this.uploader.addEventListener('error',this.handleError.bind(this));this.uploader.addEventListener('removeall',this.handleRemoveAll.bind(this));},browse:function(){this.uploader.browse();},upload:function(){this.uploader.upload();this.files=this.uploader.getFilesInfo();this.updateFiles();},removeFile:function(id){this.uploader.removeFile(id);$(this.getFileId(id)).remove();if(this.onFileRemove){this.onFileRemove(id);} this.files=this.uploader.getFilesInfo();this.updateFiles();},removeAllFiles:function(){this.files.each(function(file){this.removeFile(file.id);}.bind(this));this.files=this.uploader.getFilesInfo();this.updateFiles();},handleSelect:function(event){this.files=event.getData().files;this.checkFileSize();this.updateFiles();this.getInnerElement('upload').show();if(this.onFileSelect){this.onFileSelect();}},handleProgress:function(event){var file=event.getData().file;this.updateFile(file);if(this.onFileProgress){this.onFileProgress(file);}},handleError:function(event){this.updateFile(event.getData().file);},handleComplete:function(event){this.files=event.getData().files;this.updateFiles();if(this.onFilesComplete){this.onFilesComplete(this.files);}},handleRemoveAll:function(event){this.files.each(function(file){$(this.getFileId(file.id)).remove();}.bind(this));if(this.onFileRemoveAll){this.onFileRemoveAll();} this.files=this.uploader.getFilesInfo();this.updateFiles();},handleRemove:function(event){this.files=this.uploader.getFilesInfo();this.updateFiles();},updateFiles:function(){this.files.each(function(file){this.updateFile(file);}.bind(this));},updateFile:function(file){if(!$(this.getFileId(file))){if(this.config.replace_browse_with_remove){$(this.containerId+'-new').show();$(this.containerId+'-new').innerHTML=this.fileRowTemplate.evaluate(this.getFileVars(file));$(this.containerId+'-old').hide();this.flex.getBridge().hideBrowseButton();}else{Element.insert(this.container,{bottom:this.fileRowTemplate.evaluate(this.getFileVars(file))});}} if(file.status=='full_complete'&&file.response.isJSON()){var response=file.response.evalJSON();if(typeof response=='object'){if(typeof response.cookie=='object'){var date=new Date();date.setTime(date.getTime()+(parseInt(response.cookie.lifetime)*1000));document.cookie=escape(response.cookie.name)+"=" +escape(response.cookie.value) +"; expires="+date.toGMTString() +(response.cookie.path.blank()?"":"; path="+response.cookie.path) +(response.cookie.domain.blank()?"":"; domain="+response.cookie.domain);} if(typeof response.error!='undefined'&&response.error!=0){file.status='error';file.errorText=response.error;}}} if(file.status=='full_complete'&&!file.response.isJSON()){file.status='error';} var progress=$(this.getFileId(file)).getElementsByClassName('progress-text')[0];if((file.status=='progress')||(file.status=='complete')){$(this.getFileId(file)).addClassName('progress');$(this.getFileId(file)).removeClassName('new');$(this.getFileId(file)).removeClassName('error');if(file.progress&&file.progress.total){progress.update(this.fileProgressTemplate.evaluate(this.getFileProgressVars(file)));}else{progress.update('');} if(!this.config.replace_browse_with_remove){this.getDeleteButton(file).hide();}}else if(file.status=='error'){$(this.getFileId(file)).addClassName('error');$(this.getFileId(file)).removeClassName('progress');$(this.getFileId(file)).removeClassName('new');var errorText=file.errorText?file.errorText:this.errorText(file);if(this.config.replace_browse_with_remove){this.flex.getBridge().hideBrowseButton();}else{this.getDeleteButton(file).show();} progress.update(errorText);}else if(file.status=='full_complete'){$(this.getFileId(file)).addClassName('complete');$(this.getFileId(file)).removeClassName('progress');$(this.getFileId(file)).removeClassName('error');if(this.config.replace_browse_with_remove){this.flex.getBridge().hideRemoveButton();} progress.update(this.translate('Complete'));}},getDebugStr:function(obj){return Object.toJSON(obj).replace('&','&').replace('>','>').replace('<','<');},getFileVars:function(file){return{id:this.getFileId(file),fileId:file.id,name:file.name,size:this.formatSize(file.size)};},getFileProgressVars:function(file){return{total:this.formatSize(file.progress.total),uploaded:this.formatSize(file.progress.loaded),percent:this.round((file.progress.loaded/file.progress.total)*100)};},formatSize:function(size){if(size>1024*1024*1024*1024){return this.round(size/(1024*1024*1024*1024))+' '+this.translate('Tb');}else if(size>1024*1024*1024){return this.round(size/(1024*1024*1024))+' '+this.translate('Gb');}else if(size>1024*1024){return this.round(size/(1024*1024))+' '+this.translate('Mb');}else if(size>1024){return this.round(size/(1024))+' '+this.translate('Kb');} return size+' '+this.translate('b');},round:function(number){return Math.round(number*100)/100;},checkFileSize:function(){newFiles=[];hasTooBigFiles=false;this.files.each(function(file){if(file.size>maxUploadFileSizeInBytes){hasTooBigFiles=true;this.uploader.removeFile(file.id)}else{newFiles.push(file)}}.bind(this));this.files=newFiles;if(hasTooBigFiles){alert(this.translate('Maximum allowed file size for upload is')+' '+maxUploadFileSize+".\n"+this.translate('Please check your server PHP settings.'));}},translate:function(text){try{if(Translator){return Translator.translate(text);}} catch(e){} return text;},errorText:function(file){var error='';switch(file.errorCode){case 1:error='File size should be more than 0 bytes';break;case 2:error='Upload HTTP Error';break;case 3:error='Upload I/O Error';break;case 4:error='Upload Security Error';break;case 5:error='SSL Error: Invalid or self-signed certificate';break;} if(error){return this.translate(error);} return error;},handleContainerHideBefore:function(container){if(container&&Element.descendantOf(this.container,container)&&!this.checkAllComplete()){if(!confirm('There are files that were selected but not uploaded yet. After switching to another tab your selections will be lost. Do you wish to continue ?')){return'cannotchange';}else{this.removeAllFiles();}}},checkAllComplete:function(){if(this.files){return!this.files.any(function(file){return(file.status!=='full_complete')});} return true;}}};MediabrowserUtility={openDialog:function(url,width,height,title){if($('browser_window')&&typeof(Windows)!='undefined'){Windows.focus('browser_window');return;} this.dialogWindow=Dialog.info(null,{closable:true,resizable:false,draggable:true,className:'magento',windowClassName:'popup-window',title:title||'Insert File...',top:50,width:width||950,height:height||600,zIndex:1000,recenterAuto:false,hideEffect:Element.hide,showEffect:Element.show,id:'browser_window',onClose:this.closeDialog.bind(this)});new Ajax.Updater('modal_dialog_message',url,{evalScripts:true});},closeDialog:function(window){if(!window){window=this.dialogWindow;} if(window){WindowUtilities._showSelect();window.close();}}};Mediabrowser=Class.create();Mediabrowser.prototype={targetElementId:null,contentsUrl:null,onInsertUrl:null,newFolderUrl:null,deleteFolderUrl:null,deleteFilesUrl:null,headerText:null,tree:null,currentNode:null,storeId:null,initialize:function(setup){this.newFolderPrompt=setup.newFolderPrompt;this.deleteFolderConfirmationMessage=setup.deleteFolderConfirmationMessage;this.deleteFileConfirmationMessage=setup.deleteFileConfirmationMessage;this.targetElementId=setup.targetElementId;this.contentsUrl=setup.contentsUrl;this.onInsertUrl=setup.onInsertUrl;this.newFolderUrl=setup.newFolderUrl;this.deleteFolderUrl=setup.deleteFolderUrl;this.deleteFilesUrl=setup.deleteFilesUrl;this.headerText=setup.headerText;},setTree:function(tree){this.tree=tree;this.currentNode=tree.getRootNode();},getTree:function(tree){return this.tree;},selectFolder:function(node,event){this.currentNode=node;this.hideFileButtons();this.activateBlock('contents');if(node.id=='root'){this.hideElement('button_delete_folder');}else{this.showElement('button_delete_folder');} this.updateHeader(this.currentNode);this.drawBreadcrumbs(this.currentNode);this.showElement('loading-mask');new Ajax.Request(this.contentsUrl,{parameters:{node:this.currentNode.id},evalJS:true,onSuccess:function(transport){try{this.currentNode.select();this.onAjaxSuccess(transport);this.hideElement('loading-mask');if($('contents')!=undefined){$('contents').update(transport.responseText);$$('div.filecnt').each(function(s){Event.observe(s.id,'click',this.selectFile.bind(this));Event.observe(s.id,'dblclick',this.insert.bind(this));}.bind(this));}}catch(e){alert(e.message);}}.bind(this)});},selectFolderById:function(nodeId){var node=this.tree.getNodeById(nodeId);if(node.id){this.selectFolder(node);}},selectFile:function(event){var div=Event.findElement(event,'DIV');$$('div.filecnt.selected[id!="'+div.id+'"]').each(function(e){e.removeClassName('selected');}) div.toggleClassName('selected');if(div.hasClassName('selected')){this.showFileButtons();}else{this.hideFileButtons();}},showFileButtons:function(){this.showElement('button_delete_files');this.showElement('button_insert_files');},hideFileButtons:function(){this.hideElement('button_delete_files');this.hideElement('button_insert_files');},handleUploadComplete:function(files){$$('div[class*="file-row complete"]').each(function(e){$(e.id).remove();});this.selectFolder(this.currentNode);},insert:function(event){var div;if(event!=undefined){div=Event.findElement(event,'DIV');}else{$$('div.selected').each(function(e){div=$(e.id);});} if($(div.id)==undefined){return false;} var targetEl=this.getTargetElement();if(!targetEl){alert("Target element not found for content update");Windows.close('browser_window');return;} var params={filename:div.id,node:this.currentNode.id,store:this.storeId};if(targetEl.tagName.toLowerCase()=='textarea'){params.as_is=1;} new Ajax.Request(this.onInsertUrl,{parameters:params,onSuccess:function(transport){try{this.onAjaxSuccess(transport);if(this.getMediaBrowserOpener()){self.blur();} Windows.close('browser_window');if(targetEl.tagName.toLowerCase()=='input'){targetEl.value=transport.responseText;}else{updateElementAtCursor(targetEl,transport.responseText);if(varienGlobalEvents){varienGlobalEvents.fireEvent('tinymceChange');}}}catch(e){alert(e.message);}}.bind(this)});},getTargetElement:function(){if(typeof(tinyMCE)!='undefined'&&tinyMCE.get(this.targetElementId)){if((opener=this.getMediaBrowserOpener())){var targetElementId=tinyMceEditors.get(this.targetElementId).getMediaBrowserTargetElementId();return opener.document.getElementById(targetElementId);}else{return null;}}else{return document.getElementById(this.targetElementId);}},getMediaBrowserOpener:function(){if(typeof(tinyMCE)!='undefined'&&tinyMCE.get(this.targetElementId)&&typeof(tinyMceEditors)!='undefined'&&!tinyMceEditors.get(this.targetElementId).getMediaBrowserOpener().closed){return tinyMceEditors.get(this.targetElementId).getMediaBrowserOpener();}else{return null;}},newFolder:function(){var folderName=prompt(this.newFolderPrompt);if(!folderName){return false;} new Ajax.Request(this.newFolderUrl,{parameters:{name:folderName},onSuccess:function(transport){try{this.onAjaxSuccess(transport);if(transport.responseText.isJSON()){var response=transport.responseText.evalJSON() var newNode=new Ext.tree.AsyncTreeNode({text:response.short_name,draggable:false,id:response.id,expanded:true});var child=this.currentNode.appendChild(newNode);this.tree.expandPath(child.getPath(),'',function(success,node){this.selectFolder(node);}.bind(this));}}catch(e){alert(e.message);}}.bind(this)})},deleteFolder:function(){if(!confirm(this.deleteFolderConfirmationMessage)){return false;} new Ajax.Request(this.deleteFolderUrl,{onSuccess:function(transport){try{this.onAjaxSuccess(transport);var parent=this.currentNode.parentNode;parent.removeChild(this.currentNode);this.selectFolder(parent);} catch(e){alert(e.message);}}.bind(this)})},deleteFiles:function(){if(!confirm(this.deleteFileConfirmationMessage)){return false;} var ids=[];var i=0;$$('div.selected').each(function(e){ids[i]=e.id;i++;});new Ajax.Request(this.deleteFilesUrl,{parameters:{files:ids.toJSON()},onSuccess:function(transport){try{this.onAjaxSuccess(transport);this.selectFolder(this.currentNode);}catch(e){alert(e.message);}}.bind(this)});},drawBreadcrumbs:function(node){if($('breadcrumbs')!=undefined){$('breadcrumbs').remove();} if(node.id=='root'){return;} var path=node.getPath().split('/');var breadcrumbs='';for(var i=0,length=path.length;i';breadcrumbs+=''+currNode.text+'';if(i<(length-1)){breadcrumbs+=' /';} breadcrumbs+='';}} if(breadcrumbs!=''){breadcrumbs='';$('content_header').insert({after:breadcrumbs});}},updateHeader:function(node){var header=(node.id=='root'?this.headerText:node.text);if($('content_header_text')!=undefined){$('content_header_text').innerHTML=header;}},activateBlock:function(id){this.showElement(id);},hideElement:function(id){if($(id)!=undefined){$(id).addClassName('no-display');$(id).hide();}},showElement:function(id){if($(id)!=undefined){$(id).removeClassName('no-display');$(id).show();}},onAjaxSuccess:function(transport){if(transport.responseText.isJSON()){var response=transport.responseText.evalJSON() if(response.error){throw response;}else if(response.ajaxExpired&&response.ajaxRedirect){setLocation(response.ajaxRedirect);}}}}