Koha/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt
Jonathan Druart 9309dedb53
Bug 30578: Remove circ/ysearch.pl in favor of the /patrons REST API route
This patch removes the circ/ysearch.pl script used by the jQuery autocomplete widget.
We can now use the /api/v1/patrons endpoint to retrieve the patrons and
generate the patron result list.

Prior to this patch the different occurrences were defining the style
and the list of patron's attributes to display for each option (name,
date of birth, age, address, etc.). Now they are all displaying the same
information.

To acchieve this we had to:
* Make js-date-format.inc and js-patron-get-age.inc available from js_includes.inc
and so available from everywhere, which is certainly a good move. We
could discuss why this code is in include file instead of JS files
however.
* Remove the .ajaxSetup call in tags-review.js to reduce its scope: an
underscore parameter was added to the REST API query (?)

A better solution would have been to extend the existing widget
(https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/)
but I didn't manage to do it, and I feel like there is a bug in jQuery
autocomplete. The "source" was not taken into account.
We could think about replacing the jQuery autocomplete with something
else, but that's outside the scope of this bug.

Test plan:
Search for patrons and confirm the autocomplete works and that the
"select" action works as before (either a redirect or select the
patrons) on the different views:
* Place a hold
* Search for tags (form on the left)
* In the header, "Check out" and "Search patrons"
* Add instructors to course reserves
* View logs (the "librarian" input)

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-07-18 11:01:34 -03:00

214 lines
9.8 KiB
Text

