From 73ba193ad6082914c2694a3f700341adf2a354c5 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 12 Apr 2010 23:36:50 +0000 Subject: [PATCH] ENHANCEMENT: Select the uploaded image after uploading by default. #4962 (from r97765) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102531 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/HtmlEditorField.php | 3 ++- javascript/HtmlEditorField.js | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 51877aab7..de963cef0 100755 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -293,7 +293,8 @@ class HtmlEditorField_Toolbar extends RequestHandler { 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 LiteralField('Response', '
'), + new HiddenField('UploadMode', 'Upload Mode', 'CMSEditor') // used as a hook for doUpload switching )), new TextField('getimagesSearch', _t('HtmlEditorField.SEARCHFILENAME', 'Search by file name')), new ThumbnailStripField('FolderImages', 'FolderID', 'getimages'), diff --git a/javascript/HtmlEditorField.js b/javascript/HtmlEditorField.js index 625c4ea7c..00a873aa2 100644 --- a/javascript/HtmlEditorField.js +++ b/javascript/HtmlEditorField.js @@ -11,7 +11,7 @@ /** * On page refresh load the initial images (in root) */ - if($("#FolderImages").length > 0 && $("body.CMSMain").length > 0) loadImages(); + if($("#FolderImages").length > 0 && $("body.CMSMain").length > 0) loadImages(false); /** * Show / Hide the Upload Form @@ -25,37 +25,36 @@ $("#Form_EditorToolbarImageForm_Files-0").parents('.file').show(); $(this).text(ss.i18n._t('HtmlEditorField.HideUploadForm', 'Hide Upload Form')).addClass("showing"); } + return false; }).show(); /** * On folder change - lookup the new images */ $("#Form_EditorToolbarImageForm_Files-0").change(function() { - $("#contentPanel form").ajaxForm({ + $("#contentPanel #Form_EditorToolbarImageForm").ajaxForm({ url: 'admin/assets/UploadForm?action_doUpload=1', iframe: true, - + dataType: 'json', 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"); + $("#UploadFormResponse").text("").removeClass("loading"); $("#Form_EditorToolbarImageForm_Files-0").val("").parents('.file').show(); - $("#FolderImages").html('

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

'); + $("#FolderImages").html('

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

'); - loadImages(); + loadImages(data); } }).submit(); }); /** * Loads images from getimages() to the thumbnail view. It's called on - * - * */ - function loadImages() { + function loadImages(params) { console.debug(this); $.get('admin/EditorToolbar/ImageForm', { action_callfieldmethod: "1", @@ -72,7 +71,11 @@ $("#FolderImages").each(function() { Behaviour.apply(this); - }) + }); + + if(params) { + $("#FolderImages a[href*="+ params.Filename +"]").click(); + } }); } });