end
def new
- @au = Author.new
- @au.supply_default
+ @author = Author.new
+ @author.supply_default
respond_to do |format|
format.html # new.html.erb
end
def edit
- @au = Author.edit(params[:id], @author)
+ @author = Author.edit(params[:id], @operators)
end
def create
- @au = Author.new()
- @au.supply_default
- @au.attributes = params[:author]
- @au.overwrite @user.id
+ @author = Author.new()
+ @author.supply_default
+ @author.attributes = params[:author]
+ @author.overwrite @operators
respond_to do |format|
- if @au.save
+ if @author.save
flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human)
format.html { redirect_to root_path }
- format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist }
+ format.json { render json: @author.to_json(Author.show_json_opt), status: :created }
else
flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human)
format.html { render action: "new" }
end
def update
- @au = Author.edit(params[:id], @author)
- @au.attributes = params[:author]
- @au.overwrite @user.id
+ @author = Author.edit(params[:id], @operators)
+ @author.attributes = params[:author]
+ @author.overwrite @operators
respond_to do |format|
- if @au.save
+ if @author.save
flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human)
format.html { redirect_to '/home/configure' }
format.json { head :ok }
else
flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human)
format.html { render action: "edit" }
- format.json { render json: @au.errors, status: :unprocessable_entity }
+ format.json { render json: @author.errors, status: :unprocessable_entity }
end
end
end
validates :name, :presence => true, :length => {:maximum => 30}
validates :user_id, :numericality => true, :existence => {:both => false}
- validates :provider, :numericality => true
+ validates :provider_id, :numericality => {:allow_nil => true}
@@valid_encode_columns += ['name']
@@visible_count_options = {:conditions => ['artists.author_id is not null']}
['scroll_panels.scroll_id = ?', cid]
end
+ def self.list_order
+ 'scroll_panels.updated_at desc'
+ end
+
def self.list_where
'scrolls.visible > 0'
end
-<%= form_for(ar) do |f| %>
- <%= render 'system/error_explanation', :obj => ar %>
+<%= form_for(artist) do |f| %>
+ <%= render 'system/error_explanation', :obj => artist %>
<div class="field">
<%= f.label :name %><br />
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= render 'form', :ar => @ar %>
+<%= render 'form', :artist => @artist %>
<p>素材の投稿には絵師登録が必要です。</p>
<p>下記フォームで登録してください。</p>
-<%= render 'form', :ar => @ar %>
+<%= render 'form', :artist => @artist %>
<%= link_to t('link.back'), artists_path %>
-<%= form_for(au) do |f| %>
- <%= render 'system/error_explanation', :obj => au %>
+<%= form_for(author) do |f| %>
+ <%= render 'system/error_explanation', :obj => author %>
<div class="field">
<%= f.label :name %><br />
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= render 'form', :au => @au %>
+<%= render 'form', :author => @author %>
<h1><%= t '.title' -%></h1>
<h2><%= t '.announce' -%></h2>
-<%= render 'form', :au => @au %>
+<%= render 'form', :author => @author %>
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= t('home.configure.caption', :email => @user.email) %>
+<%= t('home.configure.caption', :email => @operators.user.email) %>
<table class="no-border" width="100%">
<tr>
<td width="70%">
<h2><%= t 'home.configure.password_caption' -%></h2>
- <%= render '/users/registrations/form', :resource => @user %>
+ <%= render '/users/registrations/form', :resource => @operators.user %>
<h2><%= t 'home.configure.token_caption' -%></h2>
- <% if @user.authentication_token %>
- <div><%= t 'home.configure.your_token', :token => @user.authentication_token -%></div>
+ <% if @operators.user.authentication_token %>
+ <div><%= t 'home.configure.your_token', :token => @operators.user.authentication_token -%></div>
<%= link_to t('home.configure.delete_token'), :action => :delete_token %>
<% else %>
<div><%= t 'home.configure.about_token' -%></div>
</td>
<td width="30%">
<h2><%= t_m 'Author' -%></h2>
- <% if @author %>
- <%= render '/authors/form', :au => @author %>
+ <% if @operators.author %>
+ <%= render '/authors/form', :author => @operators.author %>
<% else %>
<div><%= t 'home.configure.no_author' -%></div>
<div><%= t 'home.configure.about_author' -%></div>
- <% @au = Author.new ; @au.supply_default %>
- <%= render '/authors/form', :au => @au %>
+ <% @author = Author.new ; @author.supply_default %>
+ <%= render '/authors/form', :author => @author %>
<% end %>
<h2><%= t_m 'Artist' -%></h2>
- <% if @artist %>
- <%= render '/artists/form', :ar => @artist %>
+ <% if @operators.artist %>
+ <%= render '/artists/form', :artist => @operators.artist %>
<% else %>
<div><%= t 'home.configure.no_artist' -%></div>
<div><%= t 'home.configure.about_artist' -%></div>
- <% @ar = Artist.new ; @ar.supply_default %>
- <%= render '/artists/form', :ar => @ar %>
+ <% @artist = Artist.new ; @artist.supply_default %>
+ <%= render '/artists/form', :artist => @artist %>
<% end %>
</td>
</tr>
<table class="no-border">\r
<tr>\r
<td width="50%">\r
- <h3><%= link_to MagicNumber['profile']['users']['caption'], main_app.root_path %></h3>\r
+ <h3><%= link_to manifest.magic_numbers['profile']['users']['caption'], main_app.root_path %></h3>\r
</td>\r
<td width="30%">\r
<% if user_signed_in? %>\r
</td>\r
<td>\r
<div>\r
- <% if @author %>\r
- <%= link_to h(truncate(@author.name, :length => 12)), main_app.author_path(@author) %>\r
+ <% if @operators.author %>\r
+ <%= link_to h(truncate(@operators.author.name, :length => 12)), main_app.author_path(@operators.author) %>\r
<% end %>\r
</div>\r
<div>\r
- <% if @artist %>\r
- <%= link_to h(truncate(@artist.name, :length => 12)), main_app.artist_path(@artist) %>\r
+ <% if @operators.artist %>\r
+ <%= link_to h(truncate(@operators.artist.name, :length => 12)), main_app.artist_path(@operators.artist) %>\r
<% end %>\r
</div>\r
</td>\r
<div>\r
<%= 'has_many' %>\r
</div>\r
-<% profiler.each_belongs_to do |has_many_filer| %>\r
+<% profiler.each_has_many do |has_many_filer| %>\r
<%= render 'system/filer.html', :filer => has_many_filer %>\r
<% end %>\r
<div>\r
end
def paginate
- @model.list_paginate(@page, @page_size)
+ Kaminari.paginate_array(Array.new(@model.where(self.where()).includes(@model.list_opt).count, nil)).page(page).per(page_size)
end
end
end
def paginate
- @model.list_paginate(@page, @page_size)
+ Kaminari.paginate_array(Array.new(@model.where(self.where(parent_item)).includes(@model.list_opt).count, nil)).page(page).per(page_size)
end
end
@filter_key = @conf['filter_key']
end
+ def where filter_item
+ w = @model.list_where
+ w += ' and ' unless w.blank?
+ p w
+ p @model.table_name
+ p @filter_key
+ p filter_item
+ [w + @model.table_name + '.' + @filter_key + ' = ?', filter_item.id]
+ end
+
def items filter_item
- @model.filtered_list filter_item, @filter_key, @operators, @page, @page_size
+ @model.where(self.where(filter_item)).includes(@model.list_opt).order(@model.list_order).offset(@offset).limit(@page_size)
end
def paginate filter_item
- @model.list_paginate(filter_item, @filter_key, @operators, @page, @page_size)
+ Kaminari.paginate_array(Array.new(@model.where(self.where(filter_item)).includes(@model.list_opt).count, nil)).page(page).per(page_size)
end
end
def each_has_many
@has_many_conf.each do |profiler_list_name|
- model_name = @lists['model_name']
- list_name = @lists['list_name']
+ model_name = @lists[profiler_list_name]['model_name']
+ list_name = @lists[profiler_list_name]['list_name']
list = @manifest.list_managers[model_name].open(list_name, 1, 3, @operators)
- items = list.items
+ items = list.items @item
has_many_filer = @manifest.filer_managers[model_name].open model_name, items, @operators, nil
yield has_many_filer
end
end
#InstanceMethods
+ def find_user
+ @operators.each do |operator|
+ return operator if operator.is_a?(User)
+ return operator.user if operator.is_a?(Author)
+ return operator.user if operator.is_a?(Artist)
+ end
+ nil
+ end
+
def find_author
@operators.each do |operator|
return operator if operator.is_a?(Author)
nil
end
+ def user
+ return @user if @user
+ @user = find_user
+ end
+
def author
return @author if @author
@author = find_author