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"
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'));
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";
$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"),
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();
} 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) {
$this->_helper->SyjApi->setBody($path->id);
}
+
}
);
public function init() {
- $id = array('Hidden', 'geom_id');
$data = array('Hidden', 'geom_data', array('required' => true));
$title = array('Text', 'geom_title', array(
$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);
map: null,
wkt: new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
needsFormResubmit: false,
+ hasInitialGeom: false,
init: function() {
var externalGraphic, baseURL, baseLayer, layerOptions, extent, hidemessenger;
// 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);
},
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;
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;
}
}
break;
+ case 410:
+ message = SyjStrings.gonePathError;
+ break;
case 500:
message = SyjStrings.serverError;
this.needsFormResubmit = true;