gaku 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/admin/app/assets/javascripts/gaku/admin/base.js.coffee +12 -1
  4. data/admin/app/controllers/gaku/admin/campuses/addresses_controller.rb +2 -0
  5. data/admin/app/controllers/gaku/admin/presets_controller.rb +18 -1
  6. data/admin/app/controllers/gaku/admin/states_list_controller.rb +20 -0
  7. data/admin/app/helpers/gaku/shared_helper.rb +14 -4
  8. data/admin/app/views/gaku/admin/campuses/addresses/_addresses.html.slim +1 -1
  9. data/admin/app/views/gaku/admin/campuses/addresses/_form_fields.html.slim +10 -11
  10. data/admin/app/views/gaku/admin/home/index.html.slim +4 -3
  11. data/admin/app/views/gaku/admin/presets/_address.html.slim +4 -2
  12. data/admin/app/views/gaku/admin/presets/_no_states_select.html.slim +1 -0
  13. data/admin/app/views/gaku/admin/presets/_states_select.html.slim +3 -0
  14. data/admin/app/views/gaku/admin/presets/edit.js.erb +7 -1
  15. data/admin/app/views/gaku/admin/presets/states_list.js.erb +5 -0
  16. data/admin/app/views/gaku/admin/states_list/_no_states_select.html.slim +4 -0
  17. data/admin/app/views/gaku/admin/states_list/_states_select.html.slim +3 -0
  18. data/admin/app/views/gaku/admin/states_list/index.js.erb +5 -0
  19. data/admin/config/routes.rb +5 -3
  20. data/admin/gaku_admin.gemspec +2 -2
  21. data/admin/lib/tasks/admin_user.rake +3 -2
  22. data/admin/spec/features/presets/address_preset_spec.rb +6 -6
  23. data/admin/spec/features/schools/campuses/addresses_spec.rb +3 -3
  24. data/common_gaku_dependencies.rb +1 -1
  25. data/core/app/controllers/gaku/core_controller.rb +3 -0
  26. data/core/app/models/gaku/country.rb +11 -1
  27. data/core/app/models/gaku/preset.rb +17 -0
  28. data/core/app/models/gaku/state.rb +14 -1
  29. data/core/db/default/gaku/countries.rb +14 -0
  30. data/core/db/default/gaku/presets.rb +1 -1
  31. data/core/db/default/gaku/states.rb +9 -0
  32. data/core/db/migrate/20150213095508_improve_countries_and_states.rb +5 -0
  33. data/core/gaku_core.gemspec +1 -0
  34. data/core/lib/gaku/core.rb +1 -0
  35. data/frontend/app/assets/javascripts/gaku/frontend/base.js.coffee +12 -1
  36. data/frontend/app/controllers/gaku/addresses_controller.rb +3 -2
  37. data/{admin/app/controllers/gaku/states_controller.rb → frontend/app/controllers/gaku/states_list_controller.rb} +6 -4
  38. data/frontend/app/views/gaku/addresses/_form_fields.html.slim +2 -3
  39. data/frontend/app/views/gaku/addresses/edit.js.erb +1 -1
  40. data/frontend/app/views/gaku/home/index.html.slim +1 -3
  41. data/frontend/app/views/gaku/states_list/_no_states_select.html.slim +4 -0
  42. data/frontend/app/views/gaku/states_list/_states_select.html.slim +3 -0
  43. data/frontend/app/views/gaku/states_list/index.js.erb +5 -0
  44. data/frontend/config/routes.rb +2 -0
  45. data/frontend/gaku_frontend.gemspec +2 -2
  46. data/sample/lib/shared_sample_data.rb +1 -1
  47. metadata +27 -23
  48. data/admin/app/views/gaku/states/_no_states_select.html.slim +0 -1
  49. data/admin/app/views/gaku/states/_states_select.html.slim +0 -1
  50. data/admin/app/views/gaku/states/index.js.erb +0 -5
  51. data/core/db/default/gaku/countries.yml +0 -1357
  52. data/core/db/default/gaku/states.yml +0 -494
  53. data/frontend/app/controllers/gaku/states_controller.rb +0 -17
  54. data/frontend/app/views/gaku/states/_no_states_select.html.slim +0 -1
  55. data/frontend/app/views/gaku/states/_states_select.html.slim +0 -1
  56. data/frontend/app/views/gaku/states/index.js.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61cd12f8ec08530ead7130e07f3a996328ce0223
