gaku_admin 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfc13aa94367abe90c9dff56822a0bb3679a700b
4
- data.tar.gz: 5d2470d7ac12e331a6ee8b809c725ed22d6dfa0c
3
+ metadata.gz: 68a91086d9239dce0c9fc7b7d447a8a0efe811a0
4
+ data.tar.gz: a187e85465e95f439cb4d59e62d0f9f1f64511ae
5
5
  SHA512:
6
- metadata.gz: 1b504e45510d0c2d47759e15767b66a40c27af1c77a37252b0a0587adbb8b442abaa035a25087067d382d5c9a994933f8b27ccfed03070af5d36adf274da5373
7
- data.tar.gz: 38480571f8f6fc25119ad423470d35e9f91b7de015d0c0ca72dde9175b017b21486ac5f6f7d88e01d2f8ef3e62956c316731afa8d84baaeef287e945cd83aeb7
6
+ metadata.gz: 839e571029c93ba58e9b6dff85ee06bf903301149b84675940db5fe0d131f38baa45b544f036d0e3e04c50bed4172a2fe90ca5ff2fb2748308288b598d91b52e
7
+ data.tar.gz: 143effde0a02eb8f387f06d3ea49b5c32f4087e1d21c4d62b70ad32219211a3746fe554746ca08a781f085df88e62aa4f24dcddf164cc2d7cd9b3acc287c0600
@@ -26,12 +26,23 @@ $.fn.datepicker_i18n = ->
26
26
 
27
27
  $.fn.datepicker.defaults.format = "yyyy-mm-dd"
28
28
 
29
+ window.load_preset_states = (preset_id)->
30
+ countryCode = $("#country_dropdown option:selected").val()
31
+ if countryCode
32
+ $.ajax
33
+ type: 'get'
34
+ url: '/admin/presets/states_list'
35
+ dataType: 'script'
36
+ data:
37
+ country_id: countryCode
38
+ preset_id: preset_id
39
+
29
40
  window.load_states = ->
30
41
  countryCode = $("#country_dropdown option:selected").val()
31
42
  if countryCode
32
43
  $.ajax
33
44
  type: 'get'
34
- url: '/states'
45
+ url: '/admin/states_list'
35
46
  dataType: 'script'
36
47
  data:
37
48
  country_id: countryCode
@@ -13,6 +13,8 @@ module Gaku
13
13
  end
14
14
 
15
15
  def new
16
+ @default_country = Preset.country
17
+ @default_state = Preset.state
16
18
  @address = Address.new
17
19
  respond_with @address
18
20
  end
@@ -2,7 +2,7 @@ module Gaku
2
2
  class Admin::PresetsController < Admin::BaseController
3
3
 
4
4
  respond_to :js, only: %i( index edit update )
5
- before_action :set_preset, except: :index
5
+ before_action :set_preset, except: %i( index states_list )
6
6
 
7
7
  def index
8
8
  @presets = Preset.all
@@ -13,6 +13,8 @@ module Gaku
13
13
  def edit
14
14
  @per_page_values = [10, 25, 50, 100]
15
15
  @countries = Country.all
16
+ @country = @preset['address']['country'] ? Country.find(@preset['address']['country']) : Country.first
17
+ @state = @preset['address']['state'] ? State.find(@preset['address']['state']) : nil
16
18
  end
17
19
 
18
20
  def update
@@ -20,6 +22,21 @@ module Gaku
20
22
  respond_with @preset, location: [:edit, :admin, @preset]
21
23
  end
22
24
 
25
+ def states_list
26
+ if params[:country_id]
27
+ @country = Country.find(params[:country_id])
28
+
29
+ if params[:preset_id]
30
+ @preset = Preset.find(params[:preset_id])
31
+ @state = @preset['address']['state'] ? State.find(@preset['address']['state']) : nil
32
+ end
33
+
34
+ @states = State.where(country_iso: @country.iso)
35
+ else
36
+ @states = State.all
37
+ end
38
+ end
39
+
23
40
  private
24
41
 
25
42
  def preset_params
@@ -0,0 +1,20 @@
1
+ module Gaku
2
+ module Admin
3
+ class StatesListController < Admin::BaseController
4
+
5
+ respond_to :js, :json
6
+
7
+ def index
8
+ if params[:country_id]
9
+ @country = Country.find(params[:country_id])
10
+
11
+ @states = State.where(country_iso: @country.iso).order('name asc')
12
+ @state = Preset.state
13
+ else
14
+ @states = State.all
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -9,12 +9,22 @@ module Gaku
9
9
  { t(:'gender.female') => false, t(:'gender.male') => true }
10
10
  end
11
11
 
12
- def state_load(object)
13
- object.country.nil? ? Gaku::State.none : object.country.states
12
+ def state_load(country_preset)
13
+ country = Gaku::Country.find_by(iso: country_preset)
14
+ if country
15
+ country.states
16
+ else
17
+ Gaku::State.none
18
+ end
14
19
  end
