Class: Admin::ArticlesController
Instance Method Summary
collapse
Methods included from BlogHelper
#blog_base_url, #this_blog
Instance Method Details
#auto_complete_for_article_keywords ⇒ Object
95
96
97
98
|
# File 'app/controllers/admin/articles_controller.rb', line 95
def auto_complete_for_article_keywords
@items = Tag.order(:display_name).pluck(:display_name)
render json: @items
end
|
#autosave ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'app/controllers/admin/articles_controller.rb', line 100
def autosave
return false unless request.xhr?
id = params[:article][:id] || params[:id]
return if id && !access_granted?(id)
article_factory = Article::Factory.new(this_blog, current_user)
@article = article_factory.get_or_build_from(id)
fetch_fresh_or_existing_draft_for_article
@article.attributes = params[:article].permit!
@article.author = current_user
@article.save_attachments!(params[:attachments])
@article.state = "draft" unless @article.withdrawn?
@article.text_filter_name ||= default_text_filter
if @article.title.blank?
lastid = Article.order("id desc").first.id
@article.title = "Draft article #{lastid}"
end
if @article.save
flash[:success] = I18n.t("admin.articles.autosave.success")
@must_update_calendar =
params[:article][:published_at] and
params[:article][:published_at].to_time.to_i < Time.zone.now.to_time.to_i and
@article.parent_id.nil?
respond_to do |format|
format.js
end
end
end
|
#create ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/admin/articles_controller.rb', line 38
def create
article_factory = Article::Factory.new(this_blog, current_user)
@article = article_factory.get_or_build_from(params[:article][:id])
update_article_attributes
if @article.draft
@article.state = "draft"
elsif @article.draft?
@article.publish!
end
if @article.save
flash[:success] = I18n.t("admin.articles.create.success")
redirect_to action: "index"
else
@article.keywords = Tag.collection_to_string @article.tags
load_resources
render "new", layout: "editor"
end
end
|
#destroy ⇒ Object
91
92
93
|
# File 'app/controllers/admin/articles_controller.rb', line 91
def destroy
destroy_a(Article)
end
|
#edit ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/admin/articles_controller.rb', line 28
def edit
return unless access_granted?(params[:id])
@article = Article.find(params[:id])
@article.text_filter_name ||= default_text_filter
@article.keywords = Tag.collection_to_string @article.tags
load_resources
render layout: "editor"
end
|
#index ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/admin/articles_controller.rb', line 8
def index
@search = params[:search] || {}
@articles = this_blog.articles.search_with(@search).page(params[:page])
.per(this_blog.admin_display_elements)
if request.xhr?
respond_to do |format|
format.js {}
end
else
@article = Article.new(params[:article])
end
end
|
#new ⇒ Object
22
23
24
25
26
|
# File 'app/controllers/admin/articles_controller.rb', line 22
def new
@article = Article::Factory.new(this_blog, current_user).default
load_resources
render layout: "editor"
end
|
#update ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/admin/articles_controller.rb', line 60
def update
id = params[:id]
return unless access_granted?(id)
@article = Article.find(id)
if params[:article][:draft]
fetch_fresh_or_existing_draft_for_article
else
@article = Article.find(@article.parent_id) unless @article.parent_id.nil?
end
update_article_attributes
if @article.draft
@article.state = "draft"
elsif @article.draft?
@article.publish!
end
if @article.save
Article.where(parent_id: @article.id).map(&:destroy) unless @article.draft
flash[:success] = I18n.t("admin.articles.update.success")
redirect_to action: "index"
else
@article.keywords = Tag.collection_to_string @article.tags
load_resources
render "edit"
end
end
|