4
- data.tar.gz: ea89a634dc8e7a644a71e21aae97d3c3e97d6645
3
+ metadata.gz: dbff8e8ff7cf34e1fe4acb9ecb46a37454abd4a2
4
+ data.tar.gz: f2e535cb9bddff0a65bbd344a34578f20a48ccbc
5
5
  SHA512:
6
- metadata.gz: cac9f742c3f0d4a76a5aa81a3b4386b96d30e08c1b0f904f67288828b872f1b75d449bf81155349dd2e21d2e0328111818c4dafe0b290b7bfb11efcf36117ce1
7
- data.tar.gz: 864492eb9bf19cc743dcb9638bef733789aee8d64fb7fbabc1cd2718d49399fd9062edf2b10d61c1c481d252a84a8c19f5522ba69d68512bff4eb06a75945e0d
6
+ metadata.gz: 524ce4dc1e52790b22fffb7e69f9543b4fcf3396a9e9ed4962ffb4683541c890680b9a8596b8f1997da566fe08180bc5cd909e2c362563967c39718bb31676c7
7
+ data.tar.gz: 64afc20707a2fa9b66264a67b2973f5756cb87a7b462e7abcd758fae3a161d154a25dafe9a05526c03b375e22eb0c40478f3849db8e3d2035ba37611d3f1e6d9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -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
+ }
@@ -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
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'sass-rails', '~> 5.0.0'
24
24
  s.add_dependency 'sass', '~> 3.2'
25
25
  s.add_dependency 'sprockets', '2.11.0'
26
- s.add_dependency 'slim', '2.0.0'
26
+ s.add_dependency 'slim', '~> 3.0'
27
27
  s.add_dependency 'responders', '~> 2.0'
28
28
 
29
29
  s.add_dependency 'rails4_client_side_validations', '~> 4.2'
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
 
37
37
  s.add_dependency 'jquery-rails', '~> 3.1'
38
38
  s.add_dependency 'jquery-ui-rails', '~> 4.2'
39
- s.add_dependency 'jquery-minicolors-rails', '2.1.1'
39
+ s.add_dependency 'jquery-minicolors-rails', '2.1.4'
40
40
  s.add_dependency 'bootstrap-sass', '3.1.1.0'
41
41
  s.add_dependency 'bootstrap-datepicker-rails', '~> 1.3.0.1'
42
42
  s.add_dependency 'nprogress-rails'
@@ -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"
@@ -17,20 +17,20 @@ describe 'Admin Presets Students' do
17
17
  end
18
18
 
19
19
  it 'saves', js: true do
20
- select country.name, from: 'preset_address_country'
21
- fill_in 'preset_address_state', with: state.name
20
+ select country.name, from: 'country_dropdown'
21
+ select state.name, from: 'preset_address_state'
22
22
  fill_in 'preset_address_city', with: 'Varna'
23
23
  click submit
24
24
 
25
25
  flash_updated?
26
26
  click '#admin-preset-address-tab-link'
27
- expect(find_field('preset_address_country').value).to eq country.name
28
- expect(find_field('preset_address_state').value).to eq state.name
27
+ expect(find_field('country_dropdown').value).to eq "#{country.id}"
28
+ expect(find_field('preset_address_state').value).to eq "#{state.id}"
29
29
  expect(find_field('preset_address_city').value).to eq 'Varna'
30
30
 
31
31
  preset.reload
32
- expect(preset['address']['country']). to eq country.name
33
- expect(preset['address']['state']). to eq state.name
32
+ expect(preset['address']['country']). to eq "#{country.id}"
33
+ expect(preset['address']['state']). to eq "#{state.id}"
34
34
  expect(preset['address']['city']). to eq 'Varna'
35
35
  end
36
36
 
@@ -7,7 +7,7 @@ describe 'Admin School Campuses Address' do
7
7
 
8
8
  let!(:country) { create(:country, name: 'USA', iso: 'US') }
