Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 71
- Log:
Start of upgrade to Typo 4.0.0, the latest stable release since
2.6.0. Note test/mocks/themes/azure changes from a file to a
directory, so the file has been removed in this revision and
the directory will be added in the next revision.
- Author:
- adh
- Date:
- Mon Aug 07 22:18:11 +0100 2006
- Size:
- 4485 Bytes
1 | class Admin::ContentController < Admin::BaseController |
2 | def index |
3 | list |
4 | render_action 'list' |
5 | end |
6 | |
7 | def list |
8 | @articles_pages, @articles = with_blog_scoped_classes do |
9 | paginate(:article, :per_page => 15, :order_by => "created_at DESC", |
10 | :parameter => 'id') |
11 | end |
12 | setup_categories |
13 | @article = this_blog.articles.build(params[:article]) |
14 | end |
15 | |
16 | def show |
17 | @article = Article.find(params[:id]) |
18 | setup_categories |
19 | @resources = Resource.find(:all, :order => 'created_at DESC') |
20 | end |
21 | |
22 | def new; new_or_edit; end |
23 | def edit; new_or_edit; end |
24 | |
25 | def destroy |
26 | @article = Article.find(params[:id]) |
27 | if request.post? |
28 | @article.destroy |
29 | redirect_to :action => 'list' |
30 | end |
31 | end |
32 | |
33 | def category_add; do_add_or_remove_fu; end |
34 | alias_method :category_remove, :category_add |
35 | alias_method :resource_add, :category_add |
36 | alias_method :resource_remove, :category_add |
37 | |
38 | def preview |
39 | @headers["Content-Type"] = "text/html; charset=utf-8" |
40 | @article = Article.new(params[:article]) |
41 | render :layout => false |
42 | end |
43 | |
44 | def attachment_box_add |
45 | render :partial => 'admin/content/attachment', :locals => { :attachment_num => params[:id] } |
46 | end |
47 | |
48 | def attachment_box_remove |
49 | render :inline => "<%= javascript_tag 'document.getElementById(\"attachments\").removeChild(document.getElementById(\"attachment_#{params[:id]}\")); return false;' -%>" |
50 | end |
51 | |
52 | def attachment_save(attachment) |
53 | begin |
54 | Resource.create(:filename => attachment.original_filename, |
55 | :mime => attachment.content_type.chomp, :created_at => Time.now).write_to_disk(attachment) |
56 | rescue => e |
57 | logger.info(e.message) |
58 | nil |
59 | end |
60 | end |
61 | |
62 | protected |
63 | |
64 | attr_accessor :resources, :categories, :resource, :category |
65 | |
66 | def do_add_or_remove_fu |
67 | attrib, action = params[:action].split('_') |
68 | @article = Article.find(params[:id]) |
69 | self.send("#{attrib}=", self.class.const_get(attrib.classify).find(params["#{attrib}_id"])) |
70 | send("setup_#{attrib.pluralize}") |
71 | @article.send(attrib.pluralize).send(real_action_for(action), send(attrib)) |
72 | @article.save |
73 | render :partial => "show_#{attrib.pluralize}" |
74 | end |
75 | |
76 | def real_action_for(action); { 'add' => :<<, 'remove' => :delete}[action]; end |
77 | |
78 | def new_or_edit |
79 | get_or_build_article |
80 | params[:article] ||= {} |
81 | # params[:article].reverse_merge!('allow_comments' => this_blog.default_allow_comments, |
82 | # 'allow_pings' => this_blog.default_allow_pings, |
83 | # 'published' => true) |
84 | @article.attributes = (params[:article]) |
85 | setup_categories |
86 | @selected = @article.categories.collect { |c| c.id } |
87 | if request.post? |
88 | set_article_author |
89 | save_attachments |
90 | if @article.save |
91 | set_article_categories |
92 | set_the_flash |
93 | redirect_to :action => 'show', :id => @article.id |
94 | end |
95 | end |
96 | end |
97 | |
98 | def set_the_flash |
99 | case params[:action] |
100 | when 'new' |
101 | flash[:notice] = 'Article was successfully created' |
102 | when 'edit' |
103 | flash[:notice] = 'Article was successfully updated.' |
104 | else |
105 | raise "I don't know how to tidy up action: #{params[:action]}" |
106 | end |
107 | end |
108 | |
109 | def set_article_author |
110 | return if @article.author |
111 | @article.author = session[:user].login |
112 | @article.user = session[:user] |
113 | end |
114 | |
115 | def save_attachments |
116 | return if params[:attachments].nil? |
117 | params[:attachments].each do |k,v| |
118 | a = attachment_save(v) |
119 | @article.resources << a unless a.nil? |
120 | end |
121 | end |
122 | |
123 | def set_article_categories |
124 | @article.categories.clear |
125 | @article.categories = Category.find(params[:categories]) if params[:categories] |
126 | @selected = params[:categories] || [] |
127 | end |
128 | |
129 | def get_or_build_article |
130 | @article = case params[:action] |
131 | when 'new' |
132 | art = this_blog.articles.build |
133 | art.allow_comments = this_blog.default_allow_comments |
134 | art.allow_pings = this_blog.default_allow_pings |
135 | art.published = true |
136 | art |
137 | when 'edit' |
138 | this_blog.articles.find(params[:id]) |
139 | else |
140 | raise "Don't know how to get article for action: #{params[:action]}" |
141 | end |
142 | end |
143 | |
144 | def setup_categories |
145 | @categories = Category.find(:all, :order => 'UPPER(name)') |
146 | end |
147 | |
148 | def setup_resources |
149 | @resources = Resource.find(:all, :order => 'created_at DESC') |
150 | end |
151 | end |