/* Copyright (C) 2018 - 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. This library 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 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** @namespace GnuBoat JavaScript namespace */ var GnuBoat = GnuBoat || {}; /** @namespace GnuBoat Webserver JavaScript namespace */ GnuBoat.Webserver = GnuBoat.Webserver || {}; GnuBoat.Webserver.initialize = function() { GnuBoat.Webserver.private.mapSetup(); $("#loginForm").validate({ rules: { loginUsername: { required: true }, loginPassword: { required: true } }, submitHandler: function(form){ GnuBoat.Webserver.login(form); } }); $("#login").hide(); $("#myWaters").hide(); $("#linkMyGnuboat").click(function(){ $("#mapViewport").hide(); GnuBoat.Webserver.loginCheck(); }); $("#linkMap").click(function(){ $("#mapViewport").show(); }); } /** * @brief Sets the webservice base url, used by any other functions */ GnuBoat.Webserver.setServer = function(baseUrl) { if(baseUrl.slice(-1) != "/") baseUrl += "/"; GnuBoat.Webserver.private.serverBaseUrl = baseUrl; } GnuBoat.Webserver.private = { loggedin: false, map: null, mapSetup: function () { GnuBoat.Webserver.private.map = L.map('mapViewport').setView([48.43, 10.04], 17); var layer_openstreetmap = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap, OpenSeaMap, GNUBoat contributors'} ).addTo(GnuBoat.Webserver.private.map); var layer_openseamap = L.tileLayer( 'http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', {attribute: '© OpenSeaMap contributors'} ).addTo(GnuBoat.Webserver.private.map); // add GNUBoat layers var layer_gnuboat_accuracy_low = L.tileLayer( './tiles/gnuboat_10_100/{z}/{x}/{y}.png', {tms: true, opacity: 0.5, zIndex: 98, attribute: '© GNUBoat contributors'} ); var layer_gnuboat_accuracy_high = L.tileLayer( './tiles/gnuboat_100_100/{z}/{x}/{y}.png', {tms: true, opacity: 0.5, zIndex: 98, attribute: '© GNUBoat contributors'} ).addTo(GnuBoat.Webserver.private.map); // add layer control var baselayers = { "Map": layer_openstreetmap, }; // overlays var overlays = {"Seamarks": layer_openseamap, "GNUBoat Low Accuracy": layer_gnuboat_accuracy_low, "GNUBoat High Accuracy": layer_gnuboat_accuracy_high, }; GnuBoat.Webserver.private.mapControl = L.control.layers( baselayers, overlays, {hideSingleBase: true, sortLayers: true, } ).addTo(GnuBoat.Webserver.private.map); // add scale L.control.scale().addTo(GnuBoat.Webserver.private.map); } }; GnuBoat.Webserver.login = function(form) { Cookies.set('username', $("#loginUsername").val()); Cookies.set('password', $("#loginPassword").val()); GnuBoat.Webserver.private.loggedin = false; // getting my waters $.ajax({ dataType: "json", url: GnuBoat.Webserver.private.serverBaseUrl +'waters?manager='+ encodeURIComponent(Cookies.get('username')), }).done(function(data) { GnuBoat.Webserver.private.loggedin = true; GnuBoat.Webserver.loginCheck(); $("#myWatersDiv").empty(); if(data.length < 1){ $("

No Waters found!

").appendTo("#myWatersDiv"); } else{ $('').appendTo("#myWatersDiv"); data.forEach(function(value, index){ $("").appendTo("#myWatersSelect"); }) } $("#myWaters").show(); }).fail(function() { alert('request failed'); }); }; GnuBoat.Webserver.loginCheck = function() { console.log([Cookies.get('username'), Cookies.get('username') == undefined, Cookies.get('password'), Cookies.get('password') == undefined, GnuBoat.Webserver.private.loggedin]); if(Cookies.get('username') == undefined || Cookies.get('password') == undefined || !GnuBoat.Webserver.private.loggedin){ $("#login").show(); return; } $("#login").hide(); };