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);
177 .controller('PrintConfigCtrl',
179 function($scope , egCore) {
180 console.log('PrintConfigCtrl');
182 $scope.actionPending = false;
183 $scope.isTestView = false;
185 $scope.setContext = function(ctx) {
186 $scope.context = ctx;
187 $scope.isTestView = false;
188 $scope.actionPending = false;
190 $scope.setContext('default');
192 $scope.getPrinterByAttr = function(attr, value) {
194 angular.forEach($scope.printers, function(p) {
195 if (p[attr] == value) printer = p;
200 $scope.currentPrinter = function() {
201 if ($scope.printConfig && $scope.printConfig[$scope.context]) {
202 return $scope.getPrinterByAttr(
203 'name', $scope.printConfig[$scope.context].printer
208 // fetch info on all remote printers
209 egCore.hatch.getPrinters()
210 .then(function(printers) {
211 $scope.printers = printers;
212 $scope.defaultPrinter =
213 $scope.getPrinterByAttr('is-default', true);
215 .then(function() { return egCore.hatch.getPrintConfig() })
216 .then(function(config) {
217 $scope.printConfig = config;
220 if ($scope.defaultPrinter) {
221 pname = $scope.defaultPrinter.name;
223 } else if ($scope.printers.length == 1) {
224 // if the OS does not report a default printer, but only
225 // one printer is available, treat it as the default.
226 pname = $scope.printers[0].name;
229 // apply the default printer to every context which has
230 // no printer configured.
232 ['default','receipt','label','mail','offline'],
234 if (!$scope.printConfig[ctx]) {
235 $scope.printConfig[ctx] = {
244 $scope.printerConfString = function() {
245 if ($scope.printConfigError) return $scope.printConfigError;
246 if (!$scope.printConfig) return;
247 if (!$scope.printConfig[$scope.context]) return;
248 return JSON.stringify(
249 $scope.printConfig[$scope.context], undefined, 2);
252 $scope.resetConfig = function() {
253 $scope.actionPending = true;
254 $scope.printConfigError = null;
255 $scope.printConfig[$scope.context] = {
256 context : $scope.context
259 if ($scope.defaultPrinter) {
260 $scope.printConfig[$scope.context].printer =
261 $scope.defaultPrinter.name;
264 egCore.hatch.setPrintConfig($scope.printConfig)
265 .finally(function() {$scope.actionPending = false});
268 $scope.configurePrinter = function() {
269 $scope.printConfigError = null;
270 $scope.actionPending = true;
271 egCore.hatch.configurePrinter(
273 $scope.printConfig[$scope.context].printer
276 function(config) {$scope.printConfig = config},
277 function(error) {$scope.printConfigError = error}
279 .finally(function() {$scope.actionPending = false});
282 $scope.setPrinter = function(name) {
283 $scope.printConfig[$scope.context].printer = name;
287 $scope.setContentType = function(type) { $scope.contentType = type }
289 $scope.testPrint = function(withDialog) {
290 if ($scope.contentType == 'text/plain') {
292 context : $scope.context,
293 content_type : $scope.contentType,
294 content : $scope.textPrintContent,
295 show_dialog : withDialog
299 context : $scope.context,
300 content_type : $scope.contentType,
301 content : $scope.htmlPrintContent,
303 value1 : 'Value One',
304 value2 : 'Value Two',
305 date_value : '2015-02-04T14:04:34-0400'
307 show_dialog : withDialog
312 $scope.setContentType('text/plain');
316 .controller('PrintTemplatesCtrl',
317 ['$scope','$q','egCore',
318 function($scope , $q , egCore) {
321 template_name : 'bills_current',
325 // print preview scope data
326 // TODO: consider moving the template-specific bits directly
327 // into the templates or storing template- specific script files
328 // alongside the templates.
329 // NOTE: A lot of this data can be shared across templates.
331 first_given_name : 'Slow',
332 second_given_name : 'Joe',
333 family_name : 'Jones',
335 barcode : '30393830393'
339 street1 : '123 Apple Rd',
348 title : 'Traveling Pants!!',
349 author : 'Jane Jones',
354 barcode : '33434322323'
359 phone_notify : '111-222-3333',
360 sms_notify : '111-222-3333',
361 email_notify : 'user@example.org',
362 request_time : new Date().toISOString()
366 $scope.preview_scope = {
371 xact_start : new Date().toISOString(),
373 xact_type : 'circulation',
374 last_billing_type : 'Overdue materials',
376 last_payment_note : 'Test Note 1',
382 xact_start : new Date().toISOString(),
384 xact_type : 'circulation',
385 last_billing_type : 'Overdue materials',
387 last_payment_note : 'Test Note 2',
396 due_date : new Date().toISOString(),
397 target_copy : seed_copy,
398 title : seed_record.title
402 previous_balance : 8.45,
403 payment_total : 2.00,
404 payment_applied : 2.00,
408 payment_type : 'cash_payment',
409 payment_note : 'Here is a payment note',
411 create_date : new Date().toISOString(),
412 title : 'Test Note Title',
414 value : 'This patron is super nice!'
421 holds_address : seed_addr
423 target_copy : seed_copy
425 title : seed_record.title,
426 author : seed_record.author,
427 patron : egCore.idl.toHash(egCore.auth.user()),
431 {hold : one_hold, title : 'Some Title 1', author : 'Some Author 1'},
432 {hold : one_hold, title : 'Some Title 2', author : 'Some Author 2'},
433 {hold : one_hold, title : 'Some Title 3', author : 'Some Author 3'}
437 $scope.preview_scope.payments = [
438 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
439 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
441 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
442 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
443 $scope.preview_scope.payments[1].xact.title = seed_record.title;
444 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
446 // today, staff, current_location, etc.
447 egCore.print.fleshPrintScope($scope.preview_scope);
449 $scope.template_changed = function() {
450 $scope.print.load_failed = false;
451 egCore.print.getPrintTemplate($scope.print.template_name)
454 $scope.print.template_content = html;
455 console.log('set template content');
458 $scope.print.template_content = '';
459 $scope.print.load_failed = true;
464 $scope.save_locally = function() {
465 egCore.hatch.storePrintTemplate(
466 $scope.print.template_name,
467 $scope.print.template_content
471 $scope.template_changed(); // load the default
475 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
476 return function(scope, element, attrs) {
479 return scope.$eval(attrs.content);
482 // create an isolate scope and copy the print context
483 // data into the new scope.
484 // TODO: see also print security concerns in egHatch
485 var result = element.html(value);
486 var context = scope.$eval(attrs.context);
487 var print_scope = scope.$new(true);
488 angular.forEach(context, function(val, key) {
489 print_scope[key] = val;
491 $compile(element.contents())(print_scope);
497 .controller('StoredPrefsCtrl',
498 ['$scope','$q','egCore','egConfirmDialog',
499 function($scope , $q , egCore , egConfirmDialog) {
500 console.log('StoredPrefsCtrl');
502 $scope.setContext = function(ctx) {
503 $scope.context = ctx;
505 $scope.setContext('local');
507 // grab the edit perm
508 $scope.userHasDeletePerm = false;
509 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
510 .then(function(bool) { $scope.userHasDeletePerm = bool });
514 function refreshKeys() {
515 $scope.keys = {local : [], remote : []};
517 egCore.hatch.getRemoteKeys().then(
518 function(keys) { $scope.keys.remote = keys.sort() })
520 // local calls are non-async
521 $scope.keys.local = egCore.hatch.getLocalKeys();
525 $scope.selectKey = function(key) {
526 $scope.currentKey = key;
527 $scope.currentKeyContent = null;
529 if ($scope.context == 'local') {
530 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
532 egCore.hatch.getRemoteItem(key)
533 .then(function(content) {
534 $scope.currentKeyContent = content
539 $scope.getCurrentKeyContent = function() {
540 return JSON.stringify($scope.currentKeyContent, null, 2);
543 $scope.removeKey = function(key) {
544 egConfirmDialog.open(
545 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
548 if ($scope.context == 'local') {
549 egCore.hatch.removeLocalItem(key);
552 egCore.hatch.removeItem(key)
553 .then(function() { refreshKeys() });
556 cancel : function() {} // user canceled, nothing to do