From 87dfd714b21400899083e5adc13ae3d4a224990e Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 11 Nov 2009 07:06:45 +0000 Subject: [PATCH] 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 --- images/swf-upload-button-small.jpg | Bin 0 -> 1916 bytes javascript/CMSMain_upload.js | 9 --- javascript/TinyMCEImageEnhancement.js | 95 +++++++++----------------- javascript/Upload.js | 39 ++++++++--- 4 files changed, 62 insertions(+), 81 deletions(-) create mode 100644 images/swf-upload-button-small.jpg diff --git a/images/swf-upload-button-small.jpg b/images/swf-upload-button-small.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8655b8afebb4101a55e0892d83eb8c3f822fc184 GIT binary patch literal 1916 zcma)$dojE!_^~z-znUb2 zMsmyMl4iF2x(FGDG45TcEGm~0Y1V0fzdgJE{oc=c&Uv5LbDrmU%LnA+0C!-&!+rq4 z0AQ~bkWT~rzR2Uju>b-H0D$Ehngz<%>@eS-09&+1Ao&nD15gMA0*OE&k*Ia3wN_L> zp%fIc7>ptYgT-OL35Qiy!Ko-?2?QdMKp<;rX_0mQ5`;#hm9R=A9FC-^idWVAYw-UX zxd`ADfIYB)LwEqgLvTDKZv$KaU~mY6)^h$=Fa&^*a1{C<@Y@W+0T={Bz>#nTq|%=R z2FD}7#`VbU1fsRBDhho_Y@qd5wZ67Zm z1Xwt<76*<8d%?0}*W1&a#3Z*U>IwaPuUd-4rz~&g8PplNBO_(qHGYF}&B0>Hpe6KBvV97cZERE2>17;n*^>->I3`en;uKn_u71dGo$5 zTyQ%*t68w+=5=Ef|LPS>;qwBuFHbAuEois1`&3`5o0)pkEpr%oN-lm7?eX|76_=>D z<(~d2F*co)0kw|vjNDGk%O%cBY$vnnax6MNj2TryeQ6YEVigxI{&WD2y*9?kqI2yI zU_eIA2dL2GO4ReFX~F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ji= z)XtFu?7VYYL}FxB0)a1eTdi)3>m-(s^tRk;nCX>qS1cay;wK$mt^sv@k#3iRkNT7g zpE+5k)-4;I*Ld0byx&!ODE1u~4b{TMRDyD-EpqvsR1 xYnwlDCUDcX($yv!9D_%!ntY5iuX{a|N#F2>(V>hl%>m{U?iteRd7r&<*&m8~H$VUY literal 0 HcmV?d00001 diff --git a/javascript/CMSMain_upload.js b/javascript/CMSMain_upload.js index a086add2..1960ae17 100644 --- a/javascript/CMSMain_upload.js +++ b/javascript/CMSMain_upload.js @@ -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'); diff --git a/javascript/TinyMCEImageEnhancement.js b/javascript/TinyMCEImageEnhancement.js index ea6dc96f..667e9cdd 100644 --- a/javascript/TinyMCEImageEnhancement.js +++ b/javascript/TinyMCEImageEnhancement.js @@ -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() { diff --git a/javascript/Upload.js b/javascript/Upload.js index 75300928..905c1ab7 100644 --- a/javascript/Upload.js +++ b/javascript/Upload.js @@ -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