biovision-regions 0.1.180120 → 0.1.180213

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56e46f0c1c879478cd508c894658d3e4b0c530dc4a73007ab6261bbd5dab7d12
4
- data.tar.gz: fffd17eb6cb04b86a2438cea3fa951067213ec315eba598ec85aca62af0cc601
3
+ metadata.gz: 6f755fbc7eef074658f20b28e0bb0f96c243546d04d3657689ea70f7f16ef5ea
4
+ data.tar.gz: 14a3e6670be63ae9436316206d2115c1f41206c3ba87644124443036130a3239
5
5
  SHA512:
6
- metadata.gz: 4f45f1333cad9b829a4e0e687afcb36c112533eedf231d027210b9f7fd67104fcb2cb100712716af5a4942dfe4fcbc7c90fedfc633e7a105850e1b4bece17a57
7
- data.tar.gz: 005ae18487f205491ba677f7163fdd1d34d317c0ce8ed162e3ee0648026742aa2fd65ad2a33d78529bf853fe56f1cf35635136bea95665237d52be8a1b9882df
6
+ metadata.gz: 3967eb3a28a68d48129cbcdfb5c1854f119fc1f9811a2b56e3d8eadc1e699de74171f8a3d7dc8920dca022f1c2a43070b83f3d3f694b01a9568656f621d1f6b9
7
+ data.tar.gz: b4a4032f4fbf8b3041522d56378680a02ce1339f91a9666e03e309f699d24b1741f6077d6e381615b0af9f84fd9a350eb3fd22fa7145c7a293ca37e32c65c472
@@ -6,8 +6,12 @@ class RegionsController < AdminController
6
6
  def create
7
7
  @entity = Region.new(creation_parameters)
8
8
  if @entity.save
9
- cache_relatives
10
- redirect_to admin_region_path(@entity)
9
+ next_page = admin_region_path(@entity.id)
10
+ respond_to do |format|
11
+ format.html { redirect_to next_page }
12
+ format.json { render json: { links: { self: next_page } } }
13
+ format.js { render js: "document.location.href = '#{next_page}'" }
14
+ end
11
15
  else
12
16
  render :new, status: :bad_request
13
17
  end
@@ -20,8 +24,12 @@ class RegionsController < AdminController
20
24
  # patch /regions/:id
21
25
  def update
22
26
  if @entity.update(entity_parameters)
23
- cache_relatives
24
- redirect_to admin_region_path(@entity), notice: t('regions.update.success')
27
+ next_page = admin_region_path(@entity.id)
28
+ respond_to do |format|
29
+ format.html { redirect_to next_page, notice: t('regions.update.success') }
30
+ format.json { render json: { links: { self: next_page } } }
31
+ format.js { render js: "document.location.href = '#{next_page}'" }
32
+ end
25
33
  else
26
34
  render :edit, status: :bad_request
27
35
  end
@@ -61,13 +69,4 @@ class RegionsController < AdminController
61
69
  def creation_parameters
62
70
  params.require(:region).permit(Region.creation_parameters)
63
71
  end
64
-
65
- def cache_relatives
66
- @entity.cache_parents!
67
- unless @entity.parent.blank?
68
- parent = @entity.parent
69
- parent.cache_children!
70
- parent.save
71
- end
72
- end
73
72
  end
data/app/models/region.rb CHANGED
@@ -9,7 +9,7 @@ class Region < ApplicationRecord
9
9
 
10
10
  toggleable :visible
11
11
 
12
- belongs_ro :country, optional: true, counter_cache: true
12
+ belongs_to :country, optional: true, counter_cache: true
13
13
  belongs_to :parent, class_name: Region.to_s, optional: true, touch: true
14
14
  has_many :child_regions, class_name: Region.to_s, foreign_key: :parent_id
15
15
  has_many :users, dependent: :nullify
@@ -1,73 +1,122 @@
1
- <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
1
+ <%= form_with(model: entity, html: { id: 'region-form' }) do |f| %>
2
+ <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
2
3
 
