]> dev.renevier.net Git - syj.git/commitdiff
redirection after path creation is decided by server (php), not guessed by client...
authorarno <arno@renevier.net>
Wed, 11 Aug 2010 20:54:21 +0000 (22:54 +0200)
committerarno <arno@renevier.net>
Fri, 13 Aug 2010 11:55:04 +0000 (13:55 +0200)
application/controllers/GeomController.php
application/controllers/PathController.php
application/controllers/helpers/SyjApi.php
public/js/list.js
public/js/syj.js

index 70acf763e073aa8984d42561c83f0093175eb061..5e0a0340ea887ef1ba6af94b22816446d44aa7ca 100644 (file)
@@ -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);
     }
 }
index aa41866679103703bb66909032302ecd59fd645d..b521a2688f9f6f86d8c378e5098d8de57664d761 100644 (file)
@@ -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);
     }
 
 }
index 86ea00e3ff1cdc6fa6355843e81b5d164bddc496..37b010afcc95146b64f897fc53de3183a79136e4 100644 (file)
@@ -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;
index 240ffcf66b0d72260a90fc61f387eab9073d8aee..62f7b068d82c186e5e3e41dc5bf9a01177fb5393 100644 (file)
@@ -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:
index 5400ff3afcd7b4fd20516aef480a178748c3d2f8..4b7f01d9a39dda1f010856080f130cc806577a0f 100644 (file)
@@ -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;
       }