From 80c69abdb869f99eade2e60cca2440076f488a13 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 25 Jan 2010 21:10:43 +0000 Subject: [PATCH] APICHANGE: removed SWFUpload. Refactored Content Editors uploader to use standard uploader. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97489 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/HtmlEditorField.php | 43 ++++------------ javascript/HtmlEditorField.js | 80 ++++++++++++++++++++--------- javascript/tiny_mce_improvements.js | 6 --- 3 files changed, 66 insertions(+), 63 deletions(-) diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index a835fd126..88711c859 100755 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -198,6 +198,11 @@ class HtmlEditorField_Toolbar extends RequestHandler { function __construct($controller, $name) { parent::__construct(); + Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js"); + Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js"); + + Requirements::javascript(SAPPHIRE_DIR ."/thirdparty/jquery-form/jquery.form.js"); + Requirements::javascript(SAPPHIRE_DIR ."/javascript/HtmlEditorField.js"); $this->controller = $controller; $this->name = $name; @@ -210,9 +215,6 @@ class HtmlEditorField_Toolbar extends RequestHandler { * @return Form */ function LinkForm() { - Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js"); - Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js"); - $form = new Form( $this->controller, "{$this->name}/LinkForm", @@ -256,37 +258,17 @@ class HtmlEditorField_Toolbar extends RequestHandler { * @return Form */ function ImageForm() { - Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js"); - Requirements::javascript(CMS_DIR . '/thirdparty/swfupload/swfupload.js'); - Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js"); - Requirements::javascript(CMS_DIR . '/javascript/Upload.js'); - Requirements::css(CMS_DIR .'/css/TinyMCEImageEnhancement.css'); - Requirements::javascript(CMS_DIR . '/javascript/TinyMCEImageEnhancement.js'); - - /** - * @todo Adding folders via this screen is not enabled just yet as it is still - * a bit too buggy - wrossiter (09/11/09) - */ $form = new Form( $this->controller, "{$this->name}/ImageForm", new FieldSet( new LiteralField('Heading', '

' . _t('HtmlEditorField.CLOSE', 'close') . '' . _t('HtmlEditorField.IMAGE', 'Image') . '

'), new TreeDropdownField('FolderID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'), - new LiteralField('AddFolderOrUpload', - ' -
- ' . _t('HtmlEditorField.UPLOAD','Upload') . ' -
-
- -
' - ), + new CompositeField(new FieldSet( + new LiteralField('ShowUpload', '

'. _t('HtmlEditorField.SHOWUPLOADFORM', 'Upload File') .'

'), + new FileField("Files[0]" , _t('AssetAdmin.CHOOSEFILE','Choose file: ')), + new LiteralField('Response', '
') + )), new TextField('getimagesSearch', _t('HtmlEditorField.SEARCHFILENAME', 'Search by file name')), new ThumbnailStripField('FolderImages', 'FolderID', 'getimages'), new TextField('AltText', _t('HtmlEditorField.IMAGEALTTEXT', 'Alternative text (alt) - shown if image cannot be displayed'), '', 80), @@ -319,11 +301,6 @@ class HtmlEditorField_Toolbar extends RequestHandler { } function FlashForm() { - Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js"); - Requirements::javascript(CMS_DIR . '/javascript/Upload.js'); - Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js"); - Requirements::javascript(CMS_DIR . '/thirdparty/swfupload/swfupload.js'); - $form = new Form( $this->controller, "{$this->name}/FlashForm", diff --git a/javascript/HtmlEditorField.js b/javascript/HtmlEditorField.js index e34a1a67c..4a045254f 100644 --- a/javascript/HtmlEditorField.js +++ b/javascript/HtmlEditorField.js @@ -1,29 +1,61 @@ /** - * Simple TinyMCE initialisation + * Functions for HtmlEditorFields in the back end. + * Includes the JS for the ImageUpload forms. + * + * Relies on the jquery.form.js plugin to power the + * ajax / iframe submissions */ -if((typeof tinyMCE != 'undefined')) { - tinymce.PluginManager.load('advcode', '/some/dir/someplugin/editor_plugin.js'); - - tinyMCE.init({ - mode : "specific_textareas", - editor_selector : "htmleditor", - width: "100%", - auto_resize : false, - theme : "advanced", - theme_advanced_layout_manager: "SimpleLayout", - theme_advanced_toolbar_location : "top", - theme_advanced_toolbar_align : "left", - theme_advanced_toolbar_parent : "right", - plugins : "contextmenu,table,emotions,paste,-advcode,spellchecker", - blockquote_clear_tag : "p", - table_inline_editing : true, - theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,formatselect,separator,bullist,numlist,outdent,indent,blockquote,hr,charmap", - theme_advanced_buttons2 : "undo,redo,separator,cut,copy,paste,pastetext,pasteword,spellchecker,separator,advcode,search,replace,selectall,visualaid,separator,tablecontrols", - theme_advanced_buttons3 : "", +(function($) { + $(document).ready(function() { - safari_warning : false, - relative_urls : true, - verify_html : true + $("#Form_EditorToolbarImageForm .showUploadField a").click(function() { + if($(this).hasClass("showing")) { + $("#Form_EditorToolbarImageForm_Files-0").parents('.file').hide(); + $(this).text(ss.i18n._t('HtmlEditorField.ShowUploadForm', 'Upload File')).removeClass("showing"); + } + else { + $("#Form_EditorToolbarImageForm_Files-0").parents('.file').show(); + $(this).text(ss.i18n._t('HtmlEditorField.HideUploadForm', 'Hide Upload Form')).addClass("showing"); + } + }).show(); + + $("#Form_EditorToolbarImageForm_Files-0").change(function() { + $("#contentPanel form").ajaxForm({ + url: 'admin/assets/UploadForm?action_doUpload=1', + iframe: true, + + beforeSubmit: function(data) { + $("#UploadFormResponse").text("Uploading File...").addClass("loading").show(); + $("#Form_EditorToolbarImageForm_Files-0").parents('.file').hide(); + }, + success: function(data) { + $("#UploadFormResponse").text(data).removeClass("loading"); + $("#Form_EditorToolbarImageForm_Files-0").val("").parents('.file').show(); + + $("#FolderImages").html('

'+ ss.i18n._t('HtmlEditorField.Loading', 'Loading') + '

'); + + var ajaxURL = 'admin/EditorToolbar/ImageForm'; + + $.get(ajaxURL, { + action_callfieldmethod: "1", + fieldName: "FolderImages", + ajax: "1", + methodName: "getimages", + folderID: $("#Form_EditorToolbarImageForm_FolderID").val(), + searchText: $("#Form_EditorToolbarImageForm_getimagesSearch").val(), + cacheKillerDate: parseInt((new Date()).getTime()), + cacheKillerRand: parseInt(10000 * Math.random()) + }, + function(data) { + $("#FolderImages").html(data); + + $("#FolderImages").each(function() { + Behaviour.apply(this); + }) + }); + } + }).submit(); + }); }); -} +})(jQuery); \ No newline at end of file diff --git a/javascript/tiny_mce_improvements.js b/javascript/tiny_mce_improvements.js index c7dee82b2..209e3d7fe 100755 --- a/javascript/tiny_mce_improvements.js +++ b/javascript/tiny_mce_improvements.js @@ -646,12 +646,6 @@ function reselectImage(transport) { $('Image').reapplyBehaviour(); this.addToTinyMCE = this.addToTinyMCE.bind(this); - var childNodes = $('Image').childNodes[0].childNodes; - var newImages = $A(childNodes).slice(childNodes.length - this.filesUploaded); - newImages.each(function(item) { - tinyMCEImageEnhancement.addToTinyMCE(item.childNodes[0]); - }); - tinyMCEImageEnhancement.processInProgress = false; } function imageEditorClosed() {