patron reg cont.
authorBill Erickson <berickxx@gmail.com>
Sun, 10 May 2015 21:08:16 +0000 (17:08 -0400)
committerBill Erickson <berickxx@gmail.com>
Sun, 10 May 2015 21:08:16 +0000 (17:08 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/src/templates/staff/css/circ.css.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 7320247..b95af05 100644 (file)
@@ -4,27 +4,45 @@
 
 <!-- IDL field documentation -->
 <fieldset id="reg-field-doc" ng-show="selected_field_doc">
-    <legend>{{idl_fields[selected_field_doc.fm_class()][selected_field_doc.field()].label}}</legend>
+    <legend>
+    {{idl_fields[selected_field_doc.fm_class()][selected_field_doc.field()].label}}
+    </legend>
     <div>{{selected_field_doc.string()}}</div>
 </fieldset>
 
-[% MACRO formfield(cls, field, path, input_type) BLOCK %]
-[% IF NOT input_type; input_type = 'text'; END %] 
+[% MACRO formfield(cls, field, path, input_type) BLOCK;
+
+    # input field generator for text/number/checkbox fields
+
+    IF NOT input_type; input_type = 'text'; END %] 
+
 <div class="row pad-all-min form-group">
     <div class="col-md-3 reg-field-label">
+
+        <!-- field label -->
         <label>{{idl_fields.[% cls %].[% field %].label}}</label>
+
+        <!-- field documentation img/link -->
         <img ng-show="field_doc.[% cls %].[% field %]" 
             ng-click="selected_field_doc=field_doc.[% cls %].[% field %]"
             src='[% DOC_IMG %]'></img>
     </div>
     <div class="col-md-3 reg-field-input">
-        [% IF path %]
-            <!-- linked object -->
-            <input type="[% input_type %]" 
-                class="form-control" ng-model="patron.[% path %].[% field %]"/>
+        <!-- field form input -->
+
+        [%
+        model = path ? 'patron.' _ path _ '.' _ field : 'patron.' _ field;
+        IF input_type == 'checkbox' %]
+
+            <div class='checkbox'>
+                <input type='checkbox' ng-model='[% model %]'/>
+            </div>
+
         [% ELSE %]
+            <!-- text / number input -->
+
             <input type="[% input_type %]" 
-                class="form-control" ng-model="patron.[% field %]"/>
+                class="form-control" ng-model="[% model %]"/>
         [% END %]
     </div>
 </div>
@@ -61,7 +79,7 @@
             src='[% DOC_IMG %]'></img>
     </div>
     <div class="col-md-3 reg-field-input">
-        <eg-org-selector selected="patron.home_ou_obj
+        <eg-org-selector selected="patron.home_ou" 
             onchange=""></eg-org-selector>
     </div>
 </div>
 
 <div class="row pad-all-min form-group">
     <div class="col-md-3 reg-field-label">
-        <label>{{idl_fields.au.home_ou.label}}</label>
-        <img ng-show="field_doc.au.home_ou
-            ng-click="selected_field_doc=field_doc.au.home_ou"
+        <label>{{idl_fields.au.profile.label}}</label>
+        <img ng-show="field_doc.au.profile
+            ng-click="selected_field_doc=field_doc.au.profile"
             src='[% DOC_IMG %]'></img>
     </div>
     <div class="col-md-3 reg-field-input">
         <div class="btn-group" dropdown>
           <button type="button" class="btn btn-default dropdown-toggle">
             <span style="padding-right: 5px;">
-                {{patron.profile.name || "[% l('Profile Group') %]"}}
+                {{patron.profile.name() || "[% l('Profile Group') %]"}}
             </span>
             <span class="caret"></span>
           </button>
           <ul class="dropdown-menu">
             <li ng-repeat="grp in profiles">
-              <a href dropdown-toggle
+              <a href 
                 style="padding-left: {{pgt_depth(grp) * 10 + 5}}px"
                 ng-click="patron.profile = grp">{{grp.name()}}</a>
             </li>
index c0f44b8..6ffc407 100644 (file)
@@ -54,14 +54,25 @@ but the ones I'm finding aren't quite cutting it..*/
   border-bottom: 1px solid #CCC;
 }
 
