vojtasvoboda/oc-locationtowns-plugin

Adds towns to states managed by RainLab.Location plugin.

1.0.8 2019-07-28 10:44 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:29:01 UTC


README

Codacy Scrutinizer Coverage License

Adds towns to states managed by RainLab.Location plugin. Included:

  • component for state towns with pagination
  • component for Town detail
  • hooks for RainLab.Sitemap
  • extends RainLab State model

Required plugins: RainLab.Location.

Tested with the latest stable OctoberCMS build 349.

Render Town detail

This component render town detail. Just create page Town-detail with slug /town-detail/:slug? and insert Town component:

Town component

To override Town detail template just create partial file /town/default.htm as copy of /plugins/vojtasvoboda/components/town/default.htm and make own changes.

Render list of Towns

Create page Towns with slug /towns/:page? where page means paginating. Insert component Towns. Set filter for State and select page for show Town detail created above:

Towns component

To override Towns listing template just create partial file /towns/default.htm as copy of /plugins/vojtasvoboda/components/towns/default.htm and make own changes.

Add towns to sitemap

Just install RainLab.Sitemap plugin and insert one town or all towns to sitemap:

Towns in sitemap

Front-end usage

Following example from Location plugin this plugin just adds form_select_town function:

{% set countryId = countryId|default(form_value('country_id')) %}
{% set stateId = stateId|default(form_value('state_id')) %}
{% set townId = townId|default(form_value('town_id')) %}

{{ form_open() }}
    <div class="form-group">
        <label for="accountCountry">Country</label>
        {{ form_select_country('country_id', countryId, {
            id: 'accountCountry',
            class: 'form-control',
            emptyOption: '',
            'data-request': 'onInit',
            'data-request-update': {
                'country-state': '#partialCountryState'
            }
        }) }}
    </div>

    <div class="form-group">
        <label for="accountState">State</label>
        {{ form_select_state('state_id', countryId, stateId, {
            id: 'accountState',
            class: 'form-control',
            emptyOption: '',
            'data-request': 'onInit',
            'data-request-update': {
                'country-state': '#partialCountryState'
            }
        }) }}
    </div>

    <div class="form-group">
        <label for="accountTown">Town</label>
        {{ form_select_town('town_id', stateId, townId, {
            id: 'accountTown',
            class: 'form-control',
            emptyOption: ''
        }) }}
    </div>
{{ form_close() }}

Services

List of available services provided by plugin:

locationtowns service

$towns = App::make('locationstowns');
$town = $towns->findOneBySlug('praha');
$allTowns = $towns->all();
$townsByState = $towns->where('state_id', 285)->get();

RainLab State extension

$state = \RainLab\Location\Models\State::find('285');
$towns = $state->towns;

TODO

  • !!fix fixed URL path at Town:114 and Town:129 (there should by path set in component)
  • !filter only by active states in towns component
  • directly extend RainLab.Location.State form to manage towns related to this state
  • run plugin without RainLab.Location (only town management)
  • add select box 'country' to backend listing for filtrating states
  • it is not possible to do october:down
  • add import and export

Feel free to send pullrequest!

Contributing

Please send Pull Request to master branch.

License

LocationTown plugin is open-sourced software licensed under the MIT license same as OctoberCMS platform.