Commit 1c596642 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1507808: TinyMce Image browser to remember selected option



When we go back to edit the image

behatnotneeded

Change-Id: I54c44461b8c148fa4a6386060d09dba3ee5d8984
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5edaff77
......@@ -681,10 +681,10 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
this.update_metadata_to_selected_list = function () {
forEach(getElementsByTagAndClassName('input', 'btn_edit', self.id + '_filelist'), function (elem) {
forEach(getElementsByTagAndClassName('button', 'btn-default', self.id + '_filelist'), function (elem) {
var id = elem.name.replace(/.*_edit\[(\d+)\]$/, '$1');
var row = getFirstParentByTagAndClassName(elem, 'tr');
var newtitle = getFirstElementByTagAndClassName('a', null, row);
var newtitle = getFirstElementByTagAndClassName('span', 'inner-link', row);
var newdescription = getFirstElementByTagAndClassName('td', 'filedescription', row);
if (self.selecteddata[id]) {
var hiddeninput = $(self.id + '_selected[' + id + ']');
......
......@@ -31,8 +31,16 @@ tinymce.PluginManager.add('imagebrowser', function(editor) {
dom = editor.dom,
imgElm = editor.selection.getNode();
jQuery('body').addClass('modal-open');
var selected = null;
if (imgElm.nodeName == 'IMG' && !imgElm.getAttribute('data-mce-object') && !imgElm.getAttribute('data-mce-placeholder')) {
// existing values
var urlquerystr = dom.getAttrib(imgElm, 'src').match(/\?.+/)[0];
var urlparts = urlquerystr.split('&');
for (var x in urlparts) {
if (urlparts[x].match('file=')) {
selected = urlparts[x].split('=')[1];
}
}
data = {
src: dom.getAttrib(imgElm, 'src'),
alt: dom.getAttrib(imgElm, 'alt')//,
......@@ -98,12 +106,16 @@ tinymce.PluginManager.add('imagebrowser', function(editor) {
'blogpostid': blogpostid,
'group': group,
'institution': institution,
'selected': selected,
'change': 1};
sendjsonrequest(config['wwwroot'] + 'json/imagebrowser.json.php', pd, 'POST', function(ibdata) {
addImageBrowser(ibdata);
// fill url field
// fill url field and the selected image's title in the heading of the 'Image' expander
jQuery(formname + '_url').val(data.src);
if (selected) {
jQuery(formname + '_artefactfieldset_container').find('.collapse-indicator').before('<span class="text-small text-midtone file-name"> - ' + getSelectedObject().title + '</span>');
}
});
function addImageBrowser(configblock) {
......@@ -199,6 +211,16 @@ tinymce.PluginManager.add('imagebrowser', function(editor) {
return url;
}
function getSelectedObject() {
// As we can only select one image at a time we can accept the first in the array as selected item
var keys = Object.keys(window.imgbrowserconf_artefactid.selecteddata);
var selected = window.imgbrowserconf_artefactid.selecteddata[keys[0]];
if (selected) {
return selected;
}
return null;
}
function onSubmitForm(e) {
// Find which submit button was clicked
var clickedButton = jQuery('form' + formname + " input[type=submit][clicked=true]");
......@@ -245,12 +267,12 @@ tinymce.PluginManager.add('imagebrowser', function(editor) {
if (data.style === '') {
data.style = null;
}
// As we can only select one image at a time we can accept the first in the array as selected item
var keys = Object.keys(window.imgbrowserconf_artefactid.selecteddata);
var selected = window.imgbrowserconf_artefactid.selecteddata[keys[0]];
var selected = getSelectedObject();
if (selected) {
data.alt = selected.description ? selected.description : selected.title;
}
data = {
src: data.src,
alt: data.alt,
......
......@@ -19,6 +19,7 @@ $forumpostid = param_integer('post', 0);
$groupid = param_integer('group', 0);
$institution = param_alphanum('institution', 0);
$blogid = param_alphanum('blogid', 0);
$fileid = param_alphanum('selected', null);
$changebrowsetab = param_integer('imgbrowserconf_artefactid_changeowner', 0);
// Folder value is 0 when returning to Home folder
$changefolder = param_exists('imgbrowserconf_artefactid_changefolder')? true : false;
......@@ -51,7 +52,8 @@ if ($change) {
$ib = new ImageBrowser(array('view' => $viewid,
'post' => $forumpostid,
'group' => $groupid,
'institution' => $institution));
'institution' => $institution,
'selected' => $fileid));
try {
$returndata = $ib->render_image_browser();
json_reply(false, array('data' => $returndata));
......
......@@ -24,6 +24,7 @@ class ImageBrowser {
private $institution;
private $post;
private $blocktype;
private $selected;
private $configdata = array();
public function __construct($data) {
......@@ -109,6 +110,7 @@ class ImageBrowser {
'title' => get_string('url'),
'size' => 50,
);
$selected = !empty($this->selected) ? array($this->selected) : null;
$elements['artefactfieldset'] = array(
'type' => 'fieldset',
'collapsible' => true,
......@@ -116,7 +118,7 @@ class ImageBrowser {
'legend' => get_string('image'),
'class' => 'select-file mtl',
'elements' => array(
'artefactid' => self::config_filebrowser_element($this, null)
'artefactid' => self::config_filebrowser_element($this, $selected)
)
);
$configdata = $this->get('configdata');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment