MDL-53254 tags: tag collections inplace editable
authorMarina Glancy <marina@moodle.com>
Fri, 26 Feb 2016 14:02:12 +0000 (22:02 +0800)
committerMarina Glancy <marina@moodle.com>
Fri, 18 Mar 2016 00:07:19 +0000 (08:07 +0800)
12 files changed:
lang/en/tag.php
lib/amd/build/tag.min.js
lib/amd/src/tag.js
lib/classes/output/inplace_editable.php
tag/classes/collection.php
tag/classes/collection_form.php [deleted file]
tag/classes/collections_table.php
tag/classes/output/tagcollname.php [new file with mode: 0644]
tag/classes/output/tagcollsearchable.php [new file with mode: 0644]
tag/lib.php
tag/manage.php
tag/tests/behat/collections.feature

index 6c52a63..ccc6836 100644 (file)
@@ -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';
index f295000..d5fa9fb 100644 (file)
Binary files a/lib/amd/build/tag.min.js and b/lib/amd/build/tag.min.js differ
index 15154e8..08ff1a4 100644 (file)
@@ -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 = $('<div><form id="addtagcoll_form" class="form-inline">'+
+                            '<p><label for="addtagcoll_name"></label>: ' +
+                            '<input id="addtagcoll_name" type="text"/><br/>' +
+                            '<label for="addtagcoll_searchable"></label>: ' +
+                            '<input id="addtagcoll_searchable" type="checkbox" value="1" checked/></p>' +
+                            '<p class="mdl-align"><input type="submit" id="addtagcoll_submit"/>'+
+                            '<input type="button" id="addtagcoll_cancel"/></p>' +
+                            '</form></div>');
+                        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
index b32ed15..4e0d6d5 100644 (file)
@@ -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));
+    }
 }
index 902a1a7..2dd55d2 100644 (file)
@@ -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 (file)
index 04a95b7..0000000
+++ /dev/null
@@ -1,79 +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/>.
-
-/**
- * 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);
-    }
-}
index 79e0869..78cdaca 100644 (file)
@@ -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]}</li>";
             }, 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,
                 "<ul data-collectionid=\"{$tagcoll->id}\">" . join('', $areaslist) . '</ul>',
-                $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 (file)
index 0000000..dc30b8c
--- /dev/null
@@ -0,0 +1,72 @@
+<?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\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 (file)
index 0000000..87c4ce6
--- /dev/null
@@ -0,0 +1,86 @@
+<?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\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);
+    }
+}
index e67af3a..e438f8a 100644 (file)
@@ -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);
     }
 }
index d3f06c1..8cbbd74 100644 (file)
@@ -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);
index 28e7e78..ad3dd69 100644 (file)
@@ -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