register_modules/app/controllers/admin/register_desktop_widgets_co...

43 lines
1.2 KiB
Ruby
Raw Normal View History

2015-02-02 10:36:45 +00:00
class Admin::RegisterDesktopWidgetsController < OrbitAdminController
def index
@table_fields = table_fields
if current_user.is_admin?
@registered_widgets = RegisteredDesktopWidget.all.desc(:created_at)
else
@registered_widgets = RegisteredDesktopWidget.where(:create_user_id => current_user.id).desc(:created_at)
end
if request.xhr?
render :partial => "my_registered_widget"
end
end
def create
rdw = RegisteredDesktopWidget.new(registered_desktop_widget_params)
rdw.create_user_id = current_user.id
rdw.save
render :json => {"success" => true}.to_json
end
def table_fields
[:widget_name_, :widget_uid, :status, :actions]
end
def update
rdw = RegisteredDesktopWidget.find(params[:id]) rescue nil
if !rdw.nil?
rdw.update_attributes(registered_desktop_widget_params)
rdw.save
end
render :json => {"success" => true}.to_json
end
def approve_widget
rdw = RegisteredDesktopWidget.find(params[:id]) rescue nil
if !rdw.nil?
rdw.approved = true
rdw.save
end
redirect_to admin_register_desktop_widgets_path(:page => params[:page])
end
private
def registered_desktop_widget_params
params.require(:registered_widget).permit!
end
end