mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-51260 core_tag: Use new tag autocomplete for related tags
This commit is contained in:
parent
bb6ca6f360
commit
a27c42ee9a
@ -2723,3 +2723,21 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) {
|
||||
echo $OUTPUT->notification(get_string('deletedcoursetags', 'tag'), 'notifysuccess');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that returns tags that start with some text, for use by the autocomplete feature
|
||||
*
|
||||
* @package core_tag
|
||||
* @deprecated since 3.0
|
||||
* @access private
|
||||
* @param string $text string that the tag names will be matched against
|
||||
* @return mixed an array of objects, or false if no records were found or an error occured.
|
||||
*/
|
||||
function tag_autocomplete($text) {
|
||||
debugging('Function tag_autocomplete() is deprecated without replacement. ' .
|
||||
'New form element "tags" does proper autocomplete.', DEBUG_DEVELOPER);
|
||||
global $DB;
|
||||
return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
|
||||
FROM {tag} tg
|
||||
WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%"));
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ $PAGE->set_pagelayout('standard');
|
||||
$tagname = tag_display_name($tag);
|
||||
|
||||
// set the relatedtags field of the $tag object that will be passed to the form
|
||||
$tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id, TAG_RELATED_MANUAL), TAG_RETURN_TEXT);
|
||||
$tag->relatedtags = tag_get_tags_array('tag', $tag->id);
|
||||
|
||||
$options = new stdClass();
|
||||
$options->smiley = false;
|
||||
@ -141,7 +141,7 @@ if ($tagform->is_cancelled()) {
|
||||
}
|
||||
|
||||
//updated related tags
|
||||
tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags)), 'core', $systemcontext->id);
|
||||
tag_set('tag', $tagnew->id, $tagnew->relatedtags, 'core', $systemcontext->id);
|
||||
//print_object($tagnew); die();
|
||||
|
||||
$tagname = isset($tagnew->rawname) ? $tagnew->rawname : $tag->rawname;
|
||||
@ -164,7 +164,4 @@ if (!empty($errorstring)) {
|
||||
|
||||
$tagform->display();
|
||||
|
||||
$PAGE->requires->js('/tag/tag.js');
|
||||
$PAGE->requires->js_function_call('init_tag_autocomplete', null, true);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -68,11 +68,7 @@ class tag_edit_form extends moodleform {
|
||||
$mform->addElement('checkbox', 'tagtype', get_string('officialtag', 'tag'));
|
||||
}
|
||||
|
||||
$mform->addElement('html', '<br/><div id="relatedtags-autocomplete-container">');
|
||||
$mform->addElement('textarea', 'relatedtags', get_string('relatedtags','tag'), 'cols="50" rows="3"');
|
||||
$mform->setType('relatedtags', PARAM_TAGLIST);
|
||||
$mform->addElement('html', '<div id="relatedtags-autocomplete"></div>');
|
||||
$mform->addElement('html', '</div>');
|
||||
$mform->addElement('tags', 'relatedtags', get_string('relatedtags','tag'));
|
||||
|
||||
$this->add_action_buttons(true, get_string('updatetag', 'tag'));
|
||||
|
||||
|
15
tag/lib.php
15
tag/lib.php
@ -1045,21 +1045,6 @@ function tag_assign($record_type, $record_id, $tagid, $ordering, $userid = 0, $c
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that returns tags that start with some text, for use by the autocomplete feature
|
||||
*
|
||||
* @package core_tag
|
||||
* @access private
|
||||
* @param string $text string that the tag names will be matched against
|
||||
* @return mixed an array of objects, or false if no records were found or an error occured.
|
||||
*/
|
||||
function tag_autocomplete($text) {
|
||||
global $DB;
|
||||
return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
|
||||
FROM {tag} tg
|
||||
WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the tag tables, making sure all tagged object still exists.
|
||||
*
|
||||
|
30
tag/tag.js
30
tag/tag.js
@ -1,30 +0,0 @@
|
||||
var coursetagdivs = null;
|
||||
var coursetag_tags = new Array();
|
||||
|
||||
function init_tag_autocomplete() {
|
||||
YUI().use('yui2-autocomplete', 'yui2-datasource', 'yui2-animation', 'yui2-connection', function(Y) {
|
||||
var myDataSource = new Y.YUI2.util.XHRDataSource("./tag_autocomplete.php");
|
||||
myDataSource.responseType = Y.YUI2.util.XHRDataSource.TYPE_TEXT;
|
||||
myDataSource.responseSchema = {
|
||||
recordDelim: "\n",
|
||||
fieldDelim: "\t"
|
||||
};
|
||||
myDataSource.maxCacheEntries = 60;
|
||||
|
||||
// Instantiate the AutoComplete
|
||||
var myAutoComp = new Y.YUI2.widget.AutoComplete("id_relatedtags", "relatedtags-autocomplete", myDataSource);
|
||||
document.getElementById('id_relatedtags').style.width = '30%';
|
||||
myAutoComp.allowBrowserAutocomplete = false;
|
||||
myAutoComp.maxResultsDisplayed = 20;
|
||||
myAutoComp.minQueryLength = 3;
|
||||
myAutoComp.delimChar = [","," "];
|
||||
myAutoComp.formatResult = function(oResultData, sQuery, sResultMatch) {
|
||||
return (sResultMatch);
|
||||
};
|
||||
|
||||
return {
|
||||
myDataSource: myDataSource,
|
||||
myAutoComp: myAutoComp
|
||||
};
|
||||
});
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core
|
||||
* @subpackage tag
|
||||
* @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('AJAX_SCRIPT', true);
|
||||
|
||||
require_once('../config.php');
|
||||
require_once('lib.php');
|
||||
|
||||
if (empty($CFG->usetags)) {
|
||||
// Tags are disabled.
|
||||
die();
|
||||
}
|
||||
|
||||
require_login(0, false);
|
||||
if (isguestuser()) {
|
||||
// Guests should not be using this.
|
||||
die();
|
||||
}
|
||||
|
||||
// If a user cannot edit tags, they cannot add related tags which is what this auto complete is for.
|
||||
require_capability('moodle/tag:edit', context_system::instance());
|
||||
|
||||
$query = optional_param('query', '', PARAM_TAG);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Limit the query to a minimum of 3 characters.
|
||||
$similartags = array();
|
||||
if (core_text::strlen($query) >= 3) {
|
||||
$similartags = tag_autocomplete($query);
|
||||
}
|
||||
|
||||
foreach ($similartags as $tag) {
|
||||
echo clean_param($tag->name, PARAM_TAG) . "\t" . tag_display_name($tag) . "\n";
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
@ -21,6 +21,7 @@ Feature: Users can edit tags to add description or rename
|
||||
| name | tagtype |
|
||||
| Neverusedtag | official |
|
||||
|
||||
@javascript
|
||||
Scenario: User with tag editing capability can change tag description
|
||||
Given I log in as "admin"
|
||||
And I set the following system permissions of "Tag editor" role:
|
||||
@ -45,6 +46,7 @@ Feature: Users can edit tags to add description or rename
|
||||
And I should see "Related tags: Dog, Turtle, Fish"
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: Manager can change tag description, related tags and rename the tag from tag view page
|
||||
When I log in as "manager1"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
@ -61,8 +63,7 @@ Feature: Users can edit tags to add description or rename
|
||||
And "Description of tag 1" "text" should exist in the "#tag-description" "css_element"
|
||||
And I should see "Related tags: Dog, Turtle, Fish"
|
||||
And I follow "Edit this tag"
|
||||
And I set the following fields to these values:
|
||||
| Related tags | Turtle, Fish |
|
||||
And I click on "× Dog" "text"
|
||||
And I press "Update"
|
||||
Then "Kitten" "text" should exist in the ".breadcrumb-nav" "css_element"
|
||||
And "Description of tag 1" "text" should exist in the "#tag-description" "css_element"
|
||||
@ -91,6 +92,7 @@ Feature: Users can edit tags to add description or rename
|
||||
And "KITTEN" "text" should exist in the ".breadcrumb-nav" "css_element"
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: Manager can change tag description and rename the tag from tag manage page
|
||||
When I log in as "manager1"
|
||||
And I navigate to "Manage tags" node in "Site administration > Appearance"
|
||||
|
@ -770,14 +770,6 @@ tr.flagged-tag a {color:#FF0000;}
|
||||
.tag-management-table tr:hover td .tagnameedit img,
|
||||
.tag-management-table tr td .tagnameedit:focus img {opacity: 1;}
|
||||
.tag-management-table tr:hover td.tageditingon .tagnameedit img {opacity: 0.2;}
|
||||
#relatedtags-autocomplete-container {margin-left:auto;margin-right:auto;min-height:4.6em;width:100%;}
|
||||
#relatedtags-autocomplete {position:relative;display:block;width:60%;margin-left:auto;margin-right:auto;}
|
||||
#relatedtags-autocomplete .yui-ac-content {position:absolute;width:420px;left:20%;border:1px solid #404040;background:#fff;overflow:hidden;z-index:9050;}
|
||||
#relatedtags-autocomplete .ysearchquery {position:absolute;right:10px;color:#808080;z-index:10;}
|
||||
#relatedtags-autocomplete .yui-ac-shadow {position:absolute;margin:.3em;width:100%;background:#a0a0a0;z-index:9049;}
|
||||
#relatedtags-autocomplete ul {padding:0;width:100%;margin:0;list-style-type:none;}
|
||||
#relatedtags-autocomplete li {padding:0 5px;cursor:default;white-space:nowrap;}
|
||||
#relatedtags-autocomplete li.yui-ac-highlight{background:#FFFFCC;}
|
||||
h2.tag-heading,
|
||||
div#tag-description,
|
||||
div#tag-blogs,
|
||||
|
@ -871,56 +871,6 @@ tr.flagged-tag a {
|
||||
.tag-management-table tr:hover td.tageditingon .tagnameedit img {
|
||||
opacity: 0.2;
|
||||
}
|
||||
#relatedtags-autocomplete-container {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
min-height: 4.6em;
|
||||
width: 100%;
|
||||
}
|
||||
#relatedtags-autocomplete {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 60%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
#relatedtags-autocomplete .yui-ac-content {
|
||||
position: absolute;
|
||||
width: 420px;
|
||||
left: 20%;
|
||||
border: 1px solid @dropdownBorder;
|
||||
background: @dropdownBackground;
|
||||
overflow: hidden;
|
||||
z-index: 9050;
|
||||
}
|
||||
#relatedtags-autocomplete .ysearchquery {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
color: #808080;
|
||||
z-index: 10;
|
||||
}
|
||||
#relatedtags-autocomplete .yui-ac-shadow {
|
||||
position: absolute;
|
||||
margin: .3em;
|
||||
width: 100%;
|
||||
background: #a0a0a0;
|
||||
z-index: 9049;
|
||||
}
|
||||
#relatedtags-autocomplete ul {
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
list-style-type: none;
|
||||
}
|
||||
#relatedtags-autocomplete li {
|
||||
padding: 0 5px;
|
||||
cursor: default;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#relatedtags-autocomplete li.yui-ac-highlight{
|
||||
background: @dropdownLinkBackgroundHover;
|
||||
color: @dropdownLinkColorHover;
|
||||
}
|
||||
h2.tag-heading,
|
||||
div#tag-description,
|
||||
div#tag-blogs,
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user