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.
18 // called after onload of each new iframe page
22 templateUrl : './share/t_eframe',
25 ['$scope','$window','$location','$q','$timeout','egCore',
26 function($scope , $window , $location , $q , $timeout , egCore) {
28 // Set the iframe height to just under the window height.
29 // leave room for the navbar, padding, margins, etc.
30 $scope.height = $window.outerHeight - 300;
32 // browser client doesn't use cookies, so we don't load the
33 // (at the time of writing, quite limited) angular.cookies
34 // module. We could load something, but this seems to work
35 // well enough for setting the auth cookie (at least, until
38 // note: document.cookie is smart enough to leave unreferenced
39 // cookies alone, so contrary to how this might look, it's not
40 // deleting other cookies (anoncache, etc.)
42 // delete any existing ses cookie
43 $window.document.cookie = "ses=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
44 // push our authtoken in
45 $window.document.cookie = 'ses=' + egCore.auth.token() + '; path=/; secure'
47 // $location has functions for modifying paths and search,
48 // but they all assume you are staying within the angular
49 // app, which we are not. Build the URLs by hand.
50 function open_tab(path) {
51 var url = 'https://' + $window.location.hostname +
52 egCore.env.basePath + path;
53 console.debug('egEmbedFrame opening tab ' + url);
54 $window.open(url, '_blank').focus();
57 // define our own xulG functions to be inserted into the
58 // iframe. NOTE: window-level functions are bad. Though
59 // there is probably a way, I was unable to correctly wire
60 // up the iframe onload handler within the controller or link
61 // funcs. In any event, the code below is meant as a stop-gap
62 // for porting dojo, etc. apps to angular apps and should
63 // eventually go away.
64 // NOTE: catalog integration is not a stop-gap
65 $window.egEmbedFrameLoader = function(iframe) {
67 var page = iframe.contentWindow.location.href;
68 console.debug('egEmbedFrameLoader(): ' + page);
70 // reload ifram page w/o reloading the entire UI
71 $scope.reload = function() {
72 iframe.contentWindow.location.replace(
73 iframe.contentWindow.location);
76 // tell the iframe'd window its inside the staff client
77 iframe.contentWindow.IAMXUL = true;
79 // also tell it it's inside the browser client, which
80 // may be needed in a few special cases.
81 iframe.contentWindow.IAMBROWSER /* hear me roar */ = true;
83 // XUL has a dump() function which is occasinally called
84 // from embedded browsers.
85 iframe.contentWindow.dump = function(msg) {
86 console.debug('egEmbedFrame:dump(): ' + msg);
89 // define a few commonly used stock xulG handlers.
91 iframe.contentWindow.xulG = {
93 spawn_search : function(search) {
94 open_tab('/circ/patron/search?search='
95 + encodeURIComponent(js2JSON(search)));
98 // edit an existing user
99 spawn_editor : function(info) {
101 open_tab('/circ/patron/register/edit/' + info.usr);
103 } else if (info.clone) {
104 // FIXME: The save-and-clone operation in the
105 // patron editor results in this action.
106 // For some reason, this specific function results
107 // in a new browser window opening instead of a
108 // browser tab. Possibly this is caused by the
109 // fact that the action occurs as a result of a
110 // button click instead of an href. *shrug*.
112 open_tab('/circ/patron/register/clone/' + info.clone);
116 // open a user account
117 new_patron_tab : function(tab_info, usr_info) {
118 open_tab('/circ/patron/' + usr_info.id + '/checkout');
121 get_barcode_and_settings_async : function(barcode, only_settings) {
122 if (!barcode) return $q.reject();
123 var deferred = $q.defer();
125 var barcode_promise = $q.when(barcode);
126 if (!only_settings) {
128 // first verify / locate the barcode
129 barcode_promise = egCore.net.request(
131 'open-ils.actor.get_barcodes',
133 egCore.auth.user().ws_ou(), 'actor', barcode
134 ).then(function(resp) {
136 if (!resp || egCore.evt.parse(resp) || !resp.length) {
137 console.error('user not found: ' + barcode);
143 return barcode = resp.barcode;
147 barcode_promise.then(function(barcode) {
148 if (!barcode) return;
150 return egCore.net.request(
152 'open-ils.actor.user.fleshed.retrieve_by_barcode',
153 egCore.auth.token(), barcode);
155 }).then(function(user) {
156 if (!user) return null;
158 if (e = egCore.evt.parse(user)) {
159 console.error('user fetch failed : ' + e.toString());
164 // copied more or less directly from XUL menu.js
166 for(var i = 0; i < user.settings().length; i++) {
167 settings[user.settings()[i].name()] =
168 JSON2js(user.settings()[i].value());
171 if(!settings['opac.default_phone'] && user.day_phone())
172 settings['opac.default_phone'] = user.day_phone();
173 if(!settings['opac.hold_notify'] && settings['opac.hold_notify'] !== '')
174 settings['opac.hold_notify'] = 'email:phone';
176 // Taken from patron/util.js format_name
179 ( user.prefix() ? user.prefix() + ' ' : '') +
180 user.family_name() + ', ' +
181 user.first_given_name() + ' ' +
182 ( user.second_given_name() ? user.second_given_name() + ' ' : '' ) +
183 ( user.suffix() ? user.suffix() : '');
187 "settings" : settings,
188 "user_email" : user.email(),
189 "patron_name" : patron_name
193 return deferred.promise;
197 if ($scope.handlers) {
198 $scope.handlers.reload = $scope.reload;
199 angular.forEach($scope.handlers, function(val, key) {
200 iframe.contentWindow.xulG[key] = val;
204 if ($scope.onchange) $scope.onchange(page);