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

Fixed the search properly, works now with dynamic wwwroot

- Updated version number
parent 23a046a5
No related branches found
No related tags found
No related merge requests found
/*! hshcourselist 2018-08-29 */ /*! hshcourselist 2018-08-29 */
define(["jquery"],function(a){function b(){var a=document.location.toString(),b=a.indexOf("/",a.indexOf("://")+3);return a.substring(0,b)+"/"}function c(c,d,e,f,g,h,i,j){d&&(a("#hshcourseprogress").show(),a.ajax({type:"GET",url:b()+"/blocks/hshcourselist/hshcourselist.php",data:"course="+c+"&instanceid="+f+"&sesskey="+g+"&contextid="+h+"&idSearching="+i+"&orderbysemester="+j,dataType:"json",success:function(c){var d=JSON.stringify(c),f=JSON.parse(d),g=a("<ul class='list-group' id='hshcourselistul'></ul>");f.length>0&&a.each(f,function(c,d){switch(e){case"0":displaystr=d.shortname;break;case"1":displaystr=d.fullname;break;case"2":displaystr=d.shortname+": "+d.fullname;break;default:displaystr=d.fullname}a('<li class="list-group-item hshcoursesearchlistitem " value="'+d.id+'"><a href="'+b()+"/course/view.php?id="+d.id+'">'+displaystr+"</a> </li>").appendTo(g)}),a("#hshcourselistul").replaceWith(g),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(b){var d,b=b,e=b.instanceid,f=b.sesskey,g=b.displaymode,h=b.contextid,i=!1,j=!1,k=b.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){k=document.getElementById("orderbysemestercheckbox_id").checked,i=!0,d=document.getElementById("hshcourselistsearch").value,"#"===d.slice(0,1)?(a(".idSarchingLabel").show(),j=!0,d=d.slice(1)):(a(".idSarchingLabel").hide(),j=!1),c(d,i,g,e,f,h,j,k)}),a("#hshcourselistsearch").on("keyup",function(b){var l=b.keyCode;k=document.getElementById("orderbysemestercheckbox_id").checked,40!==l&&38!==l&&13!==l&&(i=!0,d=document.getElementById("hshcourselistsearch").value,"#"===d.slice(0,1)?(a(".idSarchingLabel").show(),j=!0,d=d.slice(1)):(a(".idSarchingLabel").hide(),j=!1),c(d,i,g,e,f,h,j,k))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,i=!0,j=!1,k=document.getElementById("orderbysemestercheckbox_id").checked,d=document.getElementById("hshcourselistsearch").value,"#"===d.slice(0,1)?(j=!0,d=d.slice(1)):j=!1,c(d,i,g,e,f,h,j,k)})}}}); 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=c.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){l=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)):(a(".idSarchingLabel").hide(),k=!1),b(e,j,h,f,g,i,k,l,d)}),a("#hshcourselistsearch").on("keyup",function(c){var m=c.keyCode;l=document.getElementById("orderbysemestercheckbox_id").checked,40!==m&&38!==m&&13!==m&&(j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):(a(".idSarchingLabel").hide(),k=!1),b(e,j,h,f,g,i,k,l,d))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,j=!0,k=!1,l=document.getElementById("orderbysemestercheckbox_id").checked,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(k=!0,e=e.slice(1)):k=!1,b(e,j,h,f,g,i,k,l,d)})}}});
\ No newline at end of file \ No newline at end of file
define(['jquery'], function ($) { define(['jquery'], function ($) {
function getRootWebSitePath() { function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot) {
var _location = document.location.toString();
var applicationNameIndex = _location.indexOf('/', _location.indexOf('://') + 3);
var applicationName = _location.substring(0, applicationNameIndex) + '/';
return applicationName;
//var webFolderIndex = _location.indexOf('/', _location.indexOf(applicationName) + applicationName.length);
//var webFolderFullPath = _location.substring(0, webFolderIndex);
//return webFolderFullPath;
}
function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester) {
if (reloadBool) { if (reloadBool) {
$("#hshcourseprogress").show(); $("#hshcourseprogress").show();
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: getRootWebSitePath() + '/blocks/hshcourselist/hshcourselist.php', url: wwwroot + '/blocks/hshcourselist/hshcourselist.php',
data: 'course=' + searchstring + '&instanceid=' + instanceid data: 'course=' + searchstring + '&instanceid=' + instanceid
+ '&sesskey=' + sesskey + '&contextid=' + contextid + '&sesskey=' + sesskey + '&contextid=' + contextid
+ '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester, + '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester,
...@@ -43,7 +33,7 @@ define(['jquery'], function ($) { ...@@ -43,7 +33,7 @@ define(['jquery'], function ($) {
break; break;
} }
$('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">' $('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">'
+ '<a href="' + getRootWebSitePath() + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>') + '<a href="' + wwwroot + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>')
.appendTo(list); .appendTo(list);
}); });
} }
...@@ -65,7 +55,7 @@ define(['jquery'], function ($) { ...@@ -65,7 +55,7 @@ define(['jquery'], function ($) {
} }
return { return {
init: function (jsdataobject) { init: function (jsdataobject, wwwroot) {
var jsdataobject = jsdataobject; var jsdataobject = jsdataobject;
var instanceid = jsdataobject.instanceid; var instanceid = jsdataobject.instanceid;
var sesskey = jsdataobject.sesskey; var sesskey = jsdataobject.sesskey;
...@@ -92,7 +82,7 @@ define(['jquery'], function ($) { ...@@ -92,7 +82,7 @@ define(['jquery'], function ($) {
$(".idSarchingLabel").hide(); $(".idSarchingLabel").hide();
idSearching = false; idSearching = false;
} }
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester); search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot);
}); });
$('#hshcourselistsearch').on('keyup', function (e) { $('#hshcourselistsearch').on('keyup', function (e) {
...@@ -109,7 +99,7 @@ define(['jquery'], function ($) { ...@@ -109,7 +99,7 @@ define(['jquery'], function ($) {
$(".idSarchingLabel").hide(); $(".idSarchingLabel").hide();
idSearching = false; idSearching = false;
} }
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester); search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot);
} }
}); });
$('#hshcourseform').on('submit', function (e) { $('#hshcourseform').on('submit', function (e) {
...@@ -124,7 +114,7 @@ define(['jquery'], function ($) { ...@@ -124,7 +114,7 @@ define(['jquery'], function ($) {
} else { } else {
idSearching = false; idSearching = false;
} }
search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester); search(searchstring, reloadList, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot);
}); });
}, },
} }
......
...@@ -172,7 +172,7 @@ class block_hshcourselist extends block_base { ...@@ -172,7 +172,7 @@ class block_hshcourselist extends block_base {
'orderbysemester' => $orderbysemester, 'orderbysemester' => $orderbysemester,
'contextid' => $this->page->context->id 'contextid' => $this->page->context->id
); );
$this->page->requires->js_call_amd('block_hshcourselist/jmodule', 'init', array($jsdata)); $this->page->requires->js_call_amd('block_hshcourselist/jmodule', 'init', array($jsdata, $CFG->wwwroot));
//Einstellungen für den Custom-Footer //Einstellungen für den Custom-Footer
if (!empty($this->config->footer) && $this->config->enablefooter) { if (!empty($this->config->footer) && $this->config->enablefooter) {
......
<?php <?php
$plugin->component = 'block_hshcourselist'; $plugin->component = 'block_hshcourselist';
$plugin->version = 2018082800; // YYYYMMDDHH $plugin->version = 2018082802; // YYYYMMDDHH
$plugin->requires = 2016112900; // 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