Skip to content
Snippets Groups Projects
Commit 938335e6 authored by Tobias Baden's avatar Tobias Baden
Browse files

Fixed the search function

- Search is now an "OR"-Search
-- Finding Courses containing Keyword1 OR Keyword2
- Updated Version
parent 8b97a109
No related branches found
No related tags found
No related merge requests found
/*! hshcourselist 2018-08-29 */
define(["jquery"],function(a){function b(b,c,d,e,f,g,h,i,j){c&&(a("#hshcourseprogress").show(),a.ajax({type:"GET",url:j+"/blocks/hshcourselist/hshcourselist.php",data:"course="+b+"&instanceid="+e+"&sesskey="+f+"&contextid="+g+"&idSearching="+h+"&orderbysemester="+i,dataType:"json",success:function(b){var c=JSON.stringify(b),e=JSON.parse(c),f=a("<ul class='list-group' id='hshcourselistul'></ul>");e.length>0&&a.each(e,function(b,c){switch(d){case"0":displaystr=c.shortname;break;case"1":displaystr=c.fullname;break;case"2":displaystr=c.shortname+": "+c.fullname;break;default:displaystr=c.fullname}a('<li class="list-group-item hshcoursesearchlistitem " value="'+c.id+'"><a href="'+j+"/course/view.php?id="+c.id+'">'+displaystr+"</a> </li>").appendTo(f)}),a("#hshcourselistul").replaceWith(f),a("#hshcourseprogress").hide()},error:function(){console.error("error"),"abort"!==o.statusText&&(a("#hshcourseprogress").hide(),void 0!==o.statusText&&console.error("ABORT + STATUS : "+o.statusText))}}))}return{init:function(c,d){var e,c=c,f=c.instanceid,g=c.sesskey,h=c.displaymode,i=c.contextid,j=!1,k=!1,l=!1,m=c.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){m=document.getElementById("orderbysemestercheckbox_id").checked,j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)}),a("#hshcourselistsearch").on("keyup",function(c){var n=c.keyCode;m=document.getElementById("orderbysemestercheckbox_id").checked,40!==n&&38!==n&&13!==n&&(j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,j=!0,k=!1,l=!1,m=document.getElementById("orderbysemestercheckbox_id").checked,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:k=!1,(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)})}}});
\ No newline at end of file
define(["jquery"],function(a){function b(b,c,d,e,f,g,h,i,j){if(c){var k=b.split(/[ ,]+/),l=["-1"],m=a("<ul class='list-group' id='hshcourselistul'></ul>");a("#hshcourseprogress").show(),k.forEach(function(b){a.ajax({type:"GET",url:j+"/blocks/hshcourselist/hshcourselist.php",data:"course="+b+"&instanceid="+e+"&sesskey="+f+"&contextid="+g+"&idSearching="+h+"&orderbysemester="+i,dataType:"json",success:function(b){var c=JSON.stringify(b),e=JSON.parse(c);e.length>0&&a.each(e,function(b,c){switch(d){case"0":displaystr=c.shortname;break;case"1":displaystr=c.fullname;break;case"2":displaystr=c.shortname+": "+c.fullname;break;default:displaystr=c.fullname}l.includes(c.id)||(l.push(c.id),a('<li class="list-group-item hshcoursesearchlistitem " value="'+c.id+'"><a href="'+j+"/course/view.php?id="+c.id+'">'+displaystr+"</a> </li>").appendTo(m))})},error:function(a){console.error("error - courselist")}})}),void 0!==m&&(a("#hshcourselistul").replaceWith(m),a("#hshcourseprogress").hide())}}return{init:function(c,d){var e,c=c,f=c.instanceid,g=c.sesskey,h=c.displaymode,i=c.contextid,j=!1,k=!1,l=!1,m=c.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){m=document.getElementById("orderbysemestercheckbox_id").checked,j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)}),a("#hshcourselistsearch").on("keyup",function(c){var n=c.keyCode;m=document.getElementById("orderbysemestercheckbox_id").checked,40!==n&&38!==n&&13!==n&&(j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,j=!0,k=!1,l=!1,m=document.getElementById("orderbysemestercheckbox_id").checked,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:k=!1,(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)})}}});
\ No newline at end of file
define(['jquery'], function ($) {
function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot) {
if (reloadBool) {
var splittedSearchstring = searchstring.split(/[ ,]+/);
var courseInList = ["-1"];
var list = $("<ul class='list-group' id='hshcourselistul'></ul>");;
$("#hshcourseprogress").show();
splittedSearchstring.forEach(function (searchquery) {
$.ajax({
type: 'GET',
url: wwwroot + '/blocks/hshcourselist/hshcourselist.php',
data: 'course=' + searchstring + '&instanceid=' + instanceid
data: 'course=' + searchquery + '&instanceid=' + instanceid
+ '&sesskey=' + sesskey + '&contextid=' + contextid
+ '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester,
dataType: "json",
success: function (response) {
var plainJSON = JSON.stringify(response);
var courses = JSON.parse(plainJSON);
var list = $("<ul class='list-group' id='hshcourselistul'></ul>");
if (courses.length > 0) {
$.each(courses, function (index, course) {
switch (displaymode) {
case '0':
displaystr = course.shortname;
break;
case '1':
displaystr = course.fullname;
break;
case '2':
displaystr = course.shortname + ': ' + course.fullname;
break;
default:
displaystr = course.fullname;
break;
}
if (!courseInList.includes(course.id)) {
courseInList.push(course.id);
$('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">'
+ '<a href="' + wwwroot + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>')
.appendTo(list);
} else {
// Kurs schon in der Liste
}
});
}
$("#hshcourselistul").replaceWith(list);
$("#hshcourseprogress").hide();
},
error: function () {
console.error("error");
if (o.statusText !== 'abort') {
$("#hshcourseprogress").hide();
if (o.statusText !== undefined) {
console.error("ABORT + STATUS : " + o.statusText);
}
}
error: function (o) {
console.error("error - courselist");
}
});
});
if (list !== undefined) {
$("#hshcourselistul").replaceWith(list);
$("#hshcourseprogress").hide();
} else {
}
} else {
}
}
......
......@@ -3,7 +3,6 @@
defined('MOODLE_INTERNAL') || die();
class block_hshcourselist extends block_base {
private $globalconf;
public function init() {
$this->globalconf = get_config('block_hshcourselist');
$this->title = get_string('default_blocktitle', 'block_hshcourselist');
......@@ -37,6 +36,7 @@ class block_hshcourselist extends block_base {
$this->content = new stdClass();
$context_block = context_block::instance($this->instance->id);
$search = optional_param('hshcoursesearch', '', PARAM_TEXT);
$hshcoursesubmit = optional_param('hshcoursesubmit', false, PARAM_TEXT);
// set placeholder
if($this->config->placeholder) {
......
(function($) {
/*(function($) {
function changeActionString(current) {
var actionString = getRootWebSitePath() + '/course/view.php?id=' + current.val();
$('#hshcourseform').attr('action', actionString);
......@@ -76,3 +76,4 @@
scrollIntoViewIfNeeded($current[0]);
});
}(jQuery));
*/
\ No newline at end of file
<?php
$plugin->component = 'block_hshcourselist';
$plugin->version = 2018082900; // YYYYMMDDHH
$plugin->version = 2018082901; // YYYYMMDDHH
$plugin->requires = 2016112900; // YYYYMMDDHH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment