FEATURE: reenabled the ability to upload images from the insert image tab. Still commented out while le a couple of tweaks are made

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@91302 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Will Rossiter 2009-11-11 07:06:45 +00:00
parent 9c67f3e028
commit 87dfd714b2
4 changed files with 62 additions and 81 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -6,15 +6,6 @@
CMSMain_upload = Class.create();
CMSMain_upload.prototype = {
initialize: function() {
// This is disabled until we get it working reliably
return;
// We require flash 9
pv = getFlashPlayerVersion();
if(pv.major < 9) return;
// Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
if(pv.major == 9 && pv.minor == 0 && pv.rev < 64) return;
// If those 2 checks pass, we can provide upload capabilities to the user
this.iframe = window.top.document.getElementById('AssetAdmin_upload');

View File

@ -7,21 +7,29 @@ TinyMCEImageEnhancement.prototype = {
initialize: function() {
this.filesUploaded = 0;
this.processInProgress = false;
Event.observe(window,'load',this.onWindowLoad.bind(this));
},
addListeners: function() {
$('Form_EditorToolbarImageForm_FolderID').value = "";
Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
this.onLoad();
},
/**
onLoad: function() {
this.upload = new Upload({
fileUploadLimit : '6',
button_image_url : '../cms/images/swf-upload-button-small.jpg',
button_width : 59,
button_height: 18,
fileQueued: this.uploadFileQueuedCallback.bind(this),
fileComplete: this.uploadFileCompleteCallback.bind(this),
queueComplete: this.uploadQueueCompleteCallback.bind(this)
});
},
/**
* Method creates HTML element, only reason for this method is DRY.
*/
addElement: function(tag, className, parent, properties) {
var e = document.createElement(tag);
Element.addClassName(e,className);
@ -30,17 +38,6 @@ TinyMCEImageEnhancement.prototype = {
return e;
},
onUpload: function(event) {
Event.stop(event);
if(!this.processInProgress) {
if(this.getParentID() != 'root') {
this.upload.browse();
} else {
statusMessage("Please choose folder","bad");
}
}
},
/**
* Called when user clicks "add folder" anchor.
*/
@ -115,51 +112,25 @@ TinyMCEImageEnhancement.prototype = {
return false;
},
/**
* Called on window.onload
*/
onWindowLoad: function() {
// Due to a bug in the flash plugin on Linux and Mac,
//we need at least version 9.0.64 to use SWFUpload
// see http://open.silverstripe.com/ticket/3023
pv = getFlashPlayerVersion();
if(pv.major < 9 || pv.major > 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none';
if($('PipeSeparator')) $('PipeSeparator').style.display = 'none';
if($('UploadGroup')) $('UploadGroup').style.display = 'none';
return;
}
if($('FolderID') != null) {
if($('SecurityID')) var securityid=$('SecurityID').value;
else var securityid=null;
this.upload = new Upload(
{
fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;',
fileTypesDescription : 'Image files',
fileUploadLimit : '100',
securityID : securityid,
beginUploadOnQueue : true,
buildUI : this.addListeners.bind(this),
fileQueued : this.uploadFileQueuedCallback.bind(this),
fileComplete : this.uploadFileCompleteCallback.bind(this),
queueComplete : this.uploadQueueCompleteCallback.bind(this)
}
);
uploadFileQueuedCallback: function(file,queueLength) {
if(this.getParentID() == "root") {
statusMessage("Please choose folder","bad");
}
else {
this.processInProgress = true;
this.upload.setFolderID(this.getParentID());
this.upload.addFileParam(file.id,'ID',this.folderID);
this.upload.addFileParam(file.id,'action_doUpload','1');
this.upload.addFileParam(file.id,'Files',file.name);
this.upload.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
$('UploadFiles').innerHTML = "Uploading Files...("+ this.filesUploaded +")";
this.upload.swfu.startUpload(file.id);
}
},
uploadFileQueuedCallback: function(file,queueLength) {
this.processInProgress = true;
this.upload.setFolderID(this.getParentID());
$('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload();
this.upload.startUpload();
},
uploadFileCompleteCallback: function(file,serverData) {
Element.addClassName($('UploadFiles'),'link');//Safari hack
$('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
this.filesUploaded++;
$('UploadFiles').innerHTML = 'Uploading Files..... ('+ this.filesUploaded +")";
},
uploadQueueCompleteCallback: function() {

View File

@ -14,23 +14,33 @@ Upload.prototype = {
* @param params object contains all configuration data for upload.
*/
initialize: function(params) {
this.filesUploaded = 0;
this.filesToUpload = 0;
this.folderID = 'root';
this.uploadInProgress = false;
this.uploadMessage = '';
this.queueComplete = this.uploadQueueCompleteCallback.bind(this);
this.fileComplete = this.uploadFileCompleteCallback.bind(this);
this.fileQueued = this.uploadFileQueuedCallback;
if(typeof params.fileSizeLimit != 'undefined') this.setFileSizeLimit = params.fileSizeLimit; else this.fileSizeLimit = '30720';
if(typeof params.fileTypes != 'undefined') this.fileTypes = params.fileTypes; else this.fileTypes = '*.*';
if(typeof params.fileTypesDescription != 'undefined') this.fileTypesDescription = params.fileTypesDescription; else this.fileTypesDescription = 'All Files';
if(typeof params.fileUploadLimit != 'undefined') this.fileUploadLimit = params.fileUploadLimit; else this.fileUploadLimit = '6';
if(typeof params.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = false;
if(typeof params.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = true;
if(typeof params.fileQueued != 'undefined') this.fileQueued = params.fileQueued;
if(typeof params.fileProgress != 'undefined') this.fileProgress = params.fileProgress; else this.fileProgress = Prototype.emptyFunction;
if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled;
if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete ;
if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete;
if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete;
if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI;
if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
if(typeof params.button_image_url != 'undefined') this.buttonImageURL = params.button_image_url;
if(typeof params.button_width != 'undefined') this.buttonWidth = params.button_width;
if(typeof params.button_height != 'undefined') this.buttonHeight = params.button_height;
this.onLoad();
},
@ -39,6 +49,7 @@ Upload.prototype = {
*
*/
onLoad: function() {
path = this.getBasePath();
sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
this.swfu = new SWFUpload({
@ -51,19 +62,23 @@ Upload.prototype = {
begin_upload_on_queue : this.beginUploadOnQueue,
use_server_data_event : true,
validate_files: false,
file_queued_handler : this.uploadFileQueuedCallback.bind(this),
upload_success_handler : this.uploadFileCompleteCallback.bind(this),
button_placeholder_id: "SWFUploadButton",
file_queued_handler : this.fileQueued,
upload_success_handler : this.queueComplete,
file_dialog_complete_handler : this.fileCompleted,
upload_progress_handler: this.uploadFileProgressCallback.bind(this),
error_handler : this.uploadErrorCallback.bind(this),
file_validation_handler : Prototype.emptyFunction,
file_cancelled_handler: Prototype.emptyFunction,
flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file
button_image_url : this.buttonImageURL,
button_width : this.buttonWidth,
button_height : this.buttonHeight,
flash_url : 'jsparty/SWFUpload/swfupload.swf', // Relative to this file
swfupload_loaded_handler: this.buildUI.bind(this),
debug: false
});
},
},
/**
* Retrieves base path from URL.
@ -95,7 +110,7 @@ Upload.prototype = {
*/
buildUI: function() {
this.customBuildUI();
return;
},
/**
@ -107,7 +122,7 @@ Upload.prototype = {
uploadFileQueuedCallback: function(file,queueLength) {
this.filesToUpload++;
this.fileQueued(file, queueLength);
// this.swfu.fileQueued(file, queueLength);
this.addFileParam(file);
},
@ -151,6 +166,10 @@ Upload.prototype = {
this.fileProgress(file, bytes_complete);
},
uploadQueueCompleteCallback: function(event) {
},
/**
* Called on error.
* @param error_code int