webstaff: Apply Binding Template for distributions
authorJason Etheridge <jason@equinoxinitiative.org>
Thu, 18 May 2017 22:06:31 +0000 (18:06 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:47 +0000 (12:06 -0400)
and fix Receiving and Binding Template columns in the Subscription Manager grid

Signed-off-by: Jason Etheridge <jason@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_apply_binding_template.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/serials/t_subscription_manager.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index d21f983..96af178 100644 (file)
@@ -23,6 +23,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
     s.SERIALS_ISSUANCE_SUCCESS_SAVE = "[% l('Issuance saved') %]";
     s.SERIALS_DISTRIBUTION_SUCCESS_LINK_MFHD = "[% l('Distribution linked to MFHD') %]";
     s.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD = "[% l('Failed to link distribution to MFHD') %]";
+    s.SERIALS_DISTRIBUTION_SUCCESS_BINDING_TEMPLATE = "[% l('Binding unit template applied to Distribution') %]";
+    s.SERIALS_DISTRIBUTION_FAIL_BINDING_TEMPLATE = "[% l('Failed to apply binding unit template to distribution') %]";
     s.SERIALS_EDIT_SISS_HC = "[% l('Edit issue information') %]";
     s.SERIALS_ISSUANCE_PREDICT = "[% l('Predict New Issues: Initial Values') %]";
     s.SERIALS_ISSUANCE_ADD = "[% l('Add folloing issue') %]";
diff --git a/Open-ILS/src/templates/staff/serials/t_apply_binding_template.tt2 b/Open-ILS/src/templates/staff/serials/t_apply_binding_template.tt2
new file mode 100644 (file)
index 0000000..dd0bbc2
--- /dev/null
@@ -0,0 +1,54 @@
+<form ng-submit="ok(args)" role="form">
+
+<style>
+/* odd/even row styling */
+.modal-body > div:nth-child(odd) {
+  background-color: rgb(248, 248, 248);
+}
+</style>
+
+<div class="modal-header">
+    <button type="button" class="close" ng-click="cancel()" 
+        aria-hidden="true">&times;</button>
+    <h4 class="modal-title" ng-if="rows.length != 1">
+        [% l('Apply Binding Unit Template to [_1] Selected Distributions','{{rows.length}}') %]
+    </h4>
+    <h4 class="modal-title" ng-if="rows.length == 1">
+        [% l('Apply Binding Unit Template to [_1] Selected Distribution','{{rows.length}}') %]
+    </h4>
+</div>
+
+<div class="modal-body">
+    <div class="row">
+        <div class="col-md-8">
+            <label>
+                [% l('Distribution Library') %]
+            </label>
+        </div>
+        <div class="col-md-4">
+            <label>
+                [% l('Binding Unit Template') %]
+            </label>
+        </div>
+    </div>
+    <div class="row" ng-repeat="lib in libs">
+        <div class="col-md-8">
+            <label for="ou_{{lib.id}}">
+                {{lib.name}}
+            </label>
+        </div>
+        <div class="col-md-4">
+            <select id="ou_{{lib.id}}"
+                ng-model="args.bind_unit_template[lib.id]"
+                ng-options="t.id() as t.name() for t in templates[lib.id]">
+                <option value=""></option>
+            </select>
+        </div>
+    </div>
+</div>
+
+<div class="modal-footer">
+    <input type="submit" class="btn btn-primary" value="[% l('Update') %]"></input>
+    <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+</div>
+</form>
index 6d51db7..6792379 100644 (file)
     <eg-grid-field label="[% l('End Date') %]" path="end_date" datatype="timestamp" visible></eg-grid-field>
     <eg-grid-field label="[% l('Route To') %]" path="sstr.routing_label" visible></eg-grid-field>
     <eg-grid-field label="[% l('Additional Routing') %]" path="sstr.additional_routing" visible></eg-grid-field>
-    <eg-grid-field label="[% l('Receiving Template') %]" path="sdist.receive_unit_template"></eg-grid-field>
+    <eg-grid-field label="[% l('Receiving Template') %]" path="sdist.receive_unit_template.name"></eg-grid-field>
     <eg-grid-field label="[% l('MFHD ID') %]" path="sdist.record_entry" visible></eg-grid-field>
     <eg-grid-field label="[% l('Summary Display') %]" path="sdist.summary_method" visible></eg-grid-field>
     <eg-grid-field label="[% l('Receiving Call Number') %]" path="sdist.receive_call_number.label"></eg-grid-field>
     <eg-grid-field label="[% l('Binding Call Number') %]" path="sdist.bind_call_number.label"></eg-grid-field>
-    <eg-grid-field label="[% l('Binding Template') %]" path="sdist.bind_unit_template"></eg-grid-field>
+    <eg-grid-field label="[% l('Binding Template') %]" path="sdist.bind_unit_template.name"></eg-grid-field>
     <eg-grid-field label="[% l('Unit Label Prefix') %]" path="sdist.unit_label_prefix"></eg-grid-field>
     <eg-grid-field label="[% l('Unit Label Suffix') %]" path="sdist.unit_label_suffix"></eg-grid-field>
     <eg-grid-field label="[% l('Display Grouping') %]" path="sdist.display_grouping"></eg-grid-field>
index 50464f4..000afac 100644 (file)
@@ -312,11 +312,108 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
             });
         });
     }
