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