Commit c1cbf2a6 authored by Nigel McNie's avatar Nigel McNie
Browse files

A few improvements to the tag control:

* If you have not tags, it now tells you rather than just mysteriously disappearing
* If you click on a tag and it's already in the input box, it is removed instead, giving a nice toggle ability. It handles the commas/spacing too.
* Removed a debugging line that had been there for ever.
parent dc178802
......@@ -591,7 +591,6 @@ function create_tags_control(name, value, options) {
// this function takes an existing input element and augments it
function augment_tags_control(elem, returnContainer) {
elem = getElement(elem);
log('augment_tags_control(', elem, ')');
var tagContainer = DIV();
// setElementDimensions(tagContainer, {'w': getElementDimensions(elem).w});
......@@ -603,24 +602,41 @@ function augment_tags_control(elem, returnContainer) {
replaceChildNodes(tagContainer, get_string('loading') + ' ', IMG({'src':get_themeurl('images/loading.gif')}));
sendjsonrequest(config.wwwroot + 'json/taglist.php', {}, 'GET', function (data) {
replaceChildNodes(tagContainer);
forEach(data, function(tag) {
var tagLink = A({'href':''}, tag.tag);
connect(tagLink, 'onclick', function(e) {
e.stop();
if (some(elem.value.split(/ *, */), function(t) { return t == tag.tag; })) {
return;
}
if (elem.value.match(/^ *$/) || elem.value.match(/, *$/)) {
elem.value += tag.tag;
}
else {
elem.value += ', ' + tag.tag;
}
if (data.length == 0) {
appendChildNodes(tagContainer, get_string('youhavenottaggedanythingyet'));
}
else {
var tagData = [];
forEach(data, function(tag) {
var tagLink = A({'href':''}, tag.tag);
connect(tagLink, 'onclick', function(e) {
e.stop();
if (some(elem.value.split(/ *, */), function(t) { return t == tag.tag; })) {
// If at the start of the string, remove it and the comma/spaces after
elem.value = elem.value.replace(new RegExp('^' + tag.tag + ',? *'), '');
// Otherwise, remove the comma/spaces before it
elem.value = elem.value.replace(new RegExp(', *' + tag.tag), '');
return;
}
if (elem.value.match(/^ *$/) || elem.value.match(/, *$/)) {
elem.value += tag.tag;
}
else {
elem.value += ', ' + tag.tag;
}
});
tagData.push([tagLink, '\u00A0(', tag.count, ')']);
tagData.push(', ');
//appendChildNodes(tagContainer, tagLink, '\u00A0(', tag.count, ')');
});
appendChildNodes(tagContainer, tagLink, '\u00A0(', tag.count, '), ');
});
// Remove the last comma
tagData.pop();
forEach(tagData, function(i) {
appendChildNodes(tagContainer, i);
});
}
});
});
......
......@@ -74,6 +74,7 @@ $string['select'] = 'Select';
$string['tags'] = 'Tags';
$string['tagsdesc'] = 'Enter comma separated tags for this item.';
$string['tagsdescprofile'] = 'Enter comma separated tags for this item. Items tagged with \'profile\' are displayed in your sidebar.';
$string['youhavenottaggedanythingyet'] = 'You have not tagged anything yet';
$string['selfsearch'] = 'Search My Portfolio';
$string['ssopeers'] = 'SSO Peers';
......
......@@ -458,6 +458,7 @@ function jsstrings() {
'sessiontimedout',
'loginfailed',
'home',
'youhavenottaggedanythingyet',
),
),
'tablerenderer' => array(
......
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