socialforge/app/controllers/sub_domains_controller.rb

67 lines
1.9 KiB
Ruby
Raw Normal View History

2016-05-04 09:01:51 +08:00
class SubDomainsController < ApplicationController
layout 'base_org'
2016-05-05 15:16:14 +08:00
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :domain_update_priority, :destroy, :update, :hide_sub_domain, :show_sub_domain]
2016-05-04 09:01:51 +08:00
def new
@subdomain = SubDomain.new
2016-05-04 15:05:54 +08:00
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
2016-05-04 15:50:53 +08:00
@organization = @org_subfield.organization
2016-05-04 09:01:51 +08:00
end
def create
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
@res = true
@subfield = OrgSubfield.find(params[:org_subfield_id])
2016-05-04 17:06:32 +08:00
@organization = @subfield.organization
2016-05-05 14:39:27 +08:00
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id], :priority => @subfield.sub_domains.blank? ? 1 : @subfield.sub_domains.order("priority").last.priority + 1)
2016-05-04 09:01:51 +08:00
@subdomain.update_column(:field_type, params[:field_type])
else
@res = false
end
respond_to do |format|
format.js
end
2016-05-04 09:01:51 +08:00
end
2016-05-05 11:28:28 +08:00
def update
@subdomain.update_column(:name, params[:name])
end
2016-05-05 14:39:27 +08:00
def domain_update_priority
@subdomain.update_attribute(:priority, params[:priority].to_i)
end
2016-05-05 12:27:35 +08:00
def destroy
@subdomain.destroy
end
2016-05-05 11:28:28 +08:00
2016-05-04 09:01:51 +08:00
def show
2016-05-04 11:08:16 +08:00
render_404
# @subfield_content = @organization.org_subfields.order("priority")
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
2016-05-04 09:01:51 +08:00
end
def index
end
2016-05-05 15:16:14 +08:00
def hide_sub_domain
@subdomain.update_attribute(:hide, 1)
end
def show_sub_domain
@subdomain.update_attribute(:hide, 0)
end
2016-05-04 09:01:51 +08:00
private
def find_org_subfield_and_subdomain
@subfield = OrgSubfield.find(params[:org_subfield_id])
@subdomain = SubDomain.find(params[:id])
@organization = @subfield.organization
rescue ActiveRecord::RecordNotFound
# source_subdomain not found
render_404
end
end