2012-02-14 16:32:20 +00:00
|
|
|
class Admin::TagsController < ApplicationController
|
|
|
|
|
|
|
|
layout 'new_admin'
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :is_admin?
|
|
|
|
before_filter :set_module_app
|
|
|
|
|
|
|
|
def index
|
|
|
|
get_tags
|
|
|
|
@module_app_id = @module_app.id rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@tag = Tag.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-02-15 07:18:11 +00:00
|
|
|
if params[:tag][:module_app_id].blank?
|
|
|
|
@tag = Tag.create(params[:tag])
|
|
|
|
else
|
|
|
|
module_app = ModuleApp.find(params[:tag][:module_app_id])
|
|
|
|
@tag = eval("#{module_app.key.capitalize}Tag").create(params[:tag])
|
|
|
|
end
|
2012-02-14 16:32:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@tag = Tag.find(params[:id])
|
|
|
|
@tag.update_attributes(params[:tag])
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@tag = Tag.find(params[:id])
|
|
|
|
@tag.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.js { render 'js/remove_element', :locals => {:id => "#{dom_id @tag}"} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def set_module_app
|
|
|
|
@module_app ||= ModuleApp.first(:conditions => {:key => @app_title.underscore}) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_tags
|
|
|
|
@tags = (@module_app ? @module_app.tags : Tag.all)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|