Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 4997 Bytes
1 | require 'base64' |
2 | |
3 | class Admin::ContentController < Admin::BaseController |
4 | def index |
5 | list |
6 | render_action 'list' |
7 | end |
8 | |
9 | def list |
10 | now = Time.now |
11 | count = this_blog.articles.count |
12 | @articles_pages = Paginator.new(self, count, 15, params[:id]) |
13 | @articles = this_blog.articles.find(:all, :limit => 15, :order => 'id DESC', |
14 | :offset => @articles_pages.current.offset) |
15 | setup_categories |
16 | @article = this_blog.articles.build(params[:article]) |
17 | end |
18 | |
19 | def show |
20 | @article = this_blog.articles.find(params[:id]) |
21 | setup_categories |
22 | @resources = Resource.find(:all, :order => 'created_at DESC') |
23 | end |
24 | |
25 | def new; new_or_edit; end |
26 | def edit; new_or_edit; end |
27 | |
28 | def destroy |
29 | @article = this_blog.articles.find(params[:id]) |
30 | if request.post? |
31 | @article.destroy |
32 | redirect_to :action => 'list' |
33 | end |
34 | end |
35 | |
36 | def category_add; do_add_or_remove_fu; end |
37 | alias_method :resource_add, :category_add |
38 | alias_method :resource_remove, :category_add |
39 | |
40 | def category_remove |
41 | @article = this_blog.articles.find(params[:id]) |
42 | @category = @article.categories.find(params['category_id']) |
43 | setup_categories |
44 | @article.categorizations.delete(@article.categorizations.find_by_category_id(params['category_id'])) |
45 | @article.save |
46 | render :partial => 'show_categories' |
47 | end |
48 | |
49 | def preview |
50 | headers["Content-Type"] = "text/html; charset=utf-8" |
51 | @article = this_blog.articles.build |
52 | @article.attributes = params[:article] |
53 | set_article_author |
54 | data = render_to_string(:layout => "minimal") |
55 | data = Base64.encode64(data).gsub("\n", '') |
56 | data = "data:text/html;charset=utf-8;base64,#{data}" |
57 | render :text => data |
58 | end |
59 | |
60 | def attachment_box_add |
61 | render :update do |page| |
62 | page["attachment_add_#{params[:id]}"].remove |
63 | page.insert_html :bottom, 'attachments', |
64 | :partial => 'admin/content/attachment', |
65 | :locals => { :attachment_num => params[:id], :hidden => true } |
66 | page.visual_effect(:toggle_appear, "attachment_#{params[:id]}") |
67 | end |
68 | end |
69 | |
70 | def attachment_save(attachment) |
71 | begin |
72 | Resource.create(:filename => attachment.original_filename, |
73 | :mime => attachment.content_type.chomp, :created_at => Time.now).write_to_disk(attachment) |
74 | rescue => e |
75 | logger.info(e.message) |
76 | nil |
77 | end |
78 | end |
79 | |
80 | protected |
81 | |
82 | attr_accessor :resources, :categories, :resource, :category |
83 | |
84 | def do_add_or_remove_fu |
85 | attrib, action = params[:action].split('_') |
86 | @article = this_blog.articles.find(params[:id]) |
87 | self.send("#{attrib}=", self.class.const_get(attrib.classify).find(params["#{attrib}_id"])) |
88 | send("setup_#{attrib.pluralize}") |
89 | @article.send(attrib.pluralize).send(real_action_for(action), send(attrib)) |
90 | @article.save |
91 | render :partial => "show_#{attrib.pluralize}" |
92 | end |
93 | |
94 | def real_action_for(action); { 'add' => :<<, 'remove' => :delete}[action]; end |
95 | |
96 | def new_or_edit |
97 | get_or_build_article |
98 | params[:article] ||= {} |
99 | |
100 | @article.attributes = params[:article] |
101 | setup_categories |
102 | @selected = @article.categories.collect { |c| c.id } |
103 | if request.post? |
104 | set_article_author |
105 | save_attachments |
106 | if @article.save |
107 | set_article_categories |
108 | set_the_flash |
109 | redirect_to :action => 'show', :id => @article.id |
110 | end |
111 | end |
112 | end |
113 | |
114 | def set_the_flash |
115 | case params[:action] |
116 | when 'new' |
117 | flash[:notice] = 'Article was successfully created' |
118 | when 'edit' |
119 | flash[:notice] = 'Article was successfully updated.' |
120 | else |
121 | raise "I don't know how to tidy up action: #{params[:action]}" |
122 | end |
123 | end |
124 | |
125 | def set_article_author |
126 | return if @article.author |
127 | @article.author = session[:user].login |
128 | @article.user = session[:user] |
129 | end |
130 | |
131 | def save_attachments |
132 | return if params[:attachments].nil? |
133 | params[:attachments].each do |k,v| |
134 | a = attachment_save(v) |
135 | @article.resources << a unless a.nil? |
136 | end |
137 | end |
138 | |
139 | def set_article_categories |
140 | @article.categorizations.clear |
141 | if params[:categories] |
142 | Category.find(params[:categories]).each do |cat| |
143 | @article.categories << cat |
144 | end |
145 | end |
146 | @selected = params[:categories] || [] |
147 | end |
148 | |
149 | def get_or_build_article |
150 | @article = case params[:action] |
151 | when 'new' |
152 | returning(this_blog.articles.build) do |art| |
153 | art.allow_comments = this_blog.default_allow_comments |
154 | art.allow_pings = this_blog.default_allow_pings |
155 | art.published = true |
156 | end |
157 | when 'edit' |
158 | this_blog.articles.find(params[:id]) |
159 | else |
160 | raise "Don't know how to get article for action: #{params[:action]}" |
161 | end |
162 | end |
163 | |
164 | def setup_categories |
165 | @categories = Category.find(:all, :order => 'UPPER(name)') |
166 | end |
167 | |
168 | def setup_resources |
169 | @resources = Resource.find(:all, :order => 'created_at DESC') |
170 | end |
171 | end |