From cbf219539b6202cc485b9580977ba4459393ca68 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Fri, 14 Apr 2017 23:30:07 +0200
Subject: [locationinfo] Remove more dead code, refactor javascript,
... and fix a few bugs I introduced
---
modules-available/locationinfo/page.inc.php | 47 +++----
.../locationinfo/templates/location-info.html | 150 +++++++++------------
2 files changed, 80 insertions(+), 117 deletions(-)
(limited to 'modules-available/locationinfo')
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 2408a491..d5f98cce 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -23,14 +23,17 @@ class Page_LocationInfo extends Page
$this->updateOpeningTimeEasy();
} elseif ($this->action === 'updateConfig') {
$this->updateLocationConfig();
- } elseif ($this->action === 'updateServer') {
- $this->updateServer();
} elseif ($this->action === 'deleteServer') {
$this->deleteServer();
} elseif ($this->action === 'checkConnection') {
- $this->checkConnection();
+ $this->checkConnection(Request::post('serverid', 0, 'int'));
} elseif ($this->action === 'updateServerSettings') {
$this->updateServerSettings();
+ } elseif (Request::isPost()) {
+ Messages::addWarning('main.invalid-action', $this->action);
+ }
+ if (Request::isPost()) {
+ Util::redirect('?do=locationinfo');
}
}
@@ -42,36 +45,16 @@ class Page_LocationInfo extends Page
$this->getInfoScreenTable();
}
- /**
- * Updates the server in the db.
- */
- private function updateServer()
- {
- $id = Request::post('id', 0, 'int');
- if ($id == 0) {
- Database::exec("INSERT INTO `setting_location_info` (servername, serverurl, servertype) VALUES (:name, :url, :type)",
- array('name' => Request::post('name', '', 'string'),
- 'url' => Request::post('url', '', 'string'),
- 'type' => Request::post('type', '', 'string')));
- } else {
- Database::exec("UPDATE setting_location_info SET servername = :name, serverurl = :url, servertype = :type
- WHERE serverid = :id", array(
- 'id' => $id,
- 'name' => Request::post('name', '', 'string'),
- 'url' => Request::post('url', '', 'string'),
- 'type' => Request::post('type', '', 'string')
- ));
- }
-
- $this->checkConnection();
- }
-
/**
* Deletes the server from the db.
*/
private function deleteServer()
{
- $id = Request::post('id', 0, 'int');
+ $id = Request::post('serverid', false, 'int');
+ if ($id === false) {
+ Messages::addError('server-id-missing');
+ return;
+ }
Database::exec("DELETE FROM `setting_location_info` WHERE serverid=:id", array('id' => $id));
}
@@ -141,7 +124,6 @@ class Page_LocationInfo extends Page
$counter++;
}
$params = array(
- 'id' => $serverid,
'name' => $servername,
'url' => $serverurl,
'type' => $servertype,
@@ -152,6 +134,7 @@ class Page_LocationInfo extends Page
VALUES (:name, :url, :type, :credentials)', $params);
$this->checkConnection(Database::lastInsertId());
} else {
+ $params['id'] = $serverid;
Database::exec('UPDATE `setting_location_info`
SET servername = :name, serverurl = :url, servertype = :type, credentials = :credentials
WHERE serverid = :id', $params);
@@ -268,13 +251,13 @@ class Page_LocationInfo extends Page
2 => array("Sunday"),
);
foreach ($blocks as $idx => $days) {
- if (!empty($openingtime[$idx]) && !empty($closingtime[$idx])) {
+ //if (!empty($openingtime[$idx]) && !empty($closingtime[$idx])) {
$result[] = array(
'days' => $days,
'openingtime' => $openingtime[$idx],
'closingtime' => $closingtime[$idx],
);
- }
+ //}
}
Database::exec("INSERT INTO `location_info` (locationid, openingtime)
@@ -577,7 +560,7 @@ class Page_LocationInfo extends Page
{
$row = Database::queryFirst("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $id));
if ($row !== false) {
- $openingtimes = json_decode($dbdata['openingtime'], true);
+ $openingtimes = json_decode($row['openingtime'], true);
}
if (!is_array($openingtimes)) {
$openingtimes = array();
diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html
index 321ca83e..bd3ea077 100644
--- a/modules-available/locationinfo/templates/location-info.html
+++ b/modules-available/locationinfo/templates/location-info.html
@@ -1,71 +1,56 @@
{{lang_mainHeader}}
-
{{lang_serverTable}}
-
-
+
+
+ {{lang_serverType}} |
+ {{lang_locationName}} |
+ {{lang_serverUrl}} |
+ |
+ |
+
+ {{#serverlist}}
+
- {{/serverlist}}
-
-
-
-
+
+ {{/serverlist}}
+
+
+
-
-
-
{{lang_buildingTable}}
@@ -94,7 +79,7 @@
+ onclick="loadLocationConfigModal({{locationid}}, '{{locationname}}');">
|
@@ -144,6 +129,26 @@
});
});
+ /**
+ * Confirm deleting a server.
+ */
+ $('.server-delete').click(function(ev) {
+ var del = confirm("{{lang_deleteConfirmation}}");
+ if (!del) ev.preventDefault();
+ });
+
+ /**
+ * Animate refresh icon while page is loading
+ */
+ $('.server-check').click(function() {
+ $(this).find('.glyphicon').addClass('slx-rotation');
+ });
+
+ $('button[data-server-edit]').click(function() {
+ var id = $(this).data('server-edit');
+ loadServerSettingsModal(id);
+ });
+
});
/**
@@ -163,11 +168,10 @@
* Loads the settings modal of a server.
*
* @param serverid The id of the server.
- * @param servername The name of the server.
*/
- function loadSettingsModal(serverid, servername) {
+ function loadServerSettingsModal(serverid) {
$('#myModalHeader').text("{{lang_locationSettings}}").css("font-weight", "Bold");
- $('#myModalSubmitButton').attr("Form", "settingsForm");
+ $('#myModalSubmitButton').attr("form", "settingsForm");
$('#myModal .modal-dialog').css('width', '');
$('#myModal').modal('show');
$('#myModalBody').load("?do=locationinfo&action=serverSettings&id=" + serverid);
@@ -192,9 +196,9 @@
* @param locationId The id of the location
* @param locationName the name of the location
*/
- function loadConfigModal(locationId, locationName) {
+ function loadLocationConfigModal(locationId, locationName) {
$('#myModalHeader').text("[" + locationId + "] " + locationName).css("font-weight", "Bold");
- $('#myModalSubmitButton').attr("Form", "configForm");
+ $('#myModalSubmitButton').attr("form", "configForm");
$('#myModal .modal-dialog').css('width', '90%');
$('#myModal').modal('show');
$('#myModalBody').load("?do=locationinfo&action=config&id=" + locationId);
@@ -202,34 +206,10 @@
// ########### Server Table ###########
- /**
- * Deletes a server.
- *
- * @param id The serverid
- */
- function deleteButtonClick(id) {
- var del = confirm("{{lang_deleteConfirmation}}");
- if (del == true) {
- $('#serverFormAction-' + id).val("deleteServer");
- $('#serverForm-' + id).submit();
- }
- }
-
- /**
- * Calls the checkConnection php function to check a server connection.
- *
- * @param id The id of the server.
- */
- function refreshButtonClick(id) {
- $('#refresh-btn-animate-' + id).addClass('slx-rotation');
- $('#serverFormAction-' + id).val("checkConnection");
- $('#submit-serverForm-' + id).trigger("click");
- }
-
/**
* Loads a new / empty server settings modal.
*/
function addServer() {
- loadSettingsModal(0, '');
+ loadServerSettingsModal(0);
}
//-->
--
cgit v1.2.3-55-g7522