binda 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -29
  3. data/Rakefile +16 -10
  4. data/app/assets/javascripts/binda/components/form_item.js +12 -1
  5. data/app/assets/javascripts/binda/components/form_item_asset.js +1 -0
  6. data/app/assets/javascripts/binda/components/form_item_choice.js +58 -0
  7. data/app/assets/javascripts/binda/components/form_item_editor.js +39 -0
  8. data/app/assets/javascripts/binda/components/form_item_repeater.js +7 -0
  9. data/app/assets/javascripts/binda/components/sortable.js +0 -1
  10. data/app/assets/javascripts/binda/dist/binda.bundle.js +175 -8
  11. data/app/assets/javascripts/binda/index.js +4 -0
  12. data/app/assets/stylesheets/binda/components/form_item.scss +64 -2
  13. data/app/controllers/binda/application_controller.rb +2 -10
  14. data/app/controllers/binda/choices_controller.rb +19 -0
  15. data/app/controllers/binda/components_controller.rb +38 -134
  16. data/app/controllers/binda/field_groups_controller.rb +18 -30
  17. data/app/controllers/binda/structures_controller.rb +6 -6
  18. data/app/controllers/concerns/binda/component_controller_helper.rb +16 -0
  19. data/app/models/binda/checkbox.rb +7 -0
  20. data/app/models/binda/choice.rb +11 -0
  21. data/app/models/binda/component.rb +12 -136
  22. data/app/models/binda/field_group.rb +1 -1
  23. data/app/models/binda/field_setting.rb +40 -8
  24. data/app/models/binda/radio.rb +5 -0
  25. data/app/models/binda/repeater.rb +11 -79
  26. data/app/models/binda/select.rb +7 -0
  27. data/app/models/binda/structure.rb +13 -13
  28. data/app/models/concerns/binda/component_model_helper.rb +170 -0
  29. data/app/views/binda/components/_form_item_new_repeater.html.erb +3 -5
  30. data/app/views/binda/components/_form_item_selectable.html.erb +72 -0
  31. data/app/views/binda/components/_form_section.html.erb +7 -2
  32. data/app/views/binda/components/_form_section_repeater.html.erb +10 -0
  33. data/app/views/binda/field_groups/_form_item.html.erb +54 -26
  34. data/app/views/binda/field_groups/_form_item_choice.erb +96 -0
  35. data/app/views/binda/field_groups/_form_section.html.erb +2 -2
  36. data/app/views/binda/field_groups/_form_section_repeater.html.erb +2 -2
  37. data/config/locales/en.yml +7 -0
  38. data/config/routes.rb +2 -1
  39. data/db/migrate/1_create_binda_tables.rb +17 -0
  40. data/lib/binda/engine.rb +6 -0
  41. data/lib/binda/version.rb +1 -1
  42. data/lib/generators/binda/install/install_generator.rb +6 -8
  43. data/lib/generators/binda/setup/setup_generator.rb +8 -4
  44. metadata +66 -42
  45. data/app/controllers/binda/dates_controller.rb +0 -62
  46. data/app/controllers/binda/texts_controller.rb +0 -62
  47. data/app/views/binda/dates/_form.html.erb +0 -22
  48. data/app/views/binda/dates/edit.html.erb +0 -6
  49. data/app/views/binda/dates/index.html.erb +0 -27
  50. data/app/views/binda/dates/new.html.erb +0 -5
  51. data/app/views/binda/dates/show.html.erb +0 -9
  52. data/app/views/binda/repeaters/_form.html.erb +0 -27
  53. data/app/views/binda/repeaters/edit.html.erb +0 -6
  54. data/app/views/binda/repeaters/index.html.erb +0 -29
  55. data/app/views/binda/repeaters/new.html.erb +0 -5
  56. data/app/views/binda/repeaters/show.html.erb +0 -14
  57. data/app/views/binda/structures/add_child.html.erb +0 -0
  58. data/app/views/binda/texts/_form.html.erb +0 -22
  59. data/app/views/binda/texts/edit.html.erb +0 -6
  60. data/app/views/binda/texts/index.html.erb +0 -27
  61. data/app/views/binda/texts/new.html.erb +0 -5
  62. data/app/views/binda/texts/show.html.erb +0 -9
