end
end
- def set_filer
- @page = @@model.page_number params[:page]
- @page_size = @@model.page_size params[:page_size]
- list_method = 'list' || configurations['models'][@@model.to_s.underscore]['select']['method']
- @items = @@model.__send__(list_method, @page, @page_size)
+ def self.controller
+ Pettanr::Application::manifest.controller_managers[self.model.item_name]
+ end
+
+ def self.profiler_manager
+ Pettanr::Application::manifest.profiler_managers[self.model.item_name]
+ end
+
+ def public_list
+ action_name = params[:action]
+ @action = self.class.controller.open(action_name, params, @operators)
+ @items = @action.items
+ respond_to do |format|
+ format.html {
+ @filer = @action.filer
+ render :template => 'system/filer', :locals => {
+ :filer => @filer
+ }
+ }
+ format.json { render json: @items.to_json(self.class.model.list_json_opt) }
+ format.atom
+ format.rss
+ end
end
def format_filer format
def self.model
Comic
end
- def self.controller
- Pettanr::Application::manifest.controller_managers[self.model.item_name]
- end
- def self.profiler_manager
- Pettanr::Application::manifest.profiler_managers[self.model.item_name]
- end
def index
- action_name = params[:action]
- @action = self.class.controller.open(action_name, params, @operators)
- @items = @action.items
- respond_to do |format|
- format.html {
- @filer = @action.filer
- render :template => 'system/filer', :locals => {
- :filer => @filer
- }
- }
- format.json { render json: @items.to_json(self.class.model.list_json_opt) }
- format.atom
- format.rss
- end
+ public_list
end
def show
@comic = Comic.new
@comic.supply_default
@comic.attributes = params[:comic]
- @comic.overwrite @author
+ @comic.overwrite @operators
respond_to do |format|
if @comic.save
end
def update
- @comic = Comic.edit(params[:id], @author)
+ @comic = Comic.edit(params[:id], @operators)
@comic.attributes = params[:comic]
- @comic.overwrite @author
+ @comic.overwrite @operators
respond_to do |format|
if @comic.save
flash[:notice] = I18n.t('flash.notice.updated', :model => Comic.model_name.human)
before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
end
before_filter :authenticate_admin!, :only => [:list, :browse]
-
- @@model = Scroll
- @@controller = Pettanr::Application::manifest.controller_managers[@@model.item_name]
- @@profiler_manager = Pettanr::Application::manifest.profiler_managers[@@model.item_name]
+
+ def self.model
+ Scroll
+ end
def index
- action_name = params[:action]
- @action = @@controller.open(action_name, params, @operators)
- @items = @action.items
- respond_to do |format|
- format.html {
- @filer = @action.filer
- render :template => 'system/filer', :locals => {
- :filer => @filer
- }
- }
- format.json { render json: @items.to_json(@@model.list_json_opt) }
- format.atom
- format.rss
- end
+ public_list
end
def show
validates :user_id, :numericality => true, :existence => {:both => false}
validates :provider_id, :numericality => {:allow_nil => true}
- @@valid_encode_columns += ['name']
@@visible_count_options = {:conditions => ['artists.author_id is not null']}
+ def self.singular
+ 'Artist'
+ end
+
+ def self.plural
+ 'Artists'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name']
+ end
def supply_default
self.name = 'no name' if self.name.blank?
validates :working_panel_id, :numericality => {:allow_nil => true}
validates :user_id, :numericality => true, :existence => {:both => false}
- @@singular = 'Author'
- @@plural = 'Authors'
- @@valid_encode_columns += ['name']
- # @@visible_count_options = {}
+ def self.singular
+ 'Author'
+ end
+
+ def self.plural
+ 'Authors'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name']
+ end
def supply_default
self.name = 'no name' if self.name.blank?
-class Balloon < ActiveRecord::Base
+class Balloon < Pettanr::Item
include ElementPart
belongs_to :speech_balloon
belongs_to :system_picture
# validates :caption, :presence => true
validates :settings, :extend_balloon => true
- before_validation :valid_encode
+ def self.singular
+ 'Balloon'
+ end
- def valid_encode
- ['settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'Balloons'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['settings']
end
def self.colum_structures
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
- @@valid_encode_columns += ['title', 'description']
@@visible_count_options = {:conditions => 'visible > 0'}
+ def self.singular
+ 'Comic'
+ end
+
+ def self.plural
+ 'Comics'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super + ['title', 'description']
+ end
+
def supply_default
self.visible = 0 if self.visible.blank?
end
- def overwrite au
- return false unless au
- self.author_id = au.id
+ def overwrite operators
+ return false unless operators.author
+ self.author_id = operators.author.id
end
def visible? operators
-class GroundColor < ActiveRecord::Base
+class GroundColor < Pettanr::Item
include Element
include ElementInspire
belongs_to :panel
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- before_validation :valid_encode
+ def self.singular
+ 'GroundColor'
+ end
- def valid_encode
- ['caption'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'GroundColors'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['caption']
end
def self.colum_structures
-class GroundPicture < ActiveRecord::Base
+class GroundPicture < Pettanr::Item
include Element
include ElementInspire
belongs_to :panel
@@repeat_texts = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
- before_validation :valid_encode
+ def self.singular
+ 'GroundPicture'
+ end
- def valid_encode
- ['caption'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'GroundPictures'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['caption']
end
def self.list_opt_for_panel
#
-class License < ActiveRecord::Base
+class License < Pettanr::Item
belongs_to :license_group
belongs_to :system_picture
has_many :resource_pictures
validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:message => I18n.t('errors.messages.url')} #{:allow_blank => true}
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
- before_validation :valid_encode
+ def self.singular
+ 'License'
+ end
- def valid_encode
- ['name', 'caption', 'url', 'settings', 'credit_pictures'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'Licenses'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name', 'caption', 'url', 'settings', 'credit_pictures']
end
def supply_default
#ライセンスグループ
-class LicenseGroup < ActiveRecord::Base
+class LicenseGroup < Pettanr::Item
has_many :licenses
validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
validates :caption, :presence => true, :length => {:maximum => 30}
validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
- before_validation :valid_encode
+ def self.singular
+ 'LicenseGroup'
+ end
- def valid_encode
- ['name', 'classname', 'caption', 'url'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'LicenseGroups'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name', 'classname', 'caption', 'url']
end
def supply_default
-class OriginalPicture < ActiveRecord::Base
+class OriginalPicture < Pettanr::Item
belongs_to :artist
belongs_to :original_picture_license_group
has_one :resource_picture
validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
+ def self.singular
+ 'OriginalPicture'
+ end
+
+ def self.plural
+ 'OriginalPictures'
+ end
+
+ def self.owner_type
+ :author
+ end
+
def supply_default
end
#コマ
-class Panel < ActiveRecord::Base
+class Panel < Pettanr::Item
belongs_to :author
has_many :scroll_panels
has_many :sheet_panels
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :publish, :presence => true, :numericality => true
- cattr_reader :singular, :plural
- @@singular = 'Panel'
- @@plural = 'Panels'
- def self.item_name
- self.singular.underscore
+ def self.singular
+ 'Panel'
end
- def item_name
- self.class.item_name
+ def self.plural
+ 'Panels'
end
- def self.path_name with_engine = false
- self.plural.underscore
+ def self.owner_type
+ :author
end
- def path_name
- self.class.path_name
- end
-
- before_validation :valid_encode
-
- def valid_encode
- ['caption'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.valid_encode_columns
+ super.merge ['caption']
end
def self.each_element_class_names
-class PanelPicture < ActiveRecord::Base
+class PanelPicture < Pettanr::Item
include Element
include ElementInspire
belongs_to :panel
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- before_validation :valid_encode
+ def self.singular
+ 'PanelPicture'
+ end
- def valid_encode
- ['link', 'caption'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'PanelPictures'
+ end
+
+ def self.valid_encode_columns
+ super.merge ['link', 'caption']
+ end
+
+ def self.owner_type
+ :author
end
def self.colum_structures
#実素材
-class Picture < ActiveRecord::Base
+class Picture < Pettanr::Item
belongs_to :original_picture
belongs_to :license
belongs_to :artist
validates :artist_name, :presence => true
validates :classname, :presence => true, :length => {:maximum => 50}
- before_validation :valid_encode
+ def self.singular
+ 'Picture'
+ end
- def valid_encode
- ['artist_name', 'classname', 'credit', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'Pictures'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['artist_name', 'classname', 'credit', 'settings']
end
def supply_default
#素材
-class ResourcePicture < ActiveRecord::Base
+class ResourcePicture < Pettanr::Item
belongs_to :artist
belongs_to :license
belongs_to :picture
validates :classname, :presence => true, :length => {:maximum => 50}
validates :picture_id, :presence => true, :numericality => true, :existence => {:both => false}
- before_validation :valid_encode
+ def self.singular
+ 'ResourcePicture'
+ end
- def valid_encode
- ['artist_name', 'classname', 'credit', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'ResourcePictures'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['artist_name', 'classname', 'credit', 'settings']
end
def supply_default
:author
end
+ def self.valid_encode_columns
+ super.merge ['title']
+ end
+
def supply_default
self.visible = 0 if self.visible.blank?
end
-class ScrollPanel < ActiveRecord::Base
+class ScrollPanel < Pettanr::Item
belongs_to :author
belongs_to :panel
belongs_to :scroll
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- cattr_reader :singular, :plural
- @@singular = 'ScrollPanel'
- @@plural = 'ScrollPanels'
- def self.item_name
- self.singular.underscore
+ def self.singular
+ 'ScrollPanel'
end
- def item_name
- self.class.item_name
+ def self.plural
+ 'ScrollPanels'
end
- def self.path_name with_engine = false
- self.plural.underscore
- end
-
- def path_name
- self.class.path_name
+ def self.owner_type
+ :author
end
def supply_default
-class Sheet < ActiveRecord::Base
+class Sheet < Pettanr::Item
has_many :sheet_panels
has_many :story_sheets
belongs_to :author
validates :height, :presence => true, :numericality => true, :natural_number => true
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
accepts_nested_attributes_for :sheet_panels, :allow_destroy => true
- before_validation :valid_encode
- def valid_encode
- ['caption'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.singular
+ 'Sheet'
+ end
+
+ def self.plural
+ 'Sheets'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['caption']
end
def self.each_element_class_names
-class SheetPanel < ActiveRecord::Base
+class SheetPanel < Pettanr::Item
belongs_to :author
belongs_to :panel
belongs_to :sheet
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ def self.singular
+ 'SheetPanel'
+ end
+
+ def self.plural
+ 'SheetPanels'
+ end
+
+ def self.owner_type
+ :author
+ end
+
def supply_default
self.x = 15
self.y = 15
-class Speech < ActiveRecord::Base
+class Speech < Pettanr::Item
include ElementPart
belongs_to :speech_balloon
belongs_to :writing_format
@@text_align_texts = ['left', 'left', 'right', 'center']
- before_validation :valid_encode
+ def self.singular
+ 'Speech'
+ end
- def valid_encode
- ['content', 'quotes', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'Speeches'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['content', 'quotes', 'settings']
end
def self.colum_structures
-class SpeechBalloon < ActiveRecord::Base
+class SpeechBalloon < Pettanr::Item
include Element
include ElementInspire
has_one :balloon, :dependent => :destroy
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
validates :settings, :extend_speech_balloon => true
- before_validation :valid_encode
+ def self.singular
+ 'SpeechBalloon'
+ end
- def valid_encode
- ['caption', 'classname', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'SpeechBalloons'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['caption', 'classname', 'settings']
end
def self.list_opt_for_panel
#フキダシテンプレート
-class SpeechBalloonTemplate < ActiveRecord::Base
+class SpeechBalloonTemplate < Pettanr::Item
has_many :speech_balloons
belongs_to :system_picture
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :settings, :presence => true
- before_validation :valid_encode
+ def self.singular
+ 'SpeechBalloonTemplate'
+ end
- def valid_encode
- ['name', 'classname', 'caption', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'SpeechBalloonTemplates'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name', 'classname', 'caption', 'settings']
end
def supply_default
#ストーリー
-class Story < ActiveRecord::Base
+class Story < Pettanr::Item
has_many :story_sheets
belongs_to :comic
validates :title, :presence => true, :length => {:maximum => 100}
validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- before_validation :valid_encode
- def valid_encode
- ['title', 'description'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.singular
+ 'Story'
+ end
+
+ def self.plural
+ 'Stories'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['title', 'description']
end
def supply_default
-class StorySheet < ActiveRecord::Base
+class StorySheet < Pettanr::Item
belongs_to :author
belongs_to :story
belongs_to :sheet
validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ def self.singular
+ 'StorySheet'
+ end
+
+ def self.plural
+ 'StorySheets'
+ end
+
+ def self.owner_type
+ :author
+ end
+
def supply_default
self.story_id = nil
self.sheet_id = nil
-class SystemPicture < ActiveRecord::Base
+class SystemPicture < Pettanr::Item
has_many :balloons
has_many :balloon_templates
has_many :licenses
validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
+ def self.singular
+ 'SystemPicture'
+ end
+
+ def self.plural
+ 'SystemPictures'
+ end
+
+ def self.owner_type
+ :author
+ end
+
before_destroy :destroy_with_file
def destroy_with_file
-class WritingFormat < ActiveRecord::Base
+class WritingFormat < Pettanr::Item
has_many :speeches
belongs_to :system_picture
validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :settings, :presence => true
- before_validation :valid_encode
+ def self.singular
+ 'WritingFormat'
+ end
- def valid_encode
- ['name', 'classname', 'caption', 'settings'].each do |a|
- next if attributes[a] == nil
- raise Pettanr::BadRequest unless attributes[a].valid_encoding?
- end
+ def self.plural
+ 'WritingFormats'
+ end
+
+ def self.owner_type
+ :author
+ end
+
+ def self.valid_encode_columns
+ super.merge ['name', 'classname', 'caption', 'settings']
end
def supply_default
</div>
<div class="field">
<%= f.label :author_id %><br />
- <%= h @author.name %>
+ <%= h @operators.author.name %>
</div>
<div class="row_break">
</div>
<%= l @comic.updated_at %>
</p>
-<% if @comic.own? @author -%>
+<% if @comic.own? @operators -%>
<%= link_to t('link.edit'), edit_comic_path(@comic) %>
<%= link_to t('link.destroy'), comic_path(@comic), :method => :delete %>
</div>
<div class="field">
<%= f.label :author_id %><br />
- <%= h @author.name %>
+ <%= h @operators.author.name %>
</div>
<div class="row_break">
</div>
before_validation :valid_encode
- cattr_accessor :valid_encode_columns, :visible_count_options
- @@valid_encode_columns = []
- @@visible_count_options = {}
+ def self.valid_encode_columns
+ []
+ end
+
def self.singular
- 'Item'
+ self.class.to_s
end
def self.plural
- 'Items'
+ self.singular.pluralize
end
def self.item_name
self.count self.visible_count_options
end
+ def self.visible_count_options
+ []
+ end
+
#InstanceMethods
def item_name
def type_default view, item, operators
if item.own? operators
- view.link_to tag(:img, :src => view.asset_path('edit.png'), :width => 32, :height => 32),
+ view.link_to view.tag(:img, :src => view.asset_path('edit.png'), :width => 32, :height => 32),
view.polymorphic_path(item, :action => :edit)
- view.link_to tag(:img, :src => view.asset_path('remove.png'), :width => 32, :height => 32),
+ view.link_to view.tag(:img, :src => view.asset_path('remove.png'), :width => 32, :height => 32),
item, confirm: 'Are you sure?', :method => :delete
end
end