MDL-57660 mod_forum: Preserve forum ID selection after form submission
[moodle.git] / theme / boost / templates / mod_forum / big_search_form.mustache
1 {{!
2     This file is part of Moodle - http://moodle.org/
4     Moodle is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
9     Moodle is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
14     You should have received a copy of the GNU General Public License
15     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 }}
17 {{!
18     @template mod_forum/big_search_form
20     Big search form.
22     Example context (json):
23     {
24         "actionurl": "https://example.com/mod/forum/search.php",
25         "courseid": "2",
26         "words": "apples",
27         "phrase": "Lorem ipsum dolor",
28         "notwords": "Not these words",
29         "showfullwords": [
30             {
31                 "fullwords": "Exactly"
32             }
33         ],
34         "datefromchecked": 1,
35         "datetochecked": "",
36         "forumoptions": [
37             {
38                 "name": "Forum One",
39                 "value": "23"
40             },
41             {
42                 "name": "Forum Two",
43                 "value": "34"
44             }
45         ],
46         "subject": "Help me please",
47         "user": "Helpy McUser"
48     }
49 }}
50 <div id="intro" class="box searchbox boxaligncenter">
51     {{#str}}searchforumintro, forum{{/str}}
52 </div>
53 <div class="box generalbox boxaligncenter">
54     <form id="searchform" action="{{actionurl}}" method="get">
55         <table class="searchbox table table-striped" id="form">
56             <tr>
57                 <td class="c0 text-xs-right">
58                     <label for="words">{{#str}}searchwords, forum{{/str}}</label>
59                     <input type="hidden" value="{{courseid}}" name="id">
60                 </td>
61                 <td class="c1">
62                     <input type="text" class="form-control" name="words" id="words" value="{{words}}">
63                 </td>
64             </tr>
65             <tr>
66                 <td class="c0 text-xs-right">
67                     <label for="phrase">{{#str}}searchphrase, forum{{/str}}</label>
68                 </td>
69                 <td class="c1">
70                     <input type="text" class="form-control" name="phrase" id="phrase" value="{{phrase}}">
71                 </td>
72             </tr>
73             <tr>
74                 <td class="c0 text-xs-right">
75                     <label for="notwords">{{#str}}searchnotwords, forum{{/str}}</label>
76                 </td>
77                 <td class="c1">
78                     <input type="text" class="form-control" name="notwords" id="notwords" value="{{notwords}}">
79                 </td>
80             </tr>
81             {{#showfullwords}}
82                 <tr>
83                     <td class="c0 text-xs-right">
84                         <label for="fullwords">{{#str}}searchfullwords, forum{{/str}}</label>
85                     </td>
86                     <td class="c1">
87                         <input type="text" class="form-control" name="fullwords" id="fullwords" value="{{fullwords}}">
88                     </td>
89                 </tr>
90             {{/showfullwords}}
91             <tr>
92                 <td class="c0 text-xs-right">
93                     {{#str}}searchdatefrom, forum{{/str}}
94                 </td>
95                 <td class="c1 text-nowrap form-inline">
96                     <input type="checkbox" name="timefromrestrict" value="1" {{#datefromchecked}}checked{{/datefromchecked}}>
97                     {{{datefromfields}}}
98                     <input type="hidden" name="hfromday" value="0">
99                     <input type="hidden" name="hfrommonth" value="0">
100                     <input type="hidden" name="hfromyear" value="0">
101                     <input type="hidden" name="hfromhour" value="0">
102                     <input type="hidden" name="hfromminute" value="0">
103                 </td>
104             </tr>
105             <tr>
106                 <td class="c0 text-xs-right">
107                     {{#str}}searchdateto, forum{{/str}}
108                 </td>
109                 <td class="c1 text-nowrap form-inline">
110                     <input type="checkbox" name="timetorestrict" value="1" {{#datetochecked}}checked{{/datetochecked}}>
111                     {{{datetofields}}}
112                     <input type="hidden" name="htoday" value="0">
113                     <input type="hidden" name="htomonth" value="0">
114                     <input type="hidden" name="htoyear" value="0">
115                     <input type="hidden" name="htohour" value="0">
116                     <input type="hidden" name="htominute" value="0">
117                 </td>
118             </tr>
119             <tr>
120                 <td class="c0 text-xs-right">
121                     <label for="menuforumid">{{#str}}searchwhichforums, forum{{/str}}</label>
122                 </td>
123                 <td class="c1">
124                     <select name="forumid" id="menuforumid" class="form-control">
125                         {{#forumoptions}}
126                             <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
127                         {{/forumoptions}}
128                     </select>
129                 </td>
130             </tr>
131             <tr>
132                 <td class="c0 text-xs-right">
133                     <label for="subject">{{#str}}searchsubject, forum{{/str}}</label>
134                 </td>
135                 <td class="c1">
136                     <input type="text" class="form-control" name="subject" id="subject" value="{{subject}}">
137                 </td>
138             </tr>
139             <tr>
140                 <td class="c0 text-xs-right">
141                     <label for="user">{{#str}}searchuser, forum{{/str}}</label>
142                 </td>
143                 <td class="c1">
144                     <input type="text" class="form-control" name="user" id="user" value="{{user}}">
145                 </td>
146             </tr>
147             <tr>
148                 <td> </td>
149                 <td class="submit">
150                     <button type="submit" class="btn btn-primary">{{#str}}searchforums, forum{{/str}}</button>
151                 </td>
152             </tr>
153         </table>
154     </form>
155 </div>
156 {{#js}}
157 require(['jquery'], function($) {
158     var toggleDateFields = function(prefix, disabled) {
159         $('#searchform select[name^=' + prefix + ']').prop('disabled', disabled);
160         $('#searchform input[name^=h' + prefix + ']').val(disabled ? 1 : 0);
161     };
163     toggleDateFields('from', !$("#searchform input[name='timefromrestrict']").prop('checked'));
164     $("#searchform input[name='timefromrestrict']").click(function() {
165         toggleDateFields('from', !this.checked);
166     });
168     toggleDateFields('to', !$("#searchform input[name='timetorestrict']").prop('checked'));
169     $("#searchform input[name='timetorestrict']").click(function() {
170         toggleDateFields('to', !this.checked);
171     });
172 });
173 {{/js}}