From: arno Date: Tue, 10 Aug 2010 19:28:06 +0000 (+0200) Subject: separate route to create a new path, and to update an existing one X-Git-Tag: v0.2~70 X-Git-Url: https://dev.renevier.net/?p=syj.git;a=commitdiff_plain;h=3ff82e2d9fa289beba4e965b82772cf83f905b2f separate route to create a new path, and to update an existing one --- diff --git a/application/configs/application.ini b/application/configs/application.ini index 393684c..80b2420 100644 --- a/application/configs/application.ini +++ b/application/configs/application.ini @@ -45,6 +45,16 @@ resources.router.routes.idx.defaults.action = "index" resources.router.routes.root.type = "Zend_Controller_Router_Route_Static" resources.router.routes.root.route = "/" resources.router.routes.root.defaults.controller = "idx" +; path/ +resources.router.routes.path.route = "path/" +resources.router.routes.path.defaults.controller = "path" +resources.router.routes.path.defaults.action = "index" + +; path/xxx/update +resources.router.routes.path_update.route = "path/:idx/update" +resources.router.routes.path_update.defaults.controller = "path" +resources.router.routes.path_update.defaults.action = "update" + ; login/ resources.router.routes.login.route = "login/" resources.router.routes.login.defaults.controller = "login" diff --git a/application/controllers/IdxController.php b/application/controllers/IdxController.php index caad6a1..0b53b2a 100644 --- a/application/controllers/IdxController.php +++ b/application/controllers/IdxController.php @@ -20,7 +20,7 @@ class IdxController extends Zend_Controller_Action public function indexAction() { $url = $this->getRequest()->getUserParam('url'); - $geomform = new Syj_Form_Geom(array('name' => 'geomform', 'action' => 'path')); + $geomform = new Syj_Form_Geom(array('name' => 'geomform')); $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login')); $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user')); $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd')); @@ -35,13 +35,14 @@ class IdxController extends Zend_Controller_Action throw new Syj_Exception_NotFound('Not Found', 404); } } + $geomform->setAction('path/' . (string)$path->id . '/update'); $title = $path->displayTitle; $this->view->path = $path; $geomform->geom_title->setValue($path->title); $geomform->geom_data->setValue((string)$path->geom); - $geomform->geom_id->setValue((string)$path->id); $loginform->login_geom_id->setValue((string)$path->id); } else { + $geomform->setAction('path'); $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true))); $this->view->headScript()->prependScript((string) $extent); $title = "Show your journey"; @@ -83,7 +84,7 @@ class IdxController extends Zend_Controller_Action $this->view->jslocales = array( 'saveSuccess' => __("save took place successfully"), 'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"), - 'UnreferencedError' => __("path did not exist in the server. May be it has been already deleted"), + 'gonePathError' => __("route has been deleted from the server."), 'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"), 'notReachedError' => __("server could not be reached"), 'serverError' => __("there was a server error"), diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index 6ef9529..c3c085a 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -5,33 +5,33 @@ class PathController extends Zend_Controller_Action { public function indexAction() { - $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); - $decoder = new gisconverter\WKT(); - - try { - $geom = $decoder->geomFromText($formData["geom_data"]); - } catch (gisconverter\CustomException $e) { - throw new Syj_Exception_Request(); - } - - if ($geom::name != "LineString") { - throw new Syj_Exception_Request(); - } + return $this->save(new Syj_Model_Path()); + } + public function updateAction() { + $idx = $this->getRequest()->getUserParam('idx'); $path = new Syj_Model_Path(); $pathMapper = new Syj_Model_PathMapper(); - if (isset ($formData["geom_id"]) and $formData["geom_id"]) { - if (!$pathMapper->find($formData["geom_id"], $path)) { - throw new Syj_Exception_Request("unreferenced"); + if (!$pathMapper->find($idx, $path)) { + if ($pathMapper->hasexisted($idx)) { + throw new Syj_Exception_NotFound('Gone', 410); + } else { + throw new Syj_Exception_NotFound('Not Found', 404); } } - $path->geom = $geom; + return $this->save($path); + } + + public function save(Syj_Model_Path $path) { + $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); + /* authorization check */ $user = $this->_helper->SyjSession->user(); if (!$user and !$formData["geom_accept"]) { throw new Syj_Exception_Request(); } + /* setting creator property */ if ($path->getId()) { if (!$path->isCreator($user)) { throw new Syj_Exception_Request(); @@ -39,11 +39,28 @@ class PathController extends Zend_Controller_Action } else { $path->creator = $user; } + $path->creatorIp = $this->getRequest()->getClientIp(true); + /* setting geom property */ + $decoder = new gisconverter\WKT(); + try { + $geom = $decoder->geomFromText($formData["geom_data"]); + } catch (gisconverter\CustomException $e) { + throw new Syj_Exception_Request(); + } + if ($geom::name != "LineString") { + throw new Syj_Exception_Request(); + } + $path->geom = $geom; + + /* setting title property */ if (isset($formData["geom_title"])) { $path->title = $formData["geom_title"]; } - $path->creatorIp = $this->getRequest()->getClientIp(true); + + + /* now, saving !*/ + $pathMapper = new Syj_Model_PathMapper(); try { $pathMapper->save ($path); } catch(Zend_Db_Statement_Exception $e) { @@ -61,4 +78,5 @@ class PathController extends Zend_Controller_Action $this->_helper->SyjApi->setBody($path->id); } + } diff --git a/application/forms/Geom.php b/application/forms/Geom.php index 2ae949b..b52e071 100644 --- a/application/forms/Geom.php +++ b/application/forms/Geom.php @@ -12,7 +12,6 @@ class Syj_Form_Geom extends Zend_Form ); public function init() { - $id = array('Hidden', 'geom_id'); $data = array('Hidden', 'geom_data', array('required' => true)); $title = array('Text', 'geom_title', array( @@ -33,7 +32,7 @@ class Syj_Form_Geom extends Zend_Form $submit = array('Submit', 'geom_submit', array('label' => __("save"))); - $this->addElements(array($id, $data, $title, $touaccept, $submit)); + $this->addElements(array($data, $title, $touaccept, $submit)); $decorator = $this->geom_accept->getDecorator('Zend_Form_Decorator_Label'); $decorator->setOption('escape', false); diff --git a/public/js/syj.js b/public/js/syj.js index bb8ce11..f2ae9e1 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -225,6 +225,7 @@ var SYJView = { map: null, wkt: new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }), needsFormResubmit: false, + hasInitialGeom: false, init: function() { var externalGraphic, baseURL, baseLayer, layerOptions, extent, hidemessenger; @@ -284,6 +285,7 @@ var SYJView = { // XXX: ie has not guessed height of map main div yet during map // initialisation. Now, it will read it correctly. this.map.updateSize(); + this.hasInitialGeom = true; } else { extent = new OpenLayers.Bounds(gMaxExtent.minlon, gMaxExtent.minlat, gMaxExtent.maxlon, gMaxExtent.maxlat) .transform(WGS84, Mercator); @@ -394,12 +396,12 @@ var SYJView = { }, saveSuccess: function(transport) { - if (!$("geom_id").value) { + if (!this.hasInitialGeom) { // we have created a new path, change location location = "idx/" + transport.responseText; return; } - this.messenger.setMessage(SyjStrings.saveSuccess, "success"); + this.messenger.setMessage(SyjStrings.saveSuccess, "success"); SyjSaveUI.hide(); SyjEditUI.show(); document.title = $('geom_title').value; @@ -417,13 +419,9 @@ var SYJView = { break; case 400: case 404: - case 410: message = SyjStrings.requestError; // default message if (transport.responseJSON) { switch (transport.responseJSON.message) { - case "unreferenced": - message = SyjStrings.unreferencedError; - break; case "uniquepath": message = SyjStrings.uniquePathError; break; @@ -432,6 +430,9 @@ var SYJView = { } } break; + case 410: + message = SyjStrings.gonePathError; + break; case 500: message = SyjStrings.serverError; this.needsFormResubmit = true;