15
20
 
16
- def disabled?(object)
17
- object.new_record? || object.country.states.blank?
21
+ def disabled?(country_preset)
22
+ country = Gaku::Country.find_by(iso: country_preset)
23
+ if country
24
+ country.states_required
25
+ else
26
+ true
27
+ end
18
28
  end
19
29
 
20
30
  def render_flash
@@ -13,8 +13,8 @@
13
13
  tr
14
14
  = th t(:'address.title')
15
15
  = th t(:'address.country')
16
+ = th t(:'address.state.singular')
16
17
  = th t(:'address.zipcode')
17
- = th t(:'address.state')
18
18
  = th t(:'address.city')
19
19
  = th t(:'address.address1')
20
20
  = th t(:'address.address2')
@@ -3,23 +3,22 @@
3
3
  = f.text_field :title, label: t(:'address.title')
4
4
 
5
5
  .row
6
- .col-md-3
7
- = f.select :country_id, options_from_collection_for_select(@countries, :id, :name) , { prompt: t(:'address.choose_country'), selected: f.object.country_id || Gaku::Preset.address('country') }, id: "country_dropdown", label: t(:'address.country')
8
- .col-md-3
6
+ .col-md-4
7
+ = f.select :country_id, options_from_collection_for_select(@countries, :id, :i18n_name, (f.object.country_id || @default_country.try(:id))) , { prompt: t(:'address.choose_country') }, { id: "country_dropdown", label: t(:'address.country') }
8
+ .col-md-4
9
9
  #state-dropdown
10
- = f.collection_select :state_id, state_load(f.object), :id, :name, { prompt: t(:'address.state.choose')} , disabled: disabled?(f.object), label: t(:'address.state')
11
-
12
- .col-md-3
10
+ = f.select :state_id, options_from_collection_for_select(state_load(f.object), :id, :i18n_name, (f.object.state_id || @default_state.try(:id))), { prompt: t(:'address.state.choose') }, { class: 'form-control', disabled: disabled?(f.object), label: t(:'address.state.singular') }
11
+ .col-md-4
12
+ = f.object.state_id || @default_state.try(:id)
13
+ / = f.object.to_json
13
14
  = f.text_field :zipcode, label: t(:'address.zipcode')
14
- .col-md-3
15
- button.col-md-12.btn.btn-primary = t(:'address.search')
16
15
 
17
16
  .row
18
- .col-md-3
17
+ .col-md-4
19
18
  = f.text_field :city, value: f.object.city || Gaku::Preset.address('city'), label: t(:'address.city')
20
- .col-md-3
19
+ .col-md-4
21
20
  = f.text_field :address1, label: t(:'address.address1')
22
- .col-md-3
21
+ .col-md-4
23
22
  = f.text_field :address2, label: t(:'address.address2')
24
23
 
25
24
  javascript:
@@ -1,5 +1,6 @@
1
1
  .row
2
- .col-md-2
3
- .panel-group#accordion
2
+ .panel-group#accordion
3
+ .col-md-2
4
4
  = render 'gaku/shared/menu/admin_menu'
5
- .col-md-10#ajax-load
5
+
6
+ .col-md-10.pull-right#ajax-load
@@ -4,12 +4,14 @@
4
4
  .col-md-4
5
5
  = f.fields_for :address do |a|
6
6
  = a.label t(:'preset.address.country')
7
- = a.select :country, @countries, {selected: @preset['address']['country'], prompt: t(:'address.choose_country')}, { class: 'form-control' }
7
+ = a.select :country, options_from_collection_for_select(@countries, :id, :i18n_name, @country.try(:id)) , { prompt: t(:'address.choose_country') }, { id: "country_dropdown", class: 'form-control', label: t(:'address.country') }
8
8
 
9
9
  .col-md-4
10
10
  = f.fields_for :address do |a|
11
11
  = a.label t(:'preset.address.state')
12
- = a.text_field :state, value: @preset['address']['state'], class: 'form-control'
12
+ #state-dropdown
13
+ = a.select :state, options_from_collection_for_select(state_load(@preset['address']['country']), :id, :i18n_name, @state.try(:id)), { prompt: t(:'address.state.choose') }, { class: 'form-control', disabled: disabled?(a.object), label: t(:'address.state') }
14
+
13
15
 
14
16
  .col-md-4
15
17
  = f.fields_for :address do |a|
