2-hold-request-fields-that-make-use-of-user-preferences
authorJason Etheridge <jason@EquinoxInitiative.org>
Fri, 22 Jun 2018 15:19:14 +0000 (11:19 -0400)
committerJason Etheridge <jason@EquinoxInitiative.org>
Fri, 22 Jun 2018 15:48:29 +0000 (11:48 -0400)
For new requests (or edited requests when a user barcode is scanned), the user's
preferences (if any) for hold notifications and pickup library will be used to
set various fields in the request dialog.

Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/templates/staff/acq/requests/t_edit.tt2
Open-ILS/web/js/ui/default/staff/acq/services/requests.js

index 0ce5f7a..1671334 100644 (file)
@@ -2288,7 +2288,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
                </links>
        </class>
-       <class id="aus" controller="open-ils.cstore" oils_obj:fieldmapper="actor::user_setting" oils_persist:tablename="actor.usr_setting" reporter:label="User Setting">
+       <class id="aus" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::user_setting" oils_persist:tablename="actor.usr_setting" reporter:label="User Setting">
                <fields oils_persist:primary="id" oils_persist:sequence="actor.usr_setting_id_seq">
                        <field reporter:label="Setting ID" name="id" reporter:datatype="id" />
                        <field reporter:label="Name" name="name" reporter:datatype="link"/>
@@ -2299,6 +2299,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="name" reltype="has_a" key="name" map="" class="cust"/>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
                </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <retrieve permission="VIEW_USER">
+                                       <context link="usr" field="home_ou" />
+                               </retrieve>
+                       </actions>
+               </permacrud>
        </class>
        <class id="mafe" controller="open-ils.cstore" oils_obj:fieldmapper="metabib::author_field_entry" oils_persist:tablename="metabib.author_field_entry" reporter:label="Author Field Entry">
                <fields oils_persist:primary="id" oils_persist:sequence="metabib.author_field_entry_id_seq">
index d386875..a62a228 100644 (file)
                     </span>
                 </div>
             </div>
-            <div class="row" ng-show="mode=='view'">
+            <div class="row">
                 <div class="form-group col-sm-6">
                     <label for="edit-request-email-notify">
                         <input type="checkbox" id="edit-request-email-notify"
                             ng-disabled="mode=='view'"
                             ng-model="request.email_notify"/>
-                        [% l('Email Notify?') %]
+                        [% l('Notify By Email When Hold Ready?') %]
                     </label>
                 </div>
                 <div class="form-group col-sm-6">
-                    <label for="edit-request-phone-notify">
-                        [% l('Phone Notify?') %]</label>
+                    <label for="edit-extra-phone-notify">
+                        <input type="checkbox" id="edit-extra-phone-notify"
+                            ng-disabled="mode=='view'"
+                            ng-model="extra.phone_notify"/>
+                        [% l('Notify By Phone When Hold Ready?') %]
+                    </label>
                     <input type="text" class="form-control" focus-me='focusMe'
                         id="edit-request-phone-notify"
-                        ng-model="request.phone_notify"
-                        ng-disabled="true"/>
+                        ng-disabled="mode=='view'"
+                        ng-model="request.phone_notify"/>
                 </div>
             </div>
         </div>