3
- <%= form_for entity do |f| %>
4
- <dl>
5
- <dt><%= f.label :image %></dt>
6
- <dd>
7
- <figure class="preview" id="region-image">
8
- <% if entity.image.blank? %>
9
- <% image = image_tag('region_image.svg') %>
10
- <% else %>
11
- <% image = image_tag(entity.image.url) %>
12
- <% end %>
13
- <%= label_tag('region_image', image) %>
14
- <figcaption>
15
- <%= f.file_field :image, accept: 'image/jpeg,image/png', data: { image: 'region-image' } %>
16
- </figcaption>
17
- </figure>
18
- </dd>
19
- <dt><%= f.label :header_image %></dt>
20
- <dd>
21
- <figure class="preview" id="region-header-image">
22
- <% if entity.header_image.blank? %>
23
- <% header_image = image_tag('biovision/base/placeholders/image.svg') %>
24
- <% else %>
25
- <% header_image = image_tag(entity.header_image.medium.url) %>
26
- <% end %>
27
- <%= label_tag('region_header_image', header_image) %>
28
- <figcaption>
29
- <%= f.file_field :header_image, accept: 'image/jpeg,image/png', data: { image: 'region-header-image' } %>
30
- <div class="guideline"><%= t('.guidelines.header_image') %></div>
31
- </figcaption>
32
- </figure>
33
- </dd>
4
+ <dl>
5
+ <dt><%= f.label :image %></dt>
6
+ <dd>
7
+ <figure class="preview" id="region-image">
8
+ <% if entity.image.blank? %>
9
+ <% image = image_tag('biovision/regions/placeholders/region_image.svg') %>
10
+ <% else %>
11
+ <% image = image_tag(entity.image.url) %>
12
+ <% end %>
13
+ <%= label_tag('region_image', image) %>
14
+ <figcaption>
15
+ <%=
16
+ f.file_field(
17
+ :image,
18
+ id: :region_image,
19
+ accept: 'image/jpeg,image/png',
20
+ data: { image: 'region-image' }
21
+ )
22
+ %>
23
+ </figcaption>
24
+ </figure>
25
+ </dd>
26
+ <dt><%= f.label :header_image %></dt>
27
+ <dd>
28
+ <figure class="preview" id="region-header-image">
29
+ <% if entity.header_image.blank? %>
30
+ <% header_image = image_tag('biovision/base/placeholders/image.svg') %>
31
+ <% else %>
32
+ <% header_image = image_tag(entity.header_image.medium.url) %>
33
+ <% end %>
34
+ <%= label_tag('region_header_image', header_image) %>
35
+ <figcaption>
36
+ <%=
37
+ f.file_field(
38
+ :header_image,
39
+ id: :region_header_image,
40
+ accept: 'image/jpeg,image/png',
41
+ data: { image: 'region-header-image' }
42
+ )
43
+ %>
44
+ <div class="guideline"><%= t('.guidelines.header_image') %></div>
45
+ </figcaption>
46
+ </figure>
47
+ </dd>
34
48
 
35
- <dt><%= f.label :name %></dt>
36
- <dd>
37
- <%= f.text_field :name, required: true, size: nil, maxlength: Region::NAME_LIMIT %>
38
- </dd>
49
+ <dt><%= f.label :name %></dt>
50
+ <dd>
51
+ <%=
52
+ f.text_field(
53
+ :name,
54
+ id: :region_name,
55
+ required: true,
56
+ size: nil,
57
+ maxlength: Region::NAME_LIMIT
58
+ )
59
+ %>
60
+ </dd>
39
61
 
40
- <dt><%= f.label :short_name %></dt>
41
- <dd>
42
- <%= f.text_field :short_name, required: true, size: nil, maxlength: Region::NAME_LIMIT %>
43
- <div class="guideline">
44
- <%= t('.guidelines.short_name') %>
45
- </div>
46
- </dd>
62
+ <dt><%= f.label :short_name %></dt>
63
+ <dd>
64
+ <%=
65
+ f.text_field(
66
+ :short_name,
67
+ id: :region_short_name,
68
+ required: true,
69
+ size: nil,
70
+ maxlength: Region::NAME_LIMIT
71
+ )
72
+ %>
73
+ <div class="guideline">
74
+ <%= t('.guidelines.short_name') %>
75
+ </div>
76
+ </dd>
47
77
 