@@ -5,6 +5,8 @@
5
5
  import { _FormItem } from './components/form_item'
6
6
  import { _FormItemRepeater } from './components/form_item_repeater'
7
7
  import { _FormItemAsset } from './components/form_item_asset'
8
+ import { _FormItemChoice } from './components/form_item_choice'
9
+ import { _FormItemEditor } from './components/form_item_editor'
8
10
  import setupSortable from './components/sortable'
9
11
 
10
12
  $(document).ready( function()
@@ -12,5 +14,7 @@ $(document).ready( function()
12
14
  if ( _FormItem.isSet() ) { _FormItem.setEvents() }
13
15
  if ( _FormItemRepeater.isSet() ) { _FormItemRepeater.setEvents() }
14
16
  if ( _FormItemAsset.isSet() ) { _FormItemAsset.setEvents() }
17
+ if ( _FormItemChoice.isSet() ) { _FormItemChoice.setEvents() }
18
+ if ( _FormItemEditor.isSet() ) { _FormItemEditor.setEvents() }
15
19
  setupSortable()
16
20
  })
@@ -31,6 +31,27 @@
31
31
  }
32
32
  }
33
33
 
34
+ .form-item--half-size {
35
+ position: relative;
36
+ width: 46%;
37
+ margin-right: 4%;
38
+ float: left;
39
+
40
+ h5 {
41
+ width: 100%;
42
+ }
43
+
44
+ .form-item--select-input {
45
+ margin-left: 0;
46
+ }
47
+ }
48
+
49
+ .form-item--full-size {
50
+ position: relative;
51
+ width: 96%;
52
+ clear: both;
53
+ }
54
+
34
55
  .form-item--new {
35
56
  position: absolute;
36
57
  top: 101%;
@@ -81,13 +102,13 @@
81
102
  }
82
103
 
83
104
  .form-item--editor {
84
- max-height: 1000px;
105
+ // max-height: is set via javascript in app/assets/javscripts/components/form_item_editor.js;
85
106
  overflow-y: hidden;
86
107
  transition: max-height 0.6s ease-out;
87
108
  }
88
109
 
89
110
  .form-item--editor-close {
90
- max-height: 0;
111
+ max-height: 0 !important;
91
112
  }
92
113
 
93
114
  .form-item--label-on-top .form-group {
@@ -166,4 +187,45 @@
166
187
  .form-group {
167
188
  margin-bottom: $font-size-base;
168
189
  }
190
+ }
191
+
192
+ .form-item--choices {
193
+ position: relative;
194
+ }
195
+
196
+ .form-item--editor .form-item--choice {
197
+ position: relative;
198
+ clear: left;
199
+
200
+ &:last-child {
201
+ padding-bottom: $font-size-base/2;
202
+ border-bottom: 1px solid $gray-lighter;
203
+ margin-bottom: $font-size-base;
204
+ }
205
+ }
206
+
207
+ .form-item--new-choice {
208
+ display: none;
209
+ }
210
+
211
+ .form-item--choice-label,
212
+ .form-item--choice-content {
213
+ @extend .form-item--half-size;
214
+ }
215
+
216
+ .form-item--delete-choice,
217
+ .form-item--js-delete-choice {
218
+ position: absolute;
219
+ top: 32px;
220
+ right: 0;
221
+ }
222
+
223
+ .form-item--add-choice {
224
+ position: absolute;
225
+ top: 0;
226
+ right: 0;
227
+ }
228
+
229
+ .form-item--new-choice .form-item--delete-choice {
230
+ display: none;
169
231
  }
@@ -5,6 +5,8 @@ module Binda
5
5
 
6
6
  before_action :authenticate_user!
7
7
 
8
+ include ComponentControllerHelper
9
+
8
10
  # _ indicates that we are not using the argument in the method
9
11
  def after_sign_in_path_for(_)
10
12
  binda.dashboard_path
@@ -15,15 +17,5 @@ module Binda
15
17
  root_path
16
18
  end
17
19
 
