MDL-57550 forum: remove legacy forum.js uses
authorDan Poltawski <dan@moodle.com>
Thu, 29 Dec 2016 19:32:57 +0000 (19:32 +0000)
committerDan Poltawski <dan@moodle.com>
Mon, 23 Jan 2017 09:42:29 +0000 (09:42 +0000)
The search form options can be achieved in jquery rather than using
global js function/vars.

forum_get_subscribe_link legacylink had not been useful for some time

mod/forum/classes/output/big_search_form.php
mod/forum/lib.php
mod/forum/templates/big_search_form.mustache
theme/boost/templates/mod_forum/big_search_form.mustache

index e2bd7ce..6a77898 100644 (file)
@@ -48,7 +48,6 @@ class big_search_form implements renderable, templatable {
     public $fullwords;
     public $notwords;
     public $phrase;
-    public $scripturl;
     public $showfullwords;
     public $subject;
     public $user;
@@ -65,7 +64,6 @@ class big_search_form implements renderable, templatable {
     public function __construct($course) {
         global $DB;
         $this->course = $course;
-        $this->scripturl = new moodle_url('/mod/forum/forum.js');
         $this->showfullwords = $DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres';
         $this->actionurl = new moodle_url('/mod/forum/search.php');
 
@@ -153,7 +151,6 @@ class big_search_form implements renderable, templatable {
     public function export_for_template(renderer_base $output) {
         $data = new stdClass();
 
-        $data->scripturl = $this->scripturl->out(false);
         $data->courseid = $this->course->id;
         $data->words = $this->words;
         $data->phrase = $this->phrase;
index 79168f5..c12e712 100644 (file)
@@ -4791,12 +4791,13 @@ function forum_post_subscription($fromform, $forum, $discussion) {
  *      Any strings not passed in are taken from the $defaultmessages array
  *      at the top of the function.
  * @param bool $cantaccessagroup
- * @param bool $fakelink
+ * @param bool $unused1
  * @param bool $backtoindex
- * @param array $subscribed_forums
+ * @param array $unused2
  * @return string
  */
-function forum_get_subscribe_link($forum, $context, $messages = array(), $cantaccessagroup = false, $fakelink=true, $backtoindex=false, $subscribed_forums=null) {
+function forum_get_subscribe_link($forum, $context, $messages = array(), $cantaccessagroup = false, $unused1 = true,
+    $backtoindex = false, $unused2 = null) {
     global $CFG, $USER, $PAGE, $OUTPUT;
     $defaultmessages = array(
         'subscribed' => get_string('unsubscribe', 'forum'),
@@ -4835,22 +4836,11 @@ function forum_get_subscribe_link($forum, $context, $messages = array(), $cantac
         } else {
             $backtoindexlink = '';
         }
-        $link = '';
 
-        if ($fakelink) {
-            $PAGE->requires->js('/mod/forum/forum.js');
-            $PAGE->requires->js_function_call('forum_produce_subscribe_link', array($forum->id, $backtoindexlink, $linktext, $linktitle));
-            $link = "<noscript>";
-        }
         $options['id'] = $forum->id;
         $options['sesskey'] = sesskey();
         $url = new moodle_url('/mod/forum/subscribe.php', $options);
-        $link .= $OUTPUT->single_button($url, $linktext, 'get', array('title'=>$linktitle));
-        if ($fakelink) {
-            $link .= '</noscript>';
-        }
-
-        return $link;
+        return $OUTPUT->single_button($url, $linktext, 'get', array('title' => $linktitle));
     }
 }
 
index ffdc388..57999ce 100644 (file)
@@ -52,7 +52,6 @@
     {{#str}}searchforumintro, forum{{/str}}
 </div>
 <div class="box generalbox boxaligncenter">
-    <script type="text/javascript" src="{{scripturl}}"></script>
     <form id="searchform" action="{{actionurl}}" method="get">
         <table class="searchbox" id="form" cellpadding="10">
             <tr>
@@ -95,7 +94,7 @@
                     {{#str}}searchdatefrom, forum{{/str}}
                 </td>
                 <td class="c1">
-                    <input type="checkbox" name="timefromrestrict" value="1" onclick="return lockoptions('searchform', 'timefromrestrict', timefromitems)" {{#datefromchecked}}checked{{/datefromchecked}}>
+                    <input type="checkbox" name="timefromrestrict" value="1" {{#datefromchecked}}checked{{/datefromchecked}}>
                     {{{datefromfields}}}
                     <input type="hidden" name="hfromday" value="0">
                     <input type="hidden" name="hfrommonth" value="0">
                     {{#str}}searchdateto, forum{{/str}}
                 </td>
                 <td class="c1">
-                    <input type="checkbox" name="timetorestrict" value="1" onclick="return lockoptions('searchform', 'timetorestrict', timetoitems)" {{#datetochecked}}checked{{/datetochecked}}>
+                    <input type="checkbox" name="timetorestrict" value="1" {{#datetochecked}}checked{{/datetochecked}}>
                     {{{datetofields}}}
                     <input type="hidden" name="htoday" value="0">
                     <input type="hidden" name="htomonth" value="0">
             </tr>
         </table>
     </form>
-    {{#js}}
-        lockoptions_timetoitems();
-        lockoptions_timefromitems();
-    {{/js}}
 </div>
+{{#js}}
+    require(['jquery'], function($) {
+        var toggleDateFields = function(prefix, disabled) {
+            $('#searchform select[name^=' + prefix + ']').prop('disabled', disabled);
+            $('#searchform input[name^=h' + prefix + ']').val(disabled ? 1 : 0);
+        };
+
+        toggleDateFields('from', true);
+        $("#searchform input[name='timefromrestrict']").click(function() {
+            toggleDateFields('from', !this.checked);
+        });
+
+        toggleDateFields('to', true);
+        $("#searchform input[name='timetorestrict']").click(function() {
+            toggleDateFields('to', !this.checked);
+        });
+    });
+{{/js}}
index 3e96080..a7a956c 100644 (file)
@@ -52,7 +52,6 @@
     {{#str}}searchforumintro, forum{{/str}}
 </div>
 <div class="box generalbox boxaligncenter">
-    <script type="text/javascript" src="{{scripturl}}"></script>
     <form id="searchform" action="{{actionurl}}" method="get">
         <table class="searchbox table table-striped" id="form" cellpadding="10">
             <tr>
@@ -95,7 +94,7 @@
                     {{#str}}searchdatefrom, forum{{/str}}
                 </td>
                 <td class="c1 text-nowrap form-inline">
-                    <input type="checkbox" name="timefromrestrict" value="1" onclick="return lockoptions('searchform', 'timefromrestrict', timefromitems)" {{#datefromchecked}}checked{{/datefromchecked}}>
+                    <input type="checkbox" name="timefromrestrict" value="1" {{#datefromchecked}}checked{{/datefromchecked}}>
                     {{{datefromfields}}}
                     <input type="hidden" name="hfromday" value="0">
                     <input type="hidden" name="hfrommonth" value="0">
                     {{#str}}searchdateto, forum{{/str}}
                 </td>
                 <td class="c1 text-nowrap form-inline">
-                    <input type="checkbox" name="timetorestrict" value="1" onclick="return lockoptions('searchform', 'timetorestrict', timetoitems)" {{#datetochecked}}checked{{/datetochecked}}>
+                    <input type="checkbox" name="timetorestrict" value="1" {{#datetochecked}}checked{{/datetochecked}}>
                     {{{datetofields}}}
                     <input type="hidden" name="htoday" value="0">
                     <input type="hidden" name="htomonth" value="0">
             </tr>
         </table>
     </form>
-    {{#js}}
-        lockoptions_timetoitems();
-        lockoptions_timefromitems();
-    {{/js}}
 </div>
+{{#js}}
+require(['jquery'], function($) {
+    var toggleDateFields = function(prefix, disabled) {
+        $('#searchform select[name^=' + prefix + ']').prop('disabled', disabled);
+        $('#searchform input[name^=h' + prefix + ']').val(disabled ? 1 : 0);
+    };
+
+    toggleDateFields('from', true);
+    $("#searchform input[name='timefromrestrict']").click(function() {
+        toggleDateFields('from', !this.checked);
+    });
+
+    toggleDateFields('to', true);
+    $("#searchform input[name='timetorestrict']").click(function() {
+        toggleDateFields('to', !this.checked);
+    });
+});
+{{/js}}
\ No newline at end of file