113 lines
2.7 KiB
Ruby
113 lines
2.7 KiB
Ruby
|
class Admin::UniversalTablesController < OrbitAdminController
|
||
|
def index
|
||
|
@table_fields = ["universal_table.table_name","universal_table.created_time","universal_table.total_no_of_entries"]
|
||
|
|
||
|
@tables = UTable.where(:title.ne => "")
|
||
|
.order_by(sort)
|
||
|
.with_categories(filters("category"))
|
||
|
|
||
|
@tables = search_data(@tables,[:title])
|
||
|
end
|
||
|
|
||
|
def show
|
||
|
uid = params[:id].split("-").last
|
||
|
@table = UTable.where(:uid => uid).first rescue nil
|
||
|
if !@table.nil?
|
||
|
@columns = @table.table_columns.asc(:order)
|
||
|
@table_fields = @columns.collect{|tc| tc.title}
|
||
|
@entries = @table.table_entries.page(params[:page_id]).per(10)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def new_entry
|
||
|
uid = params[:universal_table_id].split("-").last
|
||
|
@table = UTable.where(:uid => uid).first rescue nil
|
||
|
if !@table.nil?
|
||
|
@columns = @table.table_columns.asc(:order)
|
||
|
@entries = @table.table_entries
|
||
|
@entry = TableEntry.new
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def add_entry
|
||
|
entry = TableEntry.new(table_entry_params)
|
||
|
entry.save
|
||
|
table = UTable.find(params[:table_entry][:u_table_id])
|
||
|
redirect_to admin_universal_table_new_entry_path(table)
|
||
|
end
|
||
|
|
||
|
def edit_entry
|
||
|
id = params[:universal_table_id]
|
||
|
@entry = TableEntry.find(id)
|
||
|
@table = @entry.u_table
|
||
|
if !@table.nil?
|
||
|
@columns = @table.table_columns.asc(:order)
|
||
|
@entries = @table.table_entries
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def delete_entry
|
||
|
entry = TableEntry.find(params[:universal_table_id])
|
||
|
table = entry.u_table
|
||
|
entry.destroy
|
||
|
redirect_to admin_universal_table_path(table)
|
||
|
end
|
||
|
|
||
|
def update_entry
|
||
|
entry = TableEntry.find(params[:id])
|
||
|
entry.update_attributes(table_entry_params)
|
||
|
table = entry.u_table
|
||
|
redirect_to admin_universal_table_path(table)
|
||
|
end
|
||
|
|
||
|
def new
|
||
|
@table = UTable.new
|
||
|
end
|
||
|
|
||
|
def create
|
||
|
category = Category.new
|
||
|
category.title_translations = params[:u_table][:title_translations]
|
||
|
category.module_app = @module_app
|
||
|
category.save
|
||
|
p = table_params
|
||
|
p[:category_id] = category.id
|
||
|
table = UTable.new(p)
|
||
|
table.save
|
||
|
redirect_to admin_universal_tables_path
|
||
|
end
|
||
|
|
||
|
def edit
|
||
|
uid = params[:id].split("-").last
|
||
|
@table = UTable.where(:uid => uid).first
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
uid = params[:id].split("-").last
|
||
|
p = table_params
|
||
|
table = UTable.where(:uid => uid).first
|
||
|
table.update_attributes(p)
|
||
|
table.save
|
||
|
cat = table.category
|
||
|
cat.title_translations = p[:title_translations]
|
||
|
cat.save
|
||
|
redirect_to admin_universal_tables_path
|
||
|
end
|
||
|
|
||
|
def destroy
|
||
|
uid = params[:id].split("-").last
|
||
|
table = UTable.where(:uid => uid).first
|
||
|
table.category.destroy
|
||
|
table.destroy
|
||
|
redirect_to admin_universal_tables_path
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def table_params
|
||
|
params.require(:u_table).permit!
|
||
|
end
|
||
|
|
||
|
def table_entry_params
|
||
|
params.require(:table_entry).permit!
|
||
|
end
|
||
|
end
|