18
- def get_components( slug, ask_for_published = true, custom_order = '' )
19
- if ask_for_published && custom_order.blank?
20
- Binda::Structure.friendly.find( slug ).components.published.order('position')
21
- elsif custom_order.blank?
22
- Binda::Structure.friendly.find( slug ).components.order('position')
23
- else
24
- Binda::Structure.friendly.find( slug ).components.order( custom_order )
25
- end
26
- end
27
-
28
20
  end
29
21
  end
@@ -0,0 +1,19 @@
1
+ require_dependency "binda/application_controller"
2
+
3
+ module Binda
4
+ class ChoicesController < ApplicationController
5
+
6
+ before_action :set_choice
7
+
8
+ def destroy
9
+ @choice.destroy
10
+ head :ok
11
+ end
12
+
13
+ private
14
+
15
+ def set_choice
16
+ @choice = Choice.find( params[:id] )
17
+ end
18
+ end
19
+ end
@@ -25,7 +25,7 @@ module Binda
25
25
  @component = @structure.components.build(component_params)
26
26
  @component.position = @position
27
27
  if @component.save
28
- redirect_to structure_component_path( @structure.slug, @component.slug ), notice: 'Component was successfully created.'
28
+ redirect_to structure_component_path( @structure.slug, @component.slug ), notice: "A #{ @component.name } was successfully created."
29
29
  else
30
30
  redirect_to new_structure_component_path( @structure.slug ), flash: { alert: @component.errors }
31
31
  end
@@ -33,7 +33,7 @@ module Binda
33
33
 
34
34
  def update
35
35
  if @component.update(component_params)
36
- redirect_to structure_component_path( @structure.slug, @component.slug ), notice: 'Component was successfully updated.'
36
+ redirect_to structure_component_path( @structure.slug, @component.slug ), notice: "A #{ @component.name } was successfully updated."
37
37
  else
38
38
  redirect_to edit_structure_component_path( @structure.slug, @component.slug ), flash: { alert: @component.errors }
39
39
  end
@@ -41,25 +41,26 @@ module Binda
41
41
 
42
42
  def destroy
43
43
  @component.destroy
44
- redirect_to structure_components_url( @structure.slug ), notice: 'Component was successfully destroyed.'
44
+ redirect_to structure_components_url( @structure.slug ), notice: "A #{ @component.name } was successfully destroyed."
45
45
  end
46
46
 
47
47
  def new_repeater
48
- # @repeater_setting = Binda::FieldSetting.find( '3' )
49
- @repeater_setting = Binda::FieldSetting.find( params[:repeater_setting_id] )
48
+ @repeater_setting = FieldSetting.find( params[:repeater_setting_id] )
49
+ position = @component.repeaters.find_all{|r| r.field_setting_id=@repeater_setting.id }.length + 1
50
+ @repeater = @component.repeaters.create( field_setting: @repeater_setting, position: position )
50
51
  render 'binda/components/_form_item_new_repeater', layout: false
51
52
  end
52
53
 
53
54
  def sort_repeaters
54
55
  params[:repeater].each_with_index do |id, i|
55
- Binda::Repeater.find( id ).update({ position: i + 1 })
56
+ Repeater.find( id ).update({ position: i + 1 })
56
57
  end
57
58
  head :ok
58
59
  end
59
60
 
60
61
  def sort
61
62
  params[:component].each_with_index do |id, i|
62
- Binda::Component.find( id ).update({ position: i + 1 })
63
+ Component.find( id ).update({ position: i + 1 })
63
64
  end
64
65
  head :ok
65
66
  end
@@ -81,137 +82,40 @@ module Binda
81
82
  # Only allow a trusted parameter "white list" through.
82
83
  def component_params
