82 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
| class Admin::InfosController < OrbitBackendController
 | |
|   
 | |
|   before_filter :authenticate_user!
 | |
|   before_filter :is_admin?
 | |
|   before_filter :set_attribute, :only => [:index, :show, :new, :edit]
 | |
|   helper Admin::AttributeValuesViewHelper
 | |
|   
 | |
|   def index
 | |
|     @attributes = Info.all.entries
 | |
| 	
 | |
|     @roles = Role.excludes('disabled' => true)
 | |
| 	 
 | |
|     # render :template => 'admin/attributes/index'
 | |
| 	
 | |
| 	redirect_to(edit_admin_info_path(Info.first.id.to_s))
 | |
| 	
 | |
|   end
 | |
|   
 | |
|   def show
 | |
|     
 | |
|   end
 | |
|   
 | |
|   def new
 | |
|     @attribute = Info.new
 | |
|     render :template => 'admin/attributes/new'
 | |
|   end
 | |
|   
 | |
|   def edit
 | |
|     @attribute = Info.find(params[:id])
 | |
|     # @attribute_fields_upper_object = [@attribute]
 | |
|     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}
 | |
|     respond_to do |format|
 | |
| 	  format.html { redirect_to(edit_admin_info_path(params[:id])) }
 | |
|       format.js  { render 'admin/attributes/toggle_enable' }
 | |
|     end
 | |
| 	  
 | |
|   end
 | |
|   
 | |
|   def destroy
 | |
|     @attribute = Info.find(params[:id])
 | |
|     @attribute.destroy
 | |
|     redirect_to :action => :index
 | |
|   end
 | |
|   
 | |
|   def add_attribute_field
 | |
| 	
 | |
|     attribute = Info.find(params[:info_id]) rescue nil
 | |
|     @attribute_field_counter = attribute.attribute_fields.count
 | |
|     @attribute_field = attribute.attribute_fields.build
 | |
|     @attribute_field.save
 | |
| 	
 | |
|     @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
 | |
| 
 | |
|   end
 | |
|   
 | |
|   protected
 | |
|   
 | |
|   def set_attribute
 | |
|     @attribute_type = 'info'
 | |
|     @class = 'infos'
 | |
|   end
 | |
|   
 | |
| end
 |