MDL-63944 Questions Bank: Select all checkbox should be checked
authorVinhLe <lethevinh.qng@gmail.com>
Tue, 13 Nov 2018 07:47:55 +0000 (14:47 +0700)
committerVinhLe <Vinh.LeThe@Nashtechglobal.com>
Fri, 15 Feb 2019 03:07:08 +0000 (10:07 +0700)
When checkbox item be chosen then "Select All" be chosen.
When "Select All" be chosen then all checkbox item be chosen.

question/amd/build/qbankmanager.min.js [new file with mode: 0644]
question/amd/src/qbankmanager.js [new file with mode: 0755]
question/classes/bank/checkbox_column.php
question/tests/behat/select_questions.feature [new file with mode: 0644]
question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-debug.js [deleted file]
question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-min.js [deleted file]
question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager.js [deleted file]
question/yui/src/qbankmanager/build.json [deleted file]
question/yui/src/qbankmanager/js/qbankmanager.js [deleted file]
question/yui/src/qbankmanager/meta/qbankmanager.json [deleted file]

diff --git a/question/amd/build/qbankmanager.min.js b/question/amd/build/qbankmanager.min.js
new file mode 100644 (file)
index 0000000..7e5809e
Binary files /dev/null and b/question/amd/build/qbankmanager.min.js differ
diff --git a/question/amd/src/qbankmanager.js b/question/amd/src/qbankmanager.js
new file mode 100755 (executable)
index 0000000..07c41ee
--- /dev/null
@@ -0,0 +1,128 @@
+// 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/>.
+
+/**
+ * A javascript module to handle question ajax actions.
+ *
+ * @module     core_question/qbankmanager
+ * @class      qbankmanager
+ * @package    core_question
+ * @copyright 2018 The Open University
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+define(['jquery', 'core/str', 'core/notification'], function($, str, notification) {
+
+    return {
+        /**
+         * A reference to the header checkbox.
+         *
+         * @property _strings
+         * @type Node
+         * @private
+         */
+        _strings: null,
+
+        /**
+         * A reference to the add to quiz button.
+         *
+         * @property _buttons
+         * @type Node
+         * @private
+         */
+        _buttons: null,
+
+        /**
+         * Set up the Question Bank Manager.
+         *
+         * @method init
+         */
+        init: function() {
+            // Find the header checkbox, and set the initial values.
+            var header = $('#qbheadercheckbox');
+            if (header.length == 0) {
+                return;
+            }
+            var self = this;
+            str.get_strings([
+                {key: 'selectall', component: 'moodle'},
+                {key: 'deselectall', component: 'moodle'},
+            ]).then(function(strings) {
+                self._strings = strings;
+                header.attr({
+                    disabled: false,
+                    checked: self._getSizeChecked() != 0,
+                    title: strings[0]
+                });
+                header.click(self, self._headerClick);
+
+                self._buttons = $(".modulespecificbuttonscontainer input, .modulespecificbuttonscontainer select," +
+                    " .modulespecificbuttonscontainer link, .modulespecificbuttonscontainer link");
+
+                self._buttons.attr('disabled', self._getSizeChecked() == 0);
+
+                if (self._buttons.length > 0) {
+                    $('.categoryquestionscontainer')
+                        .delegate('td.checkbox input[type="checkbox"]', 'change', self, self._questionClick);
+                }
+                return;
+            }).fail(notification.exception);
+        },
+
+        /**
+         * Handle toggling of the header checkbox.
+         *
+         * @method _headerClick
+         * @param {Event} event of element.
+         * @private
+         */
+        _headerClick: function(event) {
+            var self = event.data;
+            var header = $('#qbheadercheckbox');
+            var isCheckedHeader = header.is(':checked');
+            var indexStringTitle = isCheckedHeader ? 1 : 0;
+
+            $("#categoryquestions tbody [type=checkbox]").prop("checked", isCheckedHeader);
+            self._buttons.attr('disabled', self._getSizeChecked() === 0);
+            header.attr('title', self._strings[indexStringTitle]);
+        },
+
+        /**
+         * Handle toggling of a question checkbox.
+         *
+         * @method _questionClick
+         * @param {Event} event of element.
+         * @private
+         */
+        _questionClick: function(event) {
+            var self = event.data;
+            var header = $('#qbheadercheckbox');
+            var areChecked = self._getSizeChecked();
+            var lengthCheckbox = $("#categoryquestions tbody [type=checkbox]").length;
+            var ischeckboxHeader = (areChecked != 0) && areChecked == lengthCheckbox;
+
+            header.prop('checked', ischeckboxHeader);
+            self._buttons.attr('disabled', (areChecked === 0));
+        },
+        /**
+         * Get size all row checked of table.
+         * @method _getSizeChecked
+         * @return {Number}
+         * @private
+         */
+        _getSizeChecked: function() {
+            return $('#categoryquestions td.checkbox input[type="checkbox"]:checked').length;
+        }
+    };
+});
index 289aaba..98e020e 100644 (file)
@@ -34,13 +34,14 @@ class checkbox_column extends column_base {
     }
 
     protected function get_title() {
-        return '<input type="checkbox" disabled="disabled" id="qbheadercheckbox" />';
+        return '<input type="checkbox" disabled="disabled" id="qbheadercheckbox" name="qbheadercheckbox" />' .
+                '<label class="accesshide" for="qbheadercheckbox">' . get_string('selectall', 'moodle') . '</label>';
     }
 
     protected function get_title_tip() {
         global $PAGE;
         $PAGE->requires->strings_for_js(array('selectall', 'deselectall'), 'moodle');
-        $PAGE->requires->yui_module('moodle-question-qbankmanager', 'M.question.qbankmanager.init');
+        $PAGE->requires->js_call_amd('core_question/qbankmanager', 'init');
         return get_string('selectquestionsforbulk', 'question');
 
     }
