From: Bill Erickson Date: Mon, 17 Mar 2014 19:58:57 +0000 (-0400) Subject: web staff : xul integration experiment X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=853ec746b81c1719477aed2dcab756df654ecacf;p=working%2FEvergreen.git web staff : xul integration experiment Trying to see if it's possible to run these UIs from within XUL, potentially easing integration and testing. Notes: * cookies / localStorage need XUL pass-thru's * to use websockets, a global (xul-level) websocket connection would be required (to avoid per-tab connections). * we'd probably want to trim out the nav bar along the top * debugging is a pain in the butt. For some reason, not all errors bubble up to the console. and console.log() no workee. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/staff/t_base.tt2 b/Open-ILS/src/templates/staff/t_base.tt2 index 6009417ae2..ae96b4ebe0 100644 --- a/Open-ILS/src/templates/staff/t_base.tt2 +++ b/Open-ILS/src/templates/staff/t_base.tt2 @@ -8,7 +8,7 @@ - + diff --git a/Open-ILS/src/templates/staff/t_base_js.tt2 b/Open-ILS/src/templates/staff/t_base_js.tt2 index 4686bdbdf3..51ca7fd884 100644 --- a/Open-ILS/src/templates/staff/t_base_js.tt2 +++ b/Open-ILS/src/templates/staff/t_base_js.tt2 @@ -7,22 +7,22 @@ %] - - - - + + + + - ---> @@ -36,6 +36,7 @@ + diff --git a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js index eedd8055ef..de8c434dc4 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js @@ -15,8 +15,9 @@ angular.module('egCatRecordBuckets', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egListMod']) -.config(function($routeProvider, $locationProvider) { +.config(function($routeProvider, $locationProvider, $compileProvider) { $locationProvider.html5Mode(true); + $compileProvider.aHrefSanitizationWhitelist(/^\s*(chrome|oils):/); var resolver = {delay : function(egStartup) {return egStartup.go()}}; diff --git a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js index 6d9c92653f..d9670b27f4 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js @@ -1,8 +1,11 @@ angular.module('egCheckinApp', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egListMod', 'egUserMod']) -.config(function($routeProvider, $locationProvider) { +.config(function($routeProvider, $locationProvider, $compileProvider) { $locationProvider.html5Mode(true); + + $compileProvider.aHrefSanitizationWhitelist(/^\s*(chrome|oils):/); + // no routes needed }) diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 0d8c02bc53..b09f34acf7 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -10,9 +10,11 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egListMod', 'egUserMod']) -.config(function($routeProvider, $locationProvider) { +.config(function($routeProvider, $locationProvider, $compileProvider) { $locationProvider.html5Mode(true); + $compileProvider.aHrefSanitizationWhitelist(/^\s*(chrome|oils):/); + // data loaded at startup which only requires an authtoken goes // here. this allows the requests to be run in parallel instead of // waiting until startup has completed. @@ -245,9 +247,14 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egEnv, $scope.profiles = egEnv.pgt.list.map( function(grp) {return {name : grp.name(), id : grp.id() }}) + $scope.org_units = egEnv.aou.list.map( function(org) {return {shortname : org.shortname(), id : org.id() }}) + + $scope.tips = { dismissed : function() {return true} }; + /* localStorage would need xul tie-in + // TODO: experiment // if this is useful, it should be moved into a service. $scope.tips = { @@ -259,18 +266,23 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egEnv, } // TODO: function to reset all tips }; + */ + // TODO: // another experiment -- user prefs in localStorage -- this should // be a service, which can also check (certain) user/org settings $scope.applyShowExtras = function($event, bool) { $scope.showExtras = bool; - $window.localStorage.setItem('eg.prefs.circ.patron.search.showExtras', bool); + //$window.localStorage.setItem('eg.prefs.circ.patron.search.showExtras', bool); $event.preventDefault(); } // localStorage stores strings; parse the values as JSON bools + /* $scope.showExtras = JSON.parse($window.localStorage.getItem( 'eg.prefs.circ.patron.search.showExtras')) || false; + */ + // map form arguments into search params function compileSearch(args) { diff --git a/Open-ILS/web/js/ui/default/staff/services/auth.js b/Open-ILS/web/js/ui/default/staff/services/auth.js index 3c4ad88065..44053fdae6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/auth.js +++ b/Open-ILS/web/js/ui/default/staff/services/auth.js @@ -12,8 +12,8 @@ angular.module('egCoreMod') .constant('EG_AUTH_COOKIE', 'ses') .factory('egAuth', - ['$q','$cookies','egNet','EG_AUTH_COOKIE', -function($q, $cookies, egNet, EG_AUTH_COOKIE) { + ['$q','$cookies', '$timeout','egNet','EG_AUTH_COOKIE','egXUL', +function($q, $cookies, $timeout, egNet, EG_AUTH_COOKIE , egXUL) { var service = { // expose user and token via function, since we will eventually @@ -23,7 +23,7 @@ function($q, $cookies, egNet, EG_AUTH_COOKIE) { return this._user; }, token : function() { - return $cookies[EG_AUTH_COOKIE]; + return this._token || $cookies[EG_AUTH_COOKIE]; } }; @@ -33,6 +33,16 @@ function($q, $cookies, egNet, EG_AUTH_COOKIE) { var deferred = $q.defer(); var token = service.token(); + if (egXUL.isXUL()) { + var authstuff = egXUL.getAuthInfo(); + service._user = authstuff.user; + service._token = authstuff.token; + // race condition from multiple callers of egStartup.go() + // which relies on the testAuthToken to resolve asynchronously + $timeout(function() { deferred.resolve()}, 1); + return deferred.promise; + } + if (token) { egNet.request( 'open-ils.auth', diff --git a/Open-ILS/web/js/ui/default/staff/services/xul.js b/Open-ILS/web/js/ui/default/staff/services/xul.js new file mode 100644 index 0000000000..f4cda8831d --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/services/xul.js @@ -0,0 +1,42 @@ +angular.module('egCoreMod') + +.factory('egXUL', [function() { + + var service = {}; + + service.isXUL = function() { + if(location.protocol == 'chrome:' || location.protocol == 'oils:') + return true; + return Boolean(window.IAMXUL); + } + + service.getStash = function() { + try { + var CacheClass = Components.classes[ + "@open-ils.org/openils_data_cache;1"].getService(); + return CacheClass.wrappedJSObject.data; + } catch(e) { + console.log("Error loading XUL stash: " + e); + return {error : e}; + } + } + + service.getAuthInfo = function() { + var stash = service.getStash(); + return { + user : stash.list.au[0], + token : stash.session.key + }; + } + + service.initXUL = function($compileProvider) { + // treat these URLs schemes as safe + if (service.isXUL()) + $compileProvider.aHrefSanitizationWhitelist(/^\s*(chrome|oils):/); + } + + return service; +}]); + + +