Commit 35af91f67a568ec73bb38b4ae925b0af1e378591
Merge remote-tracking branch 'origin/master'
# Conflicts: # frontend/controllers/SiteController.php
Showing
6 changed files
with
191 additions
and
349 deletions
Show diff stats
frontend/assets/MapAsset.php
| ... | ... | @@ -15,8 +15,7 @@ |
| 15 | 15 | public $baseUrl = '@web'; |
| 16 | 16 | public $css = []; |
| 17 | 17 | public $js = [ |
| 18 | - 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', | |
| 19 | - 'js/gmaps.js', | |
| 18 | + '//maps.googleapis.com/maps/api/js?key=AIzaSyCoR1Jb-mIFUjPwKiuSlmtYBEwnJOBnAgg&callback=initMap', | |
| 20 | 19 | 'js/gmaps.init.js', |
| 21 | 20 | ]; |
| 22 | 21 | public $depends = [ | ... | ... |
frontend/controllers/SiteController.php
| 1 | 1 | <?php |
| 2 | - namespace frontend\controllers; | |
| 3 | - | |
| 4 | - use artbox\core\models\Feedback; | |
| 5 | - use common\models\Settings; | |
| 6 | - use Yii; | |
| 7 | - use yii\base\InvalidParamException; | |
| 8 | - use yii\web\BadRequestHttpException; | |
| 9 | - use yii\web\Controller; | |
| 10 | - use yii\filters\VerbFilter; | |
| 11 | - use common\models\LoginForm; | |
| 12 | - use frontend\models\PasswordResetRequestForm; | |
| 13 | - use frontend\models\ResetPasswordForm; | |
| 14 | - use frontend\models\SignupForm; | |
| 15 | - use yii\web\Response; | |
| 2 | +namespace frontend\controllers; | |
| 3 | + | |
| 4 | +use artbox\core\models\Feedback; | |
| 5 | +use common\models\Settings; | |
| 6 | +use Yii; | |
| 7 | +use yii\base\InvalidParamException; | |
| 8 | +use yii\web\BadRequestHttpException; | |
| 9 | +use yii\web\Controller; | |
| 10 | +use yii\filters\VerbFilter; | |
| 11 | +use common\models\LoginForm; | |
| 12 | +use frontend\models\PasswordResetRequestForm; | |
| 13 | +use frontend\models\ResetPasswordForm; | |
| 14 | +use frontend\models\SignupForm; | |
| 15 | +use yii\web\Response; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * Site controller | |
| 19 | + */ | |
| 20 | +class SiteController extends Controller | |
| 21 | +{ | |
| 22 | + /** | |
| 23 | + * @inheritdoc | |
| 24 | + */ | |
| 25 | + public function actions() | |
| 26 | + { | |
| 27 | + return [ | |
| 28 | + 'error' => [ | |
| 29 | + 'class' => 'yii\web\ErrorAction', | |
| 30 | + ], | |
| 31 | + ]; | |
| 32 | + } | |
| 16 | 33 | |
| 17 | 34 | /** |
| 18 | - * Site controller | |
| 35 | + * @inheritdoc | |
| 19 | 36 | */ |
| 20 | - class SiteController extends Controller | |
| 37 | + public function behaviors() | |
| 21 | 38 | { |
| 22 | - /** | |
| 23 | - * @inheritdoc | |
| 24 | - */ | |
| 25 | - public function actions() | |
| 26 | - { | |
| 27 | - return [ | |
| 28 | - 'error' => [ | |
| 29 | - 'class' => 'yii\web\ErrorAction', | |
| 39 | + return [ | |
| 40 | + 'verbs' => [ | |
| 41 | + 'class' => VerbFilter::className(), | |
| 42 | + 'actions' => [ | |
| 43 | + 'feedback' => [ 'post' ], | |
| 30 | 44 | ], |
| 31 | - ]; | |
| 32 | - } | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * @inheritdoc | |
| 36 | - */ | |
| 37 | - public function behaviors() | |
| 38 | - { | |
| 39 | - return [ | |
| 40 | - 'verbs' => [ | |
| 41 | - 'class' => VerbFilter::className(), | |
| 42 | - 'actions' => [ | |
| 43 | - 'feedback' => [ 'post' ], | |
| 44 | - ], | |
| 45 | - ], | |
| 46 | - ]; | |
| 47 | - } | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Displays homepage. | |
| 51 | - * | |
| 52 | - * @return mixed | |
| 53 | - */ | |
| 54 | - public function actionIndex() | |
| 55 | - { | |
| 56 | - return $this->render('index'); | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Logs in a user. | |
| 61 | - * | |
| 62 | - * @return mixed | |
| 63 | - */ | |
| 64 | - public function actionLogin() | |
| 65 | - { | |
| 66 | - if (!Yii::$app->user->isGuest) { | |
| 67 | - return $this->goHome(); | |
| 68 | - } | |
| 69 | - | |
| 70 | - $model = new LoginForm(); | |
| 71 | - if ($model->load(Yii::$app->request->post()) && $model->login()) { | |
| 72 | - return $this->goBack(); | |
| 73 | - } else { | |
| 74 | - return $this->render( | |
| 75 | - 'login', | |
| 76 | - [ | |
| 77 | - 'model' => $model, | |
| 78 | - ] | |
| 79 | - ); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Logs out the current user. | |
| 85 | - * | |
| 86 | - * @return mixed | |
| 87 | - */ | |
| 88 | - public function actionLogout() | |
| 89 | - { | |
| 90 | - Yii::$app->user->logout(); | |
| 91 | - | |
| 92 | - return $this->goHome(); | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Displays contact page. | |
| 97 | - * | |
| 98 | - * @return mixed | |
| 99 | - */ | |
| 100 | - public function actionContact() | |
| 101 | - { | |
| 102 | - $contact = new Feedback(); | |
| 103 | - return $this->render( | |
| 104 | - 'contact', | |
| 105 | - [ | |
| 106 | - 'contact' => $contact, | |
| 107 | - ] | |
| 108 | - ); | |
| 109 | - } | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * Displays about page. | |
| 113 | - * | |
| 114 | - * @return mixed | |
| 115 | - */ | |
| 116 | - public function actionAbout() | |
| 117 | - { | |
| 118 | - return $this->render('about'); | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * Signs user up. | |
| 123 | - * | |
| 124 | - * @return mixed | |
| 125 | - */ | |
| 126 | - public function actionSignup() | |
| 127 | - { | |
| 128 | - $model = new SignupForm(); | |
| 129 | - if ($model->load(Yii::$app->request->post())) { | |
| 130 | - if ($user = $model->signup()) { | |
| 131 | - if (Yii::$app->getUser() | |
| 132 | - ->login($user) | |
| 133 | - ) { | |
| 134 | - return $this->goHome(); | |
| 135 | - } | |
| 136 | - } | |
| 137 | - } | |
| 138 | - | |
| 139 | - return $this->render( | |
| 140 | - 'signup', | |
| 141 | - [ | |
| 142 | - 'model' => $model, | |
| 143 | - ] | |
| 144 | - ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * Requests password reset. | |
| 149 | - * | |
| 150 | - * @return mixed | |
| 151 | - */ | |
| 152 | - public function actionRequestPasswordReset() | |
| 153 | - { | |
| 154 | - $model = new PasswordResetRequestForm(); | |
| 155 | - if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |
| 156 | - if ($model->sendEmail()) { | |
| 157 | - Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); | |
| 158 | - | |
| 159 | - return $this->goHome(); | |
| 160 | - } else { | |
| 161 | - Yii::$app->session->setFlash( | |
| 162 | - 'error', | |
| 163 | - 'Sorry, we are unable to reset password for the provided email address.' | |
| 164 | - ); | |
| 165 | - } | |
| 166 | - } | |
| 167 | - | |
| 168 | - return $this->render( | |
| 169 | - 'requestPasswordResetToken', | |
| 170 | - [ | |
| 171 | - 'model' => $model, | |
| 172 | - ] | |
| 173 | - ); | |
| 174 | - } | |
| 175 | - | |
| 176 | - /** | |
| 177 | - * Resets password. | |
| 178 | - * | |
| 179 | - * @param string $token | |
| 180 | - * | |
| 181 | - * @return mixed | |
| 182 | - * @throws BadRequestHttpException | |
| 183 | - */ | |
| 184 | - public function actionResetPassword($token) | |
| 185 | - { | |
| 186 | - try { | |
| 187 | - $model = new ResetPasswordForm($token); | |
| 188 | - } catch (InvalidParamException $e) { | |
| 189 | - throw new BadRequestHttpException($e->getMessage()); | |
| 190 | - } | |
| 191 | - | |
| 192 | - if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { | |
| 193 | - Yii::$app->session->setFlash('success', 'New password saved.'); | |
| 194 | - | |
| 195 | - return $this->goHome(); | |
| 196 | - } | |
| 197 | - | |
| 198 | - return $this->render( | |
| 199 | - 'resetPassword', | |
| 200 | - [ | |
| 201 | - 'model' => $model, | |
| 202 | - ] | |
| 203 | - ); | |
| 204 | - } | |
| 205 | - | |
| 45 | + ], | |
| 46 | + ]; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Displays homepage. | |
| 51 | + * | |
| 52 | + * @return mixed | |
| 53 | + */ | |
| 54 | + public function actionIndex() | |
| 55 | + { | |
| 56 | + return $this->render('index'); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Displays contact page. | |
| 61 | + * | |
| 62 | + * @return mixed | |
| 63 | + */ | |
| 64 | + public function actionContact() | |
| 65 | + { | |
| 66 | + $contact = new Feedback(); | |
| 67 | + return $this->render( | |
| 68 | + 'contact', | |
| 69 | + [ | |
| 70 | + 'contact' => $contact, | |
| 71 | + ] | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Displays about page. | |
| 77 | + * | |
| 78 | + * @return mixed | |
| 79 | + */ | |
| 80 | + public function actionAbout() | |
| 81 | + { | |
| 82 | + return $this->render('about'); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Action to view robots.txt file dinamycli | |
| 87 | + * | |
| 88 | + * @return string | |
| 89 | + */ | |
| 90 | + public function actionRobots() | |
| 91 | + { | |
| 92 | + $response = \Yii::$app->response; | |
| 206 | 93 | /** |
| 207 | - * Action to view robots.txt file dinamycli | |
| 208 | - * | |
| 209 | - * @return string | |
| 94 | + * @var Settings $settings | |
| 210 | 95 | */ |
| 211 | - public function actionRobots() | |
| 212 | - { | |
| 213 | - $response = \Yii::$app->response; | |
| 214 | - /** | |
| 215 | - * @var Settings $settings | |
| 216 | - */ | |
| 217 | - $settings = Settings::find() | |
| 218 | - ->one(); | |
| 219 | - $temp = tmpfile(); | |
| 220 | - fwrite($temp, $settings->robots); | |
| 221 | - $meta = stream_get_meta_data($temp); | |
| 222 | - $response->format = $response::FORMAT_RAW; | |
| 223 | - $response->headers->set('Content-Type', 'text/plain'); | |
| 224 | - return $this->renderFile($meta[ 'uri' ]); | |
| 225 | - } | |
| 226 | - | |
| 227 | - public function actionFeedback() | |
| 228 | - { | |
| 229 | - Yii::$app->response->format = Response::FORMAT_JSON; | |
| 230 | - if (empty( Yii::$app->request->post() )) { | |
| 231 | - throw new BadRequestHttpException(); | |
| 96 | + $settings = Settings::find() | |
| 97 | + ->one(); | |
| 98 | + $temp = tmpfile(); | |
| 99 | + fwrite($temp, $settings->robots); | |
| 100 | + $meta = stream_get_meta_data($temp); | |
| 101 | + $response->format = $response::FORMAT_RAW; | |
| 102 | + $response->headers->set('Content-Type', 'text/plain'); | |
| 103 | + return $this->renderFile($meta[ 'uri' ]); | |
| 104 | + } | |
| 105 | + | |
| 106 | + public function actionFeedback() | |
| 107 | + { | |
| 108 | + Yii::$app->response->format = Response::FORMAT_JSON; | |
| 109 | + if (empty(Yii::$app->request->post())) { | |
| 110 | + throw new BadRequestHttpException(); | |
| 111 | + } else { | |
| 112 | + $model = new Feedback(); | |
| 113 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 114 | + return [ | |
| 115 | + 'success' => true, | |
| 116 | + 'message' => 'Success message', | |
| 117 | + 'alert' => '<div class="alert alert-success"> | |
| 118 | + <h3>Success</h3> | |
| 119 | + <p> | |
| 120 | + Success text | |
| 121 | + </p> | |
| 122 | + </div>', | |
| 123 | + ]; | |
| 232 | 124 | } else { |
| 233 | - $model = new Feedback(); | |
| 234 | - if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| 235 | - return [ | |
| 236 | - 'success' => true, | |
| 237 | - 'message' => 'Success message', | |
| 238 | - ]; | |
| 239 | - } else { | |
| 240 | - return [ | |
| 241 | - 'success' => false, | |
| 242 | - 'error' => $model->errors, | |
| 243 | - ]; | |
| 244 | - } | |
| 125 | + return [ | |
| 126 | + 'success' => false, | |
| 127 | + 'error' => $model->errors, | |
| 128 | + ]; | |
| 245 | 129 | } |
| 246 | 130 | } |
| 247 | 131 | } |
| 132 | +} | ... | ... |
frontend/views/site/contact.php
| ... | ... | @@ -6,15 +6,24 @@ |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | use artbox\core\models\Feedback; |
| 9 | + use common\models\Settings; | |
| 9 | 10 | use frontend\assets\MapAsset; |
| 10 | 11 | use yii\helpers\Html; |
| 11 | 12 | use yii\bootstrap\ActiveForm; |
| 12 | 13 | use yii\web\View; |
| 13 | 14 | |
| 14 | 15 | MapAsset::register($this); |
| 16 | + $settings = Settings::getInstance(); | |
| 15 | 17 | |
| 16 | 18 | $this->title = 'Contact'; |
| 17 | 19 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 20 | + | |
| 21 | + $js = <<< JS | |
| 22 | +window.lat = {$settings->lat}; | |
| 23 | +window.lon = {$settings->lon}; | |
| 24 | +JS; | |
| 25 | + | |
| 26 | + $this->registerJs($js, View::POS_END); | |
| 18 | 27 | ?> |
| 19 | 28 | |
| 20 | 29 | <div id="content"> |
| ... | ... | @@ -144,8 +153,6 @@ |
| 144 | 153 | </div> |
| 145 | 154 | <!-- /.row --> |
| 146 | 155 | <?php ActiveForm::end(); ?> |
| 147 | - | |
| 148 | - | |
| 149 | 156 | </div> |
| 150 | 157 | </div> |
| 151 | 158 | <!-- /.row --> | ... | ... |
frontend/web/css/custom.css
| ... | ... | @@ -88,7 +88,7 @@ |
| 88 | 88 | #back-to-top { |
| 89 | 89 | position: fixed; |
| 90 | 90 | top: 100px; |
| 91 | - left: 0px; | |
| 91 | + left: 0; | |
| 92 | 92 | z-index: 9999; |
| 93 | 93 | width: 40px; |
| 94 | 94 | height: 40px; |
| ... | ... | @@ -100,7 +100,7 @@ |
| 100 | 100 | text-decoration: none; |
| 101 | 101 | transition: opacity 0.2s ease-out; |
| 102 | 102 | opacity: 0; |
| 103 | - padding: 4px; | |
| 103 | + padding: 4px 1px 4px 0; | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | #back-to-top:hover { | ... | ... |
frontend/web/js/gmaps.init.js
| 1 | 1 | $( |
| 2 | 2 | function() { |
| 3 | 3 | |
| 4 | - map(); | |
| 4 | + function initMap() { | |
| 5 | + var myLatLng = { | |
| 6 | + lat: parseFloat(window.lat), | |
| 7 | + lng: parseFloat(window.lon) | |
| 8 | + }; | |
| 5 | 9 | |
| 6 | - } | |
| 7 | -); | |
| 8 | - | |
| 9 | -/* map */ | |
| 10 | - | |
| 11 | -function map() { | |
| 12 | - | |
| 13 | - var styles = [ | |
| 14 | - { | |
| 15 | - "featureType": "landscape", | |
| 16 | - "stylers": [ | |
| 17 | - {"saturation": -100}, | |
| 18 | - {"lightness": 65}, | |
| 19 | - {"visibility": "on"} | |
| 20 | - ] | |
| 21 | - }, | |
| 22 | - { | |
| 23 | - "featureType": "poi", | |
| 24 | - "stylers": [ | |
| 25 | - {"saturation": -100}, | |
| 26 | - {"lightness": 51}, | |
| 27 | - {"visibility": "simplified"} | |
| 28 | - ] | |
| 29 | - }, | |
| 30 | - { | |
| 31 | - "featureType": "road.highway", | |
| 32 | - "stylers": [ | |
| 33 | - {"saturation": -100}, | |
| 34 | - {"visibility": "simplified"} | |
| 35 | - ] | |
| 36 | - }, | |
| 37 | - { | |
| 38 | - "featureType": "road.arterial", | |
| 39 | - "stylers": [ | |
| 40 | - {"saturation": -100}, | |
| 41 | - {"lightness": 30}, | |
| 42 | - {"visibility": "on"} | |
| 43 | - ] | |
| 44 | - }, | |
| 45 | - { | |
| 46 | - "featureType": "road.local", | |
| 47 | - "stylers": [ | |
| 48 | - {"saturation": -100}, | |
| 49 | - {"lightness": 40}, | |
| 50 | - {"visibility": "on"} | |
| 51 | - ] | |
| 52 | - }, | |
| 53 | - { | |
| 54 | - "featureType": "transit", | |
| 55 | - "stylers": [ | |
| 56 | - {"saturation": -100}, | |
| 57 | - {"visibility": "simplified"} | |
| 58 | - ] | |
| 59 | - }, | |
| 60 | - { | |
| 61 | - "featureType": "administrative.province", | |
| 62 | - "stylers": [ {"visibility": "off"} ] | |
| 63 | - }, | |
| 64 | - { | |
| 65 | - "featureType": "water", | |
| 66 | - "elementType": "labels", | |
| 67 | - "stylers": [ | |
| 68 | - {"visibility": "on"}, | |
| 69 | - {"lightness": -25}, | |
| 70 | - {"saturation": -100} | |
| 71 | - ] | |
| 72 | - }, | |
| 73 | - { | |
| 74 | - "featureType": "water", | |
| 75 | - "elementType": "geometry", | |
| 76 | - "stylers": [ | |
| 77 | - {"hue": "#ffff00"}, | |
| 78 | - {"lightness": -25}, | |
| 79 | - {"saturation": -97} | |
| 80 | - ] | |
| 81 | - } | |
| 82 | - ]; | |
| 83 | - map = new GMaps( | |
| 84 | - { | |
| 85 | - el: '#map', | |
| 86 | - lat: -12.043333, | |
| 87 | - lng: -77.028333, | |
| 88 | - zoomControl: true, | |
| 89 | - zoomControlOpt: { | |
| 90 | - style: 'SMALL', | |
| 91 | - position: 'TOP_LEFT' | |
| 92 | - }, | |
| 93 | - panControl: false, | |
| 94 | - streetViewControl: false, | |
| 95 | - mapTypeControl: false, | |
| 96 | - overviewMapControl: false, | |
| 10 | + var map = new google.maps.Map( | |
| 11 | + document.getElementById('map'), { | |
| 12 | + center: myLatLng, | |
| 97 | 13 | scrollwheel: false, |
| 98 | - draggable: false, | |
| 99 | - styles: styles | |
| 100 | - } | |
| 101 | - ); | |
| 14 | + zoom: 14 | |
| 15 | + } | |
| 16 | + ); | |
| 102 | 17 | |
| 103 | - var image = 'img/marker.png'; | |
| 18 | + var marker = new google.maps.Marker( | |
| 19 | + { | |
| 20 | + position: myLatLng, | |
| 21 | + map: map, | |
| 22 | + title: 'Hello World!' | |
| 23 | + } | |
| 24 | + ); | |
| 104 | 25 | |
| 105 | - map.addMarker( | |
| 106 | - { | |
| 107 | - lat: -12.043333, | |
| 108 | - lng: -77.028333, | |
| 109 | - icon: image/* , | |
| 110 | - title: '', | |
| 111 | - infoWindow: { | |
| 112 | - content: '<p>HTML Content</p>' | |
| 113 | - }*/ | |
| 114 | 26 | } |
| 115 | - ); | |
| 116 | -} | |
| 117 | 27 | \ No newline at end of file |
| 28 | + | |
| 29 | + window.initMap = initMap(); | |
| 30 | + } | |
| 31 | +); | ... | ... |
frontend/web/js/script.js
| 1 | 1 | $( |
| 2 | 2 | function() { |
| 3 | 3 | |
| 4 | + /** | |
| 5 | + * Modal form submit code | |
| 6 | + */ | |
| 4 | 7 | $(document) |
| 5 | 8 | .on( |
| 6 | 9 | 'beforeSubmit', '#feedback-form', function(e) { |
| ... | ... | @@ -33,6 +36,40 @@ $( |
| 33 | 36 | } |
| 34 | 37 | ); |
| 35 | 38 | |
| 39 | + /** | |
| 40 | + * Contact form submitting | |
| 41 | + */ | |
| 42 | + $(document) | |
| 43 | + .on( | |
| 44 | + 'beforeSubmit', '#contact-form', function(e) { | |
| 45 | + var f = this; | |
| 46 | + var form = $(this); | |
| 47 | + var formData = form.serialize(); | |
| 48 | + $.ajax( | |
| 49 | + { | |
| 50 | + url: form.attr("action"), | |
| 51 | + type: form.attr("method"), | |
| 52 | + data: formData, | |
| 53 | + success: function(data) { | |
| 54 | + f.reset(); | |
| 55 | + form.replaceWith(data.alert) | |
| 56 | + }, | |
| 57 | + error: function() { | |
| 58 | + | |
| 59 | + } | |
| 60 | + } | |
| 61 | + ); | |
| 62 | + } | |
| 63 | + ) | |
| 64 | + .on( | |
| 65 | + 'submit', '#contact-form', function(e) { | |
| 66 | + e.preventDefault(); | |
| 67 | + } | |
| 68 | + ); | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Button UP code | |
| 72 | + */ | |
| 36 | 73 | if ($('#back-to-top').length) { |
| 37 | 74 | var scrollTrigger = 100, // px |
| 38 | 75 | backToTop = function() { | ... | ... |