Commit 22526ad9 authored by Dan Poltawski's avatar Dan Poltawski
Browse files

MDL-57550 forum: remove legacy forum.js uses

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
parent 5130953c
......@@ -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;
......
......@@ -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));
}
}
......
......@@ -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">
......@@ -109,7 +108,7 @@
{{#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">
......@@ -153,8 +152,22 @@
</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}}
......@@ -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">
......@@ -109,7 +108,7 @@
{{#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">
......@@ -154,8 +153,22 @@
</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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment