socialforge/app/controllers/org_subfields_controller.rb

96 lines
3.7 KiB
Ruby
Raw Normal View History

class OrgSubfieldsController < ApplicationController
def create
@subfield = OrgSubfield.create(:name => params[:name])
@organization = Organization.find(params[:organization_id])
@organization.org_subfields << @subfield
2016-01-13 09:34:33 +08:00
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 => @org_subfield.id, :name => params[:sub_dir])
end
end
@subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
end
def show
2016-01-12 16:43:40 +08:00
@organization = Organization.find(params[:id])
@subfield = @organization.org_subfields.first
if @subfield.field_type == 'Post'
redirect_to organization_path(@organization, :org_subfield_id => @subfield.id)
2016-01-13 09:34:33 +08:00
end
@org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
"subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
" org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name=#{params[:name]}").first
if params[:sort]
params[:sort].split(",").each do |sort_type|
order_by = sort_type.split(":")
2016-01-12 16:43:40 +08:00
2016-01-13 09:34:33 +08:00
case order_by[0]
when "filename"
attribute = "filename"
when "size"
attribute = "filesize"
when "attach_type"
attribute = "attachtype"
when "content_type"
attribute = "created_on"
when "field_file_dense"
attribute = "is_public"
when "downloads"
attribute = "downloads"
when "created_on"
attribute = "created_on"
when "quotes"
attribute = "quotes"
else
attribute = "created_on"
end
@sort = order_by[0]
@order = order_by[1]
if order_by.count == 1 && attribute
sort += "#{Attachment.table_name}.#{attribute} asc "
if sort_type != params[:sort].split(",").last
sort += ","
end
elsif order_by.count == 2 && order_by[1]
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
if sort_type != params[:sort].split(",").last
sort += ","
end
end
end
else
sort = "#{Attachment.table_name}.created_on desc"
end
2016-01-13 09:34:33 +08:00
@container_type = 2
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
@organization = Organization.find(@containers.first.organization_id)
show_attachments @containers
@tag_list = attachment_tag_list @all_attachments
@page = params[:page] || 1
render :layout => 'base_org'
2016-01-12 16:43:40 +08:00
# @org_subfield = OrgSubfield.find(params[:id])
# @organization = @org_subfield.organization.id
# @messages = []
# @messages << @org_subfield.org_document_comments
# @messages << @org_subfield.messages
# @messages.sort{|a, b| b.updated_at <=> a.updated_at}
# respond_to do |format|
# format.html{render :layout => 'base_org'}
# end
end
def destroy
@subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id)
@subfield.destroy
end
def update
@subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id)
@subfield.update_attributes(:name => params[:name])
end
end