diff --git a/question/tests/behat/select_questions.feature b/question/tests/behat/select_questions.feature
new file mode 100644 (file)
index 0000000..9f481af
--- /dev/null
@@ -0,0 +1,56 @@
+@core @core_question
+Feature: The questions in the question bank can be selected in various ways
+  In selected to do something for questions
+  As a teacher
+  I want to choose them to move, delete it.
+
+  Background:
+    Given the following "users" exist:
+      | username | firstname | lastname | email                |
+      | teacher1 | Teacher   | 1        | teacher1@example.com |
+    And the following "courses" exist:
+      | fullname | shortname | format |
+      | Course 1 | C1        | weeks  |
+    And the following "course enrolments" exist:
+      | user     | course | role           |
+      | teacher1 | C1     | editingteacher |
+    And the following "question categories" exist:
+      | contextlevel | reference | name           |
+      | Course       | C1        | Test questions |
+    And the following "questions" exist:
+      | questioncategory | qtype     | name              | user     | questiontext    |
+      | Test questions   | essay     | A question 1 name | admin    | Question 1 text |
+      | Test questions   | essay     | B question 2 name | teacher1 | Question 2 text |
+      | Test questions   | numerical | C question 3 name | teacher1 | Question 3 text |
+    And I log in as "teacher1"
+    And I am on "Course 1" course homepage
+    And I navigate to "Questions" node in "Course administration > Question bank"
+
+  @javascript
+  Scenario: The question text can be chosen all in the list of questions
+    Given the field "Select all" matches value ""
+    When I click on "Select all" "checkbox"
+    Then the field "A question 1 name" matches value "1"
+    And the field "B question 2 name" matches value "1"
+    And the field "C question 3 name" matches value "1"
+    When I click on "Select all" "checkbox"
+    Then the field "A question 1 name" matches value ""
+    And the field "B question 2 name" matches value ""
+    And the field "C question 3 name" matches value ""
+
+  @javascript
+  Scenario: The question text can be chosen in the list of questions
+    Given the field "Select all" matches value ""
+    When I click on "A question 1 name" "checkbox"
+    Then the field "Select all" matches value ""
+    When I click on "B question 2 name" "checkbox"
+    And I click on "C question 3 name" "checkbox"
+    Then the field "Select all" matches value "1"
+
+  @javascript
+  Scenario: The action button can be disabled when the question not be chosen in the list of questions
+    Given the "Delete" "button" should be disabled
+    And the "Move to >>" "button" should be disabled
+    When I click on "Select all" "checkbox"
+    Then the "Delete" "button" should be enabled
+    And the "Move to >>" "button" should be enabled
diff --git a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-debug.js b/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-debug.js
deleted file mode 100644 (file)
index fbe45fe..0000000
Binary files a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-debug.js and /dev/null differ
diff --git a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-min.js b/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-min.js
deleted file mode 100644 (file)
index 22b2432..0000000
Binary files a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager-min.js and /dev/null differ
diff --git a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager.js b/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager.js
deleted file mode 100644 (file)
index fbe45fe..0000000
Binary files a/question/yui/build/moodle-question-qbankmanager/moodle-question-qbankmanager.js and /dev/null differ
diff --git a/question/yui/src/qbankmanager/build.json b/question/yui/src/qbankmanager/build.json
deleted file mode 100644 (file)
index 2c8d36e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-{
-    "name": "moodle-question-qbankmanager",
-    "builds": {
-        "moodle-question-qbankmanager": {
-            "jsfiles": [
-                "qbankmanager.js"
-            ]
-        }
-    }
-}
diff --git a/question/yui/src/qbankmanager/js/qbankmanager.js b/question/yui/src/qbankmanager/js/qbankmanager.js
deleted file mode 100644 (file)
index cb6ea38..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-// 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/>.
-
-/*
- * Question Bank Management.
- *
- * @package    question
- * @copyright  2014 Andrew Nicols
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * Questionbank Management.
- *
- * @module moodle-question-qbankmanager
- */
-
-/**
- * Question Bank Management.
- *
- * @class M.question.qbankmanager
- */
-
-var manager = {
-    /**
-     * A reference to the header checkbox.
-     *
-     * @property _header
-     * @type Node
-     * @private
-     */
-    _header: null,
-
-    /**
-     * A reference to the add to quiz button.
-     *
-     * @property _addbutton
-     * @type Node
-     * @private
-     */
-    _addbutton: null,
-
-    /**
-     * The ID of the first checkbox on the page.
-     *
-     * @property _firstCheckbox
-     * @type Node
-     * @private
-     */
-    _firstCheckbox: null,
-
-    /**
-     * Set up the Question Bank Manager.
-     *
-     * @method init
-     */
-    init: function() {
-        // Find the header checkbox, and set the initial values.
-        this._header = Y.one('#qbheadercheckbox');
-        if (!this._header) {
-            return;
-        }
-        this._header.setAttrs({
-            disabled: false,
-            title: M.util.get_string('selectall', 'moodle')
-        });
-
-        this._header.on('click', this._headerClick, this);
-
-        this._addbutton = Y.one('.modulespecificbuttonscontainer input[name="add"]');
-        // input[name="add"] is not always available.
-        if (this._addbutton) {
-            this._addbutton.setAttrs({
-                disabled: true
-            });
-
-            this._header.on('click', this._questionClick, this);
-            Y.one('.categoryquestionscontainer').delegate('change', this._questionClick,
-                'td.checkbox input[type="checkbox"]', this);
-        }
-
-        // Store the first checkbox details.
-        var table = this._header.ancestor('table');
-        this._firstCheckbox = table.one('tbody tr td.checkbox input');
-    },
-
-    /**
-     * Handle toggling of the header checkbox.
-     *
-     * @method _headerClick
-     * @private
-     */
-    _headerClick: function() {
-        // Get the list of questions we affect.
-        var categoryQuestions = Y.one('#categoryquestions')
-                .all('[type=checkbox],[type=radio]');
-
-        // We base the state of all of the questions on the state of the first.
-        if (this._firstCheckbox.get('checked')) {
-            categoryQuestions.set('checked', false);
-            this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
-        } else {
-            categoryQuestions.set('checked', true);
-            this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
-        }
-
-        this._header.set('checked', false);
-    },
-
-    /**
-     * Handle toggling of a question checkbox.
-     *
-     * @method _questionClick
-     * @private
-     */
-    _questionClick: function() {
-        var areChecked = Y.all('td.checkbox input[type="checkbox"]:checked').size();
-        this._addbutton.setAttrs({
-            disabled: (areChecked === 0)
-        });
-    }
-};
-
-M.question = M.question || {};
-M.question.qbankmanager = M.question.qbankmanager || manager;
diff --git a/question/yui/src/qbankmanager/meta/qbankmanager.json b/question/yui/src/qbankmanager/meta/qbankmanager.json
deleted file mode 100644 (file)
index 6410cbc..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-    "moodle-question-qbankmanager": {
-        "requires": [
-            "node",
-            "selector-css3"
-        ]
-    }
-}