index f3f1302..453a8f5 100644 (file)
@@ -6,8 +6,8 @@ angular.module('egCoreMod')
 
 .factory('egAcqRequests',
 
-       ['$uibModal','$q','egCore','ngToast',
-function($uibModal , $q , egCore , ngToast) {
+       ['$uibModal','$q','egCore','egOrg','ngToast',
+function($uibModal , $q , egCore , egOrg , ngToast) {
 
     var service = {};
 
@@ -29,7 +29,13 @@ function($uibModal , $q , egCore , ngToast) {
                 ,'request_type'
                 ,'usr'
             ]
-            ,'au'  : ['card','home_ou']
+            ,'au'  : [
+                 'card'
+                ,'home_ou'
+                ,'mailing_address'
+                ,'billing_address'
+                ,'settings'
+            ]
         }
     };
 
@@ -53,7 +59,13 @@ function($uibModal , $q , egCore , ngToast) {
                 ,'request_status'
                 ,'usr'
             ]
-            ,'au'  : ['card','home_ou']
+            ,'au'  : [
+                 'card'
+                ,'home_ou'
+                ,'mailing_address'
+                ,'billing_address'
+                ,'settings'
+            ]
         }
     };
 
@@ -187,6 +199,9 @@ function($uibModal , $q , egCore , ngToast) {
                     if (request.need_before) {
                         request.need_before = new Date(request.need_before);
                     }
+                    if (request.phone_notify) {
+                        $m_scope.extra.phone_notify = true;
+                    }
                     if (request.pickup_lib) {
                         $m_scope.request.pickup_lib =
                             egCore.idl.fromHash('aou',request.pickup_lib);
@@ -250,18 +265,36 @@ function($uibModal , $q , egCore , ngToast) {
                                     flesh : 1,
                                     flesh_fields : {
                                         'au'  : [
-                                             'mailing_address'
-                                            ,'billing_address'
+                                             'card'
                                             ,'home_ou'
+                                            ,'mailing_address'
+                                            ,'billing_address'
+                                            ,'settings'
                                         ]
                                     }
                                 },
                                 { atomic : true }
-                            ).then(function(usr) {
-                                $m_scope.extra.user_obj =
-                                    egCore.idl.toHash(usr[0]);
-                                $m_scope.request.usr =
-                                    $m_scope.extra.user_obj.id;
+                            ).then(function(users) {
+                                var usr = egCore.idl.toHash(users[0]);
+                                $m_scope.extra.user_obj = usr;
+                                $m_scope.request.usr = usr.id;
+                                angular.forEach(usr.settings, function(s) {
+                                    if (s.name == 'opac.hold_notify') {
+                                        if (s.value.match('phone')) {
+                                            $m_scope.extra.phone_notify = true;
+                                        }
+                                        if (s.value.match('email')) {
+                                            $m_scope.request.email_notify = true;
+                                        }
+                                    }
+                                    if (s.name == 'opac.default_phone') {
+                                        $m_scope.request.phone_notify = s.value;
+                                    }
+                                    if (s.name == 'opac.default_pickup_location') {
+                                        $m_scope.request.pickup_lib =
+                                            egOrg.get(s.value);
+                                    }
+                                });
                             });
                         });
                     }
@@ -283,9 +316,44 @@ function($uibModal , $q , egCore , ngToast) {
                     if (mode=='create') {
                         var aur_obj = egCore.idl.toHash(new egCore.idl.aurs());
                         if (row['usr']) {
-                            aur_obj.usr = row['usr'];
+                            return egCore.pcrud.search('au', {
+                                    id : row['usr']
+                                }, {
+                                    flesh : 1,
+                                    flesh_fields : {
+                                        'au'  : [
+                                             'card'
+                                            ,'home_ou'
+                                            ,'mailing_address'
+                                            ,'billing_address'
+                                            ,'settings'
+                                        ]
+                                    }
+                                },
+                                { atomic : true }
+                            ).then(function(users) {
+                                var usr = egCore.idl.toHash(users[0]);
+                                aur_obj.usr = usr.id;
+                                angular.forEach(usr.settings, function(s) {
+                                    if (s.name == 'opac.hold_notify') {
+                                        if (s.value.match('email')) {
+                                            aur_obj.email_notify = true;
+                                        }
+                                    }
+                                    if (s.name == 'opac.default_phone') {
+                                        aur_obj.phone_notify = s.value;
+                                    }
+                                    if (s.name == 'opac.default_pickup_location') {
+                                        aur_obj.pickup_lib = egCore.idl.toHash(
+                                            egOrg.get(s.value)
+                                        );
+                                    }
+                                });
+                                return aur_obj;
+                            });
+                        } else {
+                            return aur_obj;
                         }
-                        return aur_obj;
                     } else {
                         return egCore.pcrud.search('aurs', {
                                 id : row['id']
@@ -311,6 +379,9 @@ function($uibModal , $q , egCore , ngToast) {
             if (aur_obj.need_before() && typeof aur_obj.need_before() == 'object') {
                 aur_obj.need_before( aur_obj.need_before().toISOString() );
             }
+            if (!data.extra.phone_notify) {
+                aur_obj.phone_notify(null);
+            }
             if (mode=='create') {
                 aur_obj.isnew('t');
                 aur_obj.pickup_lib( aur_obj.pickup_lib().id() );