Bugzilla – Attachment 162514 Details for
Bug 36179
"Quick add" patron form should be a modal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36179: patron quick add wip
Bug-36179-patron-quick-add-wip.patch (text/plain), 11.59 KB, created by
Pedro Amorim
on 2024-02-27 15:42:51 UTC
(
hide
)
Description:
Bug 36179: patron quick add wip
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-02-27 15:42:51 UTC
Size:
11.59 KB
patch
obsolete
>From 4658193bde218626d60c463d18d53b26fcb96a68 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Fri, 23 Feb 2024 15:35:03 +0000 >Subject: [PATCH] Bug 36179: patron quick add wip > >--- > .../en/includes/modals/quick_add_patron.inc | 70 ++++++++ > .../prog/en/modules/members/memberentrygen.tt | 3 + > .../prog/js/modals/quick_add_patron.js | 149 ++++++++++++++++++ > 3 files changed, 222 insertions(+) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modals/quick_add_patron.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/modals/quick_add_patron.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/quick_add_patron.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/quick_add_patron.inc >new file mode 100644 >index 00000000000..74a287afae3 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/quick_add_patron.inc >@@ -0,0 +1,70 @@ >+<div class="modal" id="addQuickAddUserModal" tabindex="-1" role="dialog" >+ aria-labelledby="addQuickAddUserModalLabel" aria-hidden="true"> >+ <form id="quick_add_user_form"> >+ <div class="modal-dialog modal-md" role="document"> >+ <div class="modal-content modal-md"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" >+ aria-label="Close"> >+ <span aria-hidden="true">×</span> >+ </button> >+ <h4 class="modal-title" id="addQuickAddUserModalLabel">Add patron >+ </h4> >+ </div> >+ <div class="modal-body"> >+ <fieldset class="rows" id="quick_add_user_fieldset"> >+ <ol> >+ <li> >+ <label for="surname" class="required"> >+ Surname: </label> >+ <input type="text" id="surname_quick_add" name="surname" size="20" >+ value="" required="" class="noEnterSubmit"> >+ <span class="required">Required</span> >+ </li> >+ <li> >+ <label for="cardnumber" class="required"> >+ Card number: >+ </label> >+ <!-- NOTE: div.hint closing tag isn't on the same line --> >+ <input type="text" id="cardnumber_quick_add" name="cardnumber" size="20" >+ value="" minlength="1" maxlength="32" required="" >+ class="noEnterSubmit"> >+ <span class="required">Required</span> >+ <span id="cn_max" class="required" style="display: none;">Card number >+ must not be more than 32 characters.</span> >+ <div class="hint">Card number must be between 1 and 32 characters. >+ </div> >+ <!--/div.hint --> >+ </li> >+ <li> >+ <label for="libraries" class="required">Library:</label> >+ <select name="branchcode" id="libraries_quick_add" >+ class="noEnterSubmit"> >+ >+ </select> >+ <span class="required">Required</span> >+ </li> >+ <li> >+ <label for="categorycode_entry" class="required">Category: </label> >+ <select id="categorycode_entry_quick_add" name="categorycode" >+ class="noEnterSubmit"> >+ </select> >+ <span class="required">Required</span> >+ </li> >+ </ol> >+ </fieldset> >+ </div> <!-- /.modal-body --> >+ <div class="modal-footer"> >+ <input type="hidden" id="quick_add_user_biblio" name="biblio_id" >+ value="test"> >+ <button type="submit" class="btn btn-primary" >+ id="addConfirm">Submit <i id="user-submit-spinner" >+ class="fa fa-spinner fa-pulse fa-fw" >+ style="display:none"></i></button> >+ <button type="button" class="btn btn-default" >+ data-dismiss="modal">Cancel</button> >+ </div> <!-- /.modal-footer --> >+ </div> <!-- /.modal-content --> >+ </div> <!-- /.modal-dialog --> >+ </form> >+ </div> <!-- /#addQuickAddUserModal --> >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >index eda22f1f86e..3f0200ef1bb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -235,6 +235,7 @@ legend:hover { > [% END %] > <i class="fa fa-times"></i> Cancel > </a> >+ <a id="quick_add_user_button" href="#">+ Add new user</a> > </div> > [% END %] > >@@ -1680,7 +1681,9 @@ legend:hover { > [% Asset.js("lib/hc-sticky.js") | $raw %] > [% INCLUDE 'calendar.inc' %] > [% INCLUDE 'str/members-menu.inc' %] >+ [% INCLUDE modals/quick_add_patron.inc %] > [% Asset.js("js/members-menu.js") | $raw %] >+ [% Asset.js("js/modals/quick_add_patron.js") | $raw %] > <script> > function update_cardnumber_warning(size){ > var max_len = [% maxlength_cardnumber | html %]; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/quick_add_patron.js b/koha-tmpl/intranet-tmpl/prog/js/modals/quick_add_patron.js >new file mode 100644 >index 00000000000..525ee521059 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/modals/quick_add_patron.js >@@ -0,0 +1,149 @@ >+$(document).ready(function() { >+ $("#quick_add_user_button").on("click", function () { >+ if (!$("#libraries_quick_add").children("option").length) { >+ _GETLibraries(); >+ } >+ if (!$("#categorycode_entry_quick_add").children("optgroup").length) { >+ _GETPatronCategories(); >+ } >+ $("#addQuickAddUserModal").modal("show"); >+ $(".dialog.alert").remove(); >+ }); >+ >+ $("#addQuickAddUserModal").on("click", "#addConfirm", function (e) { >+ e.preventDefault(); >+ if (!$("#quick_add_user_form").get(0).checkValidity()) { >+ $("#quick_add_user_form").get(0).reportValidity(); >+ } else { >+ $("#user-submit-spinner").show(); >+ _POSTPatron({ >+ surname: $("#surname_quick_add").val(), >+ cardnumber: $("#cardnumber_quick_add").val(), >+ library_id: $("#libraries_quick_add").val(), >+ category_id: $("#categorycode_entry_quick_add").val(), >+ }); >+ } >+ }); >+ >+ /** >+ * Sends a GET request to the /api/v1/patron_categories endpoint to fetch patron categories >+ * >+ * Upon success, adds the categories to the category dropdown >+ */ >+ function _GETPatronCategories() { >+ $.ajax({ >+ url: "/api/v1/patron_categories", >+ type: "GET", >+ success: function (data) { >+ let groupedCategories = Object.groupBy( >+ data, >+ ({ category_type }) => category_type >+ ); >+ >+ // Add <optgroup> >+ $.each(groupedCategories, function (category_code, categories) { >+ $("#categorycode_entry_quick_add").append( >+ $( >+ '<optgroup id="' + >+ category_code + >+ '"label="' + >+ _getCategoryTypeName(category_code) + >+ '"></optgroup>' >+ ) >+ ); >+ >+ // Add <option> >+ $.each(categories, function (i, category) { >+ $( >+ "#categorycode_entry_quick_add #" + category_code >+ ).append( >+ $("<option></option>") >+ .val(category.patron_category_id) >+ .html(category.name) >+ ); >+ }); >+ }); >+ }, >+ error: function (data) { >+ console.log(data); >+ }, >+ }); >+ } >+ >+ /** >+ * Sends a GET request to the /api/v1/libraries endpoint to fetch libraries >+ * >+ * Upon success, adds the libraries to the library dropdown >+ */ >+ function _GETLibraries() { >+ $.ajax({ >+ url: "/api/v1/libraries", >+ type: "GET", >+ success: function (data) { >+ $.each(data, function (val, text) { >+ $("#libraries_quick_add").append( >+ $("<option></option>").val(text.library_id).html(text.name) >+ ); >+ }); >+ }, >+ error: function (data) { >+ console.log(data); >+ }, >+ }); >+ } >+ >+ /** >+ * Sends a POST request to the /api/v1/patrons endpoint to add a new patron >+ * >+ * Upon completion, show a dialog with appropriate message >+ * Upon success, add new patron's cardnumber to the cardnumber input >+ * >+ * @param {Object} params Patron's data to be posted. >+ */ >+ function _POSTPatron(params) { >+ $.ajax({ >+ url: "/api/v1/patrons", >+ type: "POST", >+ headers: { "Content-Type": "application/json;charset=utf-8" }, >+ data: JSON.stringify(params), >+ success: function (data) { >+ $("#user-submit-spinner").hide(); >+ $("#addQuickAddUserModal").modal("hide"); >+ $("#surname_quick_add").val(""); >+ $("#cardnumber_quick_add").val(""); >+ $("#toolbar").before( >+ '<div class="dialog message">' + >+ __( >+ 'Patron sucessfully created: </br> <strong><a target="_blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + >+ data.patron_id + >+ '">' + >+ data.surname + >+ "(" + >+ data.cardnumber + >+ ")" >+ ) + >+ "</div>" >+ ); >+ // create_form_cardnumber_input.val(data.cardnumber); >+ }, >+ error: function (data) { >+ console.log(data); >+ $("#user-submit-spinner").hide(); >+ $("#addQuickAddUserModal").modal("hide"); >+ $("#interlibraryloans").before( >+ '<div class="dialog alert">' + >+ __( >+ "There was an error creating the patron: </br> <strong>" + >+ (data.responseJSON.error >+ ? data.responseJSON.error >+ : data.responseJSON.errors >+ .map((e) => e.path + " " + e.message) >+ .join("</br>")) + >+ "</strong>" >+ ) + >+ "</div>" >+ ); >+ }, >+ }); >+ } >+}); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36179
: 162514