@@ -0,0 +1 @@
1
+ = collection_select(:address, :state, states, :id, :name, {prompt: t(:'address.state.choose') }, disabled: true, class: 'span12 form-control')
@@ -0,0 +1,3 @@
1
+ = fields_for :preset do |f|
2
+ = f.fields_for :address do |a|
3
+ = a.select :state, options_from_collection_for_select(states, :id, :name, state.try(:id)), { prompt: t(:'address.state.choose') }, { class: 'form-control', label: t(:'address.state') }
@@ -1 +1,7 @@
1
- $('#ajax-load').html('<%=j render "tabs" %>')
1
+ $('#ajax-load').html('<%=j render "tabs" %>');
2
+
3
+ $('body').on('change', '#country_dropdown', function() {
4
+ return load_preset_states(<%= @preset.id %>);
5
+ });
6
+
7
+ load_preset_states(<%= @preset.id %>);
@@ -0,0 +1,5 @@
1
+ if(<%= @states.count %> > 0 ) {
2
+ $('#state-dropdown').html("<%=j render 'states_select', states: @states, state: @state %>");
3
+ } else {
4
+ $('#state-dropdown').html("<%=j render 'no_states_select', states: @states %>");
5
+ }
@@ -0,0 +1,4 @@
1
+ = fields_for :address do |a|
2
+ = a.label :state_id, t(:'address.state.singular')
3
+ = a.select :state_id, options_from_collection_for_select(states, :id, :i18n_name), { prompt: t(:'address.state.choose') }, disabled: true, class: 'form-control'
4
+
@@ -0,0 +1,3 @@
1
+ = fields_for :address do |a|
2
+ = a.label :state_id, t(:'address.state.singular')
3
+ = a.select :state_id, options_from_collection_for_select(states, :id, :i18n_name, state.try(:id)), { prompt: t(:'address.state.choose') }, { class: 'form-control' }
@@ -0,0 +1,5 @@
1
+ if(<%= @states.count %> > 0 ) {
2
+ $('#state-dropdown').html("<%=j render 'states_select', states: @states, state: @state %>");
3
+ } else {
4
+ $('#state-dropdown').html("<%=j render 'no_states_select', states: @states %>");
5
+ }
data/config/routes.rb CHANGED
@@ -17,11 +17,11 @@ Gaku::Core::Engine.routes.draw do
17
17
  end
18
18
  end
19
19
 
20
- resources :states, only: :index
21
-
22
20
  namespace :admin do
23
21
  root to: 'home#index'
24
22
 
23
+ resources :states_list, only: :index
24
+
25
25
  get 'school_details', to: 'schools#show_master'
26
26
  get 'school_details/edit', to: 'schools#edit_master'
27
27
  patch 'school_details/update', to: 'schools#update_master'
@@ -71,7 +71,9 @@ Gaku::Core::Engine.routes.draw do
71
71
  resources :semesters, controller: 'school_years/semesters', except: %i( show )
72
72
  end
73
73
 
74
- resources :presets
74
+ resources :presets do
75
+ get :states_list, on: :collection
76
+ end
75
77
 
76
78
  end
77
79
  end
@@ -91,10 +91,11 @@ def create_admin_user
91
91
  say "\nWARNING: There is already a user with the username: #{username}, so no account changes were made. If you wish to create an additional admin user, please run rake gaku:generate_admin again with a different username.\n\n"
92
92
  else
93
93
  say "Creating user..."
94
- creator = Gaku::UserCreator.new(attributes).save
94
+ creator = Gaku::UserCreator.new(attributes)
95
+ creator.save
95
96
  admin = creator.get_user
96
97
  # create an admin role and and assign the admin user to that role
97
- role = Gaku::Role.find_or_create_by_name 'Admin'
98
+ role = Gaku::Role.where(name: 'Admin').first_or_initialize
98
99
  admin.roles << role
99
100
  if admin.save
100
101
  say "User Created"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaku_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei Kagetsuki
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-02-23 00:00:00.000000000 Z
14
+ date: 2015-03-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gaku_core
@@ -19,28 +19,28 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.2.2
22
+ version: 0.2.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.2.2
29
+ version: 0.2.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: gaku_testing
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 0.2.2
36
+ version: 0.2.3
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.2.2
43
+ version: 0.2.3
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: coffee-rails
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -101,16 +101,16 @@ dependencies:
101
101
  name: slim
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '='
104
+ - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: 2.0.0
106
+ version: '3.0'
107
107
  type: :runtime
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '='
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: 2.0.0
113
+ version: '3.0'
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: responders
116
116
  requirement: !ruby/object:Gem::Requirement
@@ -229,14 +229,14 @@ dependencies:
229
229
  requirements:
230
230
  - - '='
231
231
  - !ruby/object:Gem::Version
232
- version: 2.1.1
232
+ version: 2.1.4
233
233
  type: :runtime
234
234
  prerelease: false
235
235
  version_requirements: !ruby/object:Gem::Requirement
236
236
  requirements:
237
237
  - - '='
238
238
  - !ruby/object:Gem::Version
