From 73713d477bba92043dfa47c077c444828822a992 Mon Sep 17 00:00:00 2001 From: Franzz Date: Mon, 13 Apr 2020 22:50:37 +0200 Subject: [PATCH] Admin page: delete feed / project --- inc/feed.php | 13 ++++++- inc/project.php | 11 ++++++ inc/spot.php | 24 +++++++++++-- index.php | 7 ++-- languages/en.lang | 1 + languages/fr.lang | 1 + masks/admin.html | 82 +++++++++++++++++++++++++++--------------- script/spot.js | 12 +++++++ style/_fa.scss | 3 ++ style/_mask_admin.scss | 16 +++++++++ style/spot.css | 2 +- style/spot.css.map | 2 +- 12 files changed, 138 insertions(+), 36 deletions(-) diff --git a/inc/feed.php b/inc/feed.php index 2aeb1a9..4e328bf 100644 --- a/inc/feed.php +++ b/inc/feed.php @@ -194,4 +194,15 @@ class Feed extends PhpObject { return $bResult; } -} + + public function delete() { + $sDesc = ''; + if($this->getFeedId() > 0) { + $bSuccess = $this->oDb->deleteRow(self::FEED_TABLE, $this->getFeedId()); + if(!$bSuccess) $sDesc = $this->oDb->getLastError(); + } + else $sDesc = 'Error while setting project: no Feed ID'; + + return $sDesc; + } +} \ No newline at end of file diff --git a/inc/project.php b/inc/project.php index e251d86..60771bb 100644 --- a/inc/project.php +++ b/inc/project.php @@ -176,4 +176,15 @@ class Project extends PhpObject { return $bResult; } + + public function delete() { + $sDesc = ''; + if($this->getProjectId() > 0) { + $bSuccess = $this->oDb->deleteRow(self::PROJ_TABLE, $this->getProjectId()); + if(!$bSuccess) $sDesc = $this->oDb->getLastError(); + } + else $sDesc = 'Error while setting project: no project ID'; + + return $sDesc; + } } \ No newline at end of file diff --git a/inc/spot.php b/inc/spot.php index dba3e9f..ee54e71 100755 --- a/inc/spot.php +++ b/inc/spot.php @@ -442,11 +442,12 @@ class Spot extends Main public function getAdminSettings() { $oFeed = new Feed($this->oDb); - return self::getJsonResult(true, '', array( + $asData = array( 'project' => $this->oProject->getProjects(), 'feed' => $oFeed->getFeeds(), 'spot' => $oFeed->getSpots() - )); + ); + return self::getJsonResult(true, '', $asData); } public function setAdminSettings($sType, $iId, $sField, $sValue) { @@ -497,6 +498,25 @@ class Spot extends Main return self::getJsonResult($bSuccess, $sDesc, array($sType=>array($asResult))); } + public function delAdminSettings($sType, $iId) { + $bSuccess = false; + $sDesc = ''; + + switch($sType) { + case 'project': + $oProject = new Project($this->oDb, $iId); + $sDesc = $oProject->delete(); + break; + case 'feed': + $oFeed = new Feed($this->oDb, $iId); + $sDesc = $oFeed->delete(); + break; + } + $bSuccess = ($sDesc==''); + + return self::getJsonResult($bSuccess, $sDesc, array($sType=>array(array('id'=>$iId, 'del'=>$bSuccess)))); + } + public function createProject() { $oProject = new Project($this->oDb); $iNewProjectId = $oProject->createProjectId(); diff --git a/index.php b/index.php index bbe8055..fc8a5de 100755 --- a/index.php +++ b/index.php @@ -57,14 +57,17 @@ if($sAction!='') case 'sync_pics': $sResult = $oSpot->syncPics(); break; + case 'admin_new': + $sResult = $oSpot->createProject(); + break; case 'admin_get': $sResult = $oSpot->getAdminSettings(); break; case 'admin_set': $sResult = $oSpot->setAdminSettings($sType, $iId, $sField, $oValue); break; - case 'admin_new': - $sResult = $oSpot->createProject(); + case 'admin_del': + $sResult = $oSpot->delAdminSettings($sType, $iId); break; case 'build_geojson': $sResult = $oSpot->convertGpxToGeojson($sName); diff --git a/languages/en.lang b/languages/en.lang index 01b61c6..b41c7ca 100644 --- a/languages/en.lang +++ b/languages/en.lang @@ -59,6 +59,7 @@ status = Status last_update = Last Update ref_spot_id = Ref. Spot ID model = Model +delete = Delete date_time = $0 at $1 time_zone = Time zone diff --git a/languages/fr.lang b/languages/fr.lang index 9728007..0a9d645 100644 --- a/languages/fr.lang +++ b/languages/fr.lang @@ -59,6 +59,7 @@ status = Statut last_update = Dernière maj ref_spot_id = ID Spot ref. model = Modèle +delete = Supprimer date_time = $0 à $1 time_zone = Fuseau horaire diff --git a/masks/admin.html b/masks/admin.html index 5c90eb7..04d30dd 100644 --- a/masks/admin.html +++ b/masks/admin.html @@ -11,6 +11,7 @@ [#]lang:start[#] [#]lang:end[#] [#]lang:time_zone[#] + [#]lang:delete[#] @@ -29,6 +30,7 @@ [#]lang:name[#] [#]lang:status[#] [#]lang:last_update[#] + [#]lang:delete[#] @@ -53,11 +55,12 @@ \ No newline at end of file diff --git a/script/spot.js b/script/spot.js index 144cb72..5e769b2 100755 --- a/script/spot.js +++ b/script/spot.js @@ -266,6 +266,18 @@ $.prototype.addInput = function(sType, sName, sValue, aoEvents) return $(this).append($Input); }; +$.prototype.addButton = function(sIcon, sText, sName, fOnClick, sClass) +{ + sText = sText || ''; + sClass = sClass || ''; + var $Btn = $('