+    $scope.apply_binding_template = function(rows) {
+        if (rows.length == 0) { return; }
+        var d_rows = rows.filter(function(el) {
+            return typeof el['sdist.id'] != 'undefined';
+        });
+        if (d_rows.length == 0) { return; }
+        var libs = []; var seen_lib = {};
+        angular.forEach(d_rows, function(el) {
+            if (el['sdist.holding_lib.id'] && !seen_lib[el['sdist.holding_lib.id']]) {
+                seen_lib[el['sdist.holding_lib.id']] = 1;
+                libs.push({
+                      id: el['sdist.holding_lib.id'],
+                    name: el['sdist.holding_lib.name'],
+                });
+            }
+        });
+        $uibModal.open({
+            templateUrl: './serials/t_apply_binding_template',
+            controller: 'ApplyBindingTemplateCtrl',
+            resolve : {
+                rows : function() {
+                    return d_rows;
+                },
+                libs : function() {
+                    return libs;
+                }
+            },
+            windowClass: 'app-modal-window',
+            backdrop: 'static',
+            keyboard: false
+        }).result.then(function(args) {
+            console.log(args);
+            egCore.pcrud.search('sdist', {
+                    id: d_rows.map(function(el) { return el['sdist.id']; })
+                }, {}, { atomic : true }
+            ).then(function(resp){
+                var evt = egCore.evt.parse(resp);
+                if (evt) { // any way to just throw or return this to the error handler?
+                    console.log('failure',resp);
+                    ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_BINDING_TEMPLATE);
+                }
+                var promises = [];
+                angular.forEach(resp,function(sdist) {
+                    sdist.ischanged(true);
+                    sdist.bind_unit_template(
+                        typeof args.bind_unit_template[sdist.holding_lib()] == 'undefined'
+                        ? null
+                        : args.bind_unit_template[sdist.holding_lib()]
+                    );
+                    egCore.pcrud.apply(sdist).then(
+                        function(resp2) { // maybe success
+                            console.log('apply',resp2);
+                            var evt = egCore.evt.parse(resp2);
+                            if (evt) { // any way to just throw or return this to the error handler?
+                                console.log('failure',resp2);
+                                ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_BINDING_TEMPLATE);
+                            } else {
+                                console.log('success',resp2);
+                                ngToast.success(egCore.strings.SERIALS_DISTRIBUTION_SUCCESS_BINDING_TEMPLATE);
+                            }
+                        },
+                        function(resp2) {
+                            console.log('failure',resp2);
+                            ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD);
+                        }
+                    );
+                });
+                $q.all(promises).then(function() {
+                    reload();
+                });
+            });
+        });
+    }
 
 }]
     }
 })
 
+.controller('ApplyBindingTemplateCtrl',
+       ['$scope','$q','$uibModalInstance','egCore','egSerialsCoreSvc',
+        'rows','libs',
+function($scope , $q , $uibModalInstance , egCore , egSerialsCoreSvc ,
+         rows , libs ) {
+    $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
+    $scope.cancel = function () { $uibModalInstance.dismiss() }
+    $scope.libs = libs;
+    $scope.rows = rows;
+    $scope.args = { bind_unit_template : {} };
+    $scope.templates = {};
+    var promises = [];
+    angular.forEach(libs, function(org) {
+        promises.push(
+            egSerialsCoreSvc.fetch_templates(org.id).then(function(list){
+                $scope.templates[org.id] = list;
+            })
+        );
+    });
+    $q.all(promises).then(function() {
+        //console.log('finis',$scope.receiving_templates);
+    });
+}])
+
 .controller('LinkMFHDCtrl',
        ['$scope','$q','$uibModalInstance','egCore','row','bibId',
 function($scope , $q , $uibModalInstance , egCore , row , bibId ) {
index 073fd3a..3a418fe 100644 (file)
@@ -110,7 +110,9 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                     'ssub'  : ['owning_lib','distributions', 'scaps', 'notes'],
                     'sdist' : [ 'record_entry','holding_lib',
                                 'receive_call_number',
+                                'receive_unit_template',
                                 'bind_call_number',
+                                'bind_unit_template',
                                 'streams','notes'],
                     'sstr'  : ['routing_list_users']
                 }
@@ -438,6 +440,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                     _sdist['sdist.' + fld] = sdist[fld];
                 });
                 _sdist['sdist.holding_lib.name'] = sdist.holding_lib.name;
+                _sdist['sdist.holding_lib.id'] = sdist.holding_lib.id;
                 _sdist['sdist.receive_call_number.label'] = 
                     sdist.receive_call_number ? sdist.receive_call_number.label : null;
                 _sdist['sdist.receive_unit_template.name'] =