diff --git a/lang/en/tag.php b/lang/en/tag.php index 6c52a63e48d..ccc683637c7 100644 --- a/lang/en/tag.php +++ b/lang/en/tag.php @@ -44,7 +44,9 @@ $string['deleted'] = 'Tag(s) deleted'; $string['deletedcoursetags'] = 'Deleted - Course tags'; $string['description'] = 'Description'; $string['editisstandard'] = 'Change standard tag usage'; +$string['editcollname'] = 'Edit tag collection name'; $string['editname'] = 'Edit tag name'; +$string['editsearchable'] = 'Change searchable'; $string['edittag'] = 'Edit this tag'; $string['edittagcollection'] = 'Change tag collection'; $string['entertags'] = 'Enter tags...'; @@ -78,6 +80,7 @@ $string['managetagcolls'] = 'Manage tag collections'; $string['moretags'] = 'more...'; $string['name'] = 'Tag name'; $string['namesalreadybeeingused'] = 'Tag names already being used'; +$string['newcollnamefor'] = 'New name for tag collection {$a}'; $string['newnamefor'] = 'New name for tag {$a}'; $string['nextpage'] = 'More'; $string['notagsfound'] = 'No tags matching "{$a}" found'; diff --git a/lib/amd/build/tag.min.js b/lib/amd/build/tag.min.js index f2950005b15..d5fa9fb66a4 100644 --- a/lib/amd/build/tag.min.js +++ b/lib/amd/build/tag.min.js @@ -1 +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")}})}}}); \ No newline at end of file +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,d,e,f=b.ajaxreturn;b.oldvalue;"core_tag"===f.component&&"tagareaenable"===f.itemtype&&(c=a(this).attr("data-itemid"),a(".tag-collections-table ul[data-collectionid] li[data-areaid="+c+"]").addClass("hidden"),e=f.value,"1"===e?(a(this).closest("tr").removeClass("dimmed_text"),d=a(this).closest("tr").find('[data-itemtype="tagareacollection"]').attr("data-value"),a(".tag-collections-table ul[data-collectionid="+d+"] li[data-areaid="+c+"]").removeClass("hidden")):a(this).closest("tr").addClass("dimmed_text")),"core_tag"===f.component&&"tagareacollection"===f.itemtype&&(c=a(this).attr("data-itemid"),a(".tag-collections-table ul[data-collectionid] li[data-areaid="+c+"]").addClass("hidden"),d=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="+d+"] li[data-areaid="+c+"]").removeClass("hidden"))}),a("body").on("click",".addtagcoll > a",function(b){b.preventDefault();var c=a(this).attr("data-url")+"&sesskey="+M.cfg.sesskey;e.get_strings([{key:"addtagcoll",component:"tag"},{key:"name"},{key:"searchable",component:"tag"},{key:"create"},{key:"cancel"}]).done(function(b){var d=a('

:
:

');d.find('label[for="addtagcoll_name"]').html(b[1]),d.find('label[for="addtagcoll_searchable"]').html(b[2]),d.find("#addtagcoll_submit").attr("value",b[3]),d.find("#addtagcoll_cancel").attr("value",b[4]);var e=new M.core.dialogue({draggable:!0,modal:!0,closeButton:!0,headerContent:b[0],bodyContent:d.html()});e.show(),a("#addtagcoll_form #addtagcoll_name").focus(),a("#addtagcoll_form #addtagcoll_cancel").on("click",function(){e.destroy()}),a("#addtagcoll_form").on("submit",function(){var b=a("#addtagcoll_form #addtagcoll_name").val(),d=a("#addtagcoll_form #addtagcoll_searchable").prop("checked")?1:0;return String(b).length>0&&(window.location.href=c+"&name="+encodeURIComponent(b)+"&searchable="+d),!1})})}),a("body").on("click",".tag-collections-table .action_delete",function(b){b.preventDefault();var c=a(this).attr("data-url")+"&sesskey="+M.cfg.sesskey;e.get_strings([{key:"delete"},{key:"suredeletecoll",component:"tag",param:a(this).attr("data-collname")},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})})}}}); \ No newline at end of file diff --git a/lib/amd/src/tag.js b/lib/amd/src/tag.js index 15154e8b336..08ff1a405f7 100644 --- a/lib/amd/src/tag.js +++ b/lib/amd/src/tag.js @@ -183,30 +183,94 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' */ initManageCollectionsPage: function() { $('body').on('updated', '[data-inplaceeditable]', function(e) { - var ajaxreturn = e.ajaxreturn; - var oldvalue = e.oldvalue; + var ajaxreturn = e.ajaxreturn, + oldvalue = e.oldvalue, + areaid, collid, isenabled; if (ajaxreturn.component === 'core_tag' && ajaxreturn.itemtype === 'tagareaenable') { - var areaid = $(this).attr('data-itemid'); + areaid = $(this).attr('data-itemid'); $(".tag-collections-table ul[data-collectionid] li[data-areaid="+areaid+"]").addClass('hidden'); - var isenabled = ajaxreturn.value; + isenabled = ajaxreturn.value; if (isenabled === '1') { $(this).closest('tr').removeClass('dimmed_text'); - var collid = $(this).closest('tr').find('[data-itemtype="tagareacollection"]').attr("data-value"); + 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'); + 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"); + collid = $(this).attr('data-value'); + 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'); } } - }); + }); + + $('body').on('click', '.addtagcoll > a', function(e) { + e.preventDefault(); + var href = $(this).attr('data-url') + '&sesskey=' + M.cfg.sesskey; + str.get_strings([ + {key : 'addtagcoll', component : 'tag'}, + {key : 'name'}, + {key : 'searchable', component : 'tag'}, + {key : 'create'}, + {key : 'cancel'}, + ]).done(function(s) { + var el = $('
'+ + '

: ' + + '
' + + ': ' + + '

' + + '

'+ + '

' + + '
'); + el.find('label[for="addtagcoll_name"]').html(s[1]); + el.find('label[for="addtagcoll_searchable"]').html(s[2]); + el.find('#addtagcoll_submit').attr('value', s[3]); + el.find('#addtagcoll_cancel').attr('value', s[4]); + var panel = new M.core.dialogue ({ + draggable: true, + modal: true, + closeButton: true, + headerContent: s[0], + bodyContent: el.html() + }); + panel.show(); + $('#addtagcoll_form #addtagcoll_name').focus(); + $('#addtagcoll_form #addtagcoll_cancel').on('click', function() { + panel.destroy(); + }); + $('#addtagcoll_form').on('submit', function() { + var name = $('#addtagcoll_form #addtagcoll_name').val(); + var searchable = $('#addtagcoll_form #addtagcoll_searchable').prop('checked') ? 1 : 0; + if (String(name).length > 0) { + window.location.href = href + "&name=" + encodeURIComponent(name) + "&searchable=" + searchable; + } + return false; + }); + } + ); + + }); + + $('body').on('click', '.tag-collections-table .action_delete', function(e) { + e.preventDefault(); + var href = $(this).attr('data-url') + '&sesskey=' + M.cfg.sesskey; + str.get_strings([ + {key : 'delete'}, + {key : 'suredeletecoll', component : 'tag', param : $(this).attr('data-collname') }, + {key : 'yes'}, + {key : 'no'}, + ]).done(function(s) { + notification.confirm(s[0], s[1], s[2], s[3], function() { + window.location.href = href; + }); + } + ); + }); } }; }); \ No newline at end of file diff --git a/lib/classes/output/inplace_editable.php b/lib/classes/output/inplace_editable.php index b32ed158189..4e0d6d553c2 100644 --- a/lib/classes/output/inplace_editable.php +++ b/lib/classes/output/inplace_editable.php @@ -226,4 +226,14 @@ class inplace_editable implements templatable, renderable { 'linkeverything' => $this->get_linkeverything() ? 1 : 0, ); } + + /** + * Renders this element + * + * @param renderer_base $output typically, the renderer that's calling this function + * @return string + */ + public function render(\renderer_base $output) { + return $output->render_from_template('core/inplace_editable', $this->export_for_template($output)); + } } diff --git a/tag/classes/collection.php b/tag/classes/collection.php index 902a1a71086..2dd55d27f63 100644 --- a/tag/classes/collection.php +++ b/tag/classes/collection.php @@ -143,7 +143,7 @@ class core_tag_collection { return get_string($identifier, $component); } if (!empty($record->name)) { - return format_string($record->name, true, $syscontext); + return format_string($record->name, true, array('context' => $syscontext)); } else if ($record->isdefault) { return get_string('defautltagcoll', 'tag'); } else { @@ -216,7 +216,7 @@ class core_tag_collection { * Updates the tag collection information * * @param stdClass $tagcoll existing record in DB table tag_coll - * @param stdClass $data data from form core_tag_collection_form + * @param stdClass $data data to update * @return bool wether the record was updated */ public static function update($tagcoll, $data) { diff --git a/tag/classes/collection_form.php b/tag/classes/collection_form.php deleted file mode 100644 index 04a95b75aeb..00000000000 --- a/tag/classes/collection_form.php +++ /dev/null @@ -1,79 +0,0 @@ -. - -/** - * Contains class core_tag_collection_form - * - * @package core - * @copyright 2015 Marina Glancy - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->libdir . '/formslib.php'); - -/** - * Form for editing tag collection - * - * @package core - * @copyright 2015 Marina Glancy - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class core_tag_collection_form extends moodleform { - - /** - * Form definition - */ - public function definition() { - $data = fullclone($this->_customdata); - if (isset($data->id)) { - $data->tc = $data->id; - $data->action = 'colledit'; - } else { - $data = new stdClass(); - $data->action = 'colladd'; - $data->isdefault = false; - } - - $mform = $this->_form; - $mform->addElement('hidden', 'tc'); - $mform->setType('tc', PARAM_INT); - $mform->addElement('hidden', 'action'); - $mform->setType('action', PARAM_ALPHA); - - $mform->addElement('text', 'name', get_string('name')); - $mform->setType('name', PARAM_NOTAGS); - $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); - if (empty($data->isdefault)) { - $mform->addRule('name', get_string('required'), 'required', null, 'client'); - } else { - $mform->addElement('static', 'collnameexplained', '', get_string('collnameexplained', 'tag', - get_string('defautltagcoll', 'tag'))); - } - - $mform->addElement('advcheckbox', 'searchable', get_string('searchable', 'tag')); - $mform->addHelpButton('searchable', 'searchable', 'tag'); - $mform->setDefault('searchable', 1); - if (!empty($data->isdefault)) { - $mform->freeze('searchable'); - } - - $this->add_action_buttons(); - - $this->set_data($data); - } -} diff --git a/tag/classes/collections_table.php b/tag/classes/collections_table.php index 79e08690071..78cdaca9d56 100644 --- a/tag/classes/collections_table.php +++ b/tag/classes/collections_table.php @@ -35,6 +35,7 @@ class core_tag_collections_table extends html_table { /** * Constructor + * @global \core_renderer $OUTPUT * @param string|moodle_url $pageurl */ public function __construct($pageurl) { @@ -63,25 +64,23 @@ class core_tag_collections_table extends html_table { // Move up. if ($idx > 1) { $url->param('action', 'collmoveup'); - $actions .= $OUTPUT->action_icon($url, new pix_icon('t/up', get_string('moveup'))); + $actions .= $OUTPUT->action_icon($url, new pix_icon('t/up', get_string('moveup')), null, + array('class' => 'action-icon action_moveup')); } // Move down. if ($idx < count($tagcolls) - 1) { $url->param('action', 'collmovedown'); - $actions .= $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown'))); + $actions .= $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')), null, + array('class' => 'action-icon action_movedown')); } } - if (empty($tagcoll->component)) { - // Edit. - $url->param('action', 'colledit'); - $actions .= $OUTPUT->action_icon($url, new pix_icon('t/edit', get_string('edittagcoll', 'tag', $name))); - } if (!$tagcoll->isdefault && empty($tagcoll->component)) { // Delete. $url->param('action', 'colldelete'); - $actions .= $OUTPUT->action_icon($url, new pix_icon('t/delete', get_string('delete'))); + $actions .= $OUTPUT->action_icon('#', new pix_icon('t/delete', get_string('delete')), null, + array('data-url' => $url, 'data-collname' => $name, + 'class' => 'action-icon action_delete')); } - $manageurl = new moodle_url('/tag/manage.php', array('tc' => $tagcoll->id)); $component = ''; if ($tagcoll->component) { $component = ($tagcoll->component === 'core' || preg_match('/^core_/', $tagcoll->component)) ? @@ -94,11 +93,13 @@ class core_tag_collections_table extends html_table { (array_key_exists($key, $validareas) ? "" : "class=\"hidden\"") . ">{$allareas[$key]}"; }, array_keys($allareas)); + $displayname = new \core_tag\output\tagcollname($tagcoll); + $searchable = new \core_tag\output\tagcollsearchable($tagcoll); $this->data[] = array( - html_writer::link($manageurl, $name), + $displayname->render($OUTPUT), $component, "', - $tagcoll->searchable ? get_string('yes') : '-', + $searchable->render($OUTPUT), $actions); $idx++; } diff --git a/tag/classes/output/tagcollname.php b/tag/classes/output/tagcollname.php new file mode 100644 index 00000000000..dc30b8c8e5c --- /dev/null +++ b/tag/classes/output/tagcollname.php @@ -0,0 +1,72 @@ +. + +/** + * Contains class core_tag\output\tagcollname + * + * @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 html_writer; +use core_tag_collection; +use moodle_url; + +/** + * Class to preapare a tag name for display. + * + * @package core_tag + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class tagcollname extends \core\output\inplace_editable { + + /** + * Constructor. + * + * @param \stdClass $tagcoll + */ + public function __construct($tagcoll) { + $editable = has_capability('moodle/tag:manage', context_system::instance()); + $edithint = new lang_string('editcollname', 'core_tag'); + $value = $tagcoll->name; + $name = \core_tag_collection::display_name($tagcoll); + $editlabel = new lang_string('newcollnamefor', 'core_tag', $name); + $manageurl = new moodle_url('/tag/manage.php', array('tc' => $tagcoll->id)); + $displayvalue = html_writer::link($manageurl, $name); + parent::__construct('core_tag', 'tagcollname', $tagcoll->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) { + global $DB; + require_capability('moodle/tag:manage', context_system::instance()); + $tagcoll = $DB->get_record('tag_coll', array('id' => $itemid), '*', MUST_EXIST); + \core_tag_collection::update($tagcoll, array('name' => $newvalue)); + return new self($tagcoll); + } +} diff --git a/tag/classes/output/tagcollsearchable.php b/tag/classes/output/tagcollsearchable.php new file mode 100644 index 00000000000..87c4ce6f22c --- /dev/null +++ b/tag/classes/output/tagcollsearchable.php @@ -0,0 +1,86 @@ +. + +/** + * Contains class core_tag\output\tagcollsearchable + * + * @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_collection; + +/** + * Class to display tag collection searchable control + * + * @package core_tag + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class tagcollsearchable extends \core\output\inplace_editable { + + /** + * Constructor. + * + * @param \stdClass $tagcoll + */ + public function __construct($tagcoll) { + $defaultid = core_tag_collection::get_default(); + $editable = $tagcoll->id != $defaultid && + has_capability('moodle/tag:manage', context_system::instance()); + $edithint = new lang_string('editsearchable', 'core_tag'); + $value = $tagcoll->searchable ? 1 : 0; + + parent::__construct('core_tag', 'tagcollsearchable', $tagcoll->id, $editable, $value, $value, $edithint); + $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->displayvalue = get_string('yes'); + } else { + $this->displayvalue = get_string('no'); + } + + 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()); + $tagcoll = $DB->get_record('tag_coll', array('id' => $itemid), '*', MUST_EXIST); + core_tag_collection::update($tagcoll, array('searchable' => $newvalue)); + return new self($tagcoll); + } +} diff --git a/tag/lib.php b/tag/lib.php index e67af3ae8f4..e438f8a1a99 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -60,5 +60,9 @@ function core_tag_inplace_editable($itemtype, $itemid, $newvalue) { return \core_tag\output\tagareacollection::update($itemid, $newvalue); } else if ($itemtype === 'tagareashowstandard') { return \core_tag\output\tagareashowstandard::update($itemid, $newvalue); + } else if ($itemtype === 'tagcollname') { + return \core_tag\output\tagcollname::update($itemid, $newvalue); + } else if ($itemtype === 'tagcollsearchable') { + return \core_tag\output\tagcollsearchable::update($itemid, $newvalue); } } diff --git a/tag/manage.php b/tag/manage.php index d3f06c1b37a..8cbbd744cc1 100644 --- a/tag/manage.php +++ b/tag/manage.php @@ -36,7 +36,6 @@ $isstandard = optional_param('isstandard', null, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); -$notice = optional_param('notice', '', PARAM_ALPHA); $tagcollid = optional_param('tc', 0, PARAM_INT); $tagareaid = optional_param('ta', null, PARAM_INT); @@ -74,48 +73,18 @@ $PAGE->set_blocks_editing_capability('moodle/tag:editblocks'); switch($action) { case 'colladd': - case 'colledit': - if ($action === 'colladd' || ($action === 'colledit' && $tagcoll && empty($tagcoll->component))) { - $form = new core_tag_collection_form($manageurl, $tagcoll); - if ($form->is_cancelled()) { - redirect($manageurl); - } else if ($data = $form->get_data()) { - if ($action === 'colladd') { - core_tag_collection::create($data); - } else { - core_tag_collection::update($tagcoll, $data); - } - redirect($manageurl); - } else { - $title = ($action === 'colladd') ? - get_string('addtagcoll', 'tag') : - get_string('edittagcoll', 'tag', core_tag_collection::display_name($tagcoll)); - $PAGE->navbar->add($title); - echo $OUTPUT->header(); - echo $OUTPUT->heading($title, 2); - $form->display(); - echo $OUTPUT->footer(); - exit; - } - } + require_sesskey(); + $name = required_param('name', PARAM_NOTAGS); + $searchable = required_param('searchable', PARAM_BOOL); + core_tag_collection::create(array('name' => $name, 'searchable' => $searchable)); + redirect($manageurl); // TODO message break; case 'colldelete': - $confirm = optional_param('confirm', false, PARAM_BOOL); - if (!$confirm) { - echo $OUTPUT->header(); - $strconfirm = get_string('suredeletecoll', 'tag', core_tag_collection::display_name($tagcoll)); - $params = array('tc' => $tagcoll->id, 'confirm' => 1, 'sesskey' => sesskey(), 'action' => 'colldelete'); - $formcontinue = new single_button(new moodle_url($manageurl, $params), get_string('yes')); - $formcancel = new single_button($manageurl, get_string('no'), 'get'); - echo $OUTPUT->confirm($strconfirm, $formcontinue, $formcancel); - echo $OUTPUT->footer(); - die; - } if ($tagcoll && !$tagcoll->component) { require_sesskey(); core_tag_collection::delete($tagcoll); - redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); + \core\notification::success(get_string('changessaved', 'core_tag')); } redirect($manageurl); break; @@ -124,7 +93,7 @@ switch($action) { if ($tagcoll) { require_sesskey(); core_tag_collection::change_sortorder($tagcoll, -1); - redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); + redirect($manageurl, get_string('changessaved', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); } redirect($manageurl); break; @@ -133,7 +102,7 @@ switch($action) { if ($tagcoll) { require_sesskey(); core_tag_collection::change_sortorder($tagcoll, 1); - redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); + redirect($manageurl, get_string('changessaved', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); } redirect($manageurl); break; @@ -144,14 +113,18 @@ switch($action) { $tagschecked = array($tagid); } core_tag_tag::delete_tags($tagschecked); - redirect(new moodle_url($PAGE->url, $tagschecked ? array('notice' => 'deleted') : null)); + if ($tagschecked) { + redirect($PAGE->url, get_string('deleted', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); + } else { + redirect($PAGE->url); + } break; case 'setflag': require_sesskey(); if ($tagid) { $tagobject->flag(); - redirect(new moodle_url($PAGE->url, array('notice' => 'flagged'))); + redirect($PAGE->url, get_string('flagged', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); } redirect($PAGE->url); break; @@ -160,7 +133,7 @@ switch($action) { require_sesskey(); if ($tagid) { $tagobject->reset_flag(); - redirect(new moodle_url($PAGE->url, array('notice' => 'resetflag'))); + redirect($PAGE->url, get_string('resetflag', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); } redirect($PAGE->url); break; @@ -169,7 +142,7 @@ switch($action) { require_sesskey(); if ($tagid && $tagobject->update( array('isstandard' => $isstandard ? 1 : 0))) { - redirect(new moodle_url($PAGE->url, array('notice' => 'typechanged'))); + redirect($PAGE->url, get_string('typechanged', 'core_tag'), null, \core\output\notification::NOTIFY_SUCCESS); } redirect($PAGE->url); break; @@ -187,16 +160,13 @@ switch($action) { $tagobject->update(array('isstandard' => 1)); } } - redirect(new moodle_url($PAGE->url, $tagobjects ? array('notice' => 'added') : null)); + redirect($PAGE->url, $tagobjects ? get_string('added', 'core_tag') : null, + null, \core\output\notification::NOTIFY_SUCCESS); break; } echo $OUTPUT->header(); -if ($notice && get_string_manager()->string_exists($notice, 'tag')) { - echo $OUTPUT->notification(get_string($notice, 'tag'), 'notifysuccess'); -} - if (!$tagcoll) { // Tag collection is not specified. Display the overview of tag collections and tag areas. $tagareastable = new core_tag_areas_table($manageurl); @@ -205,7 +175,8 @@ if (!$tagcoll) { echo $OUTPUT->heading(get_string('tagcollections', 'core_tag') . $OUTPUT->help_icon('tagcollection', 'tag'), 3); echo html_writer::table($colltable); $url = new moodle_url($manageurl, array('action' => 'colladd')); - echo html_writer::div(html_writer::link($url, get_string('addtagcoll', 'tag')), 'mdl-right addtagcoll'); + echo html_writer::div(html_writer::link('#', get_string('addtagcoll', 'tag'), array('data-url' => $url)), + 'mdl-right addtagcoll'); echo $OUTPUT->heading(get_string('tagareas', 'core_tag'), 3); echo html_writer::table($tagareastable); diff --git a/tag/tests/behat/collections.feature b/tag/tests/behat/collections.feature index 28e7e78434f..ad3dd6994e4 100644 --- a/tag/tests/behat/collections.feature +++ b/tag/tests/behat/collections.feature @@ -1,4 +1,4 @@ -@core @core_tag +@core @core_tag @javascript Feature: Managers can create and manage tag collections In order to use tags effectively As a manager @@ -23,7 +23,7 @@ Feature: Managers can create and manage tag collections And I follow "Add tag collection" And I set the following fields to these values: | Name | Hobbies | - And I press "Save changes" + And I press "Create" Scenario: Adding tag collections When I follow "Hobbies" @@ -31,10 +31,9 @@ Feature: Managers can create and manage tag collections And I log out Scenario: Editing tag collections - When I follow "Edit tag collection Hobbies" - And I set the following fields to these values: - | Name | Newname | - And I press "Save changes" + When I click on "Edit tag collection name" "link" in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hobbies')]" "xpath_element" + And I set the field "New name for tag collection Hobbies" to "Newname" + And I press key "13" in the field "New name for tag collection Hobbies" Then I should not see "Hobbies" And I should see "Newname" And I log out @@ -43,7 +42,7 @@ Feature: Managers can create and manage tag collections When I follow "Add tag collection" And I set the following fields to these values: | Name | Blogging | - And I press "Save changes" + And I press "Create" Then "Blogging" "link" should appear after "Hobbies" "link" And I click on "Move up" "link" in the "Blogging" "table_row" And "Blogging" "link" should appear before "Hobbies" "link" @@ -58,7 +57,6 @@ Feature: Managers can create and manage tag collections And I should not see "Hobbies" And I log out - @javascript Scenario: Assigning tag area to tag collection 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" @@ -69,15 +67,13 @@ Feature: Managers can create and manage tag collections 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 When I click on "Disable" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element" - And I should see "User interests" in the "table.tag-collections-table" "css_element" + And I should not 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 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 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" @@ -85,10 +81,9 @@ Feature: Managers can create and manage tag collections Then I should see "Are you sure you want to delete tag collection \"Hobbies\"?" And I press "Yes" And I should not see "Hobbies" - And "User interests" "text" should exist 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(.,'Default collection')]" "xpath_element" And I log out - @javascript Scenario: Moving tags when changing tag collections And I follow "Preferences" in the user menu And I follow "Edit profile" @@ -115,23 +110,19 @@ Feature: Managers can create and manage tag collections And I should see "Tag2" And I log out - @javascript Scenario: Creating searchable and non-searchable tag collections And I follow "Add tag collection" And I set the following fields to these values: | Name | Hiddencoll | | Searchable | 0 | - And I press "Save changes" + And I press "Create" And "Yes" "text" should not exist in the "//table[contains(@class,'tag-collections-table')]//tr[contains(.,'Hiddencoll')]" "xpath_element" And I navigate to "Tags" node in "Site pages" Then the "Select tag collection" select box should contain "Default collection" And the "Select tag collection" select box should contain "Hobbies" And the "Select tag collection" select box should not contain "Hiddencoll" And I navigate to "Manage tags" node in "Site administration > Appearance" - And I click on "Edit" "link" in the "Hobbies" "table_row" - And I set the following fields to these values: - | Searchable | 0 | - And I press "Save changes" + And I click on "Change searchable" "link" in the "Hobbies" "table_row" And I navigate to "Tags" node in "Site pages" And "Select tag collection" "select" should not exist And I log out