MDL-53254 tags: tag areas inplace editable

This commit is contained in:
Marina Glancy 2016-02-26 18:21:26 +08:00
parent fed66ad9e2
commit 131b78b9a7
16 changed files with 352 additions and 87 deletions

View File

@ -43,8 +43,10 @@ $string['deleteselected'] = 'Delete selected';
$string['deleted'] = 'Tag(s) deleted';
$string['deletedcoursetags'] = 'Deleted - Course tags';
$string['description'] = 'Description';
$string['editisstandard'] = 'Change standard tag usage';
$string['editname'] = 'Edit tag name';
$string['edittag'] = 'Edit this tag';
$string['edittagcollection'] = 'Change tag collection';
$string['entertags'] = 'Enter tags...';
$string['edittagcoll'] = 'Edit tag collection {$a}';
$string['errortagfrontpage'] = 'Tagging the site main page is not allowed';

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/templates","core/notification","core/str"],function(a,b,c,d,e){return{init_tagindex_page:function(){a("body").delegate(".tagarea[data-ta] a[data-quickload=1]","click",function(d){d.preventDefault();var e=a(this),f=e.context.search.replace(/^\?/,""),g=e.closest(".tagarea[data-ta]"),h=f.split("&").reduce(function(a,b){var c=b.split("=");return a[c[0]]=decodeURIComponent(c[1]),a},{}),i=b.call([{methodname:"core_tag_get_tagindex",args:{tagindex:h}}],!0);a.when.apply(a,i).done(function(a){c.render("core_tag/index",a).done(function(a){g.replaceWith(a)})})})},init_manage_page:function(){var f=function(b){var c=b.closest("tr").get(0);if(c){var d=a(c).find("td.col-timemodified").get(0);e.get_string("now").done(function(b){a(d).html(b)})}};a(".tag-management-table").delegate(".tagisstandard","click",function(d){d.preventDefault();var e=a(this),g=e.attr("data-id"),h=e.attr("data-value"),i="1"===h?0:1,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:g,isstandard:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:g}]}}],!0);a.when.apply(a,j).done(function(a,b){void 0===a.warnings[0]&&void 0!==b.tags[0]&&c.render("core_tag/tagisstandard",b.tags[0]).done(function(a){f(e);var b=e.parent();e.replaceWith(a),b.find(".tagisstandard").get(0).focus()})})}),a(".tag-management-table").delegate(".tagflag","click",function(d){d.preventDefault();var e=a(this),g=e.attr("data-id"),h=e.attr("data-value"),i="0"===h?1:0,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:g,flag:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:g}]}}],!0);a.when.apply(a,j).done(function(b,d){if(void 0===b.warnings[0]&&void 0!==d.tags[0]){var g=e.closest("tr").get(0);g&&(d.tags[0].flag?a(g).addClass("flagged-tag"):a(g).removeClass("flagged-tag")),c.render("core_tag/tagflag",d.tags[0]).done(function(a){f(e);var b=e.parent();e.replaceWith(a),b.find(".tagflag").get(0).focus()})}})}),a(".tag-management-table").delegate("a.tagdelete","click",function(b){b.preventDefault();var c=a(this).attr("href");e.get_strings([{key:"delete"},{key:"confirmdeletetag",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})}),a("#tag-management-delete").click(function(b){var c=a(this).closest("form").get(0),f=a(c).find("input[type=checkbox]:checked").length;return f?(b.preventDefault(),void e.get_strings([{key:"delete"},{key:"confirmdeletetags",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){c.submit()})})):!1})}}});
define(["jquery","core/ajax","core/templates","core/notification","core/str"],function(a,b,c,d,e){return{initTagindexPage:function(){a("body").delegate(".tagarea[data-ta] a[data-quickload=1]","click",function(d){d.preventDefault();var e=a(this),f=e.context.search.replace(/^\?/,""),g=e.closest(".tagarea[data-ta]"),h=f.split("&").reduce(function(a,b){var c=b.split("=");return a[c[0]]=decodeURIComponent(c[1]),a},{}),i=b.call([{methodname:"core_tag_get_tagindex",args:{tagindex:h}}],!0);a.when.apply(a,i).done(function(a){c.render("core_tag/index",a).done(function(a){g.replaceWith(a)})})})},initManagePage:function(){var f=function(b){var c=b.closest("tr").get(0);if(c){var d=a(c).find("td.col-timemodified").get(0);e.get_string("now").done(function(b){a(d).html(b)})}};a(".tag-management-table").delegate(".tagisstandard","click",function(d){d.preventDefault();var e=a(this),g=e.attr("data-id"),h=e.attr("data-value"),i="1"===h?0:1,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:g,isstandard:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:g}]}}],!0);a.when.apply(a,j).done(function(a,b){void 0===a.warnings[0]&&void 0!==b.tags[0]&&c.render("core_tag/tagisstandard",b.tags[0]).done(function(a){f(e);var b=e.parent();e.replaceWith(a),b.find(".tagisstandard").get(0).focus()})})}),a(".tag-management-table").delegate(".tagflag","click",function(d){d.preventDefault();var e=a(this),g=e.attr("data-id"),h=e.attr("data-value"),i="0"===h?1:0,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:g,flag:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:g}]}}],!0);a.when.apply(a,j).done(function(b,d){if(void 0===b.warnings[0]&&void 0!==d.tags[0]){var g=e.closest("tr").get(0);g&&(d.tags[0].flag?a(g).addClass("flagged-tag"):a(g).removeClass("flagged-tag")),c.render("core_tag/tagflag",d.tags[0]).done(function(a){f(e);var b=e.parent();e.replaceWith(a),b.find(".tagflag").get(0).focus()})}})}),a(".tag-management-table").delegate("a.tagdelete","click",function(b){b.preventDefault();var c=a(this).attr("href");e.get_strings([{key:"delete"},{key:"confirmdeletetag",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})}),a("#tag-management-delete").click(function(b){var c=a(this).closest("form").get(0),f=a(c).find("input[type=checkbox]:checked").length;return f?(b.preventDefault(),void e.get_strings([{key:"delete"},{key:"confirmdeletetags",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){c.submit()})})):!1})},initManageCollectionsPage:function(){a("body").on("updated","[data-inplaceeditable]",function(b){var c=b.ajaxreturn;b.oldvalue;if("core_tag"===c.component&&"tagareaenable"===c.itemtype){var d=a(this).attr("data-itemid");a(".tag-collections-table ul[data-collectionid] li[data-areaid="+d+"]").addClass("hidden");var e=c.value;if("1"===e){a(this).closest("tr").removeClass("dimmed_text");var f=a(this).closest("tr").find('[data-itemtype="tagareacollection"]').attr("data-value");a(".tag-collections-table ul[data-collectionid="+f+"] li[data-areaid="+d+"]").removeClass("hidden")}else a(this).closest("tr").addClass("dimmed_text")}if("core_tag"===c.component&&"tagareacollection"===c.itemtype){var d=a(this).attr("data-itemid");a(".tag-collections-table ul[data-collectionid] li[data-areaid="+d+"]").addClass("hidden");var f=a(this).attr("data-value"),e=a(this).closest("tr").find('[data-itemtype="tagareaenable"]').attr("data-value");"1"===e&&a(".tag-collections-table ul[data-collectionid="+f+"] li[data-areaid="+d+"]").removeClass("hidden")}})}}});

