Commit 0bd528ea5048ca47d77cdf01ca389c2f1e004eac

Authored by Karpikau Andrei
1 parent 7c47a085

add alternative domain

... ... @@ -2136,6 +2136,17 @@ jQuery(document).ready(function(){
2136 2136 });
2137 2137
2138 2138
  2139 + $('.default-lang-checkbox').on('change', function(){
  2140 + var $this = $(this),
  2141 + $wrapper = $this.closest('.form-group').next();
  2142 + if($this.is(':checked')){
  2143 + $wrapper.addClass('not-visible');
  2144 + }else{
  2145 + $wrapper.removeClass('not-visible');
  2146 + }
  2147 + });
  2148 +
  2149 +
2139 2150
2140 2151 });
2141 2152
... ...
... ... @@ -4,7 +4,7 @@ module Kanjai
4 4
5 5 #protect_from_forgery
6 6
7   - before_action :define_locale
  7 + #before_action :define_locale
8 8 before_action :get_page
9 9
10 10 include Kanjai::ContentFunction
... ... @@ -20,7 +20,7 @@ module Kanjai
20 20
21 21 end
22 22
23   -
  23 +=begin
24 24 def define_locale
25 25 if params && params[:locale].present? && request.original_fullpath.split('/')[1].length == 2
26 26 I18n.locale = params[:locale]
... ... @@ -30,7 +30,7 @@ module Kanjai
30 30 I18n.locale = Rails.application.config.i18n.default_locale
31 31 end
32 32 end
33   -
  33 +=end
34 34
35 35 def get_page
36 36 @url = get_page_url
... ... @@ -38,16 +38,36 @@ module Kanjai
38 38 $original_format = request.format
39 39
40 40 domain_title = request.domain
41   - if request.subdomain
  41 + if request.subdomain.to_s.present?
42 42 domain_title = "#{request.subdomain}.#{domain_title}"
43 43 end
44 44
45 45 $domain = Domain.where(title: domain_title).first
46 46
  47 + lang = nil
  48 +
47 49 if $domain.nil?
48   - render plain: "Domain #{domain_title} Not Exist" and return
  50 + # try found alternative domain
  51 + lang_domain = LanguageDomain.joins(:page_langs).where(title: domain_title, kanjai_page_langs: {default_use: false}).first
  52 + if lang_domain && lang_domain.page_langs.count > 0
  53 + $domain = lang_domain.domain
  54 + lang = lang_domain.page_langs.where(default_use: false).first.code
  55 + else
  56 + render plain: "Domain #{domain_title} Not Exist" and return
  57 + end
  58 + else
  59 + lang = $domain.page_langs.where(default_use: true).first.try(:code)
49 60 end
50 61
  62 + if params && params[:locale].present? && request.original_fullpath.split('/')[1].length == 2
  63 + I18n.locale = params[:locale]
  64 + elsif lang
  65 + I18n.locale = lang
  66 + else
  67 + I18n.locale = Rails.application.config.i18n.default_locale
  68 + end
  69 +
  70 +
51 71 #@page_data = PageDatum.where(:url => @url).first
52 72 #$current_locale = PageLang.where(default_use: true).first.code
53 73 @page_data = PageDatum.joins(page: :domain).where(kanjai_domains: {id: $domain.id}).where(:url => @url, lang: I18n.locale).first
... ...
... ... @@ -17,10 +17,11 @@
17 17 <div class="form-group row">
18 18 <%= f.label :default_use, Kanjai::PageLang.human_attribute_name(:default_use), class: 'col-md-2 col-form-label' %>
19 19 <div class="col-md-10">
20   - <label class="switch switch-lg"><%= f.check_box :default_use %><span></span></label>
  20 + <label class="switch switch-lg"><%= f.check_box :default_use, class: 'default-lang-checkbox' %><span></span></label>
21 21 </div>
22 22 </div>
23 23
  24 + <div class="language-domain-wrapper <%= f.object.default_use ? 'not-visible' : '' %>" >
24 25 <% if @page_lang.domain.language_domains.count > 0 %>
25 26 <div class="form-group">
26 27 <%= f.label :language_domain_id, Kanjai::PageLang.human_attribute_name(:language_domain) + ' *', class: 'col-form-label' %>
... ... @@ -28,6 +29,7 @@
28 29 <%= error_messages(@page_lang, :language_domain_id) %>
29 30 </div>
30 31 <% end %>
  32 + </div>
31 33
32 34
33 35 <div class="card-footer mt-20">
... ...
... ... @@ -30,6 +30,7 @@
30 30 <tr>
31 31 <th><%= Kanjai::PageLang.human_attribute_name(:code) %></th>
32 32 <th><%= Kanjai::PageLang.human_attribute_name(:title) %></th>
  33 + <th><%= Kanjai::PageLang.human_attribute_name(:language_domain) %></th>
33 34 <th width="50px"></th>
34 35 </tr>
35 36 </thead>
... ... @@ -38,6 +39,7 @@
38 39 <tr id='<%= dom_id(item) %>'>
39 40 <td><%= item.code %></td>
40 41 <td><%= item.title %></td>
  42 + <td><%= !item.default_use ? item.language_domain.try(:title) : '' %></td>
41 43 <td>
42 44 <div class="dropdown">
43 45 <button class="btn btn-secondary dropdown-toggle dropdown-toggle-nocaret" type="button" data-toggle="dropdown" aria-expanded="false">
... ...
1 1 module Kanjai
2   - VERSION = "0.0.205"
  2 + VERSION = "0.0.206"
3 3 end
... ...