From 1d1b5940442782d78f796d8608e63328e2e8783b Mon Sep 17 00:00:00 2001 From: arno Date: Wed, 11 Aug 2010 22:54:21 +0200 Subject: [PATCH] redirection after path creation is decided by server (php), not guessed by client (js) --- application/controllers/GeomController.php | 2 +- application/controllers/PathController.php | 10 ++++++---- application/controllers/helpers/SyjApi.php | 5 +++++ public/js/list.js | 7 ++++++- public/js/syj.js | 6 ++---- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/application/controllers/GeomController.php b/application/controllers/GeomController.php index 70acf76..5e0a034 100644 --- a/application/controllers/GeomController.php +++ b/application/controllers/GeomController.php @@ -30,6 +30,6 @@ class GeomController extends Zend_Controller_Action $data['creator'] = (string)$path->creator->pseudo; } - $api->setCheckIfNoneMatch(true)->setBody(json_encode($data)); + $api->setCheckIfNoneMatch(true)->setBodyJson($data); } } diff --git a/application/controllers/PathController.php b/application/controllers/PathController.php index aa41866..b521a26 100644 --- a/application/controllers/PathController.php +++ b/application/controllers/PathController.php @@ -15,12 +15,16 @@ class PathController extends Zend_Controller_Action $path->creator = $user; $path->creatorIp = $this->getRequest()->getClientIp(true); - return $this->save($path, $formData); + $this->save($path, $formData); + $data = array('redirect' => "idx/" . (string)$path->id); + $this->_helper->SyjApi->setCode(201)->setBodyJson($data); } public function updateAction() { $formData = $this->_helper->SyjPostData->getPostData('Syj_Form_Geom'); - return $this->save($this->getPath(), $formData); + $path = $this->getPath(); + $this->save($path, $formData); + $this->_helper->SyjApi->setCode(204); } public function deleteAction() { @@ -84,8 +88,6 @@ class PathController extends Zend_Controller_Action throw $e; } } - - $this->_helper->SyjApi->setBody($path->id); } } diff --git a/application/controllers/helpers/SyjApi.php b/application/controllers/helpers/SyjApi.php index 86ea00e..37b010a 100644 --- a/application/controllers/helpers/SyjApi.php +++ b/application/controllers/helpers/SyjApi.php @@ -27,6 +27,11 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ $this->_contentType = $contentType; } + public function setBodyJson($data) { + $this->setBody(json_encode($data)) + ->setContentType('application/json'); + } + public function setBody($body) { $this->_body = (string)$body; return $this; diff --git a/public/js/list.js b/public/js/list.js index 240ffcf..62f7b06 100644 --- a/public/js/list.js +++ b/public/js/list.js @@ -37,12 +37,16 @@ function item(elt) { } item.prototype = { deleteSuccess: function() { + this.deactivate(); + $("message").setMessage(SyjStrings.deleteSuccess, "success"); + }, + + deactivate: function() { this.elt.down('.title').update(); this.elt.down('.geom').update().setStyle({backgroundColor: 'gray'}); this.deleteHandler.stop(); this.elt.on('click', 'a', function(evt) { evt.stop(); }); this.elt.select('a').invoke('setStyle', {textDecoration: 'line-through'}); - $("message").setMessage(SyjStrings.deleteSuccess, "success"); }, deleteFailure: function(transport) { @@ -63,6 +67,7 @@ item.prototype = { message = SyjStrings.requestError; break; case 410: + this.deactivate(); message = SyjStrings.gonePathError; break; case 500: diff --git a/public/js/syj.js b/public/js/syj.js index 5400ff3..4b7f01d 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -225,7 +225,6 @@ 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; @@ -285,7 +284,6 @@ 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); @@ -396,8 +394,8 @@ var SYJView = { }, saveSuccess: function(transport) { - if (!this.hasInitialGeom) { // we have created a new path, change location - location = "idx/" + transport.responseText; + if (transport.responseJSON && (typeof transport.responseJSON.redirect === "string")) { + location = transport.responseJSON.redirect; return; } -- 2.39.2