83
84
  params.require(:component).permit(
84
- :name,
85
- :slug,
86
- :position,
87
- :publish_state,
88
- :structure_id,
89
- :category_ids,
90
- structure_attributes: [
91
- :id
92
- ],
93
- categories_attributes: [
94
- :id,
95
- :category_id
96
- ],
97
- texts_attributes: [
98
- :id,
99
- :field_setting_id,
100
- :fieldable_type,
101
- :fieldable_id,
102
- :content
103
- ],
104
- assets_attributes: [
105
- :id,
106
- :field_setting_id,
107
- :fieldable_type,
108
- :fieldable_id,
109
- :image
110
- ],
111
- dates_attributes: [
112
- :id,
113
- :field_setting_id,
114
- :fieldable_type,
115
- :fieldable_id,
116
- :date
117
- ],
118
- galleries_attributes: [
119
- :id,
120
- :field_setting_id,
121
- :fieldable_type,
122
- :fieldable_id
123
- ],
124
- repeaters_attributes: [
125
- :id,
126
- :field_setting_id,
127
- :field_group_id,
128
- :fieldable_type,
129
- :fieldable_id,
130
- texts_attributes: [
131
- :id,
132
- :repeater_id,
133
- :field_setting_id,
134
- :fieldable_type,
135
- :fieldable_id,
136
- :content
137
- ],
138
- assets_attributes: [
139
- :id,
140
- :repeater_id,
141
- :field_setting_id,
142
- :fieldable_type,
143
- :fieldable_id,
144
- :image
145
- ],
146
- dates_attributes: [
147
- :id,
148
- :repeater_id,
149
- :field_setting_id,
150
- :fieldable_type,
151
- :fieldable_id,
152
- :date
153
- ],
154
- galleries_attributes: [
155
- :id,
156
- :repeater_id,
157
- :field_setting_id,
158
- :fieldable_type,
159
- :fieldable_id
160
- ],
161
- repeaters_attributes: [
162
- :id,
163
- :repeater_id,
164
- :field_setting_id,
165
- :field_group_id,
166
- :fieldable_type,
167
- :fieldable_id
168
- ]
169
- ])
85
+ :name, :slug, :position, :publish_state, :structure_id, :category_ids,
86
+ structure_attributes: [ :id ],
87
+ categories_attributes: [ :id, :category_id ],
88
+ texts_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :content ],
89
+ assets_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image ],
90
+ dates_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :date ],
91
+ galleries_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id ],
92
+ radios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :choice_ids ],
93
+ selects_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
94
+ checkboxes_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
95
+ repeaters_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :field_group_id,
96
+ texts_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
97
+ assets_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
98
+ dates_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
99
+ galleries_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id ],
100
+ repeaters_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :field_group_id ],
101
+ radios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :choice_ids ],
102
+ selects_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
103
+ checkboxes_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ]
104
+ ])
170
105
  end
171
106
 
172
107
  def repeater_params
173
108
  params.require(:repeater).permit(
174
- new_repeaters_attributes: [
175
- :id,
176
- :field_setting_id,
177
- :field_group_id,
178
- :fieldable_type,
179
- :fieldable_id,
180
- texts_attributes: [
181
- :id,
182
- :field_setting_id,
183
- :fieldable_type,
184
- :fieldable_id,
185
- :content
186
- ],
187
- assets_attributes: [
188
- :id,
189
- :field_setting_id,
190
- :fieldable_type,
191
- :fieldable_id,
192
- :image
193
- ],
194
- dates_attributes: [
195
- :id,
196
- :field_setting_id,
197
- :fieldable_type,
198
- :fieldable_id,
199
- :date
200
- ],
201
- galleries_attributes: [
202
- :id,
203
- :field_setting_id,
204
- :fieldable_type,
205
- :fieldable_id
206
- ],
207
- repeaters_attributes: [
208
- :id,
209
- :field_setting_id,
210
- :field_group_id,
211
- :fieldable_type,
212
- :fieldable_id
213
- ]
214
- ])
109
+ new_repeaters_attributes: [ :id, :field_setting_id, :field_group_id, :fieldable_type, :fieldable_id,
110
+ texts_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :content ],
111
+ assets_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image ],
112
+ dates_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :date ],
113
+ galleries_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id ],
114
+ repeaters_attributes: [ :id, :field_setting_id, :field_group_id, :fieldable_type, :fieldable_id ],
115
+ radios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :choice_ids ],
116
+ selects_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ],
117
+ checkboxes_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, choice_ids: [] ]
118
+ ])
215
119
  end
216
120
 
217
121
  def set_position
@@ -42,6 +42,18 @@ module Binda
42
42
  end
43
43
  end
44
44
 
