1 angular.module('egCoreMod')
4 * Iframe container for (mostly legacy) embedded interfaces
6 .directive('egEmbedFrame', function() {
11 // URL to load in the embed iframe
14 // optional hash of functions which augment or override
15 // the stock xulG functions defined below.
19 // called after onload of each new iframe page
23 templateUrl : './share/t_eframe',
26 ['$scope','$window','$location','$q','$timeout','egCore',
27 function($scope , $window , $location , $q , $timeout , egCore) {
29 // Set the iframe height to just under the window height.
30 // leave room for the navbar, padding, margins, etc.
31 $scope.height = $window.outerHeight - 300;
33 // browser client doesn't use cookies, so we don't load the
34 // (at the time of writing, quite limited) angular.cookies
35 // module. We could load something, but this seems to work
36 // well enough for setting the auth cookie (at least, until
39 // note: document.cookie is smart enough to leave unreferenced
40 // cookies alone, so contrary to how this might look, it's not
41 // deleting other cookies (anoncache, etc.)
43 // delete any existing ses cookie
44 $window.document.cookie = "ses=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
45 // push our authtoken in
46 $window.document.cookie = 'ses=' + egCore.auth.token() + '; path=/; secure'
48 // $location has functions for modifying paths and search,
49 // but they all assume you are staying within the angular
50 // app, which we are not. Build the URLs by hand.
51 function open_tab(path) {
52 var url = 'https://' + $window.location.hostname +
53 egCore.env.basePath + path;
54 console.debug('egEmbedFrame opening tab ' + url);
55 $window.open(url, '_blank').focus();
58 // define our own xulG functions to be inserted into the
59 // iframe. NOTE: window-level functions are bad. Though
60 // there is probably a way, I was unable to correctly wire
61 // up the iframe onload handler within the controller or link
62 // funcs. In any event, the code below is meant as a stop-gap
63 // for porting dojo, etc. apps to angular apps and should
64 // eventually go away.
65 // NOTE: catalog integration is not a stop-gap
66 $window.egEmbedFrameLoader = function(iframe) {
68 $scope.frame = iframe;
70 var page = iframe.contentWindow.location.href;
71 console.debug('egEmbedFrameLoader(): ' + page);
73 // reload ifram page w/o reloading the entire UI
74 $scope.reload = function() {
75 iframe.contentWindow.location.replace(
76 iframe.contentWindow.location);
79 // tell the iframe'd window its inside the staff client
80 iframe.contentWindow.IAMXUL = true;
82 // also tell it it's inside the browser client, which
83 // may be needed in a few special cases.
84 iframe.contentWindow.IAMBROWSER /* hear me roar */ = true;
86 // XUL has a dump() function which is occasinally called
87 // from embedded browsers.
88 iframe.contentWindow.dump = function(msg) {
89 console.debug('egEmbedFrame:dump(): ' + msg);
92 // define a few commonly used stock xulG handlers.
94 iframe.contentWindow.xulG = {
96 spawn_search : function(search) {
97 open_tab('/circ/patron/search?search='
98 + encodeURIComponent(js2JSON(search)));
101 // edit an existing user
102 spawn_editor : function(info) {
104 open_tab('/circ/patron/register/edit/' + info.usr);
106 } else if (info.clone) {
107 // FIXME: The save-and-clone operation in the
108 // patron editor results in this action.
109 // For some reason, this specific function results
110 // in a new browser window opening instead of a
111 // browser tab. Possibly this is caused by the
112 // fact that the action occurs as a result of a
113 // button click instead of an href. *shrug*.
115 open_tab('/circ/patron/register/clone/' + info.clone);
119 // open a user account
120 new_patron_tab : function(tab_info, usr_info) {
121 open_tab('/circ/patron/' + usr_info.id + '/checkout');
124 get_barcode_and_settings_async : function(barcode, only_settings) {
125 if (!barcode) return $q.reject();
126 var deferred = $q.defer();
128 var barcode_promise = $q.when(barcode);
129 if (!only_settings) {
131 // first verify / locate the barcode
132 barcode_promise = egCore.net.request(
134 'open-ils.actor.get_barcodes',
136 egCore.auth.user().ws_ou(), 'actor', barcode
137 ).then(function(resp) {
139 if (!resp || egCore.evt.parse(resp) || !resp.length) {
140 console.error('user not found: ' + barcode);
146 return barcode = resp.barcode;
150 barcode_promise.then(function(barcode) {
151 if (!barcode) return;
153 return egCore.net.request(
155 'open-ils.actor.user.fleshed.retrieve_by_barcode',
156 egCore.auth.token(), barcode);
158 }).then(function(user) {
159 if (!user) return null;
161 if (e = egCore.evt.parse(user)) {
162 console.error('user fetch failed : ' + e.toString());
167 // copied more or less directly from XUL menu.js
169 for(var i = 0; i < user.settings().length; i++) {
170 settings[user.settings()[i].name()] =
171 JSON2js(user.settings()[i].value());
174 if(!settings['opac.default_phone'] && user.day_phone())
175 settings['opac.default_phone'] = user.day_phone();
176 if(!settings['opac.hold_notify'] && settings['opac.hold_notify'] !== '')
177 settings['opac.hold_notify'] = 'email:phone';
179 // Taken from patron/util.js format_name
182 ( user.prefix() ? user.prefix() + ' ' : '') +
183 user.family_name() + ', ' +
184 user.first_given_name() + ' ' +
185 ( user.second_given_name() ? user.second_given_name() + ' ' : '' ) +
186 ( user.suffix() ? user.suffix() : '');
190 "settings" : settings,
191 "user_email" : user.email(),
192 "patron_name" : patron_name
196 return deferred.promise;
200 if ($scope.handlers) {
201 $scope.handlers.reload = $scope.reload;
202 angular.forEach($scope.handlers, function(val, key) {
203 iframe.contentWindow.xulG[key] = val;
207 if ($scope.onchange) $scope.onchange(page);