48
- <dt><%= f.label :locative %></dt>
49
- <dd>
50
- <%= f.text_field :locative, required: true, size: nil, maxlength: Region::NAME_LIMIT, placeholder: t('.placeholders.locative') %>
51
- <div class="guideline">
52
- <%= t('.guidelines.locative') %>
53
- </div>
54
- </dd>
78
+ <dt><%= f.label :locative %></dt>
79
+ <dd>
80
+ <%=
81
+ f.text_field(
82
+ :locative,
83
+ id: :region_locative,
84
+ required: true,
85
+ size: nil,
86
+ maxlength: Region::NAME_LIMIT,
87
+ placeholder: t('.placeholders.locative')
88
+ )
89
+ %>
90
+ <div class="guideline">
91
+ <%= t('.guidelines.locative') %>
92
+ </div>
93
+ </dd>
55
94
 
56
- <dt><%= f.label :slug %></dt>
57
- <dd>
58
- <%= f.text_field :slug, required: true, size: nil, maxlength: Region::SLUG_LIMIT %>
59
- <div class="guideline">
60
- <%= t('.guidelines.slug') %>
61
- </div>
62
- </dd>
63
- </dl>
95
+ <dt><%= f.label :slug %></dt>
96
+ <dd>
97
+ <%=
98
+ f.text_field(
99
+ :slug,
100
+ id: :region_slug,
101
+ required: true,
102
+ size: nil,
103
+ maxlength: Region::SLUG_LIMIT
104
+ )
105
+ %>
106
+ <div class="guideline">
107
+ <%= t('.guidelines.slug') %>
108
+ </div>
109
+ </dd>
110
+ </dl>
64
111
 
65
- <ul class="flags">
66
- <li><%= f.check_box :visible %><%= f.label :visible %></li>
67
- </ul>
112
+ <ul class="flags">
113
+ <li>
114
+ <%= f.check_box :visible, id: :region_visible %><%= f.label :visible %>
115
+ </li>
116
+ </ul>
68
117
 
69
- <div class="buttons">
70
- <%= f.hidden_field :parent_id if entity.id.nil? %>
71
- <%= f.button t(:save), type: :submit %>
72
- </div>
118
+ <div class="buttons">
119
+ <%= f.hidden_field :parent_id if entity.id.nil? %>
120
+ <%= f.button t(:save), type: :submit, class: 'button-save' %>
121
+ </div>
73
122
  <% end %>
@@ -0,0 +1 @@
1
+ <%= render partial: 'shared/forms/list_of_errors', locals: { entity: @entity, form_id: 'region-form' } %>
@@ -0,0 +1 @@
1
+ <%= render partial: 'shared/forms/list_of_errors', locals: { entity: @entity, form_id: 'region-form' } %>
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
- Biovision::Regions::Engine.routes.draw do
1
+ Rails.application.routes.draw do
2
2
 
3
3
  namespace :admin do
4
4
  resources :regions, only: [:index, :show] do
@@ -1,5 +1,5 @@
1
1
  module Biovision
2
2
  module Regions
3
- VERSION = '0.1.180120'
3
+ VERSION = '0.1.180213'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biovision-regions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.180120
4
+ version: 0.1.180213
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Khan-Magomedov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -202,7 +202,9 @@ files:
202
202
  - app/views/layouts/biovision/regions/application.html.erb
203
203
  - app/views/regions/_form.html.erb
204
204
  - app/views/regions/edit.html.erb
205
+ - app/views/regions/edit.js.erb
205
206
  - app/views/regions/new.html.erb
207
+ - app/views/regions/new.js.erb
206
208
  - config/locales/regions-en.yml
207
209
  - config/locales/regions-ru.yml
208
210
  - config/routes.rb