vzlogger/htdocs/frontend/javascripts/init.js

106 lines
2.8 KiB
JavaScript
Raw Normal View History

2010-09-27 01:33:49 +02:00
/**
* Initialization and configuration of frontend
2010-09-27 01:33:49 +02:00
*
* @author Florian Ziegler <fz@f10-home.de>
* @author Justin Otherguy <justin@justinotherguy.org>
* @author Steffen Vogel <info@steffenvogel.de>
2011-04-07 00:01:41 +02:00
* @copyright Copyright (c) 2011, The volkszaehler.org project
2010-09-27 01:33:49 +02:00
* @package default
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
2011-03-11 00:13:23 +01:00
/**
* volkszaehler.org namespace
*
* holds all data, options and functions for the frontend
* we dont want to pollute the global namespace
*/
var vz = {
entities: new Array, // entity properties + data
middleware: [{ // default middleware
url: '../middleware.php',
public: [ ] // public entities
/* capabilities: { } */
}],
2010-10-30 10:42:08 +02:00
// web user interface
wui: {
2011-03-25 09:24:00 +01:00
dialogs: { },
timeout: null
2010-10-30 10:42:08 +02:00
},
2010-10-04 21:10:58 +02:00
2011-03-24 22:39:26 +01:00
// debugging and runtime information from middleware
capabilities: {
definitions: { } // definitions of entities & properties
},
// flot instance
plot: { },
// options loaded from cookies in options.js
options: { }
2010-09-28 18:17:45 +02:00
};
2011-03-11 00:13:23 +01:00
/**
* Executed on document loaded complete
* this is where it all starts...
*/
$(document).ready(function() {
2011-03-11 00:13:23 +01:00
// late binding
$(window).resize(function() {
vz.options.tuples = Math.round($('#flot').width() / 3);
$('#tuples').val(vz.options.tuples);
2011-03-11 00:13:23 +01:00
vz.wui.drawPlot();
});
2011-03-11 00:13:23 +01:00
window.onerror = function(errorMsg, url, lineNumber) {
vz.wui.dialogs.error('Javascript Runtime Error', errorMsg);
};
2010-11-07 23:08:08 +01:00
vz.entities.loadCookie(); // load uuids from cookie
vz.options.loadCookies(); // load options from cookie
vz.parseUrlParams(); // parse additional url params (new uuid etc..)
2010-12-10 22:36:10 +01:00
// initialize user interface
vz.wui.init();
vz.wui.initEvents();
2010-10-04 22:37:29 +02:00
// chaining ajax request with jquery deferred object
vz.capabilities.load().done(function() {
if (vz.capabilities.formats.contains('png')) {
$('#snapshot').show();
}
var queue = new Array;
vz.entities.each(function(entity) {
queue.push(entity.loadDetails());
}, true);
$.when.apply($, queue).done(function() {
if (vz.entities.length == 0) {
vz.wui.dialogs.init();
}
vz.entities.showTable();
vz.entities.loadData().done(vz.wui.drawPlot);
});
});
});