Commit f5582e9f authored by Robert Lyon's avatar Robert Lyon

Bug 1530613: Getting excluded tags to work with Select2 4.0.1

behatnotneeded existing tests should be enough

Change-Id: I6316c6301c703353928c9e6210e02cdfc25151a8
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
Signed-off-by: Aaron Wells's avatarAaron Wells <aaronw@catalyst.net.nz>
(cherry picked from commit 1f9bbefe)
parent 24a27e88
......@@ -329,10 +329,10 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
if ($tagrecords) {
foreach ($tagrecords as $tag) {
if ($tag->tagtype == PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE) {
$tagselect[] = $tag->tag;
$tagselect[] = hsc($tag->tag);
}
else {
$tagselect[] = '-' . $tag->tag;
$tagselect[] = '-' . hsc($tag->tag);
}
}
}
......@@ -340,9 +340,12 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
$excludetag = get_string('excludetag', 'blocktype.blog/taggedposts');
$formatSelection = <<<EOF
function (item, container) {
item.title = item.id;
if (item.id[0] == "-") {
container.parent().addClass("tagexcluded");
item.text = '<span class="sr-only">{$excludetag}</span>' + item.text;
container.addClass("tagexcluded");
if (!item.text.match(/sr\-only/)) {
return '<span class="sr-only">{$excludetag}</span>' + item.text;
}
}
return item.text;
}
......@@ -361,7 +364,11 @@ EOF;
'blockconfig' => true,
'help' => true,
'mininputlength' => 0,
'extraparams' => array('formatSelection' => "$formatSelection"),
'extraparams' => array(
'templateSelection' => "$formatSelection",
// We'll escape the text on the PHP side, so select2 doesn't need to
'escapeMarkup' => 'function(textToEscape) { return textToEscape; }',
),
);
$elements['count'] = array(
'type' => 'text',
......@@ -396,7 +403,9 @@ EOF;
return <<<EOF
jQuery(function($) {
$('#instconf_tagselect').on('change', function() {
updatetagbuttons();
// Need a small delay so that MultipleSelection.prototype.update will
// fire before updatetagbuttons
setTimeout(updatetagbuttons, 1000);
});
updatetagbuttons();
......@@ -406,12 +415,12 @@ EOF;
e.stopPropagation();
e.preventDefault();
var li = $(this).parent();
var val = $('#instconf_tagselect').select2('val');
var index = val.indexOf(li[0].title);
if (index > -1) {
val.splice(index, 1);
}
$('#instconf_tagselect').select2('val', val);
var new_data = jQuery.grep($('#instconf_tagselect').select2('data'), function (value) {
if (value['id'] == li[0].title) {
$("#instconf_tagselect option[value='" + value['id'] + "']").remove();
$('#instconf_tagselect').trigger('change');
}
});
});
}
});
......
......@@ -51,8 +51,10 @@ while ($alltags !== false && $more && count($tmptags) < $tagsperpage) {
continue;
}
if (stripos($tag->tag, $request) !== false || $request === '') {
$tmptags[] = (object) array('id' => $tagexcluded . $tag->tag,
'text' => $tag->tag);
$tmptags[] = (object) array(
'id' => hsc($tagexcluded . $tag->tag),
'text' => hsc($tag->tag),
);
}
}
$page++;
......
......@@ -221,6 +221,9 @@ Version: 4.0.0 Timestamp: Jul 1 13:43:36 EDT 2015
white-space: nowrap;
text-overflow: ellipsis;
width: auto; }
.select2-container--default .select2-selection--multiple .tagexcluded {
background: #ffd9d9 !important;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
background: none;
border: none;
......
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