45
+ # Create new fields if any
46
+ unless new_params[:new_choices].nil?
47
+ new_params[:new_choices].each do |choice|
48
+ unless choice[:label].blank? || choice[:value].blank?
49
+ new_choice = Choice.create( choice )
50
+ unless new_choice
51
+ return redirect_to edit_structure_field_group_path( @structure.slug, @field_group.slug ), flash: { error: new_choice.errors }
52
+ end
53
+ end
54
+ end
55
+ end
56
+
45
57
  # Update the other ones
46
58
  if @field_group.update(field_group_params)
47
59
  reset_field_settings_cache
@@ -70,44 +82,20 @@ module Binda
70
82
  # Only allow a trusted parameter "white list" through.
71
83
  def field_group_params
72
84
  params.require(:field_group).permit(
73
- :name,
74
- :slug,
75
- :description,
76
- :position,
77
- :layout,
78
- :structure_id,
79
- field_settings_attributes: [
80
- :id,
81
- :field_group_id,
82
- :field_setting_id,
83
- :name,
84
- :slug,
85
- :description,
86
- :field_type,
87
- :position,
88
- :required,
89
- :default_text,
90
- :ancestry
85
+ :name, :slug, :description, :position, :layout, :structure_id,
86
+ field_settings_attributes: [ :id, :field_group_id, :field_setting_id, :name, :slug, :description, :field_type, :position, :required, :default_text, :ancestry, choices: [], :default_choice_id_id, :allow_null,
87
+ choices_attributes: [ :field_setting_id, :label, :value ]
91
88
  ])
92
89
  end
93
90
 
94
91
  def new_params
95
92
  params.require(:field_group).permit(
96
- new_field_settings:[
97
- :field_group_id,
98
- :field_setting_id,
99
- :name,
100
- :slug,
101
- :description,
102
- :field_type,
103
- :position,
104
- :required,
105
- :ancestry
106
- ])
93
+ new_field_settings:[ :field_group_id, :field_setting_id, :name, :slug, :description, :field_type, :position, :required, :ancestry, choices: [], :default_choice_id, :allow_null ],
94
+ new_choices: [ :field_setting_id, :label, :value ])
107
95
  end
108
96
 
109
97
  def reset_field_settings_cache
110
- Binda::FieldSetting.reset_field_settings_array
98
+ FieldSetting.reset_field_settings_array
111
99
  end
112
100
 
113
101
  end
@@ -2,7 +2,7 @@ require_dependency "binda/application_controller"
2
2
 
3
3
  module Binda
4
4
  class StructuresController < ApplicationController
5
- before_action :set_structure, only: [:show, :edit, :update, :destroy]
5
+ before_action :set_structure, only: [:show, :edit, :update, :destroy, :fields_update ]
6
6
 
7
7
  def index
8
8
  @structures = Structure.order('position').all
@@ -30,7 +30,7 @@ module Binda
30
30
  return redirect_to structure_path( @structure.slug ), flash: { error: 'General Details group hasn\'t been created' }
31
31
  end
32
32
  # ... redirect to the new structure path
33
- redirect_to structure_path( @structure.slug ), notice: 'Structure was successfully created.'
33
+ redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name } structure was successfully created."
34
34
  else
35
35
  render :new
36
36
  end
@@ -49,7 +49,7 @@ module Binda
49
49
 
50
50
  # Update the other ones
51
51
  if @structure.update(structure_params)
52
- redirect_to structure_path( @structure.slug ), notice: 'Structure was successfully updated.'
52
+ redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name } structure was successfully updated."
53
53
  else
54
54
  render :edit
55
55
  end
@@ -57,16 +57,16 @@ module Binda
57
57
 
58
58
  def destroy
59
59
  @structure.destroy
60
- redirect_to structures_url, notice: 'Structure was successfully destroyed.'
60
+ redirect_to structures_url, notice: "#{ @structure.name } structure was successfully destroyed."
61
61
  end
62
62
 
63
63
  def fields_update
64
- redirect_to :back, notice: 'Components was successfully updated.'
64
+ redirect_to :back, notice: "#{ @structure.name } structure was successfully updated."
65
65
  end
66
66
 
67
67
  def sort
68
68
  params[:structure].each_with_index do |id, i|
69
- Binda::Structure.find( id ).update({ position: i + 1 })
69
+ Structure.find( id ).update({ position: i + 1 })
70
70
  end
71
71
  head :ok
72
72
  end