From 2a253676b49357cebf135e8f819be23fe1480db9 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Mon, 22 Sep 2014 20:15:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BD=D0=BE=D0=B6=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=20=D0=B8?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=BB=D0=B5=D0=BD=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=92=20?= =?UTF-8?q?=D0=98=D0=97=D0=91=D0=A0=D0=90=D0=9D=D0=9D=D0=9E=D0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/classes/Model.php | 2 +- ground/controllers/IndexController.php | 13 +- ground/controllers/JsonController.php | 12 + ground/models/Favorite.php | 49 +++++ ground/views/layout.php | 32 +-- ground/views/metrika.php | 31 +++ public/css/style.css | 5 + public/hit (копия).gif | Bin 0 -> 916 bytes public/hit0.gif | Bin 0 -> 595 bytes public/hit1.gif | Bin 0 -> 917 bytes public/hit2.gif | Bin 0 -> 852 bytes public/img.php | 59 +++++ public/img/vk_logo.png | Bin 0 -> 855 bytes public/js/app.js | 17 ++ public/js/map.js | 294 +++++++++++++------------ 15 files changed, 337 insertions(+), 177 deletions(-) create mode 100644 ground/models/Favorite.php create mode 100644 ground/views/metrika.php create mode 100644 public/hit (копия).gif create mode 100644 public/hit0.gif create mode 100644 public/hit1.gif create mode 100644 public/hit2.gif create mode 100644 public/img.php create mode 100644 public/img/vk_logo.png diff --git a/ground/classes/Model.php b/ground/classes/Model.php index 69980f3..56683e7 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -165,7 +165,7 @@ abstract class Model $ready[$row[$this->_primaryKey_]] = isset($params['asArray'])&&$params['asArray'] ? $row : new $calledClass($row); } - return $ready; + return (isset($params['limit'])&&$params['limit']==1) ? array_shift($ready) : $ready; } /** diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index d6799c2..1d2b9c9 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -45,7 +45,12 @@ class IndexController extends Controller if (App::$user && App::$user->id) { $routes = Route::model()->getByAuthor(App::$user->id); - } + self::addVar('user', App::$user->id); + } + else + { + self::addVar('user', '0'); + } self::addVar('isAdmin', (int)(App::$user && App::$user->isAdmin == 1) ); @@ -152,4 +157,10 @@ class IndexController extends Controller print($xml->asXML()); } + static function actionTest() + { + + var_dump( Favorite::model()->getAllMy() ); + } + } diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 3a90d73..8766489 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -67,6 +67,7 @@ class JsonController extends Controller $point->categoryIcon = $categories[$point->categoryId]['icon']; $point->categoryName = $categories[$point->categoryId]['name']; $point->photosCount = $photosCount; + $point->inFavorites = Favorite::model()->checkIsMy($id); self::renderPartial('json.php', $point->getValues()); } else @@ -306,4 +307,15 @@ class JsonController extends Controller self::renderPartial('json.php', $coords); } + static function actionAddRemoveFavorites() + { + $id = (int) App::getParam('id'); + if (!$id || !App::$user) + { + App::error404(); + } + + self::renderPartial('json.php', boolval(Favorite::addRemove($id))); + } + } diff --git a/ground/models/Favorite.php b/ground/models/Favorite.php new file mode 100644 index 0000000..49ea852 --- /dev/null +++ b/ground/models/Favorite.php @@ -0,0 +1,49 @@ +_tableName_ = 'favorites'; + parent::__construct($fromArray); + $this->setRelation('user', 'userId', 'User', 'id', self::TO_ONE); + $this->setRelation('point', 'pointId', 'Point', 'id', self::TO_ONE); + } + + static function model() + { + return new self(); + } + + public static function addRemove($pointId) + { + if (!App::$user || !App::$user->id || !$pointId) + return false; + + $res = self::model()->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId, 'limit'=>1)); + + if ($res) + { + return boolval(Favorite::model()->delete($res->id)); + } else { + return Favorite::model()->add(array('userId'=>App::$user->id, 'pointId'=>$pointId)); + } + } + + public function getAllMy() + { + if (!App::$user || !App::$user->id) + return false; + + return $this->getAll(array('where' => '`userId` = '.(int)App::$user->id)); + } + + public function checkIsMy($pointId) + { + if (!App::$user || !App::$user->id || !$pointId) + return false; + + return boolval($this->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId))); + } +} + diff --git a/ground/views/layout.php b/ground/views/layout.php index e3460c5..d8f8a2c 100644 --- a/ground/views/layout.php +++ b/ground/views/layout.php @@ -46,36 +46,6 @@ - - - - - - + \ No newline at end of file diff --git a/ground/views/metrika.php b/ground/views/metrika.php new file mode 100644 index 0000000..7ef5d02 --- /dev/null +++ b/ground/views/metrika.php @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index a1ae62a..57af5fc 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -27,6 +27,11 @@ div.add {cursor: pointer;} #addPointModal .extraImage .type.button:hover {background-color: #ddd;} #addPointModal .extraImage .input-group-addon.type.button {border-left: 0px;} +div.leaflet-popup-content div.control {margin-top: 7px;} +div.leaflet-popup-content button span.label {display: none; font-size: 90%; font-weight: normal; color: #333;} +div.leaflet-popup-content button:hover {min-width: 150px;} +div.leaflet-popup-content button:hover span.label {display: inline;} + .form-group .error {display: none;} .form-group.has-error .error {display: inline-block;} diff --git a/public/hit (копия).gif b/public/hit (копия).gif new file mode 100644 index 0000000000000000000000000000000000000000..730a38d6cbec63304bc0a494910cb7f8ce249f33 GIT binary patch literal 916 zcmV;F18e+8Nk%w1VORio0FeLy00028va>HAukT%4en!`8cl>yt(&y&|=t8(5 zc37yQCq$RGsP-3mG)W1kcxhy*sl(Yx^Z8;znz*$zQ@Z7Ym|2EM#40NTORI-=+xobP z+WV-A>*X7~D{5FP+lUjpEQHKFr;K?@-3SaBjXkRkTIt#y$`vpkAVAJRUY>5Ap-z>Z zeO)ULzfs^;HZJ)53G~-ao`HrEJyG+hh@>!b zrGoi%l|hNSq&N*2P@2H4CAnFJ84v8%7F4xP841v=HIdJlhSGK|>d1>mSFqINRwjVV?e!;T9*a%?>KSz5yH&=P*M7&1SXfBSxPV^PfI(8a`k^tU)Q zV~r#aLQ^}|B<6FPRkrNRxkO=XyJ^)m7YaHQ_=Q zM%Gwrf{{4LMB`ngi&@hxCEaxS4X0d?LYB893O@pOq+UrfGD|A;#MNRQ2NhJ+VYWp1 z29egtH&mvIfN*taZL>YpuD)3JR5QUFT{ibf~BmT2-pKXhw&+P!tlId|U|Y|Qu*6ynInVPPp qmA0ENlU+%RWxg_o8>e5Go;hEN)B^c1k`XI8YsD5{j4=cS0029WYQ5S3 literal 0 HcmV?d00001 diff --git a/public/hit0.gif b/public/hit0.gif new file mode 100644 index 0000000000000000000000000000000000000000..66734e3fde140da36008975d2d7281b7a192fcad GIT binary patch literal 595 zcmV-Z0<8T>HAukT%4en!`8cl>yt(&y&|=t8(5 zc37yQCq$RGsP-3mG)W1kcxhy*sl(Yx^9c$gI%=3{8j6}qy2^U``0D8@8^{%a8z7L& zk*n*woAEnZq$}KeY(F&+GkeOnFfOO5+&-n>{^JHp-` z@(%BKQEz|WC_i69yC2{0k6xpIi~tgpVep_Eg(&nLbV%ZyvxE$vjgu&>S~C8P;37SX z*3p~DZXnm)0@+OD#bF&yKJun5CQFvf)D^Ob5nMTRyH-w&#n2r^g%AVcJBl>I!k|Kd zGG#IJVN`-e{Z-v}bzW9@TibQ5g>xoJWE`t0hM(QNaCjaSm>(>hlQ2CjSHQ>adt^K0%LQRC@ImqvfC z{JM1L+9!kZ-U>HAukT%4en!`8cl>yt(&y&|=t8(5 zc37yQCq$RGsP-3mG)W1kcxhy*sl(Yx^Z8;znz*$zQ@Z7Ym|2EM#40NTORI-=+xobP z+WV-A>*X7~D{5FP+lUjpEQHKFr;K?@-3SaBjXkRkTIt#y$`vpkAVAJRUY>5Ap-z>Z zeO)ULzfs^;HZJ)53G~-ao`HrEJyG+hh@>!b zrGoi%l|hNSq&N*2P@2H4CAnFJ84v8%7F4xP841v=HIdJlhSGK|>d1>mSFqINRwjVV?e!;T9*a%?>KSz5yH&=P*M7&1SXfBSxPV^PfI(8a`k^tU)Q zV~r#aLQ^}|B<6FPRkrNRxkO=XyJ^+zLaI{+qVVSrc_XxM-qg2q~8jV;)qGZC_Kkc5^gM%!nO zah4f)9>SHKE@n-)lyuYOH=J@l{#YK4DDVgzk$M@)$SkSU6PIi^ruSMztvxs)d|>RR zqY44d@s*ppj z*(0k(0tst!%&D5Am9)-!E1gg70V$0Hf<#{-bf~zYK++)TX$gnAP!tlfeAv<+GRL}V z$9&_FRhq52I?L03{$(U;g5qB4M5Lr}n(A$pj=SKvHgH8Ax*&e4?zi=di0Q90;fa}_ r_p;+X1}90$X`G7M)&JQXli>aw>e2{Q>+$WjB&;h6aWA_2>Hb= literal 0 HcmV?d00001 diff --git a/public/hit2.gif b/public/hit2.gif new file mode 100644 index 0000000000000000000000000000000000000000..34d9c82b14ba75ee0766aa1122ea883bc265c252 GIT binary patch literal 852 zcmV-a1FQT;Nk%w1VORio0FeLy00028va>HAukT%4en!`8cl>yt(&y&|=t8(5 zc37yQCq$RGsP-3mG)W1kcxhy*sl(Yx^I4g=wKQXb>Lm(>LxtE{Lga&(iAAaxbqk40 z`?%N03p*<#3)=`;cWS!)m|E()3Tjv@9m*Ae9Uzd+k*)2$o$)<#?2M-Te6D(^E#B?k z?j9cR_$qrW+{zm~*9b1Jq1`ub;QqNXhHTg_X64ugd^c}{z;F}~4l8G`7_t6*GYbCm zHV_-dko0<`$pMUE!j;v^P;2=j8q5H@7~c_{O}0{qjD;;byszWObQjK6MqD`1tbU$ZbcDBH7-oo%OAkG z6Z=Zs%foJ$rA-??n)om=$!&5=vQT++pQ^ly|5o-}IWWS=TrDOvSP|q%#v(z7FschB zWwk!>v9^)+^<$j0Yd>%!ds^AtUt3_$i|4X6z;WH!;8vSCq?>W_?F1Nvt-TM zT&vx$V5xdHS@-zw-n+*;I^5XuVvlDTaZPQC`pI61l~Q zaqr=Un`3i5gqb`FqHqoi*~!NifC|zl;DYWI@f}Cina3S(A?9XVi6)9=9)ur`H==AU zcE{9a%8?ZuCBZ;*(T&c5a*A`(8CK(STPc(rZan7llXNS+$QqMsb@X3I0gB^RUj(jI zR9G}7wpToeeR+GZr8rzt8Tr6gJ!6?_OH)g(e?M%t2Cs)1TfkP+%fsx+cb zma3${xk{d1^AMOGW*A~J-93kn2Bx6Ah6%@>81-3NmB1DRDC|xhQh1r2x7s>dC51T$ eEw8ousqD0^!pbSP=LPBQqvDQBZn+T@0029xOPam_ literal 0 HcmV?d00001 diff --git a/public/img.php b/public/img.php new file mode 100644 index 0000000..14961c8 --- /dev/null +++ b/public/img.php @@ -0,0 +1,59 @@ + array($b,$b,$b,$w,$b,$b), + 1 => array($w,$w,$w,$b,$w,$w), + 2 => array($b,$w,$b,$b,$b,$w), + 3 => array($b,$w,$b,$b,$w,$b), + 4 => array($w,$b,$b,$b,$w,$b), + 5 => array($b,$b,$w,$b,$w,$b), + 6 => array($b,$b,$w,$b,$b,$b), + 7 => array($b,$w,$b,$w,$w,$b), + 8 => array($b,$b,$b,$b,$b,$b), + 9 => array($b,$b,$b,$b,$w,$b), + ); + + if($im) + { + for ($index = 0; $index < 10; $index++) { + $block = 0; + if ($index >= 3) $block++; + if ($index >= 6) $block++; + if ($index >= 9) $block++; + + $x = 78 - 5*$index - 2*$block; + $y = 72; + + $digit = array( + imagecolorat($im, $x+1, $y), + imagecolorat($im, $x, $y+1), + imagecolorat($im, $x+3, $y+1), + imagecolorat($im, $x+2, $y+2), + imagecolorat($im, $x, $y+3), + imagecolorat($im, $x+3, $y+3), + ); + + $d = array_search($digit, $digits); + + if ($d !== false) { + $res[] = array_search($digit, $digits); + } + } + } + + return implode('', array_reverse($res)); +} + +for ($index = 0; $index <= 2; $index++) { + print loadGif('/home/web/poi/public/hit'.$index.'.gif'); + print '
'; +} + diff --git a/public/img/vk_logo.png b/public/img/vk_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..601e28dbe83841abb7e33d7d408d3e33f42ab9c5 GIT binary patch literal 855 zcmV-d1E~CoP)gFNn5C(;w5^|9YGEt&5i~Kp5 z3tF0Bn}lI#vOnW=*sxV6{l=Zv9q@(ku3umA2Gxd3dW~q5b7C5@9?wEmB_7KR3UKJ5A3t z_m&g|o&p!HUO0`wZtt3Xo7KWheoWvaT(ZM~AHU+b{h%GOgrXhHTJCgtGBy73 ztp-raqvzcy?zg@I&vA$;Dk9(KG)tc`BvYSLRTU!TQCa3&_K5LvN|yi{c^=TuvJR zVCvf}uH0?G%eNz2ha>@6fyT{CwU8wdOG_#qhF;@&??+f|Hau$Y!^y*Yvja(0P5$xZ zID(2jf4OlXn%L@ja&7#V$ShhrKP>MR7UVF;{-fM!rkE0c_S(HaNOBM*36v(uBUn|w zVXPse8jIPT&K1A&99En^br98+CI7#1qOmwEqOiuFF?p$!3_WKtW zqs)!Ngk*RkqB$gpl*c~*&P|~co`@JL4zzU-89q-w?HbTAnUf^ft+$58rqSHdZ&-rO z9sL-YoB_+(g!S7^DaDf)?-Bkqjry7j_`Pm8?N(ih{hVLK=wt+KU4t0;{1p~SVrP(Z z*PEE7zeFOAcr*q@NkCQgQx(rs2o@2P3VOSn{b4~6AP537ZKhB#%pv`mK>0I^h-wB^ h%@q3NwyOpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',maxZoom: 18}); - layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©',maxZoom: 18}); + layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18}); + layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©', maxZoom: 18}); layers['google'] = new L.Google('HYBRID'); layers['yandexMap'] = new L.Yandex(); layers['yandex'] = new L.Yandex('hybrid'); @@ -53,14 +53,14 @@ function init(lat, lng) { initCategories(); // getPoints внутри - myMap.on('click', function(e) { + myMap.on('click', function (e) { if (!myMap._popup) { if (status == statusHunting) { $('#addPointId').remove(); $('#addPointForm input:text').val(''); $('#addPointForm textarea').val(''); - $("#addPointCategoryId option" ).attr('selected', null); + $("#addPointCategoryId option").attr('selected', null); $('#addPointLat').val(e.latlng.lat); $('#addPointLng').val(e.latlng.lng); @@ -86,15 +86,17 @@ function init(lat, lng) { $("#wayPoints").disableSelection(); $("#imgsContainer").sortable(); - myMap.on('moveend', function(e) { - if (!myMap._popup && $('#boxRoute').css('display') == 'none') - { - history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); - document.title = pointsCount+' или даже больше поводов не сидеть дома'; - } - }); + myMap.on('moveend', function (e) { + if (!myMap._popup && $('#boxRoute').css('display') == 'none') + { + history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); + document.title = pointsCount + ' или даже больше поводов не сидеть дома'; + } + }); - $('.filterSelector').bind('change', function(){filter()}); + $('.filterSelector').bind('change', function () { + filter() + }); return true; } @@ -110,7 +112,9 @@ function constructPoint(data) points[id] = L.marker( [data['lat'], data['lng']], {icon: categories[data['categoryId']], title: data['name'], id: id, categoryId: data['categoryId']} - ).on('click', function(e){showInfo(e.target.options.id);}); + ).on('click', function (e) { + showInfo(e.target.options.id); + }); return points[id]; } @@ -123,7 +127,7 @@ function initPoints() { $.ajax({ url: "/json/points/", - success: function(data) { + success: function (data) { for (var k in data) { markers.addLayer(constructPoint(data[k])); } @@ -160,43 +164,33 @@ function initPoints() */ function showInfo(id) { - marker = points[id]; + marker = points[id]; if (!(id in points) || marker.options.description == undefined) { marker.bindPopup("Загрузка...").openPopup(); $.ajax({ url: "/json/point/id/" + id, - success: function(data) { + success: function (data) { pointsSources[id] = data; - if (typeof(data.images) == 'object') + if (typeof (data.images) == 'object') { - ph = '
'; + photos = '
'; if (data.images.length > 1) - ph += '
+' + (data.photosCount-1) + '
'; + photos += '
+' + (data.photosCount - 1) + '
'; - ph += ''; - ph += '
'; + photos += ''; + photos += '
'; } else { - ph = ''; + photos = ''; } description = '
' + '

' + data.name + '

' + - ph + - '
'; - - if (isAdmin == '1') - { - description = description + '
'; - } + photos; description = description + data.descriptionHtml; //description = description + ' Подробнее...'; @@ -207,17 +201,29 @@ function showInfo(id) } description = description + '
'; - - marker.options.description = description; - marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300}); - markers.zoomToShowLayer(marker,function() { + description = description + '
'; + description = description + ''; + description = description + ''; + description = description + ''; + description = description + ''; + + if (isAdmin == '1') + { + description = description + ''; + } + description = description + '
'; + + marker.options.description = description; + marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300}); + + markers.zoomToShowLayer(marker, function () { marker.openPopup(); history.pushState({}, document.title, "/?point=" + id); bounds = myMap.getBounds(); - diff = (bounds._northEast.lat - bounds._southWest.lat)/4; - myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom()); + diff = (bounds._northEast.lat - bounds._southWest.lat) / 4; + myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom()); history.pushState({}, document.title, "/?point=" + id); document.title = data.name; @@ -226,8 +232,8 @@ function showInfo(id) }); } else { bounds = myMap.getBounds(); - diff = (bounds._northEast.lat - bounds._southWest.lat)/4; - myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom()); + diff = (bounds._northEast.lat - bounds._southWest.lat) / 4; + myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom()); history.pushState({}, document.title, "/?point=" + id); document.title = points[id].options.title; @@ -236,11 +242,11 @@ function showInfo(id) function showRandomPoint() { - roundIndex = Math.floor(Math.random()*points.length); + roundIndex = Math.floor(Math.random() * points.length); runner = 0; - for(var key in points) + for (var key in points) { - if(runner++ >= roundIndex) + if (runner++ >= roundIndex) return showInfo(key); } } @@ -253,17 +259,17 @@ function initCategories() { $.ajax({ url: "/json/categories/", - success: function(data) { - for (var k in data) { - categories[data[k]['id']] = L.icon({ - iconUrl: data[k]['icon'], - iconSize: [32, 37], - iconAnchor: [16, 37], - popupAnchor: [0, 1] - }); - } + success: function (data) { + for (var k in data) { + categories[data[k]['id']] = L.icon({ + iconUrl: data[k]['icon'], + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] + }); + } - initPoints(); + initPoints(); } }); @@ -281,15 +287,15 @@ function searchAdderess() data: { search: $('#addressField').val() }, - success: function(data) + success: function (data) { if (data.lat && data.lng) { myMap.setView([data.lat, data.lng], defaultZoom); L.popup() - .setLatLng([data.lat, data.lng]) - .setContent('Координаты: lat:'+data.lat+' lng:'+data.lng) - .openOn(myMap); + .setLatLng([data.lat, data.lng]) + .setContent('Координаты: lat:' + data.lat + ' lng:' + data.lng) + .openOn(myMap); } else { alert('Ничего не найдено.'); @@ -304,7 +310,7 @@ function searchAdderess() */ function showMeOnTheMap() { - navigator.geolocation.getCurrentPosition(function(pos) { + navigator.geolocation.getCurrentPosition(function (pos) { coords = [pos.coords.latitude, pos.coords.longitude]; myMap.removeLayer(points.im); points.im.setLatLng(coords).addTo(myMap); @@ -321,7 +327,7 @@ function activateAddPoint() $('#addPointButton').toggleClass('active'); if ($('#addPointButton').hasClass('active')) { - $('.extraImage','#imgsContainer').remove(); + $('.extraImage', '#imgsContainer').remove(); addNewImage(); $('#map').css('cursor', 'crosshair'); setStatus(statusHunting) @@ -342,33 +348,33 @@ function activateAddPoint() function addPoint() { $('.form-group').removeClass('has-error'); - if (status != statusSendingToServer) - { + if (status != statusSendingToServer) + { setStatus(statusSendingToServer) id = $('#addPointId').length ? $('#addPointId').val() : 0; hasImages = false; - $("input[name='imgs[]']", '#addPointForm').each(function(){ - if ( $(this).val().length > 10) + $("input[name='imgs[]']", '#addPointForm').each(function () { + if ($(this).val().length > 10) hasImages = true; }); - $("input[name='photos[]']", '#addPointForm').each(function(){ - if ( $(this).val().length > 5) + $("input[name='photos[]']", '#addPointForm').each(function () { + if ($(this).val().length > 5) hasImages = true; }) - $.ajax({ - type: "POST", - url: "/json/addpoint/", - data: { - name: $('#addPointName').val(), - img: hasImages ? 1 : 0, - description: $('#addPointDescription').val(), - categoryId: $('#addPointCategoryId').val(), - source: $('#addPointSource').val(), - lat: $('#addPointLat').val(), - lng: $('#addPointLng').val(), + $.ajax({ + type: "POST", + url: "/json/addpoint/", + data: { + name: $('#addPointName').val(), + img: hasImages ? 1 : 0, + description: $('#addPointDescription').val(), + categoryId: $('#addPointCategoryId').val(), + source: $('#addPointSource').val(), + lat: $('#addPointLat').val(), + lng: $('#addPointLng').val(), id: id - }, - success: function(data) { + }, + success: function (data) { if ($("input[name='photos[]']").length > 0 || $("input[name='imgs[]']").length > 0) { $('').appendTo('#addPointForm').val(data); @@ -376,77 +382,77 @@ function addPoint() } text = id ? 'Точка успешно отредактирована!' : 'Точка успешно добавлена!'; - if ( id ) + if (id) { markers.removeLayer(points[id]); } balloon = L.popup() - .setLatLng([$('#addPointLat').val(), $('#addPointLng').val()]) - .setContent(text) - .openOn(myMap); - setTimeout(function() { - balloon._close(); + .setLatLng([$('#addPointLat').val(), $('#addPointLng').val()]) + .setContent(text) + .openOn(myMap); + setTimeout(function () { + balloon._close(); delete balloon; - }, 2000); + }, 2000); - obj = {}; - obj.id = data; - obj.name = $('#addPointName').val(); - obj.lat = $('#addPointLat').val(); - obj.lng = $('#addPointLng').val(); - obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon; + obj = {}; + obj.id = data; + obj.name = $('#addPointName').val(); + obj.lat = $('#addPointLat').val(); + obj.lng = $('#addPointLng').val(); + obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon; obj.categoryId = $('#addPointCategoryId').val(); - setTimeout(function() { + setTimeout(function () { markers.addLayer(constructPoint(obj)); - }, 2000); + }, 2000); - $('#addPointModal').modal('hide'); + $('#addPointModal').modal('hide'); - // Clear form - $('#addPointForm input').val(''); - $('#addPointForm textarea').val(''); - $('.form-group').removeClass('has-error'); - $('#addPointButton').removeClass('active'); + // Clear form + $('#addPointForm input').val(''); + $('#addPointForm textarea').val(''); + $('.form-group').removeClass('has-error'); + $('#addPointButton').removeClass('active'); $('#addPointId').remove(); - $('#map').css('cursor', 'arrow'); - setStatus(statusReady); + $('#map').css('cursor', 'arrow'); + setStatus(statusReady); - return true; - }, - error: function(data) { - response = data.responseJSON; - message = ''; - for (var k in response) { - if (typeof response[k] !== 'function') { - if (k == 1) - $('#addPointName').parent().addClass('has-error'); - else - if (k == 2) + return true; + }, + error: function (data) { + response = data.responseJSON; + message = ''; + for (var k in response) { + if (typeof response[k] !== 'function') { + if (k == 1) + $('#addPointName').parent().addClass('has-error'); + else + if (k == 2) { - $('.extraImage', '#addPointForm').addClass('has-error'); + $('.extraImage', '#addPointForm').addClass('has-error'); } - else - if (k == 3) - $('#addPointDescription').parent().addClass('has-error'); - else - message += response[k] + '; '; - } - } + else + if (k == 3) + $('#addPointDescription').parent().addClass('has-error'); + else + message += response[k] + '; '; + } + } - if (message != '') - alert(message); + if (message != '') + alert(message); - resetStatus(); - return false; - } - }); - } - else - { - alert ('Точка добавляется, нужно немного подождать.'); - } + resetStatus(); + return false; + } + }); + } + else + { + alert('Точка добавляется, нужно немного подождать.'); + } } /** @@ -460,16 +466,16 @@ function editPoint(id) $('').appendTo('#addPointForm').val(id); $('#addPointName').val(pointsSources[id].name); $('#addPointDescription').val(pointsSources[id].description); - $("#addPointCategoryId option" ).attr('selected', null); - $("#addPointCategoryId option[value='"+pointsSources[id].categoryId+"']" ).attr('selected', 'selected'); + $("#addPointCategoryId option").attr('selected', null); + $("#addPointCategoryId option[value='" + pointsSources[id].categoryId + "']").attr('selected', 'selected'); $('#addPointSource').val(pointsSources[id].source); $('#addPointLat').val(pointsSources[id].lat); $('#addPointLng').val(pointsSources[id].lng); - $('.extraImage','#imgsContainer').remove(); + $('.extraImage', '#imgsContainer').remove(); if (pointsSources[id].images != undefined && pointsSources[id].images.length > 0) { - for(var i=0; i < pointsSources[id].images.length; i++) + for (var i = 0; i < pointsSources[id].images.length; i++) { addNewImage(pointsSources[id].images[i]); } @@ -499,7 +505,7 @@ function setLayer(name) layer = name; myMap.addLayer(layers[layer]); $('.layers').removeClass('selected'); - $('.'+layer+'Layer').addClass('selected'); + $('.' + layer + 'Layer').addClass('selected'); $.cookie('mapLayer', layer); } @@ -512,11 +518,11 @@ function closePopup() function filter() { var selected = new Array(); - $('.filterSelector:checked').each(function(i, e){ + $('.filterSelector:checked').each(function (i, e) { selected.push($(e).val()); }); - for(var key in points) + for (var key in points) { if (selected.length == 0 || points[key].options.categoryId == undefined || selected.indexOf(points[key].options.categoryId) != -1) {