9
9
  let(:country_without_state) { create(:country, name: 'Japan', iso: 'JP') }
10
- let!(:state) { create(:state, name: 'Florida', country: country) }
10
+ let!(:state) { create(:state, name: 'Florida', abbr: 'FL', country: country) }
11
11
 
12
12
  before(:all) { set_resource 'admin-school-campus-address' }
13
13
  before { as :admin }
@@ -47,7 +47,7 @@ describe 'Admin School Campuses Address' do
47
47
  it 'changes country without state' do
48
48
  select "#{country_without_state}", from: 'country_dropdown'
49
49
  within('#state-dropdown') do
50
- expect(page).to have_css('select#address_state_id[disabled]')
50
+ expect(page).to have_css('select#address_state_id', visible: false)
51
51
  has_no_content? state.name
52
52
  end
53
53
  end
@@ -98,7 +98,7 @@ describe 'Admin School Campuses Address' do
98
98
  it 'changes country without state' do
99
99
  select "#{country_without_state}", from: 'country_dropdown'
100
100
  within('#state-dropdown') do
101
- expect(page).to have_css('select#address_state_id[disabled]')
101
+ expect(page).to have_css('select#address_state_id', visible: false)
102
102
  has_no_content? state.name
103
103
  end
104
104
  end
@@ -1,6 +1,6 @@
1
1
  group :test do
2
2
  gem 'capybara', '~> 2.4'
3
- gem 'selenium-webdriver', '2.43'
3
+ gem 'selenium-webdriver', '2.45'
4
4
  gem 'poltergeist'
5
5
  gem 'launchy'
6
6
  gem 'handy_controller_helpers', '0.0.3'
@@ -34,12 +34,15 @@ module Gaku
34
34
  def set_locale
35
35
  if current_user && params[:locale]
36
36
  I18n.locale = params[:locale]
37
+ Carmen.i18n_backend.locale = I18n.locale
37
38
  current_user.settings[:locale] = params[:locale]
38
39
  notice = "Language is set to #{t('languages.' + current_user.locale)}"
39
40
  flash[:notice] = notice if current_user.save
40
41
  elsif current_user
41
42
  I18n.locale = current_user.settings[:locale]
43
+ Carmen.i18n_backend.locale = I18n.locale
42
44
  else
45
+ Carmen.i18n_backend.locale = I18n.default_locale
43
46
  I18n.default_locale
44
47
  end
45
48
  end
@@ -14,7 +14,17 @@ module Gaku
14
14
  end
15
15
 
16
16
  def to_s
17
- name
17
+ i18n_name
18
18
  end
19
+
20
+ def i18n_name
21
+ carmen_country = Carmen::Country.coded(iso)
22
+ if carmen_country
23
+ carmen_country.name
24
+ else
25
+ name
26
+ end
27
+ end
28
+
19
29
  end
20
30
  end
@@ -44,5 +44,22 @@ module Gaku
44
44
  active.address[key.to_s] unless active.nil?
45
45
  end
46
46
 
47
+ def self.state
48
+ if active
49
+ State.find(active.address['state'])
50
+ else
51
+ State.first
52
+ end
53
+ end
54
+
55
+ def self.country
56
+ if active
57
+ Country.find(active.address['country'])
58
+ else
59
+ Country.first
60
+ end
61
+ end
62
+
63
+
47
64
  end
48
65
  end
@@ -1,5 +1,8 @@
1
1
  module Gaku
2
2
  class State < ActiveRecord::Base
3
+
4
+ default_scope { order(:abbr) }
5
+
3
6
  has_many :addresses
4
7
 
5
8
  belongs_to :country, foreign_key: :country_iso, primary_key: :iso
@@ -26,7 +29,17 @@ module Gaku
26
29
  end
27
30
 
28
31
  def to_s
29
- name
32
+ i18n_name
33
+ end
34
+
35
+ def i18n_name
36
+ carmen_country = Carmen::Country.coded(country_iso)
37
+ if carmen_country && carmen_country.subregions? && carmen_country.subregions.coded(abbr)
38
+ carmen_country.subregions.coded(abbr).name
39
+ else
40
+ name
41
+ end
30
42
  end
43
+
31
44
  end
32
45
  end