-.reg-field-doc {
-    width: 21px;
-    background-image: url("/opac/images/advancedsearch-icon.png");
+/* -- patron registration -- */
+
+/* make all input widgets the same width, i.e. fill their column */
+
+.reg-field-input input:not([type="checkbox"]) { width: 100%; }
+.reg-field-input > .eg-org-selector,
+.reg-field-input > .eg-org-selector button,
+.reg-field-input > .btn-group,
+.reg-field-input > .btn-group > button {
+  width: 100%; 
+  text-align: left;
 }
 
+
+/* floating div along top-right with field documentation */
+/* TODO: make this part of the floatin save/clone div */
 #reg-field-doc {
     position: fixed;
-    top:124px;
+    top:160px;
     right:30px;
     width:300px;
     border:2px dashed #d9e8f9;
@@ -72,9 +83,11 @@ but the ones I'm finding aren't quite cutting it..*/
 }
 
 #reg-field-doc legend {
+    /* otherwise the font size is quite large */
     font-size: 100%;
 }
 
+/* -- end patron registration -- */
 
 [%# 
 vim: ft=css 
index 76faf45..ce582af 100644 (file)
@@ -44,66 +44,83 @@ angular.module('egCoreMod')
         });
     };
 
+    service.init_patron = function(current) {
+        return current ?
+            service.init_existing_patron(current) :
+            service.init_new_patron();
+    }
+
+    /*
+     * Existing patron objects reqire massaging before insertion 
+     * into the scope.
+     *
+     * 1. Turn everything into a hash
+     * 2. ... Except certain fields whose widgets require objects
+     * 3. Bools must be Boolean, not t/f.
+     */
+    service.init_existing_patron = function(current) {
+
+        var patron = egCore.idl.toHash(current);
+
+        patron.home_ou = egCore.org.get(patron.home_ou.id);
+        patron.expire_date = new Date(Date.parse(patron.expire_date));
+        patron.profile = current.profile(); // pre-hash version
+
+        angular.forEach(
+            ['juvenile', 'barred', 'active', 'master_account'],
+            function(field) { patron[field] = patron[field] == 't'; }
+        );
+
+        return patron;
+    }
+
+    service.init_new_patron = function() {
+        return {
+            isnew : true,
+            active : true,
+            card : {},
+            home_ou : egCore.org.get(egCore.auth.user().ws_ou()),
+            // TODO default profile group?
+        };
+    }
 
     return service;
 }]);
 
 
 function PatronRegCtrl($scope, $routeParams, 
-    $location, egCore, patronSvc, patronRegSvc) {
+    $q, egCore, patronSvc, patronRegSvc) {
 
-    // fetch needed data and toss it into the scope.
-    patronRegSvc.init().then(function() {
+    $q.all([
+        $scope.initTab ? // initTab comes from patron app
+            $scope.initTab('edit', $routeParams.id) : $q.when(),
+        patronRegSvc.init()
+
+    ]).then(function() {
+        // called after initTab and patronRegSvc.init have completed
+
+        $scope.patron = patronRegSvc.init_patron(patronSvc.current);
         $scope.field_doc = patronRegSvc.field_doc;
         $scope.profiles = patronRegSvc.profiles;
     });
-    
-    // determine the tree depth of the profile group
+
+    // returns the tree depth of the selected profile group tree node.
     $scope.pgt_depth = function(grp) {
         var d = 0;
         while (grp = egCore.env.pgt.map[grp.parent()]) d++;
         return d;
     }
 
-    // only add the classes we care about to the scope to avoid bloat
+    // IDL fields used for labels in the UI.
     $scope.idl_fields = {
         au  : egCore.idl.classes.au.field_map,
         ac  : egCore.idl.classes.ac.field_map,
         aua : egCore.idl.classes.aua.field_map
     };
 
-    if ($scope.initTab) {
-        // Inside the patron app
-        
-        $scope.initTab('edit', $routeParams.id).then(function() {
-
-            $scope.patron = egCore.idl.toHash(patronSvc.current);
-
-            $scope.patron.home_ou_obj = 
-                egCore.org.get($scope.patron.home_ou.id);
-
-            $scope.patron.expire_date = 
-                new Date(Date.parse($scope.patron.expire_date));
-
-        });
-
-    } else {
-        // Outside of the patron app
-
-        $scope.patron_id = $routeParams.edit_id;
-        $scope.clone_id = $routeParams.clone_id;
-        $scope.stage_username = $routeParams.stage_username;
-
-        $scope.patron = {
-            card : {}
-        };
-        $scope.patron.isnew = true;
-
-        // default to local workstation org
-        $scope.patron.home_ou_obj = 
-            egCore.org.get(egCore.auth.user().ws_ou());
-
-    }
+    $scope.patron_id = $routeParams.edit_id || $routeParams.id;
+    $scope.clone_id = $routeParams.clone_id;
+    $scope.stage_username = $routeParams.stage_username;
 }