Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 9:25 PM

in-portal

Index: branches/RC/core/admin_templates/js/uploader/uploader.js
===================================================================
--- branches/RC/core/admin_templates/js/uploader/uploader.js (revision 11914)
+++ branches/RC/core/admin_templates/js/uploader/uploader.js (revision 11915)
@@ -1,590 +1,629 @@
// this js class name is hardcoded in flash object :(
var SWFUpload = function () {};
SWFUpload.instances = {};
function Uploader(id, params) {
this.id = id;
this._moved = false; // flash was moved outside scroll container
// normalize params
if (isNaN(parseInt(params.multiple))) {
// ensure that maximal file number is greather then zero
params.multiple = 1;
}
params.allowedFilesize = this._normalizeFilesize(params.allowedFilesize);
// set params to uploader
this._eventQueue = [];
this.uploadCancelled = false;
this.params = params;
this._ensureDefaultValues();
this.files_count = 0;
this.files = new Array();
this.deleted = new Array()
this.uploadURL = params.uploadURL;
this.deleteURL = params.deleteURL;
this._resetCounters();
}
/* ==== Private methods ==== */
Uploader.prototype._ensureDefaultValues = function() {
// Upload backend settings
var $defaults = {
baseUrl: '',
uploadURL : '',
useQueryString : false,
requeueOnError : false,
httpSuccess : '',
filePostName : 'Filedata',
allowedFiletypes : '*.*',
allowedFiletypesDescription : 'All Files',
allowedFilesize : 0, // Default zero means "unlimited"
multiple : 0,
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
}
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 = '';
- for (var f in this.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._getMicroTime = function() {
var $now = new Date();
return Math.round($now.getTime() / 1000); // because miliseconds are returned too
}
Uploader.prototype._getEstimatedTime = function() {
return Math.ceil((100 - this.ProgressPercent) * this.ProgressTime / this.ProgressPercent);
}
Uploader.prototype._formatTime = function ($seconds) {
$seconds = parseInt($seconds);
var $minutes = Math.floor($seconds / 60);
if ($minutes < 10) $minutes = '0' + $minutes;
$seconds = $seconds % 60;
if ($seconds < 10) $seconds = '0' + $seconds;
return $minutes + ':' + $seconds;
}
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() {
if (this.params.buttonPlaceholderId !== false) {
// use given container
var holder = document.getElementById(this.params.buttonPlaceholderId);
}
else {
// create container on the fly
var holder = document.createElement('DIV');
document.body.appendChild(holder);
}
if (UploadsManager.useTransparency) {
document.getElementById($form_name).style.display = 'block';
}
// moving out progress div to overcome loosing of flash object after setting opacity
this.div = document.getElementById(this.id+'_progress');
var clone = this.div.cloneNode(true);
this.div.parentNode.removeChild(this.div)
this.div = document.body.appendChild(clone);
this.IconPath = this.params.IconPath ? this.params.IconPath : '../admin_templates/img/browser/icons';
this.filename = document.getElementById(this.id+'_progress_filename');
this.progress = document.getElementById(this.id+'_progress_progress');
this.elapsed = document.getElementById(this.id+'_progress_elapsed');
this.remaining = document.getElementById(this.id+'_progress_remaining');
this.percent = document.getElementById(this.id+'_percent');
this.done = document.getElementById(this.id+'_done');
// 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.onHandleEverything;
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', escape(this.params.wmode));
this.swf.addVariable('movieName', escape(this.flash_id));
this.swf.addVariable('fileUploadLimit', escape(this.params.multiple));
this.swf.addVariable('fileQueueLimit', escape(this.params.fileQueueLimit));
this.swf.addVariable('fileSizeLimit', escape(this.params.allowedFilesize)); // in kilobytes
this.swf.addVariable('fileTypes', escape(this.params.allowedFiletypes));
this.swf.addVariable('fileTypesDescription', escape(this.params.allowedFiletypesDescription));
this.swf.addVariable('uploadURL', escape(this.params.uploadURL));
// upload button appearance
this.swf.addVariable('buttonImageURL', escape(this.params.buttonImageURL));
this.swf.addVariable('buttonWidth', escape(this.params.buttonWidth));
this.swf.addVariable('buttonHeight', escape(this.params.buttonHeight));
this.swf.addVariable('buttonText', escape(this.params.buttonText));
this.swf.addVariable('buttonTextTopPadding', escape(this.params.buttonTextTopPadding));
this.swf.addVariable('buttonTextLeftPadding', escape(this.params.buttonTextLeftPadding));
this.swf.addVariable('buttonTextStyle', escape(this.params.buttonTextStyle));
this.swf.addVariable('buttonAction', escape(this.params.buttonAction));
this.swf.addVariable('buttonDisabled', escape(this.params.buttonDisabled));
this.swf.addVariable('buttonCursor', escape(this.params.buttonCursor));
if (UploadsManager._debugMode) {
this.swf.addVariable('debugEnabled', escape('true')); // flash var
}
if (this.params.buttonPlaceholderId === false) {
// only write flash, when button placeholder is not used
this.swf.write(holder);
this.flash = document.getElementById(this.flash_id);
}
if (this.params.urls != '') {
var urls = this.params.urls.split('|');
var names = this.params.names.split('|');
var sizes = this.params.sizes.split('|');
- for (var i in urls) {
+ for (var i = 0; i < urls.length; i++) {
var a_file = {
id : names[i],
name : names[i],
url : urls[i],
size: sizes[i],
uploaded : 1
}
this.files.push(a_file)
this.files_count++;
}
this.updateInfo();
}
}
Uploader.prototype.moveOutside = function() {
// move flash outside scroll_container, but keeps it's position on screen
if (!UploadsManager.useTransparency) {
// moving only needed when transparency us used (e.g. in admin)
return ;
}
var $new_container = document.createElement('DIV');
$new_container.id = this.params.buttonPlaceholderId + '_outside';
$new_container.style.position = 'absolute';
var $old_container = document.getElementById(this.params.buttonPlaceholderId);
$new_container.style.top = getRealTop($old_container) + 'px';
$new_container.style.left = getRealLeft($old_container) + 'px';
var $holder_dimensions = getDimensions($old_container);
$new_container.style.width = $holder_dimensions.innerWidth + 'px';
$new_container.style.height = $holder_dimensions.innerHeight + 'px';
document.body.appendChild($new_container);
this.swf.write($new_container); // write flash outside scroll_container
this.flash = document.getElementById(this.flash_id); // fix reference to flash object
this._moved = true;
}
+Uploader.prototype.remove = function() {
+ var id = this._moved ? this.params.buttonPlaceholderId + '_outside' : 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.syncBrowseButton = function() {
// when flash is moved outside scroll_container, keeps it's position on screen during scroll operations
if (!this._moved) {
return ;
}
var $scroll_container = UploadsManager._getScrollContainer();
var $scroll_container_top = getRealTop($scroll_container);
var $scroll_container_left = getRealLeft($scroll_container);
var $scroll_top = $scroll_container.scrollTop;
var $scroll_left = $scroll_container.scrollLeft;
var $old_container = document.getElementById(this.params.buttonPlaceholderId);
var $new_container = document.getElementById(this.params.buttonPlaceholderId + '_outside');
var $old_container_top = getRealTop($old_container);
var $old_container_left = getRealLeft($old_container);
if ($scroll_container_top <= $old_container_top - $scroll_top) {
// prevents moving outside $scroll_container
$new_container.style.top = ($old_container_top - $scroll_top) + 'px';
}
else {
// move browse button outside visible area
$new_container.style.top = -this.params.buttonHeight + 'px';
}
if ($scroll_container_left <= $old_container_left - $scroll_left) {
// prevents moving outside $scroll_container
$new_container.style.left = ($old_container_left - $scroll_left) + 'px';
}
else {
// move browse button outside visible area
$new_container.style.left = -this.params.buttonWidth + 'px';
}
}
Uploader.prototype.updateInfo = function() {
var $o = '';
var $icon = '';
var $filename = '';
var $delete_code = '';
- for (var f in this.files) {
+ for (var f = 0; f < this.files.length; f++) {
this.files[f].name.match(/\.([^.]*)$/);
var ext = RegExp.$1.toLowerCase();
$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';
$icon = '<img src="' + this.IconPath + '/' + $icon + '.gif"/>&nbsp;';
if (isset(this.files[f].uploaded)) {
$filename = '<a href="' + this.files[f].url + '" target="_new">' + this.files[f].name + '</a> (' + this._formatSize(this.files[f].size) + ')';
$delete_code = 'UploadsManager.DeleteFile(\'' + this.id + '\', \'' + this.files[f].name + '\')';
}
else {
$filename = this.files[f].name + ' (' + this._formatSize(this.files[f].size) + ')';
$delete_code = 'UploadsManager.CancelFile(\'' + UploadsManager._getUploader(this.files[f]).id + '\', \'' + this.files[f].id + '\')';
}
$o += '<tr><td>' + $icon + '</td><td style="font: 11px arial, sans-serif;">' + $filename + '&nbsp;[<a href="javascript:' + $delete_code + '">Delete</a>]</td></tr>';
}
document.getElementById(this.id+'_queueinfo').innerHTML = '<table cellpadding="0" cellspacing="0">' + $o + '</table>';
this._prepareFiles();
// sync position of all uploaders below current, because file queue height change will not affect their positions
UploadsManager.iterate('syncBrowseButton');
}
Uploader.prototype.removeFile = function (file) {
var n_files = new Array();
var count = 0;
var $new_total = 0;
- for (var f in this.files) {
+ 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]);
if (!isset(this.files[f].uploaded)) {
$new_total += file.size;
}
count++;
}
}
if (this.StartTime == 0) {
// don't update total during upload, because that breaks progress bar
this.total = $new_total;
}
this.files = n_files;
this.files_count = count;
this.updateInfo();
}
Uploader.prototype.hasQueue = function() {
- for (var f in this.files) {
+ for (var f = 0; f < this.files.length; f++) {
if (isset(this.files[f].uploaded)) {
continue;
}
return true;
}
return false;
}
Uploader.prototype.startUpload = function() {
UploadsManager.uploadCancelled = this.uploadCancelled = false;
if (!this.hasQueue()) {
return;
}
if (UploadsManager.useTransparency) {
Request.setOpacity(30, UploadsManager._getFormContainer());
}
if (!document.all) {
var $winW = window.innerWidth;
var $winH = window.innerHeight;
}
else {
var $winW = window.document.body.offsetWidth;
var $winH = window.document.body.offsetHeight;
}
var left = Math.round(($winW - 350)/2)+'px';
var top = Math.round(($winH - 110)/2)+'px';
this.div.style.top = top;
this.div.style.left = left;
this.div.style.display = 'block';
if (UploadsManager.useTransparency) {
Request.setOpacity(100, this.div);
}
this.StartTime = this._getMicroTime();
this.ProgressPercent = 0; // progress percent
this.ProgressTime = new Array();
this.uploaded = 0;
this.total = 0;
- for (var f in this.files) {
+ for (var f = 0; f < this.files.length; f++) {
if (isset(this.files[f].uploaded)) {
// get total bytes of non-uploaded files
continue;
}
this.total += this.files[f].size;
}
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');
}
UploadsManager.uploadCancelled = this.uploadCancelled = true;
}
Uploader.prototype.UploadFileStart = function(file) {
this.filename.innerHTML = file.name;
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]);
UploadsManager.iterate('disableBrowse', true); // disable all "Browse" buttons (not just for current uploader)!
// we can prevent user from adding any files here :)
this.callFlash('ReturnUploadStart', [true]);
}
Uploader.prototype.UploadProgress = function(file, bytesLoaded, bytesTotal) {
this.cur_file_uploaded = bytesLoaded;
var uploaded = this.uploaded + this.cur_file_uploaded;
this.ProgressTime = this._getMicroTime() - this.StartTime;
var speed = 0;
if (this.ProgressTime > 0) {
speed = Math.round(uploaded / this.ProgressTime * 100) / 100;
}
this.progress.innerHTML = this._formatSize(uploaded) + ' / ' + this._formatSize(this.total) + ' (' + this._formatSize(speed) + '/s)';
this.ProgressPercent = Math.round(uploaded / this.total * 100);
this.done.style.width = this.ProgressPercent + '%';
this.percent.innerHTML = this.ProgressPercent + '%';
this.elapsed.innerHTML = this._formatTime(this.ProgressTime );
this.remaining.innerHTML = this._formatTime( this._getEstimatedTime() );
}
Uploader.prototype.UploadFileComplete = function(file) {
this.uploaded += this.cur_file_uploaded;
- for (var f in this.files) {
+ for (var f = 0; f < this.files.length; f++) {
if (this.files[f].id == file.id) {
this.files[f].uploaded = 1;
this.files[f].temp = 1;
this.files[f].url = this.params.tmp_url.replace('#ID#', file.id).replace('#FILE#', file.name).replace('#FIELD#', this.params.field);
}
}
this.updateInfo();
// upload next file in queue
var $stats = this.callFlash('GetStats');
if ($stats.files_queued > 0 && !UploadsManager.uploadCancelled) {
this.callFlash('StartUpload');
} else {
// all files in queue are uploaded OR upload was cancelled globally
if (UploadsManager.uploadCancelled) {
// when upload was cancelled globally -> cancel it for any other uploader
this.cancelUpload();
}
UploadsManager.UploadQueueComplete(this);
}
}
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);
// Execute the next queued event
setTimeout(
function () {
self._executeNextEvent();
}, 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() {
this.disableBrowse(false);
UploadsManager.iterate('syncBrowseButton');
}
Uploader.prototype.disableBrowse = function($disabled) {
if (!isset($disabled)) {
$disabled = true;
}
this.queueEvent(
function() {
this.callFlash('SetButtonDisabled', [$disabled]);
}
);
}
Uploader.prototype._resetCounters = function() {
this.StartTime = 0; // time, when upload was started
this.ProgressPercent = 0; // upload progress in percents
this.ProgressTime = 0; // flash upload process callback times
this.total = 0; // total bytes to upload (from all queued files)
this.uploaded = 0; // total uploaded bytes (from all queued files)
}
Uploader.prototype.finalizeUpload = function() {
// hide progress bar only of uploader, that completed it's queue
this.div.style.display = 'none';
this._resetCounters();
}
\ No newline at end of file
Index: branches/RC/core/admin_templates/js/uploader/upload_manager.js
===================================================================
--- branches/RC/core/admin_templates/js/uploader/upload_manager.js (revision 11914)
+++ branches/RC/core/admin_templates/js/uploader/upload_manager.js (revision 11915)
@@ -1,449 +1,455 @@
function UploadsManager() {
addLoadEvent(
function() {
UploadsManager._initAll();
}
);
}
UploadsManager = new UploadsManager();
/* ==== Private Attributes ==== */
UploadsManager._nextId = 0;
UploadsManager._uploadersReady = 0;
UploadsManager._debugMode = false;
-UploadsManager._Uploaders = new Object();
+UploadsManager._Uploaders = {};
UploadsManager._singleUpload = true;
/* ==== Public Attributes ==== */
UploadsManager.useToolbar = true;
UploadsManager.formContainerId = '';
UploadsManager.useTransparency = true;
UploadsManager.uploadCancelled = false;
/* ==== Private methods ==== */
UploadsManager.setScrollEvents = function() {
var $scroll_container = this._getScrollContainer();
addEvent(
$scroll_container,
'scroll',
function(ev) {
UploadsManager.iterate('syncBrowseButton');
}
)
}
UploadsManager._nextFlashId = function() {
this._nextId++;
return 'uploaderflash' + this._nextId;
}
UploadsManager._getFormContainer = function() {
if (UploadsManager.formContainerId) {
return document.getElementById(UploadsManager.formContainerId);
}
return Form.Div;
}
UploadsManager._getScrollContainer = function() {
if (UploadsManager.formContainerId) {
return document.body;
}
return document.getElementById(Form.Div.id + '_container');
}
UploadsManager._initAll = function() {
this._createHooks();
for (var i in this._Uploaders) {
this._Uploaders[i].init();
}
}
UploadsManager.iterate = function($method) {
for (var i in this._Uploaders) {
var args = Array.prototype.slice.call(arguments); // convert to array
args.splice(0, 1); // remove method name
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;
}
UploadsManager._createHooks = function () {
if (typeof Application != 'undefined') {
Application.setHook(
'm:OnAfterFormInit',
function () {
UploadsManager.setScrollEvents();
}
);
}
// hooking to standard toolbar select button to peform auto-upload when Save is clicked
if (!UploadsManager.useToolbar || !isset(a_toolbar)) {
return ;
}
if (a_toolbar.ButtonExists('select')) {
var old_onclick = a_toolbar.Buttons['select'].onClick;
a_toolbar.Buttons['select'].onClick = function() {
UploadsManager.UploadAll(
function() {
if (UploadsManager._debugMode) {
if (!confirm('Proceed with form submitting?')) {
return ;
}
}
old_onclick();
}
);
}
}
}
/* ==== Public methods ==== */
UploadsManager.AddUploader = function(id, params) {
this._Uploaders[id] = new Uploader(id, params);
}
+UploadsManager.RemoveUploader = function(id) {
+ this._Uploaders[id].remove();
+ delete this._Uploaders[id];
+ this.iterate('syncBrowseButton');
+}
+
UploadsManager.DeleteFile = function(uploader_id, fname, confirmed) {
if (!confirmed && !confirm('Are you sure you want to delete this file?')) {
return;
}
var $uploader = this._Uploaders[uploader_id];
Request.makeRequest(
$uploader.deleteURL.replace('#FILE#', fname).replace('#FIELD#', $uploader.params.field),
false, '',
function(req, fname, $uploader) {
$uploader.removeFile({id:fname})
$uploader.deleted.push(fname);
$uploader.updateInfo();
},
function(req, fname, $uploader) {
alert('Error while deleting file');
},
fname, $uploader
);
}
UploadsManager.StartUpload = function(id) {
UploadsManager._singleUpload = true;
this._Uploaders[id].startUpload();
}
UploadsManager.CancelFile = function(id, file_id) {
this._Uploaders[id].callFlash('CancelUpload', [file_id]);
}
UploadsManager.UploadAll = function(onAllUploaded) {
if (!this._hasQueue()) {
onAllUploaded();
return ;
}
UploadsManager._singleUpload = false;
for (var i in this._Uploaders) {
// could raise problems, when simultanious uploads from diffrent uploaders are made
this._Uploaders[i].startUpload();
}
this.OnAllUploaded = onAllUploaded;
}
UploadsManager.UploadQueueComplete = function($uploader) {
var $all_uploaded = true; // all queued files were uploaded
var $all_processed = true; // all queued files were processed (uploaded OR cancelled)
for (var i in this._Uploaders) {
var $queue_owner = this._Uploaders[i].id == $uploader.id;
if (UploadsManager._singleUpload && !$queue_owner) {
// count only current uploader when single upload is made
continue;
}
if ($queue_owner) {
this._Uploaders[i].finalizeUpload();
}
var $empty_queue = !this._Uploaders[i].hasQueue();
$all_uploaded = $all_uploaded && $empty_queue;
$all_processed = $all_processed && ($empty_queue || this._Uploaders[i].uploadCancelled);
}
if ($all_processed) {
// enable all browse button, when upload is totally completed or cancelled
UploadsManager.iterate('disableBrowse', false);
}
if (UploadsManager.useTransparency && $all_processed) {
// remove transparency, when all uploaders are done
Request.setOpacity(100, UploadsManager._getFormContainer());
}
if ($all_uploaded && isset(this.OnAllUploaded) && !this.uploadCancelled) {
this.OnAllUploaded();
}
}
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);
this.total += file.size;
if (this.files[0].uploaded) {
UploadsManager.DeleteFile(UploadsManager._getUploader(file).id, this.files[0].name, true);
}
else {
this.callFlash('CancelUpload', [this.files[0].id]);
}
}
}
else {
// new file will not exceed allowed file number
this.files_count++;
this.files.push(file);
this.total += file.size;
}
this.updateInfo();
}
)
}
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);
}
};
if (!window.console || !console.firebug) {
// emulate FireBug Console in other browsers to see flash debug messages
window.console = {};
window.console.log = function (message) {
var console, documentForm;
try {
console = document.getElementById('SWFUpload_Console');
if (!console) {
documentForm = document.createElement('form');
document.getElementsByTagName('body')[0].appendChild(documentForm);
console = document.createElement('textarea');
console.id = 'SWFUpload_Console';
console.style.fontFamily = 'monospace';
console.setAttribute('wrap', 'off');
console.wrap = 'off';
console.style.overflow = 'auto';
console.style.width = '700px';
console.style.height = '350px';
console.style.margin = '5px';
documentForm.appendChild(console);
}
console.value += message + "\n";
console.scrollTop = console.scrollHeight - console.clientHeight;
} catch (ex) {
alert('Exception: ' + ex.name + ' Message: ' + ex.message);
}
};
}
\ No newline at end of file

Event Timeline