]> dev.renevier.net Git - syj.git/commitdiff
separate route to create a new path, and to update an existing one
authorarno <arno@renevier.net>
Tue, 10 Aug 2010 19:28:06 +0000 (21:28 +0200)
committerarno <arno@renevier.net>
Fri, 13 Aug 2010 11:55:04 +0000 (13:55 +0200)
application/configs/application.ini
application/controllers/IdxController.php
application/controllers/PathController.php
application/forms/Geom.php
public/js/syj.js

index 393684cb918e224e48ceabe91975d065f0ad0763..80b24205b389f17d0e58260f8b83f0890e04ba9b 100644 (file)
@@ -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"
 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"
 ; login/
 resources.router.routes.login.route = "login/"
 resources.router.routes.login.defaults.controller = "login"
index caad6a1595bb51f09562d3e5698640973a013f69..0b53b2a6fd22d32db56dc274fe83aec51bd5d49b 100644 (file)
@@ -20,7 +20,7 @@ class IdxController extends Zend_Controller_Action
     public function indexAction() {
         $url = $this->getRequest()->getUserParam('url');
 
     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'));
         $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);
                 }
             }
                     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);
             $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 {
             $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";
             $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"),
         $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"),
             '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"),
index 6ef95292baf813d54c7a3a41a0dff0f032148d29..c3c085a8695ff1eddbed1874edea580e8b9644ed 100644 (file)
@@ -5,33 +5,33 @@
 class PathController extends Zend_Controller_Action
 {
     public function indexAction() {
 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();
         $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();
         }
 
         $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();
         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;
         }
         } 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"];
         }
         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) {
         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);
     }
 
         $this->_helper->SyjApi->setBody($path->id);
     }
+
 }
 }
index 2ae949b2606217939dcc7f0d0ce85eb8c7688efe..b52e0719c3e6f98c7e57c0904124e06ec05840c2 100644 (file)
@@ -12,7 +12,6 @@ class Syj_Form_Geom extends Zend_Form
                             );
 
     public function init() {
                             );
 
     public function init() {
-        $id = array('Hidden', 'geom_id');
         $data = array('Hidden', 'geom_data', array('required' => true));
 
         $title = array('Text', 'geom_title', array(
         $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")));
 
 
         $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);
 
         $decorator = $this->geom_accept->getDecorator('Zend_Form_Decorator_Label');
         $decorator->setOption('escape', false);
index bb8ce117dab0e65263eff9496b0b0df920a71cc8..f2ae9e19125230221488fe2c8eb6654a50550533 100644 (file)
@@ -225,6 +225,7 @@ var SYJView = {
     map: null,
     wkt: new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
     needsFormResubmit: false,
     map: null,
     wkt: new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
     needsFormResubmit: false,
+    hasInitialGeom: false,
 
     init: function() {
         var externalGraphic, baseURL, baseLayer, layerOptions, extent, hidemessenger;
 
     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();
             // 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);
         } 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) {
     },
 
     saveSuccess: function(transport) {
-      if (!$("geom_id").value) {
+      if (!this.hasInitialGeom) { // we have created a new path, change location
           location = "idx/" + transport.responseText;
           return;
       }
           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;
       SyjSaveUI.hide();
       SyjEditUI.show();
       document.title = $('geom_title').value;
@@ -417,13 +419,9 @@ var SYJView = {
             break;
             case 400:
             case 404:
             break;
             case 400:
             case 404:
-            case 410:
                 message = SyjStrings.requestError; // default message
                 if (transport.responseJSON) {
                     switch (transport.responseJSON.message) {
                 message = SyjStrings.requestError; // default message
                 if (transport.responseJSON) {
                     switch (transport.responseJSON.message) {
-                        case "unreferenced":
-                            message = SyjStrings.unreferencedError;
-                        break;
                         case "uniquepath":
                             message = SyjStrings.uniquePathError;
                         break;
                         case "uniquepath":
                             message = SyjStrings.uniquePathError;
                         break;
@@ -432,6 +430,9 @@ var SYJView = {
                     }
                 }
             break;
                     }
                 }
             break;
+            case 410:
+                message = SyjStrings.gonePathError;
+            break;
             case 500:
                 message = SyjStrings.serverError;
                 this.needsFormResubmit = true;
             case 500:
                 message = SyjStrings.serverError;
                 this.needsFormResubmit = true;