[open-ils-commits] r9930 - in
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb:
public/oils/media/ui_js/oils templates/oils templates/oils/default
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jun 25 14:25:45 EDT 2008
Author: erickson
Date: 2008-06-25 14:25:42 -0400 (Wed, 25 Jun 2008)
New Revision: 9930
Added:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/base.js
Modified:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/base.html
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/header.html
Log:
moved the logged in user fetching to an external JS file. shoved into onload instead of running at render time
Added: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/base.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/base.js (rev 0)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/base.js 2008-06-25 18:25:42 UTC (rev 9930)
@@ -0,0 +1,42 @@
+function loadUser(username, password) {
+ dojo.require('dojo.cookie');
+ dojo.require('openils.CGI');
+ dojo.require("openils.User");
+
+ openils.User.authcookie = 'ses';
+ openils.User.authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
+ // cache the user object as a cookie?
+ //openils.User.user = JSON2js(dojo.cookie('user'));
+
+ if(!username) return;
+
+ dojo.require('openils.Event');
+
+ function dologin() {
+ openils.User.authtoken = null;
+ user = new openils.User();
+ user.login({
+ login_type:'staff',
+ username:username,
+ passwd:password,
+ login:true
+ });
+ user.getBySession();
+ openils.User.authtoken = user.authtoken;
+ openils.User.user = user.user;
+ alert('user = ' + openils.User.user);
+ //dojo.cookie('user', js2JSON(openils.User.user),{path:'/'});
+ }
+
+ if(!openils.User.user) {
+ if(openils.User.authtoken) {
+ user = new openils.User();
+ openils.User.user = user.user;
+ if(openils.Event.parse(user.user)) // session timed out
+ dologin();
+ } else {
+ dologin();
+ }
+ }
+}
+
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/base.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/base.html 2008-06-25 17:06:05 UTC (rev 9929)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/base.html 2008-06-25 18:25:42 UTC (rev 9930)
@@ -31,10 +31,10 @@
<link rel='stylesheet' type='text/css'
href='${c.oils.core.media_prefix.value}/css/theme/${c.oils.core.theme.value}.css'/>
</%def>
-
<%def name='block_js()'>
<script type="text/javascript" src="${c.oils.core.media_prefix.value}/js/dojo/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
+ <script src='${c.oils.core.media_prefix.value}/ui_js/oils/base.js'> </script>
<script type="text/javascript">
dojo.require("dojo.parser");
@@ -43,12 +43,14 @@
</script>
<script type='text/javascript'>
- /* first thing, let's make sure we're logged in */
- dojo.require('dojo.cookie');
- dojo.require('openils.CGI');
- dojo.require("openils.User");
- openils.User.authcookie = 'ses';
- openils.User.authtoken = dojo.cookie('ses') || new openils.CGI().param('ses');
+ <% import pylons %>
+ var username = null;
+ var password = null;
+ % if 'oils_demo_user' in pylons.config:
+ username = '${pylons.config.get("oils_demo_user")}';
+ password = '${pylons.config.get("oils_demo_password")}';
+ % endif
+ dojo.addOnLoad(function(){loadUser(username, password);});
</script>
</%def>
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/header.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/header.html 2008-06-25 17:06:05 UTC (rev 9929)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/header.html 2008-06-25 18:25:42 UTC (rev 9930)
@@ -1,45 +1,10 @@
# -*- coding: utf-8 -*-
<div id='oils-base-header-content-div'>
- <%
- import pylons
- if 'oils_demo_user' in pylons.config:
- auto_login = True
- else:
- auto_login = False
- %>
- % if auto_login:
- <script>
- dojo.require('openils.User');
- dojo.require('openils.Event');
- var user;
-
- function dologin() {
- var username = '${pylons.config.get("oils_demo_user")}';
- var password = '${pylons.config.get("oils_demo_password")}';
- openils.User.authtoken = null;
- user = new openils.User();
- user.login({
- login_type:'staff',
- username:username,
- passwd:password,
- login:true
- });
- user.getBySession();
- openils.User.authtoken = user.authtoken;
- }
-
- if(openils.User.authtoken) {
- user = new openils.User();
- if(openils.Event.parse(user.user)) // session timed out
- dologin();
- } else {
- dologin();
- }
- </script>
- <span id='oils-base-header-user-info'> </span>
- <script>
+ <span id='oils-base-header-user-info'> </span>
+ <script>
+ dojo.addOnLoad(function(){
dojo.byId('oils-base-header-user-info').appendChild(
- document.createTextNode(user.user.usrname()));
- </script>
- % endif
+ document.createTextNode(openils.User.user.usrname()));
+ });
+ </script>
</div>
More information about the open-ils-commits
mailing list