239
- version: 2.1.1
239
+ version: 2.1.4
240
240
  - !ruby/object:Gem::Dependency
241
241
  name: bootstrap-sass
242
242
  requirement: !ruby/object:Gem::Requirement
@@ -364,11 +364,11 @@ files:
364
364
  - app/controllers/gaku/admin/simple_grade_types_controller.rb
365
365
  - app/controllers/gaku/admin/specialties_controller.rb
366
366
  - app/controllers/gaku/admin/states_controller.rb
367
+ - app/controllers/gaku/admin/states_list_controller.rb
367
368
  - app/controllers/gaku/admin/student_review_categories_controller.rb
368
369
  - app/controllers/gaku/admin/system_tools_controller.rb
369
370
  - app/controllers/gaku/admin/templates_controller.rb
370
371
  - app/controllers/gaku/admin/users_controller.rb
371
- - app/controllers/gaku/states_controller.rb
372
372
  - app/helpers/gaku/admin_helper.rb
373
373
  - app/helpers/gaku/presets_helper.rb
374
374
  - app/helpers/gaku/shared_helper.rb
@@ -534,15 +534,18 @@ files:
534
534
  - app/views/gaku/admin/presets/_grading.html.slim
535
535
  - app/views/gaku/admin/presets/_locale.html.slim
536
536
  - app/views/gaku/admin/presets/_names_order.html.slim
537
+ - app/views/gaku/admin/presets/_no_states_select.html.slim
537
538
  - app/views/gaku/admin/presets/_pagination.html.slim
538
539
  - app/views/gaku/admin/presets/_person.html.slim
539
540
  - app/views/gaku/admin/presets/_preset.html.slim
540
541
  - app/views/gaku/admin/presets/_presets.html.slim
542
+ - app/views/gaku/admin/presets/_states_select.html.slim
541
543
  - app/views/gaku/admin/presets/_student.html.slim
542
544
  - app/views/gaku/admin/presets/_tabs.html.slim
543
545
  - app/views/gaku/admin/presets/edit.html.slim
544
546
  - app/views/gaku/admin/presets/edit.js.erb
545
547
  - app/views/gaku/admin/presets/index.js.erb
548
+ - app/views/gaku/admin/presets/states_list.js.erb
546
549
  - app/views/gaku/admin/presets/update.js.erb
547
550
  - app/views/gaku/admin/roles/_fields.html.slim
548
551
  - app/views/gaku/admin/roles/_form.html.slim
@@ -666,6 +669,9 @@ files:
666
669
  - app/views/gaku/admin/states/index.js.erb
667
670
  - app/views/gaku/admin/states/new.js.erb
668
671
  - app/views/gaku/admin/states/update.js.erb
672
+ - app/views/gaku/admin/states_list/_no_states_select.html.slim
673
+ - app/views/gaku/admin/states_list/_states_select.html.slim
674
+ - app/views/gaku/admin/states_list/index.js.erb
669
675
  - app/views/gaku/admin/student_review_categories/_form.html.slim
670
676
  - app/views/gaku/admin/student_review_categories/_form_fields.html.slim
671
677
  - app/views/gaku/admin/student_review_categories/_modal.html.slim
@@ -724,9 +730,6 @@ files:
724
730
  - app/views/gaku/shared/menu/_admin_menu.html.erb
725
731
  - app/views/gaku/shared/multi_error.js.erb
726
732
  - app/views/gaku/shared/notice.js.erb
727
- - app/views/gaku/states/_no_states_select.html.slim
728
- - app/views/gaku/states/_states_select.html.slim
729
- - app/views/gaku/states/index.js.erb
730
733
  - config/initializers/wrap_parameters.rb
731
734
  - config/routes.rb
732
735
  - lib/gaku/admin.rb
@@ -1,19 +0,0 @@
1
- module Gaku
2
- class StatesController < CoreController
3
-
4
- respond_to :js, :json
5
-
6
- def index
7
- if params[:country_id]
8
- @country = Country.find(params[:country_id])
9
- @states = State.where(country_iso: @country.iso)
10
- .order('name asc')
11
- else
12
- @states = State.all
13
- end
14
-
15
- respond_with @states
16
- end
17
-
18
- end
19
- end
@@ -1 +0,0 @@
1
- = collection_select(:address, :state_id, states, :id, :name, {prompt: t(:'address.state.choose') }, disabled: true, class: 'span12')
@@ -1 +0,0 @@
1
- = collection_select(:address, :state_id, states, :id, :name, {prompt: t(:'address.state.choose') }, class: 'span12')
@@ -1,5 +0,0 @@
1
- if(<%= @states.count %> > 0 ){
2
- $('#state-dropdown .controls').html("<%=j render 'states_select', states: @states%>")
3
- }else{
4
- $('#state-dropdown .controls').html("<%=j render 'no_states_select', states: @states%>")
5
- }