--- /dev/null
+<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">×</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>
<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>
});
});
}
+ $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 ) {