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); };
90 // redirect the user to the login page using the current
91 // workstation as the workstation URL param
92 $scope.useWS = function() {
93 $window.location.href = $location
95 .search({ws : $scope.selectedWS})
99 $scope.registerWS = function() {
100 register_workstation(
102 $scope.contextOrg.shortname() + '-' + $scope.newWSName,
103 $scope.contextOrg.id()
107 function register_workstation(base_name, name, org_id, override) {
109 var method = 'open-ils.actor.workstation.register';
110 if (override) method += '.override';
113 'open-ils.actor', method, egCore.auth.token(), name, org_id)
115 .then(function(resp) {
116 if (evt = egCore.evt.parse(resp)) {
117 console.log('register returned ' + evt.toString());
119 if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
120 egConfirmDialog.open(
121 egCore.strings.WS_EXISTS, base_name, {
123 register_workstation(base_name, name, org_id, true);
125 cancel : function() {}
130 // TODO: provide permission error display
131 alert(evt.toString());
134 $scope.workstations.push(name);
136 allWorkstations.push({
142 egCore.hatch.setItem(
143 'eg.workstation.all', allWorkstations)
145 if (allWorkstations.length == 1) {
146 // first one registerd, also mark it as the default
147 $scope.selectedWS = name;
148 $scope.setDefaultWS();
155 $scope.wsOrgChanged = function(org) {
156 $scope.contextOrg = org;
159 // ---------------------
161 $scope.hatchURL = egCore.hatch.hatchURL();
162 $scope.hatchRequired =
163 egCore.hatch.getLocalItem('eg.hatch.required');
165 $scope.updateHatchRequired = function() {
166 egCore.hatch.setLocalItem(
167 'eg.hatch.required', $scope.hatchRequired);
170 $scope.updateHatchURL = function() {
171 egCore.hatch.setLocalItem(
172 'eg.hatch.url', $scope.hatchURL);
176 .controller('PrintConfigCtrl',
178 function($scope , egCore) {
179 console.log('PrintConfigCtrl');
181 $scope.actionPending = false;
182 $scope.isTestView = false;
184 $scope.setContext = function(ctx) {
185 $scope.context = ctx;
186 $scope.isTestView = false;
187 $scope.actionPending = false;
189 $scope.setContext('default');
191 $scope.getPrinterByAttr = function(attr, value) {
193 angular.forEach($scope.printers, function(p) {
194 if (p[attr] == value) printer = p;
199 $scope.currentPrinter = function() {
200 if ($scope.printConfig && $scope.printConfig[$scope.context]) {
201 return $scope.getPrinterByAttr(
202 'name', $scope.printConfig[$scope.context].printer
207 // fetch info on all remote printers
208 egCore.hatch.getPrinters()
209 .then(function(printers) {
210 $scope.printers = printers;
211 $scope.defaultPrinter =
212 $scope.getPrinterByAttr('is-default', true);
214 .then(function() { return egCore.hatch.getPrintConfig() })
215 .then(function(config) {
216 $scope.printConfig = config;
219 if ($scope.defaultPrinter) {
220 pname = $scope.defaultPrinter.name;
222 } else if ($scope.printers.length == 1) {
223 // if the OS does not report a default printer, but only
224 // one printer is available, treat it as the default.
225 pname = $scope.printers[0].name;
228 // apply the default printer to every context which has
229 // no printer configured.
231 ['default','receipt','label','mail','offline'],
233 if (!$scope.printConfig[ctx]) {
234 $scope.printConfig[ctx] = {
243 $scope.printerConfString = function() {
244 if ($scope.printConfigError) return $scope.printConfigError;
245 if (!$scope.printConfig) return;
246 if (!$scope.printConfig[$scope.context]) return;
247 return JSON.stringify(
248 $scope.printConfig[$scope.context], undefined, 2);
251 $scope.resetConfig = function() {
252 $scope.actionPending = true;
253 $scope.printConfigError = null;
254 $scope.printConfig[$scope.context] = {
255 context : $scope.context
258 if ($scope.defaultPrinter) {
259 $scope.printConfig[$scope.context].printer =
260 $scope.defaultPrinter.name;
263 egCore.hatch.setPrintConfig($scope.printConfig)
264 .finally(function() {$scope.actionPending = false});
267 $scope.configurePrinter = function() {
268 $scope.printConfigError = null;
269 $scope.actionPending = true;
270 egCore.hatch.configurePrinter(
272 $scope.printConfig[$scope.context].printer
275 function(config) {$scope.printConfig = config},
276 function(error) {$scope.printConfigError = error}
278 .finally(function() {$scope.actionPending = false});
281 $scope.setPrinter = function(name) {
282 $scope.printConfig[$scope.context].printer = name;
286 $scope.setContentType = function(type) { $scope.contentType = type }
288 $scope.testPrint = function(withDialog) {
289 if ($scope.contentType == 'text/plain') {
291 context : $scope.context,
292 content_type : $scope.contentType,
293 content : $scope.textPrintContent,
294 show_dialog : withDialog
298 context : $scope.context,
299 content_type : $scope.contentType,
300 content : $scope.htmlPrintContent,
302 value1 : 'Value One',
303 value2 : 'Value Two',
304 date_value : '2015-02-04T14:04:34-0400'
306 show_dialog : withDialog
311 $scope.setContentType('text/plain');
315 .controller('PrintTemplatesCtrl',
316 ['$scope','$q','egCore',
317 function($scope , $q , egCore) {
320 template_name : 'bills_current',
324 // print preview scope data
325 // TODO: consider moving the template-specific bits directly
326 // into the templates or storing template- specific script files
327 // alongside the templates.
328 // NOTE: A lot of this data can be shared across templates.
330 first_given_name : 'Slow',
331 second_given_name : 'Joe',
332 family_name : 'Jones',
334 barcode : '30393830393'
338 street1 : '123 Apple Rd',
347 title : 'Traveling Pants!!',
348 author : 'Jane Jones',
353 barcode : '33434322323'
358 phone_notify : '111-222-3333',
359 sms_notify : '111-222-3333',
360 email_notify : 'user@example.org',
361 request_time : new Date().toISOString()
365 $scope.preview_scope = {
370 xact_start : new Date().toISOString(),
372 xact_type : 'circulation',
373 last_billing_type : 'Overdue materials',
375 last_payment_note : 'Test Note 1',
381 xact_start : new Date().toISOString(),
383 xact_type : 'circulation',
384 last_billing_type : 'Overdue materials',
386 last_payment_note : 'Test Note 2',
395 due_date : new Date().toISOString(),
396 target_copy : seed_copy,
397 title : seed_record.title
401 previous_balance : 8.45,
402 payment_total : 2.00,
403 payment_applied : 2.00,
407 payment_type : 'cash_payment',
408 payment_note : 'Here is a payment note',
410 create_date : new Date().toISOString(),
411 title : 'Test Note Title',
413 value : 'This patron is super nice!'
420 holds_address : seed_addr
422 target_copy : seed_copy
424 title : seed_record.title,
425 author : seed_record.author,
426 patron : egCore.idl.toHash(egCore.auth.user()),
430 {hold : one_hold, title : 'Some Title 1', author : 'Some Author 1'},
431 {hold : one_hold, title : 'Some Title 2', author : 'Some Author 2'},
432 {hold : one_hold, title : 'Some Title 3', author : 'Some Author 3'}
436 $scope.preview_scope.payments = [
437 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
438 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
440 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
441 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
442 $scope.preview_scope.payments[1].xact.title = seed_record.title;
443 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
445 // today, staff, current_location, etc.
446 egCore.print.fleshPrintScope($scope.preview_scope);
448 $scope.template_changed = function() {
449 $scope.print.load_failed = false;
450 egCore.print.getPrintTemplate($scope.print.template_name)
453 $scope.print.template_content = html;
454 console.log('set template content');
457 $scope.print.template_content = '';
458 $scope.print.load_failed = true;
463 $scope.save_locally = function() {
464 egCore.hatch.storePrintTemplate(
465 $scope.print.template_name,
466 $scope.print.template_content
470 $scope.template_changed(); // load the default
474 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
475 return function(scope, element, attrs) {
478 return scope.$eval(attrs.content);
481 // create an isolate scope and copy the print context
482 // data into the new scope.
483 // TODO: see also print security concerns in egHatch
484 var result = element.html(value);
485 var context = scope.$eval(attrs.context);
486 var print_scope = scope.$new(true);
487 angular.forEach(context, function(val, key) {
488 print_scope[key] = val;
490 $compile(element.contents())(print_scope);
496 .controller('StoredPrefsCtrl',
497 ['$scope','$q','egCore','egConfirmDialog',
498 function($scope , $q , egCore , egConfirmDialog) {
499 console.log('StoredPrefsCtrl');
501 $scope.setContext = function(ctx) {
502 $scope.context = ctx;
504 $scope.setContext('local');
506 // grab the edit perm
507 $scope.userHasDeletePerm = false;
508 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
509 .then(function(bool) { $scope.userHasDeletePerm = bool });
513 function refreshKeys() {
514 $scope.keys = {local : [], remote : []};
516 egCore.hatch.getRemoteKeys().then(
517 function(keys) { $scope.keys.remote = keys.sort() })
519 // local calls are non-async
520 $scope.keys.local = egCore.hatch.getLocalKeys();
524 $scope.selectKey = function(key) {
525 $scope.currentKey = key;
526 $scope.currentKeyContent = null;
528 if ($scope.context == 'local') {
529 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
531 egCore.hatch.getRemoteItem(key)
532 .then(function(content) {
533 $scope.currentKeyContent = content
538 $scope.getCurrentKeyContent = function() {
539 return JSON.stringify($scope.currentKeyContent, null, 2);
542 $scope.removeKey = function(key) {
543 egConfirmDialog.open(
544 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
547 if ($scope.context == 'local') {
548 egCore.hatch.removeLocalItem(key);
551 egCore.hatch.removeItem(key)
552 .then(function() { refreshKeys() });
555 cancel : function() {} // user canceled, nothing to do