2016-04-27 17:02:44 +08:00
|
|
|
class SubDomainsController < ApplicationController
|
|
|
|
layout 'base_org'
|
2016-05-03 16:49:13 +08:00
|
|
|
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :new]
|
|
|
|
|
|
|
|
def new
|
|
|
|
@subdomain = SubDomain.new
|
|
|
|
|
|
|
|
end
|
2016-04-27 17:02:44 +08:00
|
|
|
|
|
|
|
def create
|
|
|
|
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
|
|
|
|
@res = true
|
|
|
|
# @organization = Organization.find(params[:organization_id])
|
|
|
|
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
|
|
|
# @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1)
|
|
|
|
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id],:priority => @subfield.sub_domains.blank? ? 1.1 : @subfield.sub_domains.order("priority").last.priority + 0.1)
|
|
|
|
# if !params[:sub_dir].blank?
|
|
|
|
# sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
|
|
|
|
# "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
|
|
|
|
# if SubfieldSubdomainDir.find_by_sql(sql).count == 0
|
|
|
|
# SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
@subdomain.update_column(:field_type, params[:field_type])
|
|
|
|
else
|
|
|
|
@res = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-04-28 17:36:29 +08:00
|
|
|
@subfield_content = @organization.org_subfields.order("priority")
|
2016-05-03 16:49:13 +08:00
|
|
|
render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
2016-04-28 17:36:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def find_org_subfield_and_subdomain
|
|
|
|
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
|
|
|
@subdomain = SubDomain.find(params[:id])
|
|
|
|
@organization = @subfield.organization
|
2016-04-29 11:33:56 +08:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
# source_subdomain not found
|
|
|
|
render_404
|
2016-04-27 17:02:44 +08:00
|
|
|
end
|
|
|
|
end
|