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 $scope.cant_have_users = function (id) { return !egCore.org.CanHaveUsers(id); };
89 $scope.cant_have_volumes = function (id) { return !egCore.org.CanHaveVolumes(id); };
91 // redirect the user to the login page using the current
92 // workstation as the workstation URL param
93 $scope.useWS = function() {
94 $window.location.href = $location
96 .search({ws : $scope.selectedWS})
100 $scope.registerWS = function() {
101 register_workstation(
103 $scope.contextOrg.shortname() + '-' + $scope.newWSName,
104 $scope.contextOrg.id()
108 function register_workstation(base_name, name, org_id, override) {
110 var method = 'open-ils.actor.workstation.register';
111 if (override) method += '.override';
114 'open-ils.actor', method, egCore.auth.token(), name, org_id)
116 .then(function(resp) {
117 if (evt = egCore.evt.parse(resp)) {
118 console.log('register returned ' + evt.toString());
120 if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
121 egConfirmDialog.open(
122 egCore.strings.WS_EXISTS, base_name, {
124 register_workstation(base_name, name, org_id, true);
126 cancel : function() {}
131 // TODO: provide permission error display
132 alert(evt.toString());
135 $scope.workstations.push(name);
137 allWorkstations.push({
143 egCore.hatch.setItem(
144 'eg.workstation.all', allWorkstations)
146 if (allWorkstations.length == 1) {
147 // first one registerd, also mark it as the default
148 $scope.selectedWS = name;
149 $scope.setDefaultWS();
156 $scope.wsOrgChanged = function(org) {
157 $scope.contextOrg = org;
160 // ---------------------
162 $scope.hatchURL = egCore.hatch.hatchURL();
163 $scope.hatchRequired =
164 egCore.hatch.getLocalItem('eg.hatch.required');
166 $scope.updateHatchRequired = function() {
167 egCore.hatch.setLocalItem(
168 'eg.hatch.required', $scope.hatchRequired);
171 $scope.updateHatchURL = function() {
172 egCore.hatch.setLocalItem(
173 'eg.hatch.url', $scope.hatchURL);
176 egCore.hatch.getItem('eg.audio.disable').then(function(val) {
177 $scope.disable_sound = val;
180 $scope.apply_sound = function() {
181 if ($scope.disable_sound) {
182 egCore.hatch.setItem('eg.audio.disable', true);
184 egCore.hatch.removeItem('eg.audio.disable');
188 $scope.test_audio = function(sound) {
189 egCore.audio.play(sound);
194 .controller('PrintConfigCtrl',
196 function($scope , egCore) {
197 console.log('PrintConfigCtrl');
199 $scope.actionPending = false;
200 $scope.isTestView = false;
202 $scope.setContext = function(ctx) {
203 $scope.context = ctx;
204 $scope.isTestView = false;
205 $scope.actionPending = false;
207 $scope.setContext('default');
209 $scope.getPrinterByAttr = function(attr, value) {
211 angular.forEach($scope.printers, function(p) {
212 if (p[attr] == value) printer = p;
217 $scope.currentPrinter = function() {
218 if ($scope.printConfig && $scope.printConfig[$scope.context]) {
219 return $scope.getPrinterByAttr(
220 'name', $scope.printConfig[$scope.context].printer
225 // fetch info on all remote printers
226 egCore.hatch.getPrinters()
227 .then(function(printers) {
228 $scope.printers = printers;
229 $scope.defaultPrinter =
230 $scope.getPrinterByAttr('is-default', true);
232 .then(function() { return egCore.hatch.getPrintConfig() })
233 .then(function(config) {
234 $scope.printConfig = config;
237 if ($scope.defaultPrinter) {
238 pname = $scope.defaultPrinter.name;
240 } else if ($scope.printers.length == 1) {
241 // if the OS does not report a default printer, but only
242 // one printer is available, treat it as the default.
243 pname = $scope.printers[0].name;
246 // apply the default printer to every context which has
247 // no printer configured.
249 ['default','receipt','label','mail','offline'],
251 if (!$scope.printConfig[ctx]) {
252 $scope.printConfig[ctx] = {
261 $scope.printerConfString = function() {
262 if ($scope.printConfigError) return $scope.printConfigError;
263 if (!$scope.printConfig) return;
264 if (!$scope.printConfig[$scope.context]) return;
265 return JSON.stringify(
266 $scope.printConfig[$scope.context], undefined, 2);
269 $scope.resetConfig = function() {
270 $scope.actionPending = true;
271 $scope.printConfigError = null;
272 $scope.printConfig[$scope.context] = {
273 context : $scope.context
276 if ($scope.defaultPrinter) {
277 $scope.printConfig[$scope.context].printer =
278 $scope.defaultPrinter.name;
281 egCore.hatch.setPrintConfig($scope.printConfig)
282 .finally(function() {$scope.actionPending = false});
285 $scope.configurePrinter = function() {
286 $scope.printConfigError = null;
287 $scope.actionPending = true;
288 egCore.hatch.configurePrinter(
290 $scope.printConfig[$scope.context].printer
293 function(config) {$scope.printConfig = config},
294 function(error) {$scope.printConfigError = error}
296 .finally(function() {$scope.actionPending = false});
299 $scope.setPrinter = function(name) {
300 $scope.printConfig[$scope.context].printer = name;
304 $scope.setContentType = function(type) { $scope.contentType = type }
306 $scope.testPrint = function(withDialog) {
307 if ($scope.contentType == 'text/plain') {
309 context : $scope.context,
310 content_type : $scope.contentType,
311 content : $scope.textPrintContent,
312 show_dialog : withDialog
316 context : $scope.context,
317 content_type : $scope.contentType,
318 content : $scope.htmlPrintContent,
320 value1 : 'Value One',
321 value2 : 'Value Two',
322 date_value : '2015-02-04T14:04:34-0400'
324 show_dialog : withDialog
329 $scope.setContentType('text/plain');
333 .controller('PrintTemplatesCtrl',
334 ['$scope','$q','egCore',
335 function($scope , $q , egCore) {
338 template_name : 'bills_current',
342 // print preview scope data
343 // TODO: consider moving the template-specific bits directly
344 // into the templates or storing template- specific script files
345 // alongside the templates.
346 // NOTE: A lot of this data can be shared across templates.
348 first_given_name : 'Slow',
349 second_given_name : 'Joe',
350 family_name : 'Jones',
352 barcode : '30393830393'
356 street1 : '123 Apple Rd',
365 title : 'Traveling Pants!!',
366 author : 'Jane Jones',
371 barcode : '33434322323'
376 phone_notify : '111-222-3333',
377 sms_notify : '111-222-3333',
378 email_notify : 'user@example.org',
379 request_time : new Date().toISOString()
383 $scope.preview_scope = {
388 xact_start : new Date().toISOString(),
390 xact_type : 'circulation',
391 last_billing_type : 'Overdue materials',
393 last_payment_note : 'Test Note 1',
399 xact_start : new Date().toISOString(),
401 xact_type : 'circulation',
402 last_billing_type : 'Overdue materials',
404 last_payment_note : 'Test Note 2',
413 due_date : new Date().toISOString(),
414 target_copy : seed_copy,
415 title : seed_record.title
419 previous_balance : 8.45,
420 payment_total : 2.00,
421 payment_applied : 2.00,
425 payment_type : 'cash_payment',
426 payment_note : 'Here is a payment note',
428 create_date : new Date().toISOString(),
429 title : 'Test Note Title',
431 value : 'This patron is super nice!'
438 holds_address : seed_addr
440 target_copy : seed_copy
442 title : seed_record.title,
443 author : seed_record.author,
444 patron : egCore.idl.toHash(egCore.auth.user()),
448 {hold : one_hold, title : 'Some Title 1', author : 'Some Author 1'},
449 {hold : one_hold, title : 'Some Title 2', author : 'Some Author 2'},
450 {hold : one_hold, title : 'Some Title 3', author : 'Some Author 3'}
454 $scope.preview_scope.payments = [
455 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
456 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
458 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
459 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
460 $scope.preview_scope.payments[1].xact.title = seed_record.title;
461 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
463 // today, staff, current_location, etc.
464 egCore.print.fleshPrintScope($scope.preview_scope);
466 $scope.template_changed = function() {
467 $scope.print.load_failed = false;
468 egCore.print.getPrintTemplate($scope.print.template_name)
471 $scope.print.template_content = html;
472 console.log('set template content');
475 $scope.print.template_content = '';
476 $scope.print.load_failed = true;
481 $scope.save_locally = function() {
482 egCore.print.storePrintTemplate(
483 $scope.print.template_name,
484 $scope.print.template_content
488 $scope.template_changed(); // load the default
492 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
493 return function(scope, element, attrs) {
496 return scope.$eval(attrs.content);
499 // create an isolate scope and copy the print context
500 // data into the new scope.
501 // TODO: see also print security concerns in egHatch
502 var result = element.html(value);
503 var context = scope.$eval(attrs.context);
504 var print_scope = scope.$new(true);
505 angular.forEach(context, function(val, key) {
506 print_scope[key] = val;
508 $compile(element.contents())(print_scope);
514 .controller('StoredPrefsCtrl',
515 ['$scope','$q','egCore','egConfirmDialog',
516 function($scope , $q , egCore , egConfirmDialog) {
517 console.log('StoredPrefsCtrl');
519 $scope.setContext = function(ctx) {
520 $scope.context = ctx;
522 $scope.setContext('local');
524 // grab the edit perm
525 $scope.userHasDeletePerm = false;
526 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
527 .then(function(bool) { $scope.userHasDeletePerm = bool });
531 function refreshKeys() {
532 $scope.keys = {local : [], remote : []};
534 egCore.hatch.getRemoteKeys().then(
535 function(keys) { $scope.keys.remote = keys.sort() })
537 // local calls are non-async
538 $scope.keys.local = egCore.hatch.getLocalKeys();
542 $scope.selectKey = function(key) {
543 $scope.currentKey = key;
544 $scope.currentKeyContent = null;
546 if ($scope.context == 'local') {
547 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
549 egCore.hatch.getRemoteItem(key)
550 .then(function(content) {
551 $scope.currentKeyContent = content
556 $scope.getCurrentKeyContent = function() {
557 return JSON.stringify($scope.currentKeyContent, null, 2);
560 $scope.removeKey = function(key) {
561 egConfirmDialog.open(
562 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
565 if ($scope.context == 'local') {
566 egCore.hatch.removeLocalItem(key);
569 egCore.hatch.removeItem(key)
570 .then(function() { refreshKeys() });
573 cancel : function() {} // user canceled, nothing to do