Module: Adminpanel::RestActionsHelper

Included in:
ApplicationController
Defined in:
app/helpers/adminpanel/rest_actions_helper.rb

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 23

def create
	params.merge({:model => params[:model]}) if params[:model].present?
	params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
	params.merge({:belongs_request => params[:belongs_request]}) if params[:belongs_request].present?
	create! do |success, failure|
		success.html do
			flash[:success] = I18n.t("action.save_success")
			redirect_to resource
		end
		failure.html do
			set_collections
			render "shared/new"
		end
		success.js do
			flash.now[:success] = I18n.t("action.save_success")
			if params[:belongs_request]
				render 'shared/create_belongs_to', :locals => {:resource => resource }
			else
				render 'shared/create_has_many', :locals => {:resource => resource }
			end
		end
		failure.js do
			set_collections
			render 'shared/new', :locals => {:resource => resource }
		end
	end
end

#destroy ⇒ Object



74
75
76
77
78
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 74

def destroy
	destroy! do |format|
		format.html { render "shared/index" }
	end
end

#edit ⇒ Object



52
53
54
55
56
57
58
59
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 52

def edit
    edit! do |format|
      format.html do
      	set_collections
      	render "shared/edit"
      end
    end
end

#index ⇒ Object



3
4
5
6
7
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 3

def index
    index! do |format|
      format.html { render "shared/index" }
    end
end

#move_better ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 80

def move_better
	respond_to do |format|
		format.js do
			resource = @model.find(params[:id])
			resource.move_to_better_position
			render 'shared/gallery_entries', :locals => { :collection => @model.where(@model.relation_field.to_sym => resource.send(@model.relation_field)) }
		end
	end
end

#move_worst ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 90

def move_worst
	respond_to do |format|
		format.js do
			resource = @model.find(params[:id])
			resource.move_to_worst_position
			render 'shared/gallery_entries', :locals => { :collection => @model.where(@model.relation_field.to_sym => resource.send(@model.relation_field)) }
		end
	end
end

#new ⇒ Object



15
16
17
18
19
20
21
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 15

def new
	set_collections
    new! do |format|
      format.html { render "shared/new" }
		format.js { render 'shared/new', :locals => { :resource => resource }}
    end
end

#show ⇒ Object



9
10
11
12
13
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 9

def show
	show! do |format|
		format.html { render "shared/show" }
	end
end

#update ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/adminpanel/rest_actions_helper.rb', line 61

def update
    update! do |success, failure|
      success.html do
      	flash[:success] = I18n.t("action.save_success")
      	render "shared/index"
      end
      failure.html do
      	set_collections
      	render "shared/edit"
      end
    end
end