mod_timetable/templates/searchresult.mustache
2020-09-03 21:25:42 +02:00

50 lines
2.1 KiB
Text

<div class="searchresult">
<ul>
{{#searchresults}}
<li><a href="javascript:;" class="searchresults" data-type="{{type}}" data-name="{{name}}" data-add="0">{{description}}</a> <a href="javascript:;" class="searchresults" data-type="{{type}}" data-name="{{name}}" data-add="1">+</a></li>
{{/searchresults}}
</ul>
{{^searchresults}}Keine Treffer{{/searchresults}}
</div>
{{# js }}
require([
'jquery','core/ajax','core/templates', 'core/notification'
] , function($, ajax, templates, notification) {
function load_timetable(type, name, add) {
//alert(searchstring);
var promises = ajax.call([
{ methodname: 'mod_timetable_get', args: { type: type, name: name, week: 0 } },
]);
if (add=='1') {
promises[0].done(function(response) {
console.log('mod_timetable/get is' + response);
templates.render('mod_timetable/timetable',response).done(function(html, js) {
$('.timetable').last().after(html);
templates.runTemplateJS(js);
}).fail(notification.exception);
}).fail(function(ex) {
// do something with the exception
});
} else {
promises[0].done(function(response) {
console.log('mod_timetable/get is' + response);
templates.render('mod_timetable/timetable',response).done(function(html, js) {
$('.timetable').first().replaceWith(html);
templates.runTemplateJS(js);
}).fail(notification.exception);
}).fail(function(ex) {
// do something with the exception
});
}
}
$(".searchresults").click(function() {
load_timetable($(event.target).data('type'),$(event.target).data('name'),$(event.target).data('add'));
});
});
{{/ js }}