publicMethod('regionSuggest') ->publicMethod('ajax') ->seoTemplates(); } public function ajax() { $response = []; if (! User::admin()) { $this->errors->accessDenied(); return $this->ajaxResponseForm($response); } $action = $this->input->getpost('act', TYPE_STR); switch ($action) { /** * Список станций метро города * @param int $cityID ID города */ case 'city-metro': $cityID = $this->input->postget('city', TYPE_UINT); $data = $this->cityMetro($cityID, ['html' => true]); $response['html'] = $data['html']; break; case 'country-presuggest': $countryID = $this->input->postget('country', TYPE_UINT); $response = false; if ($countryID) { $response = $this->regionPreSuggest($countryID, ['json' => false]); } return $this->ajaxResponse($response); case 'district-options': $cityID = $this->input->postget('city', TYPE_UINT); $empty = $this->input->postget('empty', TYPE_NOTAGS); if (! $empty) { $empty = false; } $response['html'] = $this->districtOptions($cityID, 0, $empty); break; default: { $this->app->hook('geo.admin.ajax.default.action', $action, $this); } break; } return $this->ajaxResponseForm($response); } /** * Добавление инпута выбора города в форму select страна + autocomplete город * @param Form $form * @param string $name * @param array $opts * @return Form */ public function citySelectForm($form, $name = 'geo_city', array $opts = []) { $opts = $this->defaults($opts, [ 'title' => _t('@', 'City'), 'fieldNameCity' => $name, 'fieldNameCountry' => 'geo_region1', 'countryEmpty' => false, 'ac' => [], 'custom' => [], 'placeholder' => '', 'suggest' => [], ]); /** Параметры автокомплитера @see regionSuggest */ $opts['suggest'] = $this->defaults($opts['suggest'], [ 'reg' => false, 'country' => false, ]); $opts['form'] = $form; $this->template('admin/form.city.input', $opts); return $form; } /** * Добавление инпута ввода адреса и точки на карте в форму * @param $form * @param string $name * @param array $opts * @return Form */ public function mapAddrPointForm($form, $name = 'addr_addr', array $opts = []) { $opts = $this->defaults($opts, [ 'fieldName' => $name, 'fieldLatName' => 'addr_lat', 'fieldLonName' => 'addr_lon', 'title' => _t('@', 'Address'), 'default' => '', 'height' => '260px', 'lang' => false, ]); $opts['form'] = $form; $this->template('admin/form.map.input', $opts); return $form; } }