Commit da4a7ac9 authored by Robert Lyon's avatar Robert Lyon Committed by Aaron Wells
Browse files

Bug 1564733: Moving tag select functions to filebrowser



And tidying up a hardcoded string

behatnotneeded

Change-Id: I6f42d57adf414c94b6522602742c4f36d4d7367f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent f4502a3c
......@@ -303,7 +303,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
$(self.id + '_edit_allowcomments').checked = self.filedata[id].allowcomments;
$(self.id + '_edit_tags').selectedIndex = -1;
tag_select2_clear(self.id + '_edit_tags');
self.tag_select2_clear(self.id + '_edit_tags');
if (self.filedata[id].tags) {
for (var x in self.filedata[id].tags) {
var option = document.createElement("option");
......@@ -326,7 +326,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
// $(self.id + '_edit_artefact').value = id; // Changes button text in IE
setNodeAttribute(self.id + '_edit_artefact', 'name', self.id + '_update[' + id + ']');
tag_select2(self.id + '_edit_tags');
self.tag_select2(self.id + '_edit_tags');
var edit_row = removeElement(self.id + '_edit_row');
var this_row = getFirstParentByTagAndClassName(this, 'tr');
insertSiblingNodesAfter(this_row, edit_row);
......@@ -348,6 +348,51 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
return false;
}
this.tag_select2_clear = function (id) {
var select2 = jQuery('#' + id).data('select2');
if (select2) {
jQuery('#' + id).select2();
}
jQuery('#' + id).find('option').remove();
}
this.tag_select2 = function (id) {
var placeholder = get_string('defaulthint');
jQuery('#' + id).select2({
ajax: {
url: self.config.wwwroot + "json/taglist.php",
dataType: 'json',
type: 'POST',
delay: 250,
data: function(params) {
return {
'q': params.term,
'page': params.page || 0,
'sesskey': self.config.sesskey,
'offset': 0,
'limit': 10,
}
},
processResults: function(data, page) {
return {
results: data.results,
pagination: {
more: data.more
}
};
}
},
language: globalconfig.select2_lang,
multiple: true,
width: "300px",
allowClear: false,
placeholder: placeholder,
minimumInputLength: 1,
tags: true,
});
}
this.edit_init = function () { }
this.browse_init = function () {
......
......@@ -168,6 +168,7 @@ class PluginArtefactFile extends PluginArtefact {
'mahara' => array(
'remove',
'cancel',
'defaulthint',
),
'artefact.file' => array(
'confirmdeletefile',
......
......@@ -781,48 +781,6 @@ function keepElementInViewport(element) {
}
}
function tag_select2_clear(id) {
var select2 = jQuery('#' + id).data('select2');
if (select2) {
jQuery('#' + id).select2();
}
jQuery('#' + id).find('option').remove();
}
function tag_select2(id) {
jQuery('#' + id).select2({
ajax: {
url: config.wwwroot + "json/taglist.php",
dataType: 'json',
type: 'POST',
delay: 250,
data: function(params) {
return {
'q': params.term,
'page': params.page || 0,
'sesskey': config.sesskey,
'offset': 0,
'limit': 10,
}
},
processResults: function(data, page) {
return {
results: data.results,
pagination: {
more: data.more
}
};
}
},
multiple: true,
width: "300px",
allowClear: false,
placeholder: "Type in a search term",
minimumInputLength: 1,
tags: true,
});
}
function progressbarUpdate(artefacttype, remove) {
if (! $('progressbarwrap')) {
return;
......
......@@ -154,7 +154,7 @@ function pieform_element_autocomplete_language() {
* @param array $element The element to get <head> code for
* @return array An array of HTML elements to go in the <head>
*/
function pieform_element_autocomplete_get_headdata($element) {
function pieform_element_autocomplete_get_headdata() {
global $THEME;
$cssfile = $THEME->get_url('style/select2.css');
$lang = pieform_element_autocomplete_language();
......
......@@ -10,7 +10,7 @@
*/
defined('INTERNAL') || die();
define('FILEBROWSERS', 1);
/**
* Browser for files area.
*
......
......@@ -589,6 +589,15 @@ EOF;
$smarty->assign('MOBILE', $SESSION->get('mobile'));
$smarty->assign('HANDHELD_DEVICE', $SESSION->get('handheld_device'));
if (defined('FILEBROWSERS') ||
(defined('SECTION_PAGE') && SECTION_PAGE == 'blocks')) {
// Need to add the headers for select2 here so filebrowser has correct language
require_once(get_config('libroot') . 'form/elements/autocomplete.php');
$select2lang = pieform_element_autocomplete_language();
$select2headdata = pieform_element_autocomplete_get_headdata();
$headers = array_merge($headers, $select2headdata);
$smarty->assign('select2_language', $select2lang);
}
$sitename = get_config('sitename');
if (!$sitename) {
......
......@@ -742,3 +742,7 @@ html[dir="rtl"] .select2-container-multi .select2-search-choice-close {
background-position: 100% -21px !important;
}
}
.select2-container.select2-container--default.select2-container--open {
z-index: 2001;
}
\ No newline at end of file
......@@ -18,7 +18,8 @@
'mobile': {if $MOBILE}1{else}0{/if},
'handheld_device': {if $HANDHELD_DEVICE}1{else}0{/if},
'cc_enabled': {$CC_ENABLED|intval},
'mathjax': {ifconfig key=mathjax}1{else}0{/ifconfig}
'mathjax': {ifconfig key=mathjax}1{else}0{/ifconfig},
'select2_lang': '{$select2_language}'
{literal}}{/literal};
</script>
{$STRINGJS|safe}
......
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