| Class | Sadmin::NewsController |
| In: |
app/controllers/sadmin/news_controller.rb
|
| Parent: | Sadmin::BaseController |
# File app/controllers/sadmin/news_controller.rb, line 120
120: def auto_complete_for_news_tag_list
121: auto_complete_for_tag_list(params[:news][:tag_list])
122: if @tags.length > 0
123: render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>"
124: else
125: render :nothing => true
126: end
127: end
# File app/controllers/sadmin/news_controller.rb, line 73
73: def create
74: set_current_tab
75: @title = t('sadmin.news.crear_noticia')
76: @news = News.new(params[:news])
77:
78: if @news.save
79: flash[:notice] = t('sadmin.guardado_correctamente', :what => t('documents.News'))
80: submit_to_ubervu(@news)
81: redirect_to sadmin_news_path(@news.id)
82: else
83: render :action => 'new'
84: end
85: end
# File app/controllers/sadmin/news_controller.rb, line 107
107: def destroy
108: @news = News.find(params[:id])
109: set_current_tab
110:
111: if @news.destroy
112: flash[:notice] = t('sadmin.eliminado_correctamente', :what => t('documents.News'))
113: redirect_to sadmin_news_index_path
114: else
115: flash[:error] = t('sadmin.no_eliminado_correctamente', :what => t('documents.News'))
116: redirect_to sadmin_news_path(@news.id)
117: end
118: end
# File app/controllers/sadmin/news_controller.rb, line 87
87: def edit
88: set_current_tab
89: @title = t('sadmin.modificar_what', :what => t('documents.News'))
90: end
# File app/controllers/sadmin/news_controller.rb, line 133
133: def export_for_enet
134: FileUtils.rm_r(Dir.glob("#{Document::ENET_EXPORT_PATH}*"))
135:
136: File.open("#{Document::ENET_EXPORT_PATH}contents-description.txt", 'w') do |f|
137: params[:news_to_export].each do |news_id|
138: f.write("#{news_id}|N|ejld003|euskadiplus|r01_euskadi_cont_loc|wreclg1|euskadi|prensa_comunicacion|noticia|S\n")
139: end
140: end
141:
142: params[:news_to_export].each do |news_id|
143: @news = News.find(news_id)
144: Document::LANGUAGES.each do |l|
145: if @news.translated_to?(l)
146: FileUtils.mkdir_p("#{Document::ENET_EXPORT_PATH}#{news_id}/#{l}_#{news_id}/data")
147:
148: if @news.has_cover_photo? && File.exists?(@news.cover_photo.path(:medium))
149: images_dir = "#{Document::ENET_EXPORT_PATH}#{news_id}/#{l}_#{news_id}/images"
150: FileUtils.mkdir_p(images_dir)
151: FileUtils.cp(@news.cover_photo.path(:medium), images_dir)
152: end
153:
154: # if @news.has_files?
155: # files_dir = "#{Document::ENET_EXPORT_PATH}#{news_id}/#{l}_#{news_id}/adjuntos"
156: # FileUtils.mkdir_p(files_dir)
157: # files_to_show = @news.a_documents.find(:all, :conditions => ["show_in_#{l}=?", true], :order => "created_at").each do |f|
158: # FileUtils.cp(f.file.path, files_dir)
159: # end
160: # end
161:
162: File.open("#{Document::ENET_EXPORT_PATH}#{news_id}/#{l}_#{news_id}/#{news_id}.html", 'w') do |f|
163: f.write(Iconv.iconv("iso-8859-1", "utf-8", render_to_string(:partial => "enet", :locals => {:l => l})).join)
164: end
165:
166: File.open("#{Document::ENET_EXPORT_PATH}#{news_id}/#{l}_#{news_id}/data/#{l}_#{news_id}.xml", 'w') do |f|
167: f.write("<?xml version='1.0' encoding='UTF-8'?><newDate>#{@news.published_at.to_s(:enet_xml)}</newDate>")
168: end
169: end
170: end
171:
172: File.open("#{Document::ENET_EXPORT_PATH}#{news_id}/#{news_id}-content.xml", 'w') do |f|
173: f.write(render_to_string(:action => "enet.xml.builder", :layout => false))
174: end
175: end
176:
177: FileUtils.cd(Document::ENET_EXPORT_PATH)
178: system("zip -r noticias-irekia.zip *")
179:
180: flash[:notice] = "Las noticias marcadas han sido exportadas al directorio #{Document::ENET_EXPORT_PATH}"
181: redirect_to sadmin_news_index_path
182: end
# File app/controllers/sadmin/news_controller.rb, line 14
14: def home
15: if (logged_in? && can_access?("news"))
16: if current_user.is_a?(StaffChief)
17: redirect_to sadmin_events_path
18: else
19: redirect_to sadmin_news_index_path
20: end
21: elsif logged_in? && can_access?("events")
22: redirect_to sadmin_events_path
23: elsif logged_in? && current_user.is_a?(StreamingOperator)
24: redirect_to admin_stream_flows_path
25: else
26: flash[:notice] = t('no_tienes_permiso')
27: access_denied
28: end
29: end
# File app/controllers/sadmin/news_controller.rb, line 31
31: def index
32: @sort_order = params[:sort] || "update"
33:
34: case @sort_order
35: when "update"
36: order = "featured DESC, updated_at DESC, title_es, published_at DESC"
37: when "publish"
38: order = "featured DESC, published_at DESC, title_es, updated_at DESC"
39: when "title"
40: order = "featured DESC, lower(tildes(title_es)), published_at DESC, updated_at DESC"
41: end
42:
43: conditions = nil
44: if params[:q].present?
45: conditions = ["lower(tildes(coalesce(title_es, '') || ' ' || coalesce(title_eu, ''))) like ?", "%#{params[:q].tildes.downcase}%"]
46: end
47:
48: set_current_tab
49:
50: @news = News.paginate :page => params[:page], :per_page => 20,
51: :order => order,
52: :conditions => conditions
53:
54: @title = t("documents.News")
55:
56: end
# File app/controllers/sadmin/news_controller.rb, line 62
62: def new
63: @t = params[:t] || 'doc'
64: @title = t('sadmin.news.crear_noticia')
65: @news = News.new
66: if current_user.is_a?(DepartmentEditor)
67: @news.organization_id = current_user.department_id
68: end
69:
70: set_current_tab
71: end
# File app/controllers/sadmin/news_controller.rb, line 129
129: def published
130: @news = News.published.in_agencia.find(:all, :order => "published_at DESC")
131: end
# File app/controllers/sadmin/news_controller.rb, line 92
92: def update
93: @news.attributes = params[:news]
94: set_current_tab
95: @title = t('sadmin.modificar_what', :what => t('documents.News'))
96:
97: if @news.save
98: flash[:notice] = t('sadmin.guardado_correctamente', :what => t('documents.News'))
99: submit_to_ubervu(@news)
100: redirect_to sadmin_news_path(@news.id)
101: else
102: render :action => params[:return_to] || 'edit'
103: end
104: end