MDL-64787 tool_analytics: New template to select the evaluation mode
authorDavid Monllaó <davidm@moodle.com>
Thu, 7 Mar 2019 20:00:51 +0000 (21:00 +0100)
committerDavid Monllaó <davidm@moodle.com>
Thu, 7 Mar 2019 20:06:17 +0000 (21:06 +0100)
admin/tool/analytics/amd/build/model.min.js
admin/tool/analytics/amd/src/model.js
admin/tool/analytics/templates/evaluation_mode_selection.mustache [new file with mode: 0644]

index 661afb1..180805d 100644 (file)
Binary files a/admin/tool/analytics/amd/build/model.min.js and b/admin/tool/analytics/amd/build/model.min.js differ
index 2b4ac16..f39c577 100644 (file)
@@ -20,8 +20,8 @@
  * @copyright  2017 David Monllao
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-define(['jquery', 'core/str', 'core/log', 'core/notification', 'core/modal_factory', 'core/modal_events'],
-    function($, Str, log, Notification, ModalFactory, ModalEvents) {
+define(['jquery', 'core/str', 'core/log', 'core/notification', 'core/modal_factory', 'core/modal_events', 'core/templates'],
+    function($, Str, log, Notification, ModalFactory, ModalEvents, Templates) {
 
     /**
      * List of actions that require confirmation and confirmation message.
@@ -48,20 +48,6 @@ define(['jquery', 'core/str', 'core/log', 'core/notification', 'core/modal_facto
         }
     };
 
-    /**
-     * Template to display the evaluation mode choices.
-     */
-    var evaluationRadioHTML = '<div class="box mb-4">{{evaluationmodeinfo}}</div>' +
-        '<div class="form-check">' +
-            '<input class="form-check-input" type="radio" name="evaluationmode" id="id-mode-trainedmodel" value="trainedmodel" ' +
-                'checked>' +
-            '<label class="form-check-label" for="id-mode-trainedmodel">{{trainedmodellabel}}</label>' +
-        '</div>' +
-        '<div class="form-check">' +
-            '<input class="form-check-input" type="radio" name="evaluationmode" id="id-mode-configuration" value="configuration">' +
-            '<label class="form-check-label" for="id-mode-configuration">{{configurationlabel}}</label>' +
-        '</div>';
-
     /**
      * Returns the model name.
      *
@@ -140,18 +126,10 @@ define(['jquery', 'core/str', 'core/log', 'core/notification', 'core/modal_facto
                     }, {
                         key: 'evaluationmode',
                         component: 'tool_analytics'
-                    }, {
-                        key: 'evaluationmodeinfo',
-                        component: 'tool_analytics'
-                    }, {
-                        key: 'evaluationmodetrainedmodel',
-                        component: 'tool_analytics'
-                    }, {
-                        key: 'evaluationmodeconfiguration',
-                        component: 'tool_analytics'
                     }
                 ]);
                 var modalPromise = ModalFactory.create({type: ModalFactory.types.SAVE_CANCEL});
+                var bodyPromise = Templates.render('tool_analytics/evaluation_mode_selection', {});
 
                 $.when(stringsPromise, modalPromise).then(function(strings, modal) {
 
@@ -160,11 +138,7 @@ define(['jquery', 'core/str', 'core/log', 'core/notification', 'core/modal_facto
 
                     modal.setTitle(strings[1]);
                     modal.setSaveButtonText(strings[0]);
-
-                    var body = evaluationRadioHTML.replace(/{{evaluationmodeinfo}}/, strings[2])
-                        .replace(/{{trainedmodellabel}}/, strings[3])
-                        .replace(/{{configurationlabel}}/, strings[4]);
-                    modal.setBody(body);
+                    modal.setBody(bodyPromise);
 
                     modal.getRoot().on(ModalEvents.save, function() {
                         var evaluationMode = $("input[name='evaluationmode']:checked").val();
diff --git a/admin/tool/analytics/templates/evaluation_mode_selection.mustache b/admin/tool/analytics/templates/evaluation_mode_selection.mustache
new file mode 100644 (file)
index 0000000..e9b32ce
--- /dev/null
@@ -0,0 +1,42 @@
+{{!
+    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/>.
+}}
+{{!
+    @template tool_analytics/evaluation_mode_selector
+
+    Evaluation mode selector.
+
+    The purpose of this template is to render the evaluation mode radio button.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Example context (json):
+    {
+    }
+}}
+<div class="box mb-4">{{#str}} evaluationmodeinfo, tool_analytics {{/str}}</div>
+<div class="form-check">
+    <input class="form-check-input" type="radio" name="evaluationmode" id="id-mode-trainedmodel" value="trainedmodel" checked>
+    <label class="form-check-label" for="id-mode-trainedmodel">{{#str}} evaluationmodetrainedmodel, tool_analytics {{/str}}</label>
+</div>
+<div class="form-check">
+    <input class="form-check-input" type="radio" name="evaluationmode" id="id-mode-configuration" value="configuration">
+    <label class="form-check-label" for="id-mode-configuration">{{#str}} evaluationmodeconfiguration, tool_analytics {{/str}}</label>
+</div>
\ No newline at end of file