/** * Javascript functions for the frontend * * @author Florian Ziegler * @author Justin Otherguy * @author Steffen Vogel * @copyright Copyright (c) 2011, The volkszaehler.org project * @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 . */ /** * Initialize the WUI (Web User Interface) */ vz.wui.init = function() { vz.options.tuples = Math.round($('#flot').width() / 3); // initialize dropdown accordion $('#accordion h3').click(function() { $(this).next().toggle('fast'); return false; }).next().hide(); $('#entity-list').show(); // open entity list by default // buttons $('button, input[type=button],[type=image],[type=submit]').button(); $('button[name=options-save]').click(vz.options.saveCookies); $('button[name=entity-add]').click(this.dialogs.init); $('#export select').change(function(event) { switch ($(this).val()) { case 'permalink': window.location = vz.wui.getPermalink(); break; case 'png': case 'csv': case 'xml': window.location = vz.wui.getLink($(this).val()); break; } $('#export option[value=default]').attr('selected', true); }); // bind plot actions $('#controls button').click(this.handleControls); $('#controls').buttonset(); // auto refresh if (vz.options.refresh) { $('#refresh').attr('checked', true); vz.wui.setTimeout(); } $('#refresh').change(function() { if (vz.options.refresh = $(this).attr('checked')) { vz.wui.refresh(); // refresh once vz.wui.setTimeout(); } else { vz.wui.clearTimeout(); } }); // plot rendering $('#render-lines').attr('checked', (vz.options.render == 'lines')); $('#render-points').attr('checked', (vz.options.render == 'points')); $('input[name=render][type=radio]').change(function() { if ($(this).attr('checked')) { vz.options.render = $(this).val(); vz.wui.drawPlot(); } }); }; /** * Initialize dialogs */ vz.wui.dialogs.init = function() { // initialize dialogs $('#entity-add.dialog').dialog({ title: 'Kanal hinzufügen', width: 530, resizable: false }); $('#entity-add.dialog > div').tabs({ show: function(event, ui) { // lazy loading public entities if (ui.index != 1) { return; // abort, we are not in public tab } vz.load({ controller: 'entity', success: function(json) { var public = new Array; json.entities.each(function(index, json) { public.push(new Entity(json)); }); public.sort(Entity.compare); vz.middleware[0].public = public; $('#entity-public-entity').empty(); public.each(function(index, entity) { $('#entity-public-entity').append( $('