<h2>[% l('Print Templates') %]</h2>
<div class="row">
- <div class="col-md-2">[% l('Template Name') %]</div>
- <div class="col-md-3">
- <select class="form-control" ng-model="print.template_name" ng-change="template_changed()">
- <option value="bills_current">[% l('Bills, Current') %]</option>
- <option value="bills_historical">[% l('Bills, Historical') %]</option>
- <option value="bill_payment">[% l('Bills, Payment') %]</option>
- <option value="checkout">[% l('Checkout') %]</option>
- <option value="hold_transit_slip">[% l('Hold Transit Slip') %]</option>
- <option value="hold_shelf_slip">[% l('Hold Shelf Slip') %]</option>
- <option value="holds_for_bib">[% l('Holds for Bib Record') %]</option>
- <option value="holds_for_patron">[% l('Holds for Patron') %]</option>
- <option value="hold_pull_list">[% l('Hold Pull List') %]</option>
- <option value="hold_shelf_list">[% l('Hold Shelf List') %]</option>
- <option value="patron_address">[% l('Patron Address') %]</option>
- <option value="patron_note">[% l('Patron Note') %]</option>
- <option value="transit_slip">[% l('Transit Slip') %]</option>
- </select>
+ <div class="col-md-5">
+ <div class="form-inline">
+ <div class="form-group">
+ <label for="print_tempate_name">[% l('Template Name') %]</label>
+ <select id="print_template_name" class="form-control" ng-model="print.template_name" ng-change="template_changed()">
+ <option value="bills_current">[% l('Bills, Current') %]</option>
+ <option value="bills_historical">[% l('Bills, Historical') %]</option>
+ <option value="bill_payment">[% l('Bills, Payment') %]</option>
+ <option value="checkout">[% l('Checkout') %]</option>
+ <option value="hold_transit_slip">[% l('Hold Transit Slip') %]</option>
+ <option value="hold_shelf_slip">[% l('Hold Shelf Slip') %]</option>
+ <option value="holds_for_bib">[% l('Holds for Bib Record') %]</option>
+ <option value="holds_for_patron">[% l('Holds for Patron') %]</option>
+ <option value="hold_pull_list">[% l('Hold Pull List') %]</option>
+ <option value="hold_shelf_list">[% l('Hold Shelf List') %]</option>
+ <option value="patron_address">[% l('Patron Address') %]</option>
+ <option value="patron_note">[% l('Patron Note') %]</option>
+ <option value="transit_slip">[% l('Transit Slip') %]</option>
+ </select>
+ <label for="print_context">[% l('Force Printer Context') %]</label>
+ <select class="form-control" ng-model="print.template_context">
+ <option value="default">[% l('Default') %]</option>
+ <option value="receipt">[% l('Receipt') %]</option>
+ <option value="label">[% l('Label') %]</option>
+ <option value="mail">[% l('Mail') %]</option>
+ <option value="offline">[% l('Offline') %]</option>
+ </select>
+ </div>
+ </div>
</div>
<div class="col-md-7">
<button class="btn btn-default pull-left" ng-click="save_locally()">[% l('Save Locally') %]</button>
$scope.print = {
template_name : 'bills_current',
- template_output : ''
+ template_output : '',
+ template_context : 'default'
};
// print preview scope data
$scope.print.load_failed = true;
}
);
+ egCore.print.getPrintTemplateContext($scope.print.template_name)
+ .then(function(template_context) {
+ $scope.print.template_context = template_context;
+ });
}
$scope.save_locally = function() {
$scope.print.template_name,
$scope.print.template_content
);
+ egCore.print.storePrintTemplateContext(
+ $scope.print.template_name,
+ $scope.print.template_context
+ );
}
$scope.exportable_templates = function() {
var templates = {};
+ var contexts = {};
var deferred = $q.defer();
var promises = [];
- egCore.hatch.getKeys('eg.print.template.').then(function(keys) {
+ egCore.hatch.getKeys('eg.print.template').then(function(keys) {
angular.forEach(keys, function(key) {
- promises.push(egCore.hatch.getItem(key).then(function(value) {
- templates[key.replace('eg.print.template.', '')] = value;
- }));
+ if (key.match(/^eg\.print\.template\./)) {
+ promises.push(egCore.hatch.getItem(key).then(function(value) {
+ templates[key.replace('eg.print.template.', '')] = value;
+ }));
+ } else {
+ promises.push(egCore.hatch.getItem(key).then(function(value) {
+ contexts[key.replace('eg.print.template_context.', '')] = value;
+ }));
+ }
});
$q.all(promises).then(function() {
if (Object.keys(templates).length) {
- deferred.resolve(templates);
+ deferred.resolve({
+ templates: templates,
+ contexts: contexts
+ });
} else {
ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT);
deferred.reject();
$scope.$watch('imported_print_templates.data', function(newVal, oldVal) {
if (newVal && newVal != oldVal) {
try {
- var templates = JSON.parse(newVal);
- angular.forEach(templates, function(template_content, template_name) {
+ var data = JSON.parse(newVal);
+ angular.forEach(data.templates, function(template_content, template_name) {
egCore.print.storePrintTemplate(template_name, template_content);
});
+ angular.forEach(data.contexts, function(template_context, template_name) {
+ egCore.print.storePrintTemplateContext(template_name, template_context);
+ });
$scope.template_changed(); // refresh
ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
} catch (E) {
/**
* egPrint : manage print templates, process templates, print content
*
- * TODO: create configurable links between print template and context.
*/
angular.module('egCoreMod')
.then(function(content) {
args.content = content;
if (!args.content_type) args.content_type = 'html';
- return service.print_content(args);
+ service.getPrintTemplateContext(args.template)
+ .then(function(context) {
+ args.context = context;
+ return service.print_content(args);
+ });
});
}
promise = $q.when(args.content);
}
- // TODO: link print context to template type
var context = args.context || 'default';
return promise.then(function(html) {
return egHatch.setItem('eg.print.template.' + name, html);
}
+ service.getPrintTemplateContext = function(name) {
+ var deferred = $q.defer();
+
+ egHatch.getItem('eg.print.template_context.' + name)
+ .then(
+ function(context) { deferred.resolve(context); },
+ function() { deferred.resolve('default'); }
+ );
+
+ return deferred.promise;
+ }
+ service.storePrintTemplateContext = function(name, context) {
+ return egHatch.setItem('eg.print.template_context.' + name, context);
+ }
+
return service;
}])