Moodle

autocomplete tags (interests) in Blog's "new post" 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: Accessibility, Blog, Usability
  • Labels:
    None
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE

Description

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

two files are involved in the patch: blog/edit.php and blog/edit_form.php
see comments for actual patches

Activity

Hide
Nadav Kavalerchik added a comment - - edited

open blog/edit.php

just after the line that has "require_login($courseid);" 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 "$blogeditform->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_ptags","ptags-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}

open blog/edit_form.php

remark (or remove) the following lines:

$mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
  $mform->setType('ptagsadd', PARAM_NOTAGS);

and add the following lines of code instead:

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

	    $mform->setHelpButton('ptags', array('interestslist', get_string('helpinterestslist'), false, true, false));

Show
Nadav Kavalerchik added a comment - - edited

open blog/edit.php

just after the line that has "require_login($courseid);" 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 "$blogeditform->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_ptags","ptags-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}

open blog/edit_form.php

remark (or remove) the following lines:

$mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
  $mform->setType('ptagsadd', PARAM_NOTAGS);
and add the following lines of code instead:
/// support YUI autocomplete Tags / Interests for users
	    $mform->addElement('html', '<br/><div id="ptags-autocomplete-container">');
	    $mform->addElement('textarea', 'ptags', get_string('ptags','tag'), 'cols="50" rows="3"');
	    $mform->setType('ptags', PARAM_TAGLIST);
	    $mform->addElement('html', '</div>');
	    $mform->addElement('html', '<div id="ptags-autocomplete" class="yui-skin-sam"></div>');

	    $mform->setHelpButton('ptags', array('interestslist', get_string('helpinterestslist'), false, true, false));
Hide
Nadav Kavalerchik added a comment -

autocomplete tags in user's profile

Show
Nadav Kavalerchik added a comment - autocomplete tags in user's profile
Hide
Nadav Kavalerchik added a comment -

i made a mistake in the tracker

i set this issue to block issue 19860
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 19860 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
Leo Thiessen added a comment -

Hi Nadav,

re "mistake...delete block issue..." - I did same thing on one of my items. To fix you simply click on the "Issue Links:" title (it's a link) and then delete the linked issue by clicking the garbage can icon beside it (I deleted this one for you so you won't see it here... )

Show
Leo Thiessen added a comment - Hi Nadav, re "mistake...delete block issue..." - I did same thing on one of my items. To fix you simply click on the "Issue Links:" title (it's a link) and then delete the linked issue by clicking the garbage can icon beside it (I deleted this one for you so you won't see it here... )
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: