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.action_name, @operators, params
123 respond_to do |format|
125 @filer = Locmare::Filer.new @list.item_name, @items, @list.page_status, @operators
126 render @filer.template_name, :locals => {
132 :page_status => @list.page_status.to_hash,
133 # rails3.2 has problem
134 # y method defined as private
135 # attribute y conflict at PanelPicture, balloon ..etc
136 # use i.attributes[name]
137 :list => @items.map{|i| i.attributes}
138 # :list => @items.to_json
140 render json: res.to_json
149 @binder_controller = Manifest.manifest.controllers[params[:controller].to_s]
150 @binder_action = @my_controller.actions[params[:action].to_s]
151 @binder_model = Manifest.manifest.models[@binder_action.item_name]
152 @binder_model_class = @binder_model.classify
153 @item = @binder_model_class.show(params[:id], @operators)
158 @options[:my_play] = @item.own?(@operators)
159 list_result = @list.open(@operators)
160 @items = list_result.items
161 @count = list_result.count
162 @pager = list_result.paginate
167 @item = @my_model_class.show(params[:id], @operators)
170 def show_prof_format format
172 self.formats = [:html]
173 @profiler = Locmare::Profiler.new @my_model_class.item_name, @item, @operators
174 render @profiler.template_name, :locals => {
175 :profiler => @profiler
180 def show_json_format format
181 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
184 def show_json_format_for_root format
185 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
190 @item = @my_model_class.new
197 @item = @my_model_class.edit(params[:id], @operators)
202 respond_to do |format|
204 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
205 render @form.template_name, :locals => {
209 format.json { render json: @item.to_json }
223 def created_html_format format, redirect_url = nil
225 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
226 redirect_to (redirect_url ? redirect_url : @item)
230 def created_json_format format
232 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
236 def not_created_html_format format
238 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
243 def not_created_json_format format
245 render json: @item.errors, status: :unprocessable_entity
249 def render_create redirect_url = nil
251 respond_to do |format|
252 created_html_format format, redirect_url
253 created_json_format format
256 respond_to do |format|
257 not_created_html_format format
258 not_created_json_format format
263 def leaf_created_html_format format, redirect_url
265 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
266 redirect_to redirect_url
270 def leaf_not_created_html_format format, redirect_url
272 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
273 redirect_to redirect_url
277 def leaf_render_create redirect_url
278 if @item.store @operators
279 respond_to do |format|
280 leaf_created_html_format format, redirect_url
281 created_json_format format
284 respond_to do |format|
285 leaf_not_created_html_format format, redirect_url
286 not_created_json_format format
291 def updated_html_format format, redirect_url = nil
293 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
294 redirect_to (redirect_url ? redirect_url : @item)
298 def updated_json_format format
304 def not_updated_html_format format
306 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
311 def not_updated_json_format format
313 render json: @item.errors, status: :unprocessable_entity
317 def render_update redirect_url = nil
319 respond_to do |format|
320 updated_html_format format, redirect_url
321 updated_json_format format
324 respond_to do |format|
325 not_updated_html_format format
326 not_updated_json_format format
331 def leaf_updated_html_format format, redirect_url
333 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
334 redirect_to redirect_url
338 def leaf_not_updated_html_format format, redirect_url
340 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
341 redirect_to redirect_url
345 def leaf_render_update ot, redirect_url
346 if @item.store @operators, ot
347 respond_to do |format|
348 leaf_updated_html_format format, redirect_url
349 updated_json_format format
352 respond_to do |format|
353 leaf_not_updated_html_format format, redirect_url
354 not_updated_json_format format
359 def destroyed_html_format format, redirect_url
361 flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human)
362 redirect_to redirect_url
366 def destroyed_json_format format
372 def not_destroyed_html_format format
374 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human)
379 def not_destroyed_json_format format
381 render json: @item.errors, status: :unprocessable_entity
385 def render_destroy redirect_url = nil
387 respond_to do |format|
388 destroyed_html_format format, redirect_url
389 destroyed_json_format format
392 respond_to do |format|
393 not_destroyed_html_format format
394 not_destroyed_json_format format
401 j = {:count => @list.count()}
402 respond_to do |format|
403 format.json { render json: j.to_json }
407 def format_filer format
409 @paginate = @@model.list_paginate(@page, @page_size)
410 render :template => 'system/filer', :locals => {
411 :items => @items, :model => @@model,
412 :operators => @operators, :pager => @paginate
417 def format_prof format
419 @profiler = self.class.profiler_manager.open(@item, @operators)
420 render :template => 'system/prof', :locals => {
421 :profiler => @profiler
426 def assist_items controller_name, list_name
427 list = Locmare::ListGroup.list controller_name, list_name, @operators, {:id => @item.id, :page => 1, :page_size => 5}
428 list_result = list.open(@operators)
433 if file.respond_to?(:read)
436 Base64.decode64(file.to_s.gsub(' ', '+'))
440 def ymd_to_time ymd_str
441 return nil if ymd_str.blank?
444 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
451 def export_url demander_url, action, token, date
452 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
453 prm = '?auth_token=' + token
454 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
455 u = URI.join(u, action + '.json' + prm)
459 def export_from_provider url
462 json = RestClient.get url
463 res = JSON.parse json
469 def export_by action, provider_status, ymd
471 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
472 export_from_provider(url)
475 rescue_from Pettanr::NotWork, :with => :render_not_work
476 def render_not_work(exception = nil)
478 logger.info "Rendering , :: #{exception.message}"
480 respond_to do |format|
482 render :file => "#{Rails.root}/public/not_work.html", :layout => false
485 render :text => "400 Not work", :status => 400
490 if Rails.env == 'production'
491 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
492 rescue_from ActiveRecord::Forbidden, :with => :render_403
495 def render_404(exception = nil)
497 logger.info "Rendering 404: #{exception.message}"
499 respond_to do |format|
501 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
504 render :text => "404 Not found", :status => 404
509 def render_403(exception = nil)
511 logger.info "Rendering 403: #{exception.message}"
513 respond_to do |format|
515 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
518 render :text => "403 Forbidden", :status => 403