[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% IF course_name %] Edit [% course_name | html %] [% ELSE %] New course [% END %] &rsaquo; Course reserves &rsaquo; Koha</title>
[% INCLUDE 'doc-head-close.inc' %]
<style>
#course_instructors {
float: left;
}
.instructor_line {
padding: .3em;
}
</style>
</head>
<body id="courses_course" class="course">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
<ol>
<li>
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
</li>
<li>
<a href="/cgi-bin/koha/course_reserves/course-reserves.pl">Course reserves</a>
</li>
<li>
<a href="#" aria-current="page">
[% IF course_name %] Edit <em>[% course_name | html %]</em> [% ELSE %] New course [% END %]
</a>
</li>
</ol>
</nav>
[% IF ( departments ) %]
<div class="main container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1>[% IF course_name %] Edit <em>[% course_name | html %]</em> [% ELSE %] New course [% END %]</h1>
<form method="post" action="/cgi-bin/koha/course_reserves/mod_course.pl" class="validated">
[% IF course_id %]<input type="hidden" name="course_id" value="[% course_id | html %]" />[% END %]
<fieldset class="rows">
<legend>[% IF course_id %]Edit course[% ELSE %]Create course[% END %]</legend>
<ol>
<li>
<label class="required" for="department">Department:</label>
<select id="department" name="department" required="required" class="required">
<option value="">Select a department</option>
[% FOREACH d IN departments %]
[% IF d.authorised_value == department %]
<option value="[% d.authorised_value | html %]" selected="selected">[% d.lib | html %]</option>
[% ELSE %]
<option value="[% d.authorised_value | html %]">[% d.lib | html %]</option>
[% END %]
[% END %]
</select>
<span class="required">Required</span>
</li>
<li>
<label class="required" for="course_number">Course number:</label>
<input id="course_number" name="course_number" type="text" value="[% course_number | html %]" required="required" class="required" />
<span class="required">Required</span>
</li>
<li>
<label for="section">Section:</label>
<input id="section" name="section" type="text" value="[% section | html %]"/>
</li>
<li>
<label class="required" for="course_name">Course name:</label>
<input id="course_name" name="course_name" type="text" value="[% course_name | html %]" required="required" class="required" />
<span class="required">Required</span>
</li>
<li>
[% IF terms %]
<label for="term">[% tp('Semester', 'Term:') | html %]</label>
<select id="term" name="term">
<option value=""></option>
[% FOREACH t IN terms %]
[% IF t.authorised_value == term %]
<option value="[% t.authorised_value | html %]" selected="selected">[% t.lib | html %]</option>
[% ELSE %]
<option value="[% t.authorised_value | html %]">[% t.lib | html %]</option>
[% END %]
[% END %]
</select>
[% ELSE %]
<span class="label">[% tp('Semester', 'Term:') | html %] </span>
<span id="term">No TERM authorised values found! Please create one or more authorised values with the category TERM.</span>
[% END %]
</li>
<li>
<span class="label">Instructors:</span>
<div id="course_instructors">
<div id="instructors">
[% FOREACH i IN instructors %]
<div class="instructor_line" id="borrower_[% i.borrowernumber | html %]">[% i.surname | html %], [% i.firstname | html %] ( <a href="#" class="removeInstructor"><i class="fa fa-trash"></i> Remove </a> )
<input type='hidden' name='instructors' value='[% i.borrowernumber | html %]' />
</div>
[% END %]
</div>
<p>
<label for="find_instructor">Instructor search:</label>
<input autocomplete="off" id="find_instructor" type="text" style="width:150px" class="noEnterSubmit"/>
</p>
<div id="find_instructor_container"></div>
</div>
<li>
<label for="staff_note">Staff note:</label>
<textarea name="staff_note" id="staff_note">[% staff_note | html %]</textarea>
</li>
<li>
<label for="public_note">Public note:</label>
<textarea name="public_note" id="public_note">[% public_note | html %]</textarea>
</li>
<li>
<label for="students_count">Number of students:</label>
<input id="students_count" name="students_count" type="text" value="[% students_count | html %]" />
</li>
<li>
<label for="enabled">Enabled?</label>
[% IF enabled == 'no' %]
<input type="checkbox" name="enabled" id="enabled" />
[% ELSE %]
<input type="checkbox" name="enabled" id="enabled" checked="checked" />
[% END %]
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" value="Save" class="submit" />
[% IF course_id %]
<a href="/cgi-bin/koha/course_reserves/course-details.pl?course_id=[% course_id | uri %]" class="cancel">Cancel</a>
[% ELSE %]
<a href="/cgi-bin/koha/course_reserves/course-reserves.pl" class="cancel">Cancel</a>
[% END %]
</fieldset>
</form>
</div>
</div>
[% ELSE %]
<div class="dialog alert">
<h1>No DEPARTMENT authorized values found!</h1>
<p>
[% IF ( CAN_user_parameters ) %]
<span>Please <a href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=DEPARTMENT">create one or more authorized values</a> with the category DEPARTMENT.</span>
[% ELSE %]
<span>An administrator must create one or more authorized values with the category DEPARTMENT.</span>
[% END %]
</p>
</div>
[% END %]
[% IF ( departments ) %]
[% MACRO jsinclude BLOCK %]
<script>
$(document).ready(function(){
patron_autocomplete($("#find_instructor"), { 'on-select-callback': function( event, ui ) {
AddInstructor( ui.item.surname + ", " + ui.item.firstname, ui.item.patron_id );
return false;
}
});
if ( ! $('#instructors').html() ) {
$('#course_instructors').hide();
}
$("body").on("click",".removeInstructor",function(e){
e.preventDefault();
var divid = $(this).parent().attr("id");
var borrowernumber = divid.replace("borrower_","");
RemoveInstructor(borrowernumber);
});
});
function AddInstructor( name, borrowernumber ) {
div = "<div class='instructor_line' id='borrower_" + borrowernumber + "'>" + ( name ? name.escapeHtml() : "" ) + " ( <a href='#' class='removeInstructor'><i class='fa fa-trash'></i> " + _("Remove")+ " </a> ) <input type='hidden' name='instructors' value='" + borrowernumber + "' /></div>";
$('#instructors').append( div );
$('#find_instructor').val('').focus();
$('#course_instructors').show();
}
function RemoveInstructor( borrowernumber ) {
$( '#borrower_' + borrowernumber ).remove();
if ( ! $('#instructors').html() ) {
$('#course_instructors').hide( 800 );
}
}
</script>
[% END %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]