View File

@ -29,9 +29,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
/**
* Initialises tag index page.
*
* @method init_tagindex_page
* @method initTagindexPage
*/
init_tagindex_page: function() {
initTagindexPage: function() {
// Click handler for changing tag type.
$('body').delegate('.tagarea[data-ta] a[data-quickload=1]', 'click', function(e) {
e.preventDefault();
@ -57,9 +57,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
/**
* Initialises tag management page.
*
* @method init_manage_page
* @method initManagePage
*/
init_manage_page: function() {
initManagePage: function() {
var update_modified = function(el) {
var row = el.closest('tr').get(0);
@ -174,6 +174,39 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
}
);
});
},
/**
* Initialises tag collection management page.
*
* @method initManageCollectionsPage
*/
initManageCollectionsPage: function() {
$('body').on('updated', '[data-inplaceeditable]', function(e) {
var ajaxreturn = e.ajaxreturn;
var oldvalue = e.oldvalue;
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareaenable') {
var areaid = $(this).attr('data-itemid');
$(".tag-collections-table ul[data-collectionid] li[data-areaid="+areaid+"]").addClass('hidden');
var isenabled = ajaxreturn.value;
if (isenabled === '1') {
$(this).closest('tr').removeClass('dimmed_text');
var collid = $(this).closest('tr').find('[data-itemtype="tagareacollection"]').attr("data-value");
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]").removeClass('hidden');
} else {
$(this).closest('tr').addClass('dimmed_text');
}
}
if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareacollection') {
var areaid = $(this).attr('data-itemid');
$(".tag-collections-table ul[data-collectionid] li[data-areaid="+areaid+"]").addClass('hidden');
var collid = $(this).attr('data-value');
var isenabled = $(this).closest('tr').find('[data-itemtype="tagareaenable"]').attr("data-value");
if (isenabled === "1") {
$(".tag-collections-table ul[data-collectionid="+collid+"] li[data-areaid="+areaid+"]").removeClass('hidden');
}
}
});
}
};
});

