43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
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 |