/** * Javascript functions for the frontend * * @author Florian Ziegler * @author Justin Otherguy * @author Steffen Vogel * @copyright Copyright (c) 2010, 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() { // 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]').button(); $('button[name=options-save]').click(vz.options.save); $('#permalink').click(function() { var uuids = []; var url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?from=' + vz.options.plot.xaxis.min + '&to=' + vz.options.plot.xaxis.max; vz.entities.each(function(entity, parent) { if (entity.active && entity.definition.model == 'Volkszaehler\\Model\\Channel') { uuids.push(entity.uuid); } }); uuids.unique().each(function(key, value) { url += '&uuid=' + value; }); window.location = url; }); $('button[name=entity-add]').click(this.dialogs.init); // bind plot actions $('#controls button').click(this.handleControls); $('#controls').buttonset(); // tuple resolution vz.options.tuples = Math.round($('#flot').width() / 4); $('#tuples').val(vz.options.tuples).change(function() { vz.options.tuples = $(this).val(); vz.entities.loadData().done(vz.wui.drawPlot); }); // backend address $('#backend-url') .val(vz.options.backendUrl) .change(function() { vz.options.backendUrl = $(this).val(); }); // auto refresh if (vz.options.refresh) { $('#refresh').attr('checked', true); var delta = vz.options.plot.xaxis.max - vz.options.plot.xaxis.min; this.timeout = window.setTimeout( this.refresh, (delta / 100 < 3000) ? 3000 : delta / 100 ); } $('#refresh').change(function() { vz.options.refresh = $(this).attr('checked'); if (vz.options.refresh) { vz.wui.timeout = window.setTimeout(vz.wui.refresh, 3000); } else { window.clearTimeout(this.timeout); } }); // 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(); // load public entities vz.load({ controller: 'entity', success: function(json) { if (json.entities.length > 0) { json.entities.each(function(index, entity) { $('#entity-subscribe-public select#public').append( $('