2 * App to drive the base page.
7 angular.module('egWorkstationAdmin',
8 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod'])
10 .config(['$routeProvider','$locationProvider','$compileProvider',
11 function($routeProvider , $locationProvider , $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/);
15 var resolver = {delay : function(egStartup) {return egStartup.go()}};
17 $routeProvider.when('/admin/workstation/print/config', {
18 templateUrl: './admin/workstation/t_print_config',
19 controller: 'PrintConfigCtrl',
23 $routeProvider.when('/admin/workstation/print/templates', {
24 templateUrl: './admin/workstation/t_print_templates',
25 controller: 'PrintTemplatesCtrl',
29 $routeProvider.when('/admin/workstation/stored_prefs', {
30 templateUrl: './admin/workstation/t_stored_prefs',
31 controller: 'StoredPrefsCtrl',
37 $routeProvider.otherwise({
38 templateUrl : './admin/workstation/t_splash',
39 controller : 'SplashCtrl',
44 .controller('SplashCtrl',
45 ['$scope','$window','$location','egCore','egConfirmDialog',
46 function($scope , $window , $location , egCore , egConfirmDialog) {
48 var allWorkstations = [];
50 $scope.contextOrg = egCore.org.get(egCore.auth.user().ws_ou());
52 egCore.perm.hasPermAt('REGISTER_WORKSTATION', true)
53 .then(function(orgList) {
55 // hide orgs in the context org selector where this login
56 // does not have the reg_ws perm
57 $scope.wsOrgHidden = function(id) {
58 return orgList.indexOf(id) == -1;
60 $scope.userHasRegPerm =
61 orgList.indexOf($scope.contextOrg.id()) > -1;
64 // fetch the stored WS info
65 egCore.hatch.getItem('eg.workstation.all')
67 allWorkstations = all || [];
69 allWorkstations.map(function(w) { return w.name });
70 return egCore.hatch.getItem('eg.workstation.default');
73 $scope.defaultWS = def;
74 $scope.activeWS = $scope.selectedWS = egCore.auth.workstation() || def;
77 $scope.getWSLabel = function(ws) {
78 return ws == $scope.defaultWS ?
79 egCore.strings.$replace(egCore.strings.DEFAULT_WS_LABEL, {ws:ws}) : ws;
82 $scope.setDefaultWS = function() {
84 'eg.workstation.default', $scope.selectedWS)
85 .then(function() { $scope.defaultWS = $scope.selectedWS });
88 // redirect the user to the login page using the current
89 // workstation as the workstation URL param
90 $scope.useWS = function() {
91 $window.location.href = $location
93 .search({ws : $scope.selectedWS})
97 $scope.registerWS = function() {
100 $scope.contextOrg.shortname() + '-' + $scope.newWSName,
101 $scope.contextOrg.id()
105 function register_workstation(base_name, name, org_id, override) {
107 var method = 'open-ils.actor.workstation.register';
108 if (override) method += '.override';
111 'open-ils.actor', method, egCore.auth.token(), name, org_id)
113 .then(function(resp) {
114 if (evt = egCore.evt.parse(resp)) {
115 console.log('register returned ' + evt.toString());
117 if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
118 egConfirmDialog.open(
119 egCore.strings.WS_EXISTS, base_name, {
121 register_workstation(base_name, name, org_id, true);
123 cancel : function() {}
128 // TODO: provide permission error display
129 alert(evt.toString());
132 $scope.workstations.push(name);
134 allWorkstations.push({
140 egCore.hatch.setItem(
141 'eg.workstation.all', allWorkstations)
143 if (allWorkstations.length == 1) {
144 // first one registerd, also mark it as the default
145 $scope.selectedWS = name;
146 $scope.setDefaultWS();
153 $scope.wsOrgChanged = function(org) {
154 $scope.contextOrg = org;
157 // ---------------------
159 $scope.hatchURL = egCore.hatch.hatchURL();
160 $scope.hatchRequired =
161 egCore.hatch.getLocalItem('eg.hatch.required');
163 $scope.updateHatchRequired = function() {
164 egCore.hatch.setLocalItem(
165 'eg.hatch.required', $scope.hatchRequired);
168 $scope.updateHatchURL = function() {
169 egCore.hatch.setLocalItem(
170 'eg.hatch.url', $scope.hatchURL);
174 .controller('PrintConfigCtrl',
176 function($scope , egCore) {
177 console.log('PrintConfigCtrl');
179 $scope.actionPending = false;
180 $scope.isTestView = false;
182 $scope.setContext = function(ctx) {
183 $scope.context = ctx;
184 $scope.isTestView = false;
185 $scope.actionPending = false;
187 $scope.setContext('default');
189 $scope.getPrinterByAttr = function(attr, value) {
191 angular.forEach($scope.printers, function(p) {
192 if (p[attr] == value) printer = p;
197 $scope.currentPrinter = function() {
198 if ($scope.printConfig && $scope.printConfig[$scope.context]) {
199 return $scope.getPrinterByAttr(
200 'name', $scope.printConfig[$scope.context].printer
205 // fetch info on all remote printers
206 egCore.hatch.getPrinters()
207 .then(function(printers) {
208 $scope.printers = printers;
209 $scope.defaultPrinter =
210 $scope.getPrinterByAttr('is-default', true);
212 .then(function() { return egCore.hatch.getPrintConfig() })
213 .then(function(config) {
214 $scope.printConfig = config;
217 if ($scope.defaultPrinter) {
218 pname = $scope.defaultPrinter.name;
220 } else if ($scope.printers.length == 1) {
221 // if the OS does not report a default printer, but only
222 // one printer is available, treat it as the default.
223 pname = $scope.printers[0].name;
226 // apply the default printer to every context which has
227 // no printer configured.
229 ['default','receipt','label','mail','offline'],
231 if (!$scope.printConfig[ctx]) {
232 $scope.printConfig[ctx] = {
241 $scope.printerConfString = function() {
242 if ($scope.printConfigError) return $scope.printConfigError;
243 if (!$scope.printConfig) return;
244 if (!$scope.printConfig[$scope.context]) return;
245 return JSON.stringify(
246 $scope.printConfig[$scope.context], undefined, 2);
249 $scope.resetConfig = function() {
250 $scope.actionPending = true;
251 $scope.printConfigError = null;
252 $scope.printConfig[$scope.context] = {
253 context : $scope.context
256 if ($scope.defaultPrinter) {
257 $scope.printConfig[$scope.context].printer =
258 $scope.defaultPrinter.name;
261 egCore.hatch.setPrintConfig($scope.printConfig)
262 .finally(function() {$scope.actionPending = false});
265 $scope.configurePrinter = function() {
266 $scope.printConfigError = null;
267 $scope.actionPending = true;
268 egCore.hatch.configurePrinter(
270 $scope.printConfig[$scope.context].printer
273 function(config) {$scope.printConfig = config},
274 function(error) {$scope.printConfigError = error}
276 .finally(function() {$scope.actionPending = false});
279 $scope.setPrinter = function(name) {
280 $scope.printConfig[$scope.context].printer = name;
284 $scope.setContentType = function(type) { $scope.contentType = type }
286 $scope.testPrint = function(withDialog) {
287 if ($scope.contentType == 'text/plain') {
289 context : $scope.context,
290 content_type : $scope.contentType,
291 content : $scope.textPrintContent,
292 show_dialog : withDialog
296 context : $scope.context,
297 content_type : $scope.contentType,
298 content : $scope.htmlPrintContent,
300 value1 : 'Value One',
301 value2 : 'Value Two',
302 date_value : '2015-02-04T14:04:34-0400'
304 show_dialog : withDialog
309 $scope.setContentType('text/plain');
313 .controller('PrintTemplatesCtrl',
314 ['$scope','$q','egCore',
315 function($scope , $q , egCore) {
318 template_name : 'bills_current',
322 // print preview scope data
323 // TODO: consider moving the template-specific bits directly
324 // into the templates or storing template- specific script files
325 // alongside the templates.
326 // NOTE: A lot of this data can be shared across templates.
328 first_given_name : 'Slow',
329 second_given_name : 'Joe',
330 family_name : 'Jones',
332 barcode : '30393830393'
336 street1 : '123 Apple Rd',
345 title : 'Traveling Pants!!',
346 author : 'Jane Jones',
351 barcode : '33434322323'
356 phone_notify : '111-222-3333',
357 sms_notify : '111-222-3333',
358 email_notify : 'user@example.org',
359 request_time : new Date().toISOString()
363 $scope.preview_scope = {
368 xact_start : new Date().toISOString(),
370 xact_type : 'circulation',
371 last_billing_type : 'Overdue materials',
373 last_payment_note : 'Test Note 1',
379 xact_start : new Date().toISOString(),
381 xact_type : 'circulation',
382 last_billing_type : 'Overdue materials',
384 last_payment_note : 'Test Note 2',
393 due_date : new Date().toISOString(),
394 target_copy : seed_copy,
395 title : seed_record.title
399 previous_balance : 8.45,
400 payment_total : 2.00,
401 payment_applied : 2.00,
405 payment_type : 'cash_payment',
406 payment_note : 'Here is a payment note',
408 create_date : new Date().toISOString(),
409 title : 'Test Note Title',
411 value : 'This patron is super nice!'
418 holds_address : seed_addr
420 target_copy : seed_copy
422 title : seed_record.title,
423 author : seed_record.author,
424 patron : egCore.idl.toHash(egCore.auth.user()),
428 {hold : one_hold, title : 'Some Title 1', author : 'Some Author 1'},
429 {hold : one_hold, title : 'Some Title 2', author : 'Some Author 2'},
430 {hold : one_hold, title : 'Some Title 3', author : 'Some Author 3'}
434 $scope.preview_scope.payments = [
435 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
436 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
438 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
439 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
440 $scope.preview_scope.payments[1].xact.title = seed_record.title;
441 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
443 // today, staff, current_location, etc.
444 egCore.print.fleshPrintScope($scope.preview_scope);
446 $scope.template_changed = function() {
447 $scope.print.load_failed = false;
448 egCore.print.getPrintTemplate($scope.print.template_name)
451 $scope.print.template_content = html;
452 console.log('set template content');
455 $scope.print.template_content = '';
456 $scope.print.load_failed = true;
461 $scope.save_locally = function() {
462 egCore.hatch.storePrintTemplate(
463 $scope.print.template_name,
464 $scope.print.template_content
468 $scope.template_changed(); // load the default
472 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
473 return function(scope, element, attrs) {
476 return scope.$eval(attrs.content);
479 // create an isolate scope and copy the print context
480 // data into the new scope.
481 // TODO: see also print security concerns in egHatch
482 var result = element.html(value);
483 var context = scope.$eval(attrs.context);
484 var print_scope = scope.$new(true);
485 angular.forEach(context, function(val, key) {
486 print_scope[key] = val;
488 $compile(element.contents())(print_scope);
494 .controller('StoredPrefsCtrl',
495 ['$scope','$q','egCore','egConfirmDialog',
496 function($scope , $q , egCore , egConfirmDialog) {
497 console.log('StoredPrefsCtrl');
499 $scope.setContext = function(ctx) {
500 $scope.context = ctx;
502 $scope.setContext('local');
504 // grab the edit perm
505 $scope.userHasDeletePerm = false;
506 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
507 .then(function(bool) { $scope.userHasDeletePerm = bool });
511 function refreshKeys() {
512 $scope.keys = {local : [], remote : []};
514 egCore.hatch.getRemoteKeys().then(
515 function(keys) { $scope.keys.remote = keys.sort() })
517 // local calls are non-async
518 $scope.keys.local = egCore.hatch.getLocalKeys();
522 $scope.selectKey = function(key) {
523 $scope.currentKey = key;
524 $scope.currentKeyContent = null;
526 if ($scope.context == 'local') {
527 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
529 egCore.hatch.getRemoteItem(key)
530 .then(function(content) {
531 $scope.currentKeyContent = content
536 $scope.getCurrentKeyContent = function() {
537 return JSON.stringify($scope.currentKeyContent, null, 2);
540 $scope.removeKey = function(key) {
541 egConfirmDialog.open(
542 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
545 if ($scope.context == 'local') {
546 egCore.hatch.removeLocalItem(key);
549 egCore.hatch.removeItem(key)
550 .then(function() { refreshKeys() });
553 cancel : function() {} // user canceled, nothing to do