This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/infos_controller.rb

83 lines
1.8 KiB
Ruby
Raw Normal View History

class Admin::InfosController < OrbitBackendController
2011-12-23 10:34:21 +00:00
layout "new_admin"
2011-12-23 10:34:21 +00:00
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
helper Admin::AttributeValuesViewHelper
2011-12-23 10:34:21 +00:00
def index
@attributes = Info.all.entries
2012-12-05 12:32:28 +00:00
@roles = Role.excludes('disabled' => true)
2013-01-18 02:37:55 +00:00
# render :template => 'admin/attributes/index'
redirect_to(edit_admin_info_path(Info.first.id.to_s))
2011-12-23 10:34:21 +00:00
end
def show
end
def new
@attribute = Info.new
render :template => 'admin/attributes/new'
end
def edit
@attribute = Info.find(params[:id])
2012-12-05 12:32:28 +00:00
# @attribute_fields_upper_object = [@attribute]
2011-12-23 10:34:21 +00:00
render :template => 'admin/attributes/edit'
end
def create
@attribute = Info.new(params[:info])
@attribute.save
redirect_to :action => :index
end
def update
@attribute = Info.find(params[:id])
@attribute.update_attributes(params[:info])
@attribute.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
2011-12-23 10:34:21 +00:00
respond_to do |format|
2013-01-14 10:19:14 +00:00
format.html { redirect_to(edit_admin_info_path(params[:id])) }
2011-12-23 10:34:21 +00:00
format.js { render 'admin/attributes/toggle_enable' }
end
2013-01-14 10:19:14 +00:00
2011-12-23 10:34:21 +00:00
end
def destroy
@attribute = Info.find(params[:id])
@attribute.destroy
redirect_to :action => :index
end
def add_attribute_field
2012-12-05 12:32:28 +00:00
attribute = Info.find(params[:info_id]) rescue nil
@attribute_field_counter = attribute.attribute_fields.count
@attribute_field = attribute.attribute_fields.build
@attribute_field.save
2012-12-05 12:32:28 +00:00
@attribute_field[:af_count] = @attribute_field_counter
@attribute = Info.find(params[:info_id])
respond_to do |format|
format.js { render 'admin/attributes/add_attribute_field' }
end
2011-12-23 10:34:21 +00:00
end
protected
def set_attribute
@attribute_type = 'info'
@class = 'infos'
end
end