Moodle

autocomplete tags (interests) in user's profile edit page

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Not a bug
  • Affects Version/s: 1.9
  • Fix Version/s: None
  • Component/s: Administration, AJAX, Tags, Usability
  • Labels:
    None
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE

Description

enable autocomplete tags (interests) when editing user's profile (properties)
(functionality was copied from "edit tag page" )

two files are involved in the patch: user/editadvanced.php and user/editlib.php
see comments for actual patches

Activity

Hide
Nadav Kavalerchik added a comment - - edited

open user/editadvanced.php

just after the line that has "httpsrequired();" add:

/// support YUI autocomplete Tags / Interests for users
    require_js(array('yui_dom-event', 'yui_connection', 'yui_animation','yui_datasource', 'yui_autocomplete'));
    echo '<style>'."\n";
    include ($CFG->libdir.'/yui/autocomplete/assets/skins/sam/autocomplete.css');
    echo '</style>'."\n";

just after the line that has "$userform->display();" add:

/// Tag auto complete YUI addon
if (ajaxenabled()) {
?>

<script type="text/javascript">

// An XHR DataSource
var myServer = "<?php echo $CFG->wwwroot;?>/tag/tag_autocomplete.php";
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
myDataSource.maxCacheEntries = 60;
myDataSource.queryMatchSubset = true;

var myAutoComp = new YAHOO.widget.AutoComplete("id_interests","interests-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}

open user/editlib.php

replace the line :

$mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');

with these lines:

/// support YUI autocomplete Tags / Interests for users
	$mform->addElement('html', '<br/><div id="interests-autocomplete-container">');
        $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="50" rows="3"');
        $mform->setType('interests', PARAM_TAGLIST);
        $mform->addElement('html', '</div>');
        $mform->addElement('html', '<div id="interests-autocomplete" class="yui-skin-sam"></div>');

Show
Nadav Kavalerchik added a comment - - edited

open user/editadvanced.php

just after the line that has "httpsrequired();" add:

/// support YUI autocomplete Tags / Interests for users
    require_js(array('yui_dom-event', 'yui_connection', 'yui_animation','yui_datasource', 'yui_autocomplete'));
    echo '<style>'."\n";
    include ($CFG->libdir.'/yui/autocomplete/assets/skins/sam/autocomplete.css');
    echo '</style>'."\n";

just after the line that has "$userform->display();" add:

/// Tag auto complete YUI addon
if (ajaxenabled()) {
?>

<script type="text/javascript">

// An XHR DataSource
var myServer = "<?php echo $CFG->wwwroot;?>/tag/tag_autocomplete.php";
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
myDataSource.maxCacheEntries = 60;
myDataSource.queryMatchSubset = true;

var myAutoComp = new YAHOO.widget.AutoComplete("id_interests","interests-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}

open user/editlib.php

replace the line :

$mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
with these lines:
/// support YUI autocomplete Tags / Interests for users
	$mform->addElement('html', '<br/><div id="interests-autocomplete-container">');
        $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="50" rows="3"');
        $mform->setType('interests', PARAM_TAGLIST);
        $mform->addElement('html', '</div>');
        $mform->addElement('html', '<div id="interests-autocomplete" class="yui-skin-sam"></div>');
Hide
Olli Savolainen added a comment -

Thanks Nadav! Great that we are getting moodle more alive.
Hope to try this out in a timely manner, though to be honest, without a demo probably it will wait quite a while. But it is great to know we have such functionality ready. You might also want to post this to the General Developer Forum if you haven't already.

Show
Olli Savolainen added a comment - Thanks Nadav! Great that we are getting moodle more alive. Hope to try this out in a timely manner, though to be honest, without a demo probably it will wait quite a while. But it is great to know we have such functionality ready. You might also want to post this to the General Developer Forum if you haven't already.
Hide
Nadav Kavalerchik added a comment -

if you liked this one, you would probably like:
http://tracker.moodle.org/browse/MDL-19865
that enables autocomplete tags in user's blog post

Show
Nadav Kavalerchik added a comment - if you liked this one, you would probably like: http://tracker.moodle.org/browse/MDL-19865 that enables autocomplete tags in user's blog post
Hide
Nadav Kavalerchik added a comment -

i made a mistake in the tracker

i set this issue to block issue 19865
and i only wanted to link them up
if anyone can fix this...

Show
Nadav Kavalerchik added a comment - i made a mistake in the tracker i set this issue to block issue 19865 and i only wanted to link them up if anyone can fix this...
Hide
Nadav Kavalerchik added a comment -

here is a screen-cast of the tags in action:
http://www.screentoaster.com/watch/stU0hcQkxIR11YSVxVU11YVl5R

Show
Nadav Kavalerchik added a comment - here is a screen-cast of the tags in action: http://www.screentoaster.com/watch/stU0hcQkxIR11YSVxVU11YVl5R
Hide
Rossiani Wijaya added a comment -

Thanks Nadav Kavalerchik

Closing

Show
Rossiani Wijaya added a comment - Thanks Nadav Kavalerchik Closing

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: