1 class ApplicationController < ActionController::Base
23 :location => {:controller => params[:controller], :action => params[:action]}
25 @server_result[:location][:id] = params[:id] if params[:id]
26 user = if user_signed_in?
41 admin = if admin_signed_in?
46 demand_user = if demand_user_signed_in?
51 @operators = Operator.new [user, author, artist, admin, demand_user]
54 def authenticate_reader
55 authenticate_user! unless @operators.reader?
59 authenticate_user! unless @operators.user?
62 def authenticate_resource_reader
63 authenticate_user! unless @operators.resource_reader?
66 def authenticate_admin
67 authenticate_admin! unless @operators.admin?
70 def authenticate_author
74 respond_to do |format|
75 format.html { redirect_to main_app.new_author_path, :status => :found }
77 raise ActiveRecord::Forbidden
84 def authenticate_artist
88 respond_to do |format|
89 format.html { redirect_to main_app.new_artist_path, :status => :found }
91 raise ActiveRecord::Forbidden
99 Manifest.manifest.controllers[self.model.item_name]
102 def self.profiler_manager
103 Manifest.manifest.profiler_managers[self.model.item_name]
107 @my_controller = Manifest.manifest.controllers[params[:controller].to_s]
108 @my_action = @my_controller.actions[params[:action].to_s]
109 @my_model = Manifest.manifest.models[@my_action.item_name]
110 @my_model_class = @my_model.classify
115 @my_list_model = Manifest.manifest.models[@my_action.item_name]
116 @my_list_model_class = @my_list_model.classify
117 @list = Locmare::ListGroup.list @my_controller.name, @my_action.name, @operators, params
122 list_result = @list.open(@operators)
123 @items = list_result.items
124 respond_to do |format|
126 @filer = Locmare::Filer.new @list.item_name, list_result.items, list_result, :default, @operators
127 render @filer.template_name, :locals => {
131 format.json { render json: @items.map{|i| i.attributes}.to_json }
132 # rails3.2 has problem
133 # y method defined as private
134 # attribute y conflict at PanelPicture, balloon ..etc
135 # use i.attributes[name]
136 # format.json { render json: @items.to_json }
144 @binder_controller = Manifest.manifest.controllers[params[:controller].to_s]
145 @binder_action = @my_controller.actions[params[:action].to_s]
146 @binder_model = Manifest.manifest.models[@binder_action.item_name]
147 @binder_model_class = @binder_model.classify
148 @item = @binder_model_class.show(params[:id], @operators)
153 @options[:my_play] = @item.own?(@operators)
154 list_result = @list.open(@operators)
155 @items = list_result.items
156 @count = list_result.count
157 @pager = list_result.paginate
162 @item = @my_model_class.show(params[:id], @operators)
165 def show_prof_format format
167 self.formats = [:html]
168 @profiler = Locmare::Profiler.new @my_model_class.item_name, @item, @operators
169 render @profiler.template_name, :locals => {
170 :profiler => @profiler
175 def show_json_format format
176 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
179 def show_json_format_for_root format
180 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
185 @item = @my_model_class.new
192 @item = @my_model_class.edit(params[:id], @operators)
197 respond_to do |format|
199 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
200 render @form.template_name, :locals => {
204 format.json { render json: @item.to_json }
218 def created_html_format format, redirect_url = nil
220 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
221 redirect_to (redirect_url ? redirect_url : @item)
225 def created_json_format format
227 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
231 def not_created_html_format format
233 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
238 def not_created_json_format format
240 render json: @item.errors, status: :unprocessable_entity
244 def render_create redirect_url = nil
246 respond_to do |format|
247 created_html_format format, redirect_url
248 created_json_format format
251 respond_to do |format|
252 not_created_html_format format
253 not_created_json_format format
258 def leaf_created_html_format format, redirect_url
260 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
261 redirect_to redirect_url
265 def leaf_not_created_html_format format, redirect_url
267 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
268 redirect_to redirect_url
272 def leaf_render_create redirect_url
273 if @item.store @operators
274 respond_to do |format|
275 leaf_created_html_format format, redirect_url
276 created_json_format format
279 respond_to do |format|
280 leaf_not_created_html_format format, redirect_url
281 not_created_json_format format
286 def updated_html_format format, redirect_url = nil
288 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
289 redirect_to (redirect_url ? redirect_url : @item)
293 def updated_json_format format
299 def not_updated_html_format format
301 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
306 def not_updated_json_format format
308 render json: @item.errors, status: :unprocessable_entity
312 def render_update redirect_url = nil
314 respond_to do |format|
315 updated_html_format format, redirect_url
316 updated_json_format format
319 respond_to do |format|
320 not_updated_html_format format
321 not_updated_json_format format
326 def leaf_updated_html_format format, redirect_url
328 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
329 redirect_to redirect_url
333 def leaf_not_updated_html_format format, redirect_url
335 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
336 redirect_to redirect_url
340 def leaf_render_update ot, redirect_url
341 if @item.store @operators, ot
342 respond_to do |format|
343 leaf_updated_html_format format, redirect_url
344 updated_json_format format
347 respond_to do |format|
348 leaf_not_updated_html_format format, redirect_url
349 not_updated_json_format format
354 def destroyed_html_format format, redirect_url
356 flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human)
357 redirect_to redirect_url
361 def destroyed_json_format format
367 def not_destroyed_html_format format
369 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human)
374 def not_destroyed_json_format format
376 render json: @item.errors, status: :unprocessable_entity
380 def render_destroy redirect_url = nil
382 respond_to do |format|
383 destroyed_html_format format, redirect_url
384 destroyed_json_format format
387 respond_to do |format|
388 not_destroyed_html_format format
389 not_destroyed_json_format format
396 j = {:count => @list.count(@operators)}
397 respond_to do |format|
398 format.json { render json: j.to_json }
402 def format_filer format
404 @paginate = @@model.list_paginate(@page, @page_size)
405 render :template => 'system/filer', :locals => {
406 :items => @items, :model => @@model,
407 :operators => @operators, :pager => @paginate
412 def format_prof format
414 @profiler = self.class.profiler_manager.open(@item, @operators)
415 render :template => 'system/prof', :locals => {
416 :profiler => @profiler
421 def assist_items controller_name, list_name
422 list = Locmare::ListGroup.list controller_name, list_name, @operators, {:id => @item.id, :page => 1, :page_size => 5}
423 list_result = list.open(@operators)
428 if file.respond_to?(:read)
431 Base64.decode64(file.to_s.gsub(' ', '+'))
435 def ymd_to_time ymd_str
436 return nil if ymd_str.blank?
439 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
446 def export_url demander_url, action, token, date
447 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
448 prm = '?auth_token=' + token
449 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
450 u = URI.join(u, action + '.json' + prm)
454 def export_from_provider url
457 json = RestClient.get url
458 res = JSON.parse json
464 def export_by action, provider_status, ymd
466 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
467 export_from_provider(url)
470 rescue_from Pettanr::NotWork, :with => :render_not_work
471 def render_not_work(exception = nil)
473 logger.info "Rendering , :: #{exception.message}"
475 respond_to do |format|
477 render :file => "#{Rails.root}/public/not_work.html", :layout => false
480 render :text => "400 Not work", :status => 400
485 if Rails.env == 'production'
486 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
487 rescue_from ActiveRecord::Forbidden, :with => :render_403
490 def render_404(exception = nil)
492 logger.info "Rendering 404: #{exception.message}"
494 respond_to do |format|
496 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
499 render :text => "404 Not found", :status => 404
504 def render_403(exception = nil)
506 logger.info "Rendering 403: #{exception.message}"
508 respond_to do |format|
510 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
513 render :text => "403 Forbidden", :status => 403