All Downloads are FREE. Search and download functionalities are using the official Maven repository.

client.otpa.js.Widgets.js Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
/* This program is free software: you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.
   
   This program 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 this program.  If not, see . 
 */

otp.namespace("otp.analyst");

/**
 * Widget class. Control the parameters of a request.
 * 
 * Require jQuery/jQueryUI.
 */
otp.analyst.ParamsWidget = otp.Class({

    /**
     * Constructor.
     * 
     * @param node
     *            The DOM container to contain the widget.
     * @param options
     *            Object containing the various options.
     * 
     */
    initialize : function(node, options) {
        this.options = $.extend({
            defaultRouterId : "",
            selectDateTime : true,
            defaultArriveBy : false,
            defaultDateTime : new Date(),
            dateFormat : "yy/mm/dd",
            selectModes : true,
            defaultModes : "TRANSIT,WALK",
            selectWalkParams : true,
            defaultMaxWalk : 1000,
            defaultWalkSpeed : 1.389,
            defaultBikeSpeed : 4.167,
            coordinateOrigin : null,
            selectMaxTime : false,
            defaultMaxTime : 3600,
            defaultPrecision : 100,
            selectDataType : true,
            defaultDataType : "TIME",
            refreshButton : false
        }, options);
        this.locale = otp.locale.analyst;
        this.parentNode = node;
        var thisRw = this;
        // Refresh callbacks list
        this.refreshCallbacks = $.Callbacks();
        // Origin marker
        if (this.options.map) {
            if (this.options.extend) {
                // Same origin or not
                var locationDiv = $("
"); node.append(locationDiv); this.locationCheckbox = $("").attr({ type : "checkbox" }).click(function() { thisRw.enableLocationMarker(this.checked); }); locationDiv.text(this.locale.differentOrigin); locationDiv.append(this.locationCheckbox); } else { thisRw.enableLocationMarker(true); } } // ArriveBy/Date/time picker if (this.options.selectDateTime) { var dateTimeDiv = $("
"); node.append(dateTimeDiv); // Arrive By this.arriveByInput = this._createSelect(this.locale.arriveDepart, this.options.extend, this.options.defaultArriveBy); dateTimeDiv.append(this.arriveByInput); // Date if (!this.options.extend) { this.dateInput = $("").attr({ size : 12, maxlength : 12, }).datepicker({ dateFormat : this.options.dateFormat }).datepicker("setDate", this.options.defaultDateTime); dateTimeDiv.append(this.dateInput); } // Hour:minutes (ev. delta) var hour = this.options.defaultDateTime.getHours(); var min = this.options.defaultDateTime.getMinutes(); this.timeInput = $("").attr({ size : 5, maxlength : 5, length : 5, value : this.options.extend ? "0:00" : (hour + ":" + (min < 10 ? "0" : "") + min) }); dateTimeDiv.append(this.timeInput); } // Mode selector + combo box if (this.options.selectModes) { var modesDiv = $("
"); node.append(modesDiv); modesDiv.text(this.locale.modesLabel); this.modesInput = this._createSelect(this.locale.modes, this.options.extend, this.options.defaultModes, this._modeChanged); modesDiv.append(this.modesInput); this.transitModesDiv = $("
"); this.transitModes = []; $.each(this.locale.transitModes, function(i, mode) { thisRw.transitModes[mode[0]] = true; var label = $('
"); this.maxWalkDiv.text(this.locale.walkLabel); node.append(this.maxWalkDiv); this.maxWalkInput = this._createSelect(this.locale.maxWalkDistance, this.options.extend, this.options.defaultMaxWalk); this.maxWalkDiv.append(this.maxWalkInput); this.walkSpeedInput = this._createSelect(this.locale.walkSpeed, this.options.extend, this.options.defaultWalkSpeed); this.maxWalkDiv.append(this.walkSpeedInput); // Bike this.maxBikeDiv = $("
"); this.maxBikeDiv.text(this.locale.bikeLabel); node.append(this.maxBikeDiv); this.bikeSpeedInput = this._createSelect(this.locale.bikeSpeed, this.options.extend, this.options.defaultBikeSpeed); this.maxBikeDiv.append(this.bikeSpeedInput); } // Max time if (this.options.selectMaxTime) { var maxTimeDiv = $("
"); node.append(maxTimeDiv); maxTimeDiv.text(this.locale.maxTimeLabel); this.maxTimeInput = this._createSelect(this.locale.maxTime, this.options.extend, this.options.defaultMaxTime); maxTimeDiv.append(this.maxTimeInput); } // Data type (time, boardings, max walk) if (this.options.selectDataType && !this.options.extend) { this.dataTypeDiv = $("
"); node.append(this.dataTypeDiv); this.dataTypeDiv.text(this.locale.dataTypeLabel); this.dataTypeInput = this._createSelect(this.locale.dataType, this.options.extend, this.options.defaultDataType); this.dataTypeDiv.append(this.dataTypeInput); } // Refresh button if (this.options.refreshButton) { this.refreshButton = $("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy