From 39a97f554fbf349bd7b9890259620e85577c9959 Mon Sep 17 00:00:00 2001 From: Zavier Banks Date: Thu, 19 Sep 2019 16:27:08 +0000 Subject: [PATCH] lp#1016102: Solve the Problem of the UI allowing unreasonable dates from the user I added a date limiter in the checkout.js file, that prevents the user from making unreasonable dates. Signed-off-by: Zavier Banks lp#1016102: due date fields allow non-sane due dates I added in a conditional that checks if the date is valid, and not unreasonable. Additionally, I added a YAOUS that gives the amount of years maximum, you can check out a book. The code can be changed to be more specific, if necessary. Signed-off-by: Zavier Banks lp#1016102 due date fields allow non-sane due dates I reconfigured the way I found and implemented the maximum due date. In the initialization of the checkout.js document, I added a way to get the maximum date from the database, and add it to the current date. In the t_checkout.tt2 file, I added a max_date to the date input as well. Signed-off-by: Zavier Banks --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 13 +++++++++-- ...a.lp1016102-due-date-max-checkout-interval.sql | 15 +++++++++++++ .../src/templates/staff/circ/patron/t_checkout.tt2 | 4 ++-- .../js/ui/default/staff/circ/patron/checkout.js | 26 ++++++++++++++++------ 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index daf37c36d3..716c501b92 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -3002,8 +3002,17 @@ SELECT SETVAL('acq.user_request_type_id_seq'::TEXT, 7); -- org_unit setting types INSERT into config.org_unit_setting_type ( name, grp, label, description, datatype, fm_class ) VALUES - -( 'acq.copy_creator_uses_receiver', 'acq', +( 'circ.maximum_due_date','gui', + oils_i18n_gettext( + 'circ.maximum_due_date_length', + 'Maximum Future Due Date Interval.', + 'coust', 'label'), + oils_i18n_gettext( + 'circ.maximum_due_date_length', + 'How far in the future you can set a due date', + 'coust', 'label'), + 'interval', null ) +,( 'acq.copy_creator_uses_receiver', 'acq', oils_i18n_gettext('acq.copy_creator_uses_receiver', 'Set copy creator as receiver', 'coust', 'label'), diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql new file mode 100644 index 0000000000..423237bacb --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.lp1016102-due-date-max-checkout-interval.sql @@ -0,0 +1,15 @@ +INSERT into config.org_unit_setting_type + (name, datatype, grp, label, description) +VALUES ( + 'circ.maximum_due_date', 'interval', 'gui' + oils_i18n_gettext( + 'circ.maximum_due_date_length', + 'Maximum Future Due Date Interval.', + 'coust', 'label' + ), + oils_i18n_gettext( + 'circ.maximum_due_date_length', + 'How far in the future you can set a due date' + 'coust', 'label' + ) +); \ No newline at end of file diff --git a/Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2 index c7c6fc54b8..08ba06c41d 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2 @@ -75,8 +75,8 @@ [% l('Specific Due Date') %] --> -
- +
+
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js index d79811c705..1d71ed3805 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js @@ -10,7 +10,20 @@ angular.module('egPatronApp').controller('PatronCheckoutCtrl', function($scope , $q , $routeParams , egCore , egUser , patronSvc , egGridDataProvider , $location , $timeout , egCirc , ngToast) { - $scope.initTab('checkout', $routeParams.id).finally(function(){ + $scope.initTab('checkout', $routeParams.id).then(function(){ + var dateLimit; + var limitedDate; + egCore.org.settings([ + 'circ.maximum_due_date' + ]).then(function(settings) { //Then log the maximum date set by the user. + dateLimit= settings['circ.maximum_due_date']; + if(dateLimit!=null){ + limitedDate = new Date(); + limitedDate.setSeconds(limitedDate.getSeconds()+egCore.date.intervalToSeconds(dateLimit)) + } + $scope.maxDate=limitedDate; + }) + }).finally(function(){ $scope.focusMe = true; }); $scope.checkouts = patronSvc.checkouts; @@ -140,15 +153,14 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc , $scope.checkout = function(args) { var params = angular.copy(args); - params.patron_id = patronSvc.current.id(); - - if (args.sticky_date) { - params.due_date = args.due_date.toISOString(); + params.patron_id = patronSvc.current.id(); + + if (args.sticky_date) {//If the date, given by the user, is less that the date limit set by the admin + params.due_date = args.due_date.toISOString();//Add the due date to the parameters. } else { delete params.due_date; } - delete params.sticky_date; - + delete params.sticky_date; if (params.noncat_type == 'barcode') { if (!args.copy_barcode) return; -- 2.11.0