LP1717025: Persist Specific Due Dates Until Logout
authorJason Boyer <JBoyer@library.in.gov>
Wed, 13 Sep 2017 20:36:47 +0000 (15:36 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 16 Oct 2017 19:37:37 +0000 (15:37 -0400)
Add an option to the specific due date feature to
save the specified date until logout. This allows
all circulations from a given workstation to be due
on the same date.

Signed-off-by: Jason Boyer <JBoyer@library.in.gov>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js

index 9343c92..a2db38e 100644 (file)
   <div class="col-md-6">
     <div class="flex-row">
       <div class="flex-cell"></div>
-      <div class="checkbox pad-horiz">
+
+<div class="input-group">
+<div class="input-group-btn" uib-dropdown>
+      <button type="button" class="btn btn-default" uib-dropdown-toggle>
+        [% l('Date Options') %]
+        <span class="caret"></span>
+      </button>
+      <ul class="pull-right" uib-dropdown-menu>
+        <li>
+          <a href
+            ng-click="toggle_opt('sticky_date')">
+            <span ng-if="date_options.sticky_date"
+              class="label label-success">&#x2713;</span>
+            <span ng-if="!date_options.sticky_date"
+              class="label label-warning">&#x2717;</span>
+            <span>[% l('Specific Due Date') %]</span>
+          </a>
+        </li>
+        <li>
+          <a href
+            ng-click="toggle_opt('until_logout')">
+            <span ng-if="date_options.until_logout"
+              class="label label-success">&#x2713;</span>
+            <span ng-if="!date_options.until_logout"
+              class="label label-warning">&#x2717;</span>
+            <span>[% l('Use Specific Due Date Until Logout') %]</span>
+          </a>
+        </li>
+      </ul>
+</div>
+
+      <!-- <div class="checkbox pad-horiz">
         <label>
           <input type="checkbox" ng-model="checkoutArgs.sticky_date"/>
           [% l('Specific Due Date') %]
         </label>
-      </div>
-      <!--
-      <div><input type="checkbox" class="checkbox" ng-model="checkoutArgs.sticky_date"/></div>
-      <div class="pad-horiz">[% l('Specific Due Date') %]</div>
-      -->
+      </div> -->
       <!-- FIXME: This needs a time component as well, but type="datetime" 
             is not yet supported by any browsers -->
       <div><eg-date-input ng-model="checkoutArgs.due_date"></eg-date-input>
       </div>
+</div>
     </div>
   </div>
 </div>
index e85a3f7..7c42a27 100644 (file)
@@ -45,6 +45,53 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
         }
     }
 
+    $scope.date_options = {
+        due_date : egCore.hatch.getSessionItem('eg.circ.checkout.due_date'),
+        sticky_date : egCore.hatch.getSessionItem('eg.circ.checkout.until_logout'),
+        until_logout : egCore.hatch.getSessionItem('eg.circ.checkout.until_logout')
+    }
+
+    if ($scope.date_options.until_logout) { // If until_logout is set there should also be a date set. 
+        $scope.checkoutArgs.due_date = new Date($scope.date_options.due_date);
+        $scope.checkoutArgs.sticky_date = true;
+    }
+
+    $scope.toggle_opt = function(opt) {
+        if ($scope.date_options[opt]) {
+            $scope.date_options[opt] = false;
+        } else {
+            $scope.date_options[opt] = true;
+        }
+    }
+
+    // The interactions between these options are complicated enough that $watch'ing them all is the only safe way to keep things sane.
+    $scope.$watch('date_options.sticky_date', function(newval) {
+        if ( newval ) { // was false, is true
+            // $scope.date_options.due_date = checkoutArgs.due_date;
+        } else {
+            $scope.date_options.until_logout = false;
+        }
+        $scope.checkoutArgs.sticky_date = newval;
+    });
+
+    $scope.$watch('date_options.until_logout', function(newval) {
+        if ( newval ) { // was false, is true
+            $scope.date_options.sticky_date = true;
+            $scope.date_options.due_date = $scope.checkoutArgs.due_date;
+            egCore.hatch.setSessionItem('eg.circ.checkout.until_logout', true);
+            egCore.hatch.setSessionItem('eg.circ.checkout.due_date', $scope.checkoutArgs.due_date);
+        } else {
+            egCore.hatch.removeSessionItem('eg.circ.checkout.until_logout');
+            egCore.hatch.removeSessionItem('eg.circ.checkout.due_date');
+        }
+    });
+
+    $scope.$watch('checkoutArgs.due_date', function(newval) {
+        if ( $scope.date_options.until_logout ) {
+            egCore.hatch.setSessionItem('eg.circ.checkout.due_date', newval);
+        }
+    });
+
     $scope.has_email_address = function() {
         return (
             patronSvc.current &&