]> dev.renevier.net Git - syj.git/blob - application/controllers/IdxController.php
ask a confirmation when users leaves with unsaved route
[syj.git] / application / controllers / IdxController.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class IdxController extends Zend_Controller_Action
6 {
7
8     public function init() {
9         $this->view->headScript()->appendFile('js/OpenLayers.js');
10         $this->view->headScript()->appendFile('js/ModifiablePath.js');
11         $this->view->headScript()->appendFile('js/prototype.js');
12         $this->view->headScript()->appendFile('js/simplebox.js');
13         $this->view->headScript()->appendFile('js/utils.js');
14         $this->view->headScript()->appendFile('js/syj.js');
15         $this->view->headLink()->appendStylesheet('css/openlayers/style.css');
16         $this->view->headLink()->appendStylesheet('css/generic.css');
17         $this->view->headLink()->appendStylesheet('css/syj.css');
18     }
19
20     public function indexAction() {
21         $url = $this->getRequest()->getUserParam('url');
22
23         $geomform = new Syj_Form_Geom(array('name' => 'geomform'));
24         $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login'));
25         $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user'));
26         $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd'));
27
28         if (isset($url)) {
29             $pathMapper = new Syj_Model_PathMapper();
30             $path = new Syj_Model_Path();
31             if (!$pathMapper->findByUrl($url, $path)) {
32                 if (is_numeric($url) and $pathMapper->hasexisted($url)) {
33                     throw new Syj_Exception_NotFound('Gone', 410);
34                 } else {
35                     throw new Syj_Exception_NotFound('Not Found', 404);
36                 }
37             }
38             $geomform->setAction('path/' . (string)$path->id . '/update');
39             $title = $path->displayTitle;
40             $this->view->path = $path;
41             $geomform->geom_title->setValue($path->title);
42             $geomform->geom_data->setValue((string)$path->geom);
43             $loginform->login_geom_id->setValue((string)$path->id);
44         } else {
45             $geomform->setAction('path');
46             $extent = new phptojs\JsObject('gMaxExtent', $this->_helper->syjGeoip($this->getRequest()->getClientIp(true)));
47             $this->view->headScript()->prependScript((string) $extent);
48             $title = "Show your journey";
49         }
50
51         $this->_jsLoggedInfo(isset($url) ? $path: null);
52         $this->_jsLocaleStrings();
53         $this->view->headTitle($title);
54         $this->view->geomform = $geomform;
55         $this->view->loginform = $loginform;
56         $this->view->userform = $userform;
57         $this->view->newpwdform = $newpwdform;
58         $this->view->loggedUser = $this->_helper->SyjSession->user();
59     }
60
61     protected function _jsLoggedInfo(Syj_Model_Path $path = null) {
62         $loggedinfo = new phptojs\JsObject('gLoggedInfo', array('connections' => 0));
63
64         $user = $this->_helper->SyjSession->user();
65         if ($user) {
66             $loggedinfo->logged = true;
67         } else {
68             $loggedinfo->logged = false;
69         }
70
71         if (isset($path)) {
72             $loggedinfo->iscreator = $path->isCreator($user);
73             if ($path->creator) {
74                 $loggedinfo->creatorname = $this->view->escape((string)$path->creator->pseudo);
75             }
76             $loggedinfo->pathid = (string)$path->id;
77         } else {
78             $loggedinfo->iscreator = true;
79         }
80
81         $this->view->headScript()->prependScript((string) $loggedinfo);
82     }
83
84     protected function _jsLocaleStrings() {
85         $this->view->jslocales = array(
86             'saveSuccess' => __("save took place successfully"),
87             'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"),
88             'gonePathError' => __("route not referenced on the server. It has probably been deleted."),
89             'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"),
90             'notReachedError' => __("server could not be reached"),
91             'serverError' => __("there was a server error"),
92             'unknownError' => __("there was an unknown error"),
93             'userEmptyWarn' => __("you must enter a login name"),
94             'loginSuccess' => __("Login correct"),
95             'loginFailure' => __("Wrong login/password"),
96             'passwordEmptyWarn' => __("you must enter a password"),
97             'passwordNoMatchWarn' => __("Password do not match"),
98             'acceptTermsofuseWarn' => __("You must accept terms of use"),
99             'emailEmptyWarn' => __("you must enter an email"),
100             'emailInvalidWarn' => __("invalid email"),
101             'uniqueEmailError' => __("an user is already registered with this email"),
102             'userSuccess' => __("Account created"),
103             'newpwdSuccess' => __("A link to reset your password has been emailed to you"),
104             'canResubmit' => __("Now, you can retry to save"),
105             'routeBy' => __("route by"),
106             'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>"),
107             'pseudoChecking' => __("checking availibilty"),
108             'availablePseudo' => __("available pseudo"),
109             'unavailablePseudo' => __("unavailable pseudo"),
110             'editAction' => __("edit"),
111             'createAction' => __("create"),
112             'cloneAction' => __("duplicate"),
113             'unsavedConfirmExit' => __("You have an unsaved route"),
114             );
115     }
116
117 }