Index: themes/advanced/platform/inc/uploader/upload_manager.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/inc/uploader/upload_manager.js (revision ) +++ themes/advanced/platform/inc/uploader/upload_manager.js (revision ) @@ -0,0 +1,352 @@ +function UploadsManager() { + var $me = this; + + $(document).bind('FormManager.Form.Ready', function ($e, $prefix) { + var $form_id = FormManager.form_param($prefix, 'form_id'); + + $me.Init($form_id); + }); +} + +UploadsManager = new UploadsManager(); + +/* ==== Private Attributes ==== */ +UploadsManager._nextId = 0; +UploadsManager._uploadersReady = 0; + +UploadsManager._debugMode = false; +UploadsManager._Uploaders = {}; + +/* ==== Private methods ==== */ +UploadsManager._nextFlashId = function() { + this._nextId++; + return 'uploaderflash' + this._nextId; +}; + +UploadsManager.iterate = function($method, $timeout) { + var $me = this; + var args = Array.prototype.slice.call(arguments); // convert to array + + if ($timeout !== undefined) { + // 2nd parameter is given + if ((Object.prototype.toString.call($timeout) === '[object String]') && $timeout.match(/^timeout:([\d]+)$/)) { + // it's string in format "timeout:" + $timeout = parseInt(RegExp.$1); + } + else { + // this is not the timeout, but 1st parameter of iteratable method + $timeout = undefined; + } + } + + if ($timeout !== undefined) { + // make delayed iteration (helps with direct innerHTML assignments in IE) + args.splice(args.length - 1, 1); // remove timeout + + setTimeout(function() { $me.iterate.apply($me, args); }, $timeout); + return ; + } + + args.splice(0, 1); // remove method name + + for (var i in this._Uploaders) { + this._Uploaders[i][$method].apply(this._Uploaders[i], args); + } +}; + +UploadsManager._hasQueue = function() { + var has_queue = false; + + for (var i in this._Uploaders) { + var tmp = this._Uploaders[i].hasQueue(); + has_queue = has_queue || tmp; + } + + return has_queue; +}; + +UploadsManager._getUploader = function (file) { + var $flash_id = file.id.match(/(.*)_[\d]+/) ? RegExp.$1 : file.id; + + for (var $uploader_index in this._Uploaders) { + if (this._Uploaders[$uploader_index].flash_id == $flash_id) { + return this._Uploaders[$uploader_index]; + } + } + + return null; +}; + +/* ==== Public methods ==== */ +UploadsManager.Init = function ($form_id) { + var $me = this, + $submit_handler = function ($e) { + if ($me._hasQueue()) { + submitted = false; + $e.stopImmediatePropagation(); + alert('File upload is in progress. Please cancel the upload or wait until it\'s completed.'); + + return false; + } + + return true; + }; + + if ( $form_id === undefined ) { + $form_id = $form_name; + } + + $('#' + $form_id).unbind('submit', $submit_handler).submit($submit_handler); +}; + +UploadsManager.AddUploader = function(id, params) { + this.Init(); + + this._Uploaders[id] = new Uploader(id, params); +}; + +UploadsManager.RemoveUploader = function(id) { + this._Uploaders[id].remove(); + delete this._Uploaders[id]; +}; + +UploadsManager.DeleteFile = function(uploader_id, fname, confirmed) { + if (!confirmed && !confirm('Are you sure you want to delete "' + fname + '" file?')) { + return false; + } + + var $uploader = this._Uploaders[uploader_id]; + + $.get( + $uploader.deleteURL.replace('#FILE#', encodeURIComponent(fname)).replace('#FIELD_ID#', $uploader.id), + function ($data) { + $uploader.removeFile({id:fname}); + $uploader.deleted.push(fname); + $uploader.updateInfo(undefined, true); + } + ); + + return true; +}; + +UploadsManager.StartUpload = function(id) { + this._Uploaders[id].startUpload(); +}; + +UploadsManager.CancelFile = function(id, file_id) { + this._Uploaders[id].callFlash('CancelUpload', [file_id]); +}; + +UploadsManager.UploadQueueComplete = function($uploader) { + +}; + +UploadsManager.CancelUpload = function(id) { + this._Uploaders[id].cancelUpload(); +}; + +UploadsManager.setDebugMode = function ($enabled) { + /*for (var $uploader_index in this._Uploaders) { + this._Uploaders[$uploader_index].clallFlash('SetDebugEnabled', [$enabled]); + }*/ + + this._debugMode = $enabled; +}; + + +/* ==== Flash event handlers ==== */ +UploadsManager.onHandleEverything = function () { + if (UploadsManager._debugMode) { + console.log('default swf handler'); + } +}; + +UploadsManager.onUploadStart = function(file) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.UploadFileStart(file); + } + ); +}; + +UploadsManager.onUploadProgress = function(file, bytesLoaded, bytesTotal) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.UploadProgress(file, bytesLoaded, bytesTotal); + } + ); +}; + +UploadsManager.onUploadComplete = function(file) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.UploadFileComplete(file); + } + ); +}; + +UploadsManager.onFileQueued = function(file) { + var $uploader = UploadsManager._getUploader(file); +// file = this.unescapeFilePostParams(file); + + $uploader.queueEvent( + function() { + if (this.files_count >= this.params.multiple) { + // new file can exceed allowed file number + if (this.params.multiple > 1) { + // it definetly exceed it + UploadsManager.onFileQueueError(file, -100, this.params.multiple); + this.callFlash('CancelUpload', [file.id]); + } + else { + // delete file added + this.files_count++; + this.files.push(file); + + if (this.files[0].uploaded) { + UploadsManager.DeleteFile(UploadsManager._getUploader(file).id, this.files[0].name, true); + } + else { + this.callFlash('CancelUpload', [this.files[0].id]); + } + + this.startUpload(); + } + } + else { + // new file will not exceed allowed file number + this.files_count++; + this.files.push(file); + + this.startUpload(); + } + + this.updateInfo(this.files.length - 1); + } + ) +}; + +UploadsManager.onUploadSuccess = function(file, serverData, receivedResponse) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.UploadSuccess(file, serverData, receivedResponse); + } + ); +}; + +UploadsManager.onUploadError = function(file, errorCode, message) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.removeFile(file); + + switch (errorCode) { + case -200: + // HTTP Error + message = parseInt(message); // HTTP Error Code + switch (message) { + case 403: + message = "You don't have permission to upload"; + break; + + case 413: + message = 'File size exceeds allowed limit'; + break; + + case 500: + message = 'Write permissions not set on the server, please contact server administrator'; + break; + } + + if (isNaN(message)) { + // message is processed + alert('Error: ' + message + "\n" + 'Occured on file ' + file.name); + return ; + } + break; + + case -280: + // File Cancelled + return ; + break; + + case -290: + // Upload Stopped + UploadsManager.UploadQueueComplete(this); + return ; + break; + } + + // all not processed error messages go here + alert('Error [' + errorCode + ']: ' + message + "\n" + 'Occured on file ' + file.name); + } + ); +}; + +UploadsManager.onFileQueueError = function(file, errorCode, message) { + switch (errorCode) { + case -100: + // maximal allowed file count reached + alert('Error: Files count exceeds allowed limit' + "\n" + 'Occured on file ' + file.name); + return ; + break; + + case -110: + // maximal allowed filesize reached + alert('Error: File size exceeds allowed limit' + "\n" + 'Occured on file ' + file.name); + return ; + break; + + case -130: + // maximal allowed filesize reached + alert('Error: File is not an allowed file type.' + "\n" + 'Occured on file ' + file.name); + return ; + break; + } + + // all not processed error messages go here + alert('Error [' + errorCode + ']: ' + message + "\n" + 'Occured on file ' + file.name); +}; + +UploadsManager.onFlashReady = function ($uploader_id) { + this._Uploaders[$uploader_id].onFlashReady(); + this._uploadersReady++; + + if (this._uploadersReady == this._nextId) { + // all uploaders are ready + Application.processHooks('m:OnUploadersReady'); + } +}; + +UploadsManager.onDebug = function (message) { + if (!UploadsManager._debugMode) { + return ; + } + + var exceptionMessage, exceptionValues = []; + + // Check for an exception object and print it nicely + if (typeof(message) === 'object' && typeof(message.name) === 'string' && typeof(message.message) === 'string') { + for (var key in message) { + if (message.hasOwnProperty(key)) { + exceptionValues.push(key + ': ' + message[key]); + } + } + exceptionMessage = exceptionValues.join("\n") || ''; + exceptionValues = exceptionMessage.split("\n"); + exceptionMessage = 'EXCEPTION: ' + exceptionValues.join("\nEXCEPTION: "); + + console.log(exceptionMessage); + } else { + console.log(message); + } +}; \ No newline at end of file Index: themes/advanced/platform/inc/swfobject.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/inc/swfobject.js (revision ) +++ themes/advanced/platform/inc/swfobject.js (revision ) @@ -0,0 +1,8 @@ +/** + * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/ + * + * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License: + * http://www.opensource.org/licenses/mit-license.php + * + */ +if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="";_19+="";var _1d=this.getParams();for(var key in _1d){_19+="";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="";}_19+="";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.majorfv.major){return true;}if(this.minorfv.minor){return true;}if(this.rev=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject; \ No newline at end of file Index: themes/advanced/platform/inc/styles.css IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/inc/styles.css (revision 15892) +++ themes/advanced/platform/inc/styles.css (revision ) @@ -639,4 +639,48 @@ list-style-position: outside; list-style-type: disc; padding: 5px 0 0; -} \ No newline at end of file +} + +/* Uploader */ +.uploader-queue div.file { + font-size: 11px; + border: 1px solid #7F99C5; + padding: 3px; + background-color: #DEE7F6; + margin-bottom: 2px; +} + +.uploader-queue .left { + float: left; + vertical-align: top; +} + +.uploader-queue .file-label { + margin-left: 5px; +} + +.uploader-queue .preview .delete-checkbox { + margin-top: -3px; +} + +.uploader-queue .progress-container { + margin: 2px 5px 0px 5px; +} + +.uploader-queue .progress-empty { + width: 150px; + height: 9px; + border: 1px solid black; + background: url('@templates_base@/platform/img/progress_left.gif') repeat-x; +} + +.uploader-queue .progress-full { + height: 9px; + background: url('@templates_base@/platform/img/progress_done.gif'); +} + +.uploader-queue .thumbnail { + /*margin-bottom: 2px;*/ + border: 1px solid black; + background-color: grey; +} Index: themes/advanced/platform/inc/uploader/uploader.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/inc/uploader/uploader.js (revision ) +++ themes/advanced/platform/inc/uploader/uploader.js (revision ) @@ -0,0 +1,749 @@ +// this js class name is hardcoded in flash object :( +var SWFUpload = function () {}; +SWFUpload.instances = {}; + +function Uploader(id, params) { + this.id = id; + + // normalize params + if (isNaN(parseInt(params.multiple))) { + // ensure that maximal file number is greater then zero + params.multiple = 1; + } + + params.allowedFilesize = this._normalizeFilesize(params.allowedFilesize); + + // set params to uploader + this._eventQueue = []; + this.uploadCancelled = false; + this.flashReady = false; + + this.params = params; + this._ensureDefaultValues(); + + this.files = []; + this.files_count = 0; + this.deleted = []; + + // because used outside this class + this.deleteURL = params.deleteURL; + + this.enableUploadButton(); + this._attachEventHandler(); + + var $me = this; + + if ( this.params.ajax ) { + $(document).bind('FormManager.WindowManager.Ready', function ($e) { + $me.init(); + }); + } + else { + $(document).ready(function() { + $me.init(); + }); + } +} + +/* ==== Private methods ==== */ +Uploader.prototype._attachEventHandler = function() { + var $me = this; + + $(document).bind('UploadsManager.Uploader.' + crc32(this.id), function ($e, $method) { + $me[$method].apply($me, Array.prototype.slice.call(arguments, 2)); + }); +}; + +Uploader.prototype._ensureDefaultValues = function() { + // Upload backend settings + var $defaults = { + baseUrl : '', + uploadURL : '', + deleteURL : '', + previewURL : '', + useQueryString : false, + requeueOnError : false, + httpSuccess : '', + filePostName : 'Filedata', + allowedFiletypes : '*.*', + allowedFiletypesDescription : 'All Files', + allowedFilesize : 0, // Default zero means "unlimited" + multiple : 0, + field : '', + thumb_format: '', + urls : '', + names : '', + sizes : '', + fileQueueLimit : 0, + buttonImageURL : '', + buttonWidth : 1, + buttonHeight : 1, + buttonText : '', + buttonTextTopPadding : 0, + buttonTextLeftPadding : 0, + buttonTextStyle : 'color: #000000; font-size: 16pt;', + buttonAction : parseInt(this.params.multiple) == 1 ? -100 : -110, // SELECT_FILE : -100, SELECT_FILES : -110 + buttonDisabled : true, //false, + buttonCursor : -1, // ARROW : -1, HAND : -2 + wmode : 'transparent', // "window", "transparent", "opaque" + buttonPlaceholderId: false, + ajax: false + }; + + for (var $param_name in $defaults) { + if (this.params[$param_name] == null) { +// console.log('setting default value [', $defaults[$param_name], '] for missing parameter [', $param_name, '] instead of [', this.params[$param_name], ']'); + this.params[$param_name] = $defaults[$param_name]; + } + } +}; + +Uploader.prototype._normalizeFilesize = function($file_size) { + var $normalize_size = parseInt($file_size); + if (isNaN($normalize_size)) { + return $file_size; + } + + // in kilobytes (flash doesn't recognize numbers, that are longer, then 9 digits) + return $normalize_size / 1024; +}; + +Uploader.prototype._prepareFiles = function() { + var ids = ''; + var names = ''; + + // process uploaded files + for (var f = 0; f < this.files.length; f++) { + if (isset(this.files[f].uploaded) && !isset(this.files[f].temp)) { + continue; + } + + ids += this.files[f].id + '|'; + names += this.files[f].name + '|'; + } + + ids = ids.replace(/\|$/, '', ids); + names = names.replace(/\|$/, '', names); + + document.getElementById(this.id+'[tmp_ids]').value = ids; + document.getElementById(this.id+'[tmp_names]').value = names; + document.getElementById(this.id+'[tmp_deleted]').value = this.deleted.join('|'); +}; + +Uploader.prototype._formatSize = function (bytes) { + var kb = Math.round(bytes / 1024); + + if (kb < 1024) { + return kb + ' KB'; + } + + var mb = Math.round(kb / 1024 * 100) / 100; + + return mb + ' MB'; +}; + +Uploader.prototype._executeNextEvent = function () { + var f = this._eventQueue ? this._eventQueue.shift() : null; + if (typeof(f) === 'function') { + f.apply(this); + } +}; + +/* ==== Public methods ==== */ +Uploader.prototype.init = function() { + this.IconPath = this.params.IconPath ? this.params.IconPath : '../admin_templates/img/browser/icons'; + + // initialize flash object + this.flash_id = UploadsManager._nextFlashId(); + + // add callbacks for every event, because none of callbacks will work in other case (see swfupload documentation) + SWFUpload.instances[this.flash_id] = this; + SWFUpload.instances[this.flash_id].flashReady = function () { UploadsManager.onFlashReady(this.id); }; + SWFUpload.instances[this.flash_id].fileDialogStart = UploadsManager.onHandleEverything; + SWFUpload.instances[this.flash_id].fileQueued = UploadsManager.onFileQueued; + SWFUpload.instances[this.flash_id].fileQueueError = UploadsManager.onFileQueueError; + SWFUpload.instances[this.flash_id].fileDialogComplete = UploadsManager.onHandleEverything; + + SWFUpload.instances[this.flash_id].uploadStart = UploadsManager.onUploadStart; + SWFUpload.instances[this.flash_id].uploadProgress = UploadsManager.onUploadProgress; + SWFUpload.instances[this.flash_id].uploadError = UploadsManager.onUploadError; + SWFUpload.instances[this.flash_id].uploadSuccess = UploadsManager.onUploadSuccess; + SWFUpload.instances[this.flash_id].uploadComplete = UploadsManager.onUploadComplete; + SWFUpload.instances[this.flash_id].debug = UploadsManager.onDebug; + + this.swf = new SWFObject(this.params.baseUrl + '/swfupload.swf', this.flash_id, this.params.buttonWidth, this.params.buttonHeight, '9', '#FFFFFF'); + this.swf.setAttribute('style', ''); + this.swf.addParam('wmode', encodeURIComponent(this.params.wmode)); + + this.swf.addVariable('movieName', encodeURIComponent(this.flash_id)); + this.swf.addVariable('fileUploadLimit', 0); + this.swf.addVariable('fileQueueLimit', encodeURIComponent(this.params.fileQueueLimit)); + this.swf.addVariable('fileSizeLimit', encodeURIComponent(this.params.allowedFilesize)); // in kilobytes + this.swf.addVariable('fileTypes', encodeURIComponent(this.params.allowedFiletypes)); + this.swf.addVariable('fileTypesDescription', encodeURIComponent(this.params.allowedFiletypesDescription)); + this.swf.addVariable('uploadURL', encodeURIComponent(this.params.uploadURL)); + + // upload button appearance + this.swf.addVariable('buttonImageURL', encodeURIComponent(this.params.buttonImageURL)); + this.swf.addVariable('buttonWidth', encodeURIComponent(this.params.buttonWidth)); + this.swf.addVariable('buttonHeight', encodeURIComponent(this.params.buttonHeight)); + this.swf.addVariable('buttonText', encodeURIComponent(this.params.buttonText)); + this.swf.addVariable('buttonTextTopPadding', encodeURIComponent(this.params.buttonTextTopPadding)); + this.swf.addVariable('buttonTextLeftPadding', encodeURIComponent(this.params.buttonTextLeftPadding)); + this.swf.addVariable('buttonTextStyle', encodeURIComponent(this.params.buttonTextStyle)); + this.swf.addVariable('buttonAction', encodeURIComponent(this.params.buttonAction)); + this.swf.addVariable('buttonDisabled', encodeURIComponent(this.params.buttonDisabled)); + this.swf.addVariable('buttonCursor', encodeURIComponent(this.params.buttonCursor)); + + if (UploadsManager._debugMode) { + this.swf.addVariable('debugEnabled', encodeURIComponent('true')); // flash var + } + + this.renderBrowseButton(); + + this.refreshQueue(); +}; + +Uploader.prototype.refreshQueue = function($params) { + if ( $params !== undefined ) { + $.extend(true, this.params, $params); + + document.getElementById(this.id+'[upload]').value = this.params.names; + document.getElementById(this.id+'[order]').value = this.params.names; + } + + // 1. remove queue DIVs for files, that doesn't exist after upload was made + var $new_file_ids = this.getFileIds(this.params.names); + + for (var $i = 0; $i < this.files.length; $i++) { + if ( !in_array(this.files[$i].id, $new_file_ids) ) { + this.updateQueueFile($i, true); + } + } + + this.files = []; + this.files_count = 0; + this.deleted = []; + + if (this.params.urls != '') { + var urls = this.params.urls.split('|'), + names = this.params.names.split('|'), + sizes = this.params.sizes.split('|'); + + for (var i = 0; i < urls.length; i++) { + var a_file = { + id : this.getUploadedFileId(names[i]), + name : names[i], + url : urls[i], + size: sizes[i], + uploaded : 1, + progress: 100 + }; + + this.files_count++; + this.files.push(a_file); + } + + this.updateInfo(); + } +}; + +Uploader.prototype.getFileIds = function($file_names) { + var $ret = []; + + if ( !$file_names.length ) { + return $ret; + } + + if ( !$.isArray($file_names) ) { + $file_names = $file_names.split('|'); + } + + for (var i = 0; i < $file_names.length; i++) { + $ret.push(this.getUploadedFileId($file_names[i])) + } + + return $ret; +}; + +Uploader.prototype.getUploadedFileId = function($file_name) { + return 'uploaded_' + crc32($file_name); +}; + +Uploader.prototype.enableUploadButton = function() { + var $me = this; + + // enable upload button, when flash is fully loaded + this.queueEvent( + function() { + setTimeout( + function () { + $me.callFlash('SetButtonDisabled', [false]); + }, 0 + ) + } + ); +}; + +Uploader.prototype.renderBrowseButton = function() { + var holder = document.getElementById(this.params.buttonPlaceholderId); + this.swf.write(holder); + + this.flash = document.getElementById(this.flash_id); +}; + +Uploader.prototype.remove = function() { + var id = this.params.buttonPlaceholderId; + + var obj = document.getElementById(id); + + if (obj/* && obj.nodeName == "OBJECT"*/) { + var u = navigator.userAgent.toLowerCase(); + var p = navigator.platform.toLowerCase(); + var windows = p ? /win/.test(p) : /win/.test(u); + var $me = this; + + if (document.all && windows) { + obj.style.display = "none"; + (function(){ + if (obj.readyState == 4) { + $me.removeObjectInIE(id); + } + else { + setTimeout(arguments.callee, 10); + } + })(); + } + else { + obj.parentNode.removeChild(obj); + } + } +}; + +Uploader.prototype.removeObjectInIE = function(id) { + var obj = document.getElementById(id); + if (obj) { + for (var i in obj) { + if (typeof obj[i] == 'function') { + obj[i] = null; + } + } + obj.parentNode.removeChild(obj); + } +}; + +Uploader.prototype.isImage = function($filename) { + this.removeTempExtension($filename).match(/\.([^.]*)$/); + + var $ext = RegExp.$1.toLowerCase(); + + return $ext.match(/^(bmp|gif|jpg|jpeg|png)$/); +}; + +Uploader.prototype.getFileIcon = function($filename) { + this.removeTempExtension($filename).match(/\.([^.]*)$/); + + var $ext = RegExp.$1.toLowerCase(), + $ext_overrides = { + 'doc': '^(docx|dotx|docm|dotm)$', + 'xls': '^(xlsx|xltx|xlsm|xltm|xlam|xlsb)$', + 'ppt': '^(pptx|potx|ppsx|ppam|pptm|potm|ppsm)$' + }; + + $.each($ext_overrides, function ($new_ext, $expression) { + var $regexp = new RegExp($expression); + + if ( $ext.match($regexp) ) { + $ext = $new_ext; + + return false; + } + + return true; + }); + + var $icon = $ext.match(/^(ai|avi|bmp|cs|dll|doc|dot|exe|fla|gif|htm|html|jpg|js|mdb|mp3|pdf|ppt|rdp|swf|swt|txt|vsd|xls|xml|zip)$/) ? $ext : 'default.icon'; + + return this.IconPath + '/' + $icon + '.gif'; +}; + +Uploader.prototype.removeTempExtension = function ($file) { + return $file.replace(/(_[\d]+)?\.tmp$/, ''); +}; + +Uploader.prototype.getQueueElement = function($file) { + var $ret = ''; + var $icon_image = this.getFileIcon($file.name); + var $file_label = this.removeTempExtension($file.name) + ' (' + this._formatSize($file.size) + ')'; + var $need_preview = false; + + if (isset($file.uploaded)) { + // add deletion checkbox + $need_preview = (this.params.thumb_format.length > 0) && this.isImage($file.name); + $ret += '
'; + + // add icon based on file type + $ret += '
'; + + if ($need_preview) { + $ret += ''; + } + else { + $ret += ''; + } + + $ret += '
'; + + // add filename + preview link + $ret += ''; + } + else { + // add icon based on file type + $ret += '
'; + + // add filename + $ret += '
' + $file_label + '
'; + + // add empty progress bar + $ret += '
'; + + // add cancel upload link + $ret += ''; + } + + $ret += '
'; + $ret = $('
' + $ret + '
'); + + // set click events + var $me = this; + + $('.delete-file-btn', $ret).click( + function ($e) { + $(this).prop('checked', !UploadsManager.DeleteFile($me.id, $file.name)); + } + ); + + $('.cancel-upload-btn', $ret).click( + function ($e) { + UploadsManager.CancelFile(UploadsManager._getUploader($file).id, $file.id); + return false; + } + ); + + // prepare auto-loading preview + var $image = $('img.thumbnail-image', $ret); + + if ($image.length > 0) { + var $tmp_image = new Image(); + $tmp_image.src = $image.attr('large_src'); + + $($tmp_image).load ( + function ($e) { + $image.attr('src', $tmp_image.src).addClass('thumbnail'); + } + ); + } + + return $ret; +}; + +Uploader.prototype.getSortedFiles = function($ordered_queue) { + var $me = this; + + var $ret = $.map($me.files, function ($elem, $index) { + var $file_id = $ordered_queue[$index].replace(/_queue_row$/, ''), + $file_index = $me.getFileIndex({id: $file_id}); + + return $me.files[$file_index].name; + }); + + return $ret; +}; + +Uploader.prototype.updateQueueFile = function($file_index, $delete_file) { + var $queue_container = $( jq('#' + this.id + '_queueinfo') ); + + if ($delete_file !== undefined && $delete_file) { + $( jq('#' + this.files[$file_index].id + '_queue_row') ).remove(); + + if (this.files.length == 1) { + $queue_container.css('margin-top', '0px'); + } + return ; + } + + var $ret = this.getQueueElement(this.files[$file_index]), + $row = $(jq('#' + this.files[$file_index].id + '_queue_row')); + + if ($row.length > 0) { + // file round -> replace + $row.replaceWith($ret); + } + else { + // file not found - add + $( jq('#' + this.id + '_queueinfo') ).append($ret); + $queue_container.css('margin-top', '8px'); + } +}; + +Uploader.prototype.updateInfo = function($file_index, $prepare_only) { + if ($prepare_only === undefined || !$prepare_only) { + if ($file_index === undefined) { + for (var f = 0; f < this.files.length; f++) { + this.updateQueueFile(f); + } + } + else { + this.updateQueueFile($file_index); + } + } + + this._prepareFiles(); +}; + +Uploader.prototype.updateProgressOnly = function ($file_index) { + var $progress_code = '
'; + + $('#' + this.files[$file_index].id + '_progress').html($progress_code); +}; + +Uploader.prototype.removeFile = function (file) { + var count = 0, + n_files = [], + $to_delete = []; + + for (var f = 0; f < this.files.length; f++) { + if (this.files[f].id != file.id && this.files[f].name != file.id) { + n_files.push(this.files[f]); + count++; + } + else { + $to_delete.push(f); + } + } + + for (var $i = 0; $i < $to_delete.length; $i++) { + this.updateQueueFile($to_delete[$i], true); + } + + this.files = n_files; + this.files_count = count; + this.updateInfo(undefined, true); +}; + +Uploader.prototype.hasQueue = function() { + for (var f = 0; f < this.files.length; f++) { + if (isset(this.files[f].uploaded)) { + continue; + } + + return true; + } + + return false; +}; + +Uploader.prototype.startUpload = function() { + this.uploadCancelled = false; + + if (!this.hasQueue()) { + return; + } + + this.callFlash('StartUpload'); +}; + +Uploader.prototype.cancelUpload = function() { + this.callFlash('StopUpload'); + var $stats = this.callFlash('GetStats'); + + while ($stats.files_queued > 0) { + this.callFlash('CancelUpload'); + $stats = this.callFlash('GetStats'); + } + + this.uploadCancelled = true; +}; + +Uploader.prototype.UploadFileStart = function(file) { + var $file_index = this.getFileIndex(file); + this.files[$file_index].progress = 0; + this.updateProgressOnly($file_index); + + this.callFlash('AddFileParam', [file.id, 'field', this.params.field]); + this.callFlash('AddFileParam', [file.id, 'id', file.id]); + this.callFlash('AddFileParam', [file.id, 'flashsid', this.params.flashsid]); + + // we can prevent user from adding any files here :) + this.callFlash('ReturnUploadStart', [true]); +}; + +Uploader.prototype.UploadProgress = function(file, bytesLoaded, bytesTotal) { + var $file_index = this.getFileIndex(file); + this.files[$file_index].progress = Math.round(bytesLoaded / bytesTotal * 100); + this.updateProgressOnly($file_index); +}; + +Uploader.prototype.UploadSuccess = function(file, serverData, receivedResponse) { + if (!receivedResponse) { + return ; + } + + for (var f = 0; f < this.files.length; f++) { + if (this.files[f].id == file.id) { + // new uploaded file name returned by OnUploadFile event + this.files[f].name = serverData; + } + } +}; + +Uploader.prototype.UploadFileComplete = function(file) { + // file was uploaded OR file upload was cancelled + var $file_index = this.getFileIndex(file); + + if ($file_index !== false) { + // in case if file upload was cancelled, then no info here + this.files[$file_index].uploaded = 1; + this.files[$file_index].progress = 100; + this.files[$file_index].temp = 1; + this.files[$file_index].url = this.getUrl(this.files[$file_index]); + this.updateInfo($file_index); + } + + // upload next file in queue + var $stats = this.callFlash('GetStats'); + + if ($stats.files_queued > 0) { + this.callFlash('StartUpload'); + } + else { + UploadsManager.UploadQueueComplete(this); + } +}; + +Uploader.prototype.getUrl = function($file, $preview) { + var $url = this.params.previewURL.replace('#FILE#', encodeURIComponent($file.name)).replace('#FIELD#', this.params.field); + + if ( $file.temp !== undefined && $file.temp ) { + $url += '&tmp=1&id=' + $file.id; + } + + if ( $preview !== undefined && $preview === true ) { + $url += '&thumb=1'; + } + + return $url; +}; + +Uploader.prototype.getFileIndex = function(file) { + for (var f = 0; f < this.files.length; f++) { + if (this.files[f].id == file.id) { + return f; + } + } + + return false; +}; + +Uploader.prototype.queueEvent = function (function_body) { + // Warning: Don't call this.debug inside here or you'll create an infinite loop + var self = this; + + // Queue the event + this._eventQueue.push(function_body); + + if (!this.flashReady) { + // don't execute any flash-related events, while it's not completely loaded + return ; + } + + // Execute the next queued event + setTimeout( + function () { + self._executeNextEvent(); + }, 0 + ); +}; + +Uploader.prototype._executeQueuedEvents = function() { + var $me = this; + + setTimeout( + function () { + $me._executeNextEvent(); + + if ($me._eventQueue.length > 0) { + $me._executeQueuedEvents(); + } + + }, 0 + ); +}; + +// Private: callFlash handles function calls made to the Flash element. +// Calls are made with a setTimeout for some functions to work around +// bugs in the ExternalInterface library. +Uploader.prototype.callFlash = function (functionName, argumentArray) { + argumentArray = argumentArray || []; + + var returnValue; + + if (typeof this.flash[functionName] === 'function') { + // We have to go through all this if/else stuff because the Flash functions don't have apply() and only accept the exact number of arguments. + if (argumentArray.length === 0) { + returnValue = this.flash[functionName](); + } else if (argumentArray.length === 1) { + returnValue = this.flash[functionName](argumentArray[0]); + } else if (argumentArray.length === 2) { + returnValue = this.flash[functionName](argumentArray[0], argumentArray[1]); + } else if (argumentArray.length === 3) { + returnValue = this.flash[functionName](argumentArray[0], argumentArray[1], argumentArray[2]); + } else { + throw 'Too many arguments'; + } + + // Unescape file post param values + if (returnValue != undefined && typeof returnValue.post === 'object') { + returnValue = this.unescapeFilePostParams(returnValue); + } + + return returnValue; + } else { +// alert('invalid function name: ' + functionName); + throw "Invalid function name: " + functionName; + } +}; + +// Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have +// properties that contain characters that are not valid for JavaScript identifiers. To work around this +// the Flash Component escapes the parameter names and we must unescape again before passing them along. +Uploader.prototype.unescapeFilePostParams = function (file) { + var reg = /[$]([0-9a-f]{4})/i; + var unescapedPost = {}; + var uk; + + if (file != undefined) { + for (var k in file.post) { + if (file.post.hasOwnProperty(k)) { + uk = k; + var match; + while ((match = reg.exec(uk)) !== null) { + uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16))); + } + unescapedPost[uk] = file.post[k]; + } + } + + file.post = unescapedPost; + } + + return file; +}; + +Uploader.prototype.onFlashReady = function() { + var $me = this; + this.flashReady = true; + + // process events, queued before flash load + this._executeQueuedEvents(); +}; \ No newline at end of file Index: themes/advanced/platform/inc/script.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/inc/script.js (revision 15892) +++ themes/advanced/platform/inc/script.js (revision ) @@ -1,3 +1,5 @@ +var $form_name = 'kernel_form'; + String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); }; function update_checkbox(cb, cb_hidden) { @@ -46,6 +48,32 @@ $prepend = $prepend !== undefined ? $prepend + '_' : ''; return document.getElementById($prepend + $mask.replace('#FIELD_NAME#', $field) + $append); +} + +function crc32(str) { + var table = '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'; + + var crc = 0; + var x = 0; + var y = 0; + + crc = crc ^ (-1); + + for (var i = 0, iTop = str.length; i < iTop; i++) { + y = ( crc ^ str.charCodeAt(i) ) & 0xFF; + x = "0x" + table.substr(y * 9, 8); + crc = ( crc >>> 8 ) ^ x; + } + + return crc ^ (-1); +} + +function isset(variable) { + if ( variable == null ) { + return false; + } + + return (typeof(variable) == 'undefined') ? false : true; } // ItemCategories class Index: themes/advanced/platform/elements/forms.elm.tpl IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- themes/advanced/platform/elements/forms.elm.tpl (revision 15892) +++ themes/advanced/platform/elements/forms.elm.tpl (revision ) @@ -218,6 +218,62 @@ + + + + + + + + +
+   +
+ +
+ + + + + + + + +
+
+ @@ -503,4 +559,4 @@ - \ No newline at end of file +