View File

@ -69,34 +69,15 @@ class core_tag_areas_table extends html_table {
foreach ($tagareas as $itemtype => $it) {
foreach ($it as $component => $record) {
$areaname = core_tag_area::display_name($record->component, $record->itemtype);
$baseurl = new moodle_url($pageurl, array('ta' => $record->id, 'sesskey' => sesskey()));
if ($record->enabled) {
$enableurl = new moodle_url($baseurl, array('action' => 'areadisable'));
$enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/hide', get_string('disable')));
} else {
$enableurl = new moodle_url($baseurl, array('action' => 'areaenable'));
$enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/show', get_string('enable')));
}
if ($record->enabled && empty($record->locked) && count($tagcollections) > 1) {
$changecollurl = new moodle_url($baseurl, array('action' => 'areasetcoll'));
$tmpl = new \core_tag\output\tagareaenabled($record);
$enabled = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT));
$select = new single_select($changecollurl, 'areacollid', $tagcollections, $record->tagcollid, null);
$select->set_label(get_string('changetagcoll', 'core_tag', $areaname), array('class' => 'accesshide'));
$collectionselect = $OUTPUT->render($select);
} else {
$collectionselect = $tagcollectionsall[$record->tagcollid];
}
$tmpl = new \core_tag\output\tagareacollection($record);
$collectionselect = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT));
if ($record->enabled) {
$changeshowstandardurl = new moodle_url($baseurl, array('action' => 'areasetshowstandard'));
$select = new single_select($changeshowstandardurl, 'showstandard', $standardchoices,
$record->showstandard, null);
$select->set_label(get_string('changeshowstandard', 'core_tag', $areaname), array('class' => 'accesshide'));
$showstandardselect = $OUTPUT->render($select);
} else {
$showstandardselect = $standardchoices[$record->showstandard];
}
$tmpl = new \core_tag\output\tagareashowstandard($record);
$showstandardselect = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT));
$this->data[] = array(
$areaname,

View File

@ -174,12 +174,12 @@ class core_tag_collection {
* @param int $tagcollid
* @return array
*/
public static function get_areas_names($tagcollid) {
$allitemtypes = core_tag_area::get_areas($tagcollid, true);
public static function get_areas_names($tagcollid, $enabledonly = true) {
$allitemtypes = core_tag_area::get_areas($tagcollid, $enabledonly);
$itemtypes = array();
foreach ($allitemtypes as $itemtype => $it) {
foreach ($it as $component => $v) {
$itemtypes[] = core_tag_area::display_name($component, $itemtype);
$itemtypes[$v->id] = core_tag_area::display_name($component, $itemtype);
}
}
return $itemtypes;

View File

@ -87,10 +87,17 @@ class core_tag_collections_table extends html_table {
$component = ($tagcoll->component === 'core' || preg_match('/^core_/', $tagcoll->component)) ?
get_string('coresystem') : get_string('pluginname', $tagcoll->component);
}
$allareas = core_tag_collection::get_areas_names(null, false);
$validareas = core_tag_collection::get_areas_names($tagcoll->id);
$areaslist = array_map(function($key) use ($allareas, $validareas) {
return "<li data-areaid=\"{$key}\" " .
(array_key_exists($key, $validareas) ? "" : "class=\"hidden\"") .
">{$allareas[$key]}</li>";
}, array_keys($allareas));
$this->data[] = array(
html_writer::link($manageurl, $name),
$component,
join(', ', core_tag_collection::get_areas_names($tagcoll->id)),
"<ul data-collectionid=\"{$tagcoll->id}\">" . join('', $areaslist) . '</ul>',
$tagcoll->searchable ? get_string('yes') : '-',
$actions);
$idx++;

View File

@ -99,7 +99,7 @@ class core_tag_manage_table extends table_sql {
$this->collapsible(true);
$PAGE->requires->js_call_amd('core/tag', 'init_manage_page', array());
$PAGE->requires->js_call_amd('core/tag', 'initManagePage', array());
}

View File

@ -0,0 +1,81 @@
<?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/>.
/**
* Contains class core_tag\output\tagareacollection
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_tag\output;
use context_system;
use lang_string;
use core_tag_area;
/**
* Class to display collection select for the tag area
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tagareacollection extends \core\output\inplace_editable {
/**
* Constructor.
*
* @param \stdClass $tagarea
*/
public function __construct($tagarea) {
$tagcollections = \core_tag_collection::get_collections_menu(true);
$editable = (count($tagcollections) > 1) && empty($tagarea->locked) &&
has_capability('moodle/tag:manage', context_system::instance());
$areaname = core_tag_area::display_name($tagarea->component, $tagarea->itemtype);
$edithint = new lang_string('edittagcollection', 'core_tag');
$editlabel = new lang_string('changetagcoll', 'core_tag', $areaname);
$value = $tagarea->tagcollid;
parent::__construct('core_tag', 'tagareacollection', $tagarea->id, $editable,
null, $value, $edithint, $editlabel);
$this->set_type_select($tagcollections);
}
/**
* Updates the value in database and returns itself, called from inplace_editable callback
*
* @param int $itemid
* @param mixed $newvalue
* @return \self
*/
public static function update($itemid, $newvalue) {
global $DB;
require_capability('moodle/tag:manage', \context_system::instance());
$tagarea = $DB->get_record('tag_area', array('id' => $itemid), '*', MUST_EXIST);
$newvalue = clean_param($newvalue, PARAM_INT);
$tagcollections = \core_tag_collection::get_collections_menu(true);
if (!array_key_exists($newvalue, $tagcollections)) {
throw new \moodle_exception('invalidparameter', 'debug');
}
$data = array('tagcollid' => $newvalue);
core_tag_area::update($tagarea, $data);
$tagarea->tagcollid = $newvalue;
$tmpl = new self($tagarea);
return $tmpl;
}
}

View File

@ -0,0 +1,87 @@
<?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/>.
/**
* Contains class core_tag\output\tagareaenabled
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_tag\output;
use context_system;
/**
* Class to display tag area enabled control
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tagareaenabled extends \core\output\inplace_editable {
/**
* Constructor.
*
* @param \stdClass $tagarea
*/
public function __construct($tagarea) {
$editable = has_capability('moodle/tag:manage', context_system::instance());
$value = $tagarea->enabled ? 1 : 0;
parent::__construct('core_tag', 'tagareaenable', $tagarea->id, $editable, '', $value);
$this->set_type_toggle();
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \renderer_base $output
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
if ($this->value) {
$this->edithint = get_string('disable');
$this->displayvalue = $output->pix_icon('i/hide', get_string('disable'));
} else {
$this->edithint = get_string('enable');
$this->displayvalue = $output->pix_icon('i/show', get_string('enable'));
}
return parent::export_for_template($output);
}
/**
* Updates the value in database and returns itself, called from inplace_editable callback
*
* @param int $itemid
* @param mixed $newvalue
* @return \self
*/
public static function update($itemid, $newvalue) {
global $DB;
require_capability('moodle/tag:manage', context_system::instance());
$tagarea = $DB->get_record('tag_area', array('id' => $itemid), '*', MUST_EXIST);
$newvalue = $newvalue ? 1 : 0;
$data = array('enabled' => $newvalue);
\core_tag_area::update($tagarea, $data);
$tagarea->enabled = $newvalue;
$tmpl = new self($tagarea);
return $tmpl;
}
}

View File

@ -0,0 +1,82 @@
<?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/>.
/**
* Contains class core_tag\output\tagareashowstandard
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_tag\output;
use context_system;
use lang_string;
use core_tag_tag;
use core_tag_area;
/**
* Class to display tag area show standard control
*
* @package core_tag
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tagareashowstandard extends \core\output\inplace_editable {
/**
* Constructor.
*
* @param \stdClass $tagarea
*/
public function __construct($tagarea) {
$editable = has_capability('moodle/tag:manage', context_system::instance());
$edithint = new lang_string('editisstandard', 'core_tag');
$value = $tagarea->showstandard;
$areaname = core_tag_area::display_name($tagarea->component, $tagarea->itemtype);
$editlabel = new lang_string('changeshowstandard', 'core_tag', $areaname);
parent::__construct('core_tag', 'tagareashowstandard', $tagarea->id, $editable,
null, $value, $edithint, $editlabel);
$standardchoices = array(
core_tag_tag::BOTH_STANDARD_AND_NOT => get_string('standardsuggest', 'tag'),
core_tag_tag::STANDARD_ONLY => get_string('standardforce', 'tag'),
core_tag_tag::HIDE_STANDARD => get_string('standardhide', 'tag')
);
$this->set_type_select($standardchoices);
}
/**
* Updates the value in database and returns itself, called from inplace_editable callback
*
* @param int $itemid
* @param mixed $newvalue
* @return \self
*/
public static function update($itemid, $newvalue) {
global $DB;
require_capability('moodle/tag:manage', context_system::instance());
$tagarea = $DB->get_record('tag_area', array('id' => $itemid), '*', MUST_EXIST);
$newvalue = clean_param($newvalue, PARAM_INT);
$data = array('showstandard' => $newvalue);
core_tag_area::update($tagarea, $data);
$tagarea->showstandard = $newvalue;
$tmpl = new self($tagarea);
return $tmpl;
}
}

View File

@ -41,7 +41,7 @@ class tagname extends \core\output\inplace_editable {
/**
* Constructor.
*
* @param stdClass|core_tag $tag
* @param \stdClass|core_tag_tag $tag
*/
public function __construct($tag) {
$editable = has_capability('moodle/tag:manage', context_system::instance());
@ -52,4 +52,18 @@ class tagname extends \core\output\inplace_editable {
core_tag_tag::make_display_name($tag));
parent::__construct('core_tag', 'tagname', $tag->id, $editable, $displayvalue, $value, $edithint, $editlabel);
}
/**
* Updates the value in database and returns itself, called from inplace_editable callback
*
* @param int $itemid
* @param mixed $newvalue
* @return \self
*/
public static function update($itemid, $newvalue) {
require_capability('moodle/tag:manage', context_system::instance());
$tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
$tag->update(array('rawname' => $newvalue));
return new self($tag);
}
}

View File

@ -76,7 +76,7 @@ class core_tag_renderer extends plugin_renderer_base {
*/
public function tag_index_page($tag, $entities, $tagareaid, $exclusivemode, $fromctx, $ctx, $rec, $page) {
global $CFG, $OUTPUT;
$this->page->requires->js_call_amd('core/tag', 'init_tagindex_page');
$this->page->requires->js_call_amd('core/tag', 'initTagindexPage');
$tagname = $tag->get_display_name();
$systemcontext = context_system::instance();

View File

@ -44,6 +44,8 @@ function tag_page_type_list($pagetype, $parentcontext, $currentcontext) {
/**
* Implements callback inplace_editable() allowing to edit values in-place
*
* @global moodle_database $DB
*
* @param string $itemtype
* @param int $itemid
* @param mixed $newvalue
@ -51,9 +53,12 @@ function tag_page_type_list($pagetype, $parentcontext, $currentcontext) {
*/
function core_tag_inplace_editable($itemtype, $itemid, $newvalue) {
if ($itemtype === 'tagname') {
require_capability('moodle/tag:manage', context_system::instance());
$tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
$tag->update(array('rawname' => $newvalue));
return new \core_tag\output\tagname($tag);
return \core_tag\output\tagname::update($itemid, $newvalue);
} else if ($itemtype === 'tagareaenable') {
return \core_tag\output\tagareaenabled::update($itemid, $newvalue);
} else if ($itemtype === 'tagareacollection') {
return \core_tag\output\tagareacollection::update($itemid, $newvalue);
} else if ($itemtype === 'tagareashowstandard') {
return \core_tag\output\tagareashowstandard::update($itemid, $newvalue);
}
}

View File

@ -138,39 +138,6 @@ switch($action) {
redirect($manageurl);
break;
case 'areaenable':
case 'areadisable':
if ($tagarea) {
require_sesskey();
$data = array('enabled' => ($action === 'areaenable') ? 1 : 0);
core_tag_area::update($tagarea, $data);
redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
}
redirect($manageurl);
break;
case 'areasetcoll':
if ($tagarea) {
require_sesskey();
if ($newtagcollid = optional_param('areacollid', null, PARAM_INT)) {
core_tag_area::update($tagarea, array('tagcollid' => $newtagcollid));
redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
}
}
redirect($manageurl);
break;
case 'areasetshowstandard':
if ($tagarea) {
require_sesskey();
if (($showstandard = optional_param('showstandard', null, PARAM_INT)) !== null) {
core_tag_area::update($tagarea, array('showstandard' => $showstandard));
redirect(new moodle_url($manageurl, array('notice' => 'changessaved')));
}
}
redirect($manageurl);
break;
case 'delete':
require_sesskey();
if (!$tagschecked && $tagid) {
@ -243,6 +210,8 @@ if (!$tagcoll) {
echo $OUTPUT->heading(get_string('tagareas', 'core_tag'), 3);
echo html_writer::table($tagareastable);
$PAGE->requires->js_call_amd('core/tag', 'initManageCollectionsPage', array());
echo $OUTPUT->footer();
exit;
}

View File

@ -60,26 +60,27 @@ Feature: Managers can create and manage tag collections
@javascript
Scenario: Assigning tag area to tag collection
And "User interests" "text" should exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And "User interests" "text" should not exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element"
When I set the field "Change tag collection of area User interests" to "Hobbies"
Then "User interests" "text" should not exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And "User interests" "text" should exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element"
And the field "Change tag collection of area User interests" matches value "Hobbies"
And I should see "User interests" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And I should not see "User interests" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element"
When I click on "Change tag collection" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And I set the field "Change tag collection of area User interests" to "Hobbies"
Then I should not see "User interests" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And I should see "User interests" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element"
And I should see "Hobbies" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And I log out
@javascript
Scenario: Disabling tag areas
And "Change tag collection of area User interests" "select" should exist
When I click on "Disable" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
Then "Change tag collection of area User interests" "select" should not exist
And "User interests" "text" should not exist in the "table.tag-collections-table" "css_element"
And I should see "User interests" in the "table.tag-collections-table" "css_element"
And I click on "Enable" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And "User interests" "text" should exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And "Change tag collection of area User interests" "select" should exist
And I should see "User interests" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Default collection')]" "xpath_element"
And I log out
@javascript
Scenario: Deleting non-empty tag collections
When I set the field "Change tag collection of area User interests" to "Hobbies"
When I click on "Change tag collection" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And I set the field "Change tag collection of area User interests" to "Hobbies"
And I click on "Delete" "link" in the "Hobbies" "table_row"
Then I should see "Are you sure you want to delete tag collection \"Hobbies\"?"
And I press "Yes"
@ -95,7 +96,8 @@ Feature: Managers can create and manage tag collections
And I set the field "List of interests" to "Swimming, Tag0, Tag3"
And I press "Update profile"
And I navigate to "Manage tags" node in "Site administration > Appearance"
When I set the field "Change tag collection of area User interests" to "Hobbies"
When I click on "Change tag collection" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And I set the field "Change tag collection of area User interests" to "Hobbies"
And I follow "Hobbies"
Then I should see "Swimming"
And I should see "Tag0"

View File

@ -114,6 +114,7 @@ Feature: Manager can add standard tags and change the tag type of existing tags
| List of interests | Tag3 , Tag2 |
And I press "Update profile"
And I navigate to "Manage tags" node in "Site administration > Appearance"
And I click on "Change standard tag usage" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And the field "Change showing standard tags in area User interests" matches value "Don't suggest"
And I set the field "Change showing standard tags in area User interests" to "Suggest"
And I follow "Profile" in the user menu
@ -121,6 +122,7 @@ Feature: Manager can add standard tags and change the tag type of existing tags
And I expand all fieldsets
And I should see "Manage standard tags"
And I navigate to "Manage tags" node in "Site administration > Appearance"
And I click on "Change standard tag usage" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element"
And the field "Change showing standard tags in area User interests" matches value "Suggest"
And I set the field "Change showing standard tags in area User interests" to "Force"
And I follow "Profile" in the user menu