Class: Alchemy::Admin::PagesController
Instance Method Summary
collapse
#leave
Methods included from Modules
included, #module_definition_for, register_module
#configuration, #multi_language?, #multi_site?
Instance Method Details
Set page configuration like page names, meta tags and states.
76
77
78
79
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 76
def configure
@page_layouts = PageLayout.layouts_with_own_for_select(@page.page_layout, Language.current.id, @page.layoutpage?)
render @page.redirects_to_external? ? 'configure_external' : 'configure'
end
|
#copy_language_tree ⇒ Object
168
169
170
171
172
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 168
def copy_language_tree
language_root_to_copy_from.copy_children_to(copy_of_language_root)
flash[:notice] = _t(:language_pages_copied)
redirect_to admin_pages_path
end
|
#create ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 49
def create
@page = paste_from_clipboard || Page.new(page_params)
if @page.save
flash[:notice] = _t("Page created", name: @page.name)
do_redirect_to(redirect_path_after_create_page)
else
@page_layouts = PageLayout.layouts_for_select(Language.current.id, @page.layoutpage?)
@clipboard = get_clipboard('pages')
@clipboard_items = Page.all_from_clipboard_for_select(@clipboard, Language.current.id, @page.layoutpage?)
render :new
end
end
|
#destroy ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 96
def destroy
name = @page.name
@page_id = @page.id
@layoutpage = @page.layoutpage?
if @page.destroy
set_root_page
@message = _t("Page deleted", :name => name)
flash[:notice] = @message
respond_to do |format|
format.js
end
@clipboard = get_clipboard('pages')
@clipboard.delete_if { |item| item['id'] == @page_id.to_s }
end
end
|
#edit ⇒ Object
Edit the content of the page and all its elements and contents.
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 63
def edit
if page_is_locked?
flash[:notice] = _t('This page is locked', name: @page.locker_name)
redirect_to admin_pages_path
else
@page.lock_to!(current_alchemy_user)
@locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
end
@layoutpage = @page.layoutpage?
end
|
#flush ⇒ Object
200
201
202
203
204
205
206
207
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 200
def flush
Language.current.pages.flushables.each do |page|
page.publish!
end
respond_to do |format|
format.js
end
end
|
#fold ⇒ Object
132
133
134
135
136
137
138
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 132
def fold
@page.fold!(current_alchemy_user.id, !@page.folded?(current_alchemy_user.id))
respond_to do |format|
format.js
end
end
|
#index ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 17
def index
authorize! :index, :alchemy_admin_pages
@locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
@languages = Language.all
if !@page_root
@language = Language.current
@languages_with_page_tree = Language.with_root_page
end
end
|
#info ⇒ Object
38
39
40
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 38
def info
render layout: !request.xhr?
end
|
#link ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 114
def link
@url_prefix = ""
if configuration(:show_real_root)
@page_root = Page.root
else
set_root_page
end
@area_name = params[:area_name]
@content_id = params[:content_id]
@attachments = Attachment.all.collect { |f| [f.name, download_attachment_path(:id => f.id, :name => f.urlname)] }
if params[:link_urls_for] == "newsletter"
@url_prefix = current_server
end
if multi_language?
@url_prefix = "#{Language.current.code}/"
end
end
|
#order ⇒ Object
Receives a JSON object representing a language tree to be ordered and updates all pages in that language structure to their correct indexes
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 180
def order
neworder = JSON.parse(params[:set])
tree = create_tree(neworder, @page_root)
Alchemy::Page.transaction do
tree.each do |key, node|
dbitem = Page.find(key)
dbitem.update_node!(node)
end
end
flash[:notice] = _t("Pages order saved")
do_redirect_to admin_pages_path
end
|
#publish ⇒ Object
Sets the page public and updates the published_at attribute that is used as cache_key
161
162
163
164
165
166
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 161
def publish
@page.publish!
flash[:notice] = _t(:page_published, :name => @page.name)
redirect_back_or_to_default(admin_pages_path)
end
|
#show ⇒ Object
Used by page preview iframe in Page#edit view.
30
31
32
33
34
35
36
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 30
def show
@preview_mode = true
Page.current_preview = @page
::I18n.locale = @page.language_code
render layout: 'application'
end
|
#sort ⇒ Object
174
175
176
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 174
def sort
@sorting = true
end
|
#switch_language ⇒ Object
195
196
197
198
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 195
def switch_language
set_alchemy_language(params[:language_id])
do_redirect_to redirect_path_for_switch_language
end
|
#unlock ⇒ Object
Leaves the page editing mode and unlocks the page for other users
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 141
def unlock
@page.unlock!
flash[:notice] = _t(:unlocked_page, :name => @page.name)
@pages_locked_by_user = Page.from_current_site.all_locked_by(current_alchemy_user)
respond_to do |format|
format.js
format.html {
redirect_to params[:redirect_to].blank? ? admin_pages_path : params[:redirect_to]
}
end
end
|
#update ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 85
def update
@old_page_layout = @page.page_layout
if @page.update_attributes(page_params)
@notice = _t("Page saved", :name => @page.name)
@while_page_edit = request.referer.include?('edit')
else
configure
end
end
|
#visit ⇒ Object
154
155
156
157
|
# File 'app/controllers/alchemy/admin/pages_controller.rb', line 154
def visit
@page.unlock!
redirect_to show_page_path(urlname: @page.urlname, locale: multi_language? ? @page.language_code : nil)
end
|