summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/hosting/server/htdocs/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/hosting/server/htdocs/index.html')
-rw-r--r--sca-cpp/trunk/hosting/server/htdocs/index.html261
1 files changed, 166 insertions, 95 deletions
diff --git a/sca-cpp/trunk/hosting/server/htdocs/index.html b/sca-cpp/trunk/hosting/server/htdocs/index.html
index b46141919d..e3e046136d 100644
--- a/sca-cpp/trunk/hosting/server/htdocs/index.html
+++ b/sca-cpp/trunk/hosting/server/htdocs/index.html
@@ -26,6 +26,7 @@
<link rel="apple-touch-icon" href="/public/touchicon.png"/>
<base href="/"/>
<script type="text/javascript">
+(function() {
window.appcache = {};
@@ -44,59 +45,77 @@ appcache.get = function(uri) {
return item;
// Get resource from network
+ //if (window.debug) debug('appcache.get', u);
var http = new XMLHttpRequest();
http.open("GET", u, false);
http.setRequestHeader("Accept", "*/*");
http.send(null);
if (http.status == 200) {
if (http.getResponseHeader("X-Login") != null) {
- if (debug) debug('http error', u, 'X-Login');
+ if (window.debug) debug('http error', u, 'X-Login');
// Redirect to login page if not signed in
document.location = '/login/';
return null;
} else if (http.responseText == '' || http.getResponseHeader("Content-Type") == null) {
- if (debug) debug('http error', u, 'No-Content');
+ if (window.debug) debug('http error', u, 'No-Content');
return null;
}
try { ls.setItem(u, http.responseText); } catch(e) {}
return http.responseText;
}
- if (debug) debug('http error', u, http.status, http.statusText);
+ if (window.debug) debug('http error', u, http.status, http.statusText);
// Redirect to login page if not signed in
if (http.status == 403)
document.location = '/login/';
return null;
};
-// Load Javascript and CSS
+appcache.remove = function(uri) {
+ var h = uri.indexOf('#');
+ var u = h == -1? uri : uri.substring(0, h);
+ var ls = window.lstorage || localStorage;
+ try { ls.removeItem(u); } catch(e) {}
+ return true;
+};
+
+})();
+
+/**
+ * Load Javascript and CSS.
+ */
(function() {
- var bootjs = document.createElement('script');
- bootjs.type = 'text/javascript';
- bootjs.text = appcache.get('/all-min.js');
- document.head.appendChild(bootjs);
- document.head.appendChild(ui.declareCSS(appcache.get('/ui-min.css')));
- // Disable cache for testing
- lstorage.enabled = false;
+var bootjs = document.createElement('script');
+bootjs.type = 'text/javascript';
+bootjs.text = appcache.get('/all-min.js');
+document.head.appendChild(bootjs);
+document.head.appendChild(ui.declareCSS(appcache.get('/ui-min.css')));
+
+// Disable cache for testing
+//lstorage.enabled = false;
})();
-</script>
-<script type="text/javascript">
+/**
+ * Redirect to login page if not signed in.
+ */
+(function() {
-// Redirect to login page if not signed in
if (document.location.protocol == 'https:' && !hasauthcookie())
document.location = '/login/';
+})();
</script>
</head>
-<body class="delayed" onload="onload();">
+<body class="delayed">
<div id="mainbodydiv" class="mainbody">
<div id="headdiv" class="hsection">
<script type="text/javascript">
(function() {
+
$('headdiv').appendChild(ui.declareScript(appcache.get('/config-min.js')));
+
})();
</script>
</div>
@@ -109,28 +128,45 @@ $('headdiv').appendChild(ui.declareScript(appcache.get('/config-min.js')));
<div id="viewcontainer"></div>
+<div id="viewfootbackground" class="viewfootbackground fixed"></div>
+<div id="viewfoot" class="viewfoot fixed"></div>
+<div id="status" class="status fixed" style="visibility: hidden;"></div>
+
<script type="text/javascript">
+(function() {
-// Init service references
-var editWidget = sca.component("EditWidget");
-var user= sca.defun(sca.reference(editWidget, "user"));
-var accounts = sca.reference(editWidget, "accounts");
+/**
+ * Init service references.
+ */
+var editorComp = sca.component("Editor");
+var user= sca.defun(sca.reference(editorComp, "user"));
+var accounts = sca.reference(editorComp, "accounts");
-// Set page title
-document.title = ui.windowtitle(location.hostname);
+/**
+ * Set page title.
+ */
+document.title = config.windowtitle();
-// Init div variables
+/**
+ * Init div variables.
+ */
var bdiv = $('mainbodydiv');
var mdiv = $('menu');
var hdiv = $('viewhead');
var vcontainer = $('viewcontainer');
vcontainer.className = ui.isMobile()? 'viewcontainer3dm' : 'viewcontainer3d';
+var fdiv = $('viewfoot');
/**
* The current user name and account entry.
*/
-var username;
-var accountentry;
+window.username = 'anonymous';
+
+/**
+ * The current store category.
+ */
+var storecat = 'top';
+var storeidx = 0;
/**
* Pre-fetch app resources.
@@ -138,26 +174,66 @@ var accountentry;
var appresources = [
['/all-min.js'],
['/ui-min.css'],
- ['/account/', '9'],
- ['/clone/', '3'],
- ['/create/', '2'],
- ['/delete/', '3'],
- ['/graph/', '5'],
+ ['/account/', 9],
+ ['/clone/', 3],
+ ['/create/', 2],
+ ['/delete/', 3],
+ ['/graph/', 5],
['/config-min.js'],
- ['/home/', '0'],
+ ['/home/', 0],
['/home/home.b64'],
- ['/page/', '4'],
+ ['/page/', 4],
['/public/app.b64'],
['/public/config-min.js'],
['/public/grid72.b64'],
['/public/iframe-min.html'],
['/public/img.b64'],
['/public/user.b64'],
- ['/stats/', '2'],
- ['/store/', '1']
+ ['/stats/', 2],
+ ['/store/', 1]
];
/**
+ * Show a status message.
+ */
+window.showStatus = function(s, c) {
+ //debug('status', s);
+ var sdiv = $('status');
+ if (isNil(sdiv))
+ return s;
+ sdiv.innerHTML = '<span class="' + (c? c : 'okstatus') + '">' + s + '</span>';
+ sdiv.className = 'status fixed';
+ sdiv.style.visibility = 'visible';
+
+ function divtransitionend(e) {
+ e.target.style.visibility = 'hidden';
+ e.target.className = 'status fixed';
+ }
+ if (!sdiv.addedTransitionEnd) {
+ sdiv.addEventListener('webkitTransitionEnd', divtransitionend, false);
+ sdiv.addEventListener('transitionend', divtransitionend, false);
+ sdiv.addedTransitionEnd = true;
+ }
+ sdiv.className = 'statusout3 fixed';
+ return s;
+}
+
+/**
+ * Show an error message.
+ */
+window.showError = function(s) {
+ //debug('error', s);
+ return showStatus(s, 'errorstatus');
+}
+
+/**
+ * Show the online/offline status.
+ */
+window.showOnlineStatus = function() {
+ return navigator.onLine? showStatus('Online') : showError('Offline');
+}
+
+/**
* Handle application cache events.
*/
applicationCache.addEventListener('checking', function(e) {
@@ -166,11 +242,11 @@ applicationCache.addEventListener('checking', function(e) {
}, false);
applicationCache.addEventListener('error', function(e) {
//debug('appcache error', e);
- showStatus(defaultStatus());
+ showOnlineStatus();
}, false);
applicationCache.addEventListener('noupdate', function(e) {
//debug('appcache noupdate', e);
- showStatus(defaultStatus());
+ showOnlineStatus();
}, false);
applicationCache.addEventListener('downloading', function(e) {
//debug('appcache downloading', e);
@@ -185,16 +261,27 @@ applicationCache.addEventListener('updateready', function(e) {
try {
applicationCache.swapCache();
} catch(e) {}
- showStatus(defaultStatus());
+ showOnlineStatus();
//debug('appcache swapped', e);
+
+ // Update offline resources in local storage and reload the page
+ map(function(res) {
+ showStatus('Updating');
+ appcache.remove(res[0]);
+ appcache.get(res[0]);
+ }, append(appresources, config.appresources()));
+ window.location.reload();
}, false);
applicationCache.addEventListener('cached', function(e) {
//debug('appcache cached', e);
+ showOnlineStatus();
+
+ // Install offline resources in local storage
map(function(res) {
- showStatus('Updating');
+ showStatus('Installing');
+ appcache.remove(res[0]);
appcache.get(res[0]);
- }, appresources);
- showStatus(defaultStatus());
+ }, append(appresources, config.appresources()));
}, false);
/**
@@ -214,11 +301,9 @@ window.addEventListener('online', function(e) {
/**
* Handle view transitions.
*/
-
-// Keep track of the current view url and uri
var viewurl = '';
var viewuri = '';
-var viewidx = '';
+var viewidx = 0;
var viewdiv;
/**
@@ -228,7 +313,7 @@ var apptransitions = {};
map(function(res) {
if (res.length > 1)
apptransitions[res[0]] = res[1];
-}, appresources);
+}, append(appresources, config.appresources()));
/**
* Return the transition that should be applied to a resource.
@@ -266,7 +351,9 @@ function mkviewdiv(cname) {
* Return the last visited location.
*/
function lastvisited() {
- return lstorage.getItem('ui.lastvisited');
+ if (username != lstorage.getItem('ui.lastvisit.user'))
+ return null;
+ return lstorage.getItem('ui.lastvisit.url');
}
/**
@@ -274,49 +361,22 @@ function lastvisited() {
*/
function showmenu(mdiv, view, appname) {
mdiv.innerHTML = ui.menubar(
- append(mklist(ui.menu('Home', '/', '_view', view == 'home'), ui.menu('Store', '/#view=store', '_view', view === 'store')),
+ append(mklist(ui.menu('menuhome', 'Home', '/', '_view', view == 'home'),
+ ui.menu('menustore', 'Store', '/#view=store&category=' + storecat + '&idx=' + storeidx, '_view', view === 'store')),
(isNil(appname) || appname == 'undefined')?
mklist() :
mklist(
- ui.menu('Stats', '/#view=stats&app=' + appname, '_view', view == 'stats'),
- ui.menu('Page', '/#view=page&app=' + appname, '_view', view == 'page'),
- ui.menu(config.logic, '/#view=graph&app=' + appname, '_view', view == 'graph'),
- ui.menu('<span class="greentext" style="font-weight: bold">Run!</span>', '/' + appname + '/', '_blank', false))),
+ ui.menu('menustats', 'Stats', '/#view=stats&app=' + appname, '_view', view == 'stats'),
+ ui.menu('menupage', 'Page', '/#view=page&app=' + appname, '_view', view == 'page'),
+ ui.menu('menulogic', config.logic(), '/#view=graph&app=' + appname, '_view', view == 'graph'),
+ ui.menu('menurun', '<span class="greentext" style="font-weight: bold">Run!</span>', '/' + appname + '/', '_blank', false))),
(isNil(appname) || appname == 'undefined')? mklist(
- hasauthcookie()? ui.menufunc('Sign out', 'logout();', false) : ui.menu('Sign in', '/login/', '_self', false),
- ui.menu('Account', '/#view=account', '_view', view == 'account')) :
+ hasauthcookie()? ui.menufunc('menusignout', 'Sign out', 'return logout();', false) : ui.menu('menusignin', 'Sign in', '/login/', '_self', false),
+ ui.menu('menuaccount', 'Account', '/#view=account', '_view', view == 'account')) :
mklist());
-}
-/**
- * Show a status message.
- */
-function showStatus(s) {
- var sdiv = $('status');
- if (isNil(sdiv))
- return s;
- sdiv.style.color = '#808080'
- sdiv.innerHTML = s;
- return s;
-}
-
-/**
- * Show an error message.
- */
-function showError(s) {
- var sdiv = $('status');
- if (isNil(sdiv))
- return s;
- sdiv.style.color = '#dd4b39'
- sdiv.innerHTML = s;
- return s;
-}
-
-/**
- * Return the default status message.
- */
-function defaultStatus() {
- return navigator.onLine? 'Online' : 'Offline';
+ if (fdiv.innerHTML == '')
+ fdiv.innerHTML = config.viewfoot();
}
/**
@@ -326,12 +386,10 @@ function getaccount() {
var doc = accounts.get();
// Stop now if we didn't get an account
- if (doc == null) {
- username = 'anonymous';
+ if (doc == null)
return false;
- }
- accountentry = car(elementsToValues(atom.readATOMEntry(mklist(doc))));
+ var accountentry = car(elementsToValues(atom.readATOMEntry(mklist(doc))));
username = cadr(assoc("'id", cdr(accountentry)));
return true;
}
@@ -343,13 +401,20 @@ function showview(url) {
//debug('showview', url);
// Save last visited location
- lstorage.setItem('ui.lastvisited', url);
+ lstorage.setItem('ui.lastvisit.user', username);
+ lstorage.setItem('ui.lastvisit.url', url);
// Determine the view to show
var params = ui.fragmentParams(url);
var view = isNil(params['view'])? 'home' : params['view'];;
var uri = '/' + view + '/';
- var idx = isNil(params['idx'])? '1' : params['idx'];
+ var idx = isNil(params['idx'])? 0 : parseInt(params['idx']);
+
+ // Track store category view
+ if (view == 'store') {
+ storecat = isNil(params['category'])? 'top' : params['category'];
+ storeidx = idx;
+ }
// Determine the transition to use
var vtransition = uri == viewuri? (idx >= viewidx? 'left' : 'right') : viewtransition(viewuri, uri);
@@ -424,7 +489,7 @@ function showview(url) {
// Track the current visible view
viewdiv = vdiv;
-
+
return true;
}
@@ -455,6 +520,7 @@ function updatelocation(url) {
window.onnavigate = function(url) {
//debug('onnavigate', url);
+ // Update the browser window location
updatelocation(url);
// Show the specified view
@@ -473,13 +539,13 @@ window.onloginredirect = function(e) {
/**
* Log the current user out.
*/
-function logout() {
+window.logout = function() {
// Clear session cookie and user-specific local storage entries
clearauthcookie();
- lstorage.removeItem('/r/EditWidget/accounts');
- lstorage.removeItem('/r/EditWidget/dashboards');
+ lstorage.removeItem('/r/Editor/accounts');
+ lstorage.removeItem('/r/Editor/dashboards');
document.location = '/login/';
- return true;
+ return false;
}
/**
@@ -523,7 +589,7 @@ document.body.onorientationchange = function(e) {
};
/**
- * Document load post processing.
+ * Initialize the document.
*/
function onload() {
//debug('onload', history.length);
@@ -542,8 +608,10 @@ function onload() {
}
// Show the last visited view
- if (ui.isMobile() && (document.referrer == null || document.referrer == '')) {
- //debug('show lastvisited');
+ if (ui.isMobile() && (document.referrer == null || document.referrer == '' ||
+ document.referrer.indexOf('//' + location.hostname + '/login/') != -1 ||
+ document.referrer.indexOf('//accounts.google.com/ServiceLogin') != -1 ||
+ document.referrer.indexOf('//www.facebook.com/login.php') != -1)) {
var lv = lastvisited();
var url = isNil(lv)? location.pathname : lv;
updatelocation(url);
@@ -559,6 +627,9 @@ function onload() {
return showview(url);
}
+onload();
+
+})();
</script>
<div id="footdiv" class="fsection">