From 9e6a7b976f22e15609976da5194ea6344e71ea4d Mon Sep 17 00:00:00 2001 From: yasushiito Date: Wed, 11 Dec 2013 11:56:30 +0900 Subject: [PATCH] temp --- app/controllers/application_controller.rb | 28 +++++++++++++++++++++++----- app/controllers/comics_controller.rb | 27 ++++----------------------- app/controllers/scrolls_controller.rb | 23 +++++------------------ app/models/artist.rb | 16 +++++++++++++++- app/models/author.rb | 19 +++++++++++++++---- app/models/balloon.rb | 21 ++++++++++++++------- app/models/comic.rb | 23 +++++++++++++++++++---- app/models/ground_color.rb | 21 ++++++++++++++------- app/models/ground_picture.rb | 21 ++++++++++++++------- app/models/license.rb | 21 ++++++++++++++------- app/models/license_group.rb | 21 ++++++++++++++------- app/models/original_picture.rb | 14 +++++++++++++- app/models/panel.rb | 30 +++++++++--------------------- app/models/panel_picture.rb | 21 ++++++++++++++------- app/models/picture.rb | 21 ++++++++++++++------- app/models/resource_picture.rb | 21 ++++++++++++++------- app/models/scroll.rb | 4 ++++ app/models/scroll_panel.rb | 21 +++++++-------------- app/models/sheet.rb | 22 +++++++++++++++------- app/models/sheet_panel.rb | 14 +++++++++++++- app/models/speech.rb | 21 ++++++++++++++------- app/models/speech_balloon.rb | 21 ++++++++++++++------- app/models/speech_balloon_template.rb | 21 ++++++++++++++------- app/models/story.rb | 22 +++++++++++++++------- app/models/story_sheet.rb | 14 +++++++++++++- app/models/system_picture.rb | 14 +++++++++++++- app/models/writing_format.rb | 21 ++++++++++++++------- app/views/comics/_form.html.erb | 2 +- app/views/comics/show.html.erb | 2 +- app/views/stories/_form.html.erb | 2 +- lib/item.rb | 15 ++++++++++----- lib/manifest/filer.rb | 4 ++-- 32 files changed, 366 insertions(+), 202 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa4f3a6a..3d6d1af1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -100,11 +100,29 @@ class ApplicationController < ActionController::Base 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 diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index 57f1efff..f1f2909a 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -13,28 +13,9 @@ class ComicsController < ApplicationController 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 @@ -102,7 +83,7 @@ class ComicsController < ApplicationController @comic = Comic.new @comic.supply_default @comic.attributes = params[:comic] - @comic.overwrite @author + @comic.overwrite @operators respond_to do |format| if @comic.save @@ -118,9 +99,9 @@ class ComicsController < ApplicationController 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) diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index ef9bb0c9..863243e6 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -9,26 +9,13 @@ class ScrollsController < ApplicationController 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 diff --git a/app/models/artist.rb b/app/models/artist.rb index e1ef12d4..9f702a4c 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -8,8 +8,22 @@ class Artist < Pettanr::Owner 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? diff --git a/app/models/author.rb b/app/models/author.rb index d0956137..fda9f342 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -10,10 +10,21 @@ class Author < Pettanr::Owner 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? diff --git a/app/models/balloon.rb b/app/models/balloon.rb index 611481fc..33e2c406 100644 --- a/app/models/balloon.rb +++ b/app/models/balloon.rb @@ -1,4 +1,4 @@ -class Balloon < ActiveRecord::Base +class Balloon < Pettanr::Item include ElementPart belongs_to :speech_balloon belongs_to :system_picture @@ -13,13 +13,20 @@ class Balloon < ActiveRecord::Base # 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 diff --git a/app/models/comic.rb b/app/models/comic.rb index fbb04e27..19149d5b 100644 --- a/app/models/comic.rb +++ b/app/models/comic.rb @@ -7,16 +7,31 @@ class Comic < Pettanr::Content 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 diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index 2f61ce16..5e8651f8 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -1,4 +1,4 @@ -class GroundColor < ActiveRecord::Base +class GroundColor < Pettanr::Item include Element include ElementInspire belongs_to :panel @@ -12,13 +12,20 @@ class GroundColor < ActiveRecord::Base 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 diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index 647bf232..4b4269ec 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -1,4 +1,4 @@ -class GroundPicture < ActiveRecord::Base +class GroundPicture < Pettanr::Item include Element include ElementInspire belongs_to :panel @@ -14,13 +14,20 @@ class GroundPicture < ActiveRecord::Base @@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 diff --git a/app/models/license.rb b/app/models/license.rb index 50c5116a..f162b27e 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,5 +1,5 @@ # -class License < ActiveRecord::Base +class License < Pettanr::Item belongs_to :license_group belongs_to :system_picture has_many :resource_pictures @@ -10,13 +10,20 @@ class License < ActiveRecord::Base 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 diff --git a/app/models/license_group.rb b/app/models/license_group.rb index cc09080d..dad81570 100644 --- a/app/models/license_group.rb +++ b/app/models/license_group.rb @@ -1,5 +1,5 @@ #ライセンスグループ -class LicenseGroup < ActiveRecord::Base +class LicenseGroup < Pettanr::Item has_many :licenses validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true @@ -7,13 +7,20 @@ class LicenseGroup < ActiveRecord::Base 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 diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index db527442..c141cc80 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -1,4 +1,4 @@ -class OriginalPicture < ActiveRecord::Base +class OriginalPicture < Pettanr::Item belongs_to :artist belongs_to :original_picture_license_group has_one :resource_picture @@ -11,6 +11,18 @@ class OriginalPicture < ActiveRecord::Base 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 diff --git a/app/models/panel.rb b/app/models/panel.rb index 7856a9b3..33a99b61 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -1,5 +1,5 @@ #コマ -class Panel < ActiveRecord::Base +class Panel < Pettanr::Item belongs_to :author has_many :scroll_panels has_many :sheet_panels @@ -18,32 +18,20 @@ class Panel < ActiveRecord::Base 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 diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 8aa6809e..ccb5cd07 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -1,4 +1,4 @@ -class PanelPicture < ActiveRecord::Base +class PanelPicture < Pettanr::Item include Element include ElementInspire belongs_to :panel @@ -14,13 +14,20 @@ class PanelPicture < ActiveRecord::Base 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 diff --git a/app/models/picture.rb b/app/models/picture.rb index dc043294..16f654c8 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -1,5 +1,5 @@ #実素材 -class Picture < ActiveRecord::Base +class Picture < Pettanr::Item belongs_to :original_picture belongs_to :license belongs_to :artist @@ -17,13 +17,20 @@ class Picture < ActiveRecord::Base 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 diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 935c3e2f..92da32ba 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -1,5 +1,5 @@ #素材 -class ResourcePicture < ActiveRecord::Base +class ResourcePicture < Pettanr::Item belongs_to :artist belongs_to :license belongs_to :picture @@ -17,13 +17,20 @@ class ResourcePicture < ActiveRecord::Base 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 diff --git a/app/models/scroll.rb b/app/models/scroll.rb index 73eed47d..291ff0c8 100644 --- a/app/models/scroll.rb +++ b/app/models/scroll.rb @@ -18,6 +18,10 @@ class Scroll < Pettanr::Item :author end + def self.valid_encode_columns + super.merge ['title'] + end + def supply_default self.visible = 0 if self.visible.blank? end diff --git a/app/models/scroll_panel.rb b/app/models/scroll_panel.rb index 1860ac15..048c2898 100644 --- a/app/models/scroll_panel.rb +++ b/app/models/scroll_panel.rb @@ -1,4 +1,4 @@ -class ScrollPanel < ActiveRecord::Base +class ScrollPanel < Pettanr::Item belongs_to :author belongs_to :panel belongs_to :scroll @@ -8,23 +8,16 @@ class ScrollPanel < ActiveRecord::Base 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 diff --git a/app/models/sheet.rb b/app/models/sheet.rb index 780cdbe6..0d9def85 100644 --- a/app/models/sheet.rb +++ b/app/models/sheet.rb @@ -1,4 +1,4 @@ -class Sheet < ActiveRecord::Base +class Sheet < Pettanr::Item has_many :sheet_panels has_many :story_sheets belongs_to :author @@ -8,13 +8,21 @@ class Sheet < ActiveRecord::Base 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 diff --git a/app/models/sheet_panel.rb b/app/models/sheet_panel.rb index 1ff1de2c..547d638c 100644 --- a/app/models/sheet_panel.rb +++ b/app/models/sheet_panel.rb @@ -1,4 +1,4 @@ -class SheetPanel < ActiveRecord::Base +class SheetPanel < Pettanr::Item belongs_to :author belongs_to :panel belongs_to :sheet @@ -12,6 +12,18 @@ class SheetPanel < ActiveRecord::Base 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 diff --git a/app/models/speech.rb b/app/models/speech.rb index 7f310642..af6f09e8 100644 --- a/app/models/speech.rb +++ b/app/models/speech.rb @@ -1,4 +1,4 @@ -class Speech < ActiveRecord::Base +class Speech < Pettanr::Item include ElementPart belongs_to :speech_balloon belongs_to :writing_format @@ -17,13 +17,20 @@ class Speech < ActiveRecord::Base @@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 diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 00b5901d..10333606 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -1,4 +1,4 @@ -class SpeechBalloon < ActiveRecord::Base +class SpeechBalloon < Pettanr::Item include Element include ElementInspire has_one :balloon, :dependent => :destroy @@ -16,13 +16,20 @@ class SpeechBalloon < ActiveRecord::Base 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 diff --git a/app/models/speech_balloon_template.rb b/app/models/speech_balloon_template.rb index a639bf60..edcd2d8b 100644 --- a/app/models/speech_balloon_template.rb +++ b/app/models/speech_balloon_template.rb @@ -1,5 +1,5 @@ #フキダシテンプレート -class SpeechBalloonTemplate < ActiveRecord::Base +class SpeechBalloonTemplate < Pettanr::Item has_many :speech_balloons belongs_to :system_picture @@ -10,13 +10,20 @@ class SpeechBalloonTemplate < ActiveRecord::Base 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 diff --git a/app/models/story.rb b/app/models/story.rb index 3d20165f..88ce1702 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -1,5 +1,5 @@ #ストーリー -class Story < ActiveRecord::Base +class Story < Pettanr::Item has_many :story_sheets belongs_to :comic @@ -7,13 +7,21 @@ class Story < ActiveRecord::Base 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 diff --git a/app/models/story_sheet.rb b/app/models/story_sheet.rb index 0f493b15..08eac83a 100644 --- a/app/models/story_sheet.rb +++ b/app/models/story_sheet.rb @@ -1,4 +1,4 @@ -class StorySheet < ActiveRecord::Base +class StorySheet < Pettanr::Item belongs_to :author belongs_to :story belongs_to :sheet @@ -8,6 +8,18 @@ class StorySheet < ActiveRecord::Base 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 diff --git a/app/models/system_picture.rb b/app/models/system_picture.rb index 1d090bc1..a9cf03ec 100644 --- a/app/models/system_picture.rb +++ b/app/models/system_picture.rb @@ -1,4 +1,4 @@ -class SystemPicture < ActiveRecord::Base +class SystemPicture < Pettanr::Item has_many :balloons has_many :balloon_templates has_many :licenses @@ -9,6 +9,18 @@ class SystemPicture < ActiveRecord::Base 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 diff --git a/app/models/writing_format.rb b/app/models/writing_format.rb index 9ea43fc7..e7d04a27 100644 --- a/app/models/writing_format.rb +++ b/app/models/writing_format.rb @@ -1,4 +1,4 @@ -class WritingFormat < ActiveRecord::Base +class WritingFormat < Pettanr::Item has_many :speeches belongs_to :system_picture @@ -9,13 +9,20 @@ class WritingFormat < ActiveRecord::Base 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 diff --git a/app/views/comics/_form.html.erb b/app/views/comics/_form.html.erb index 5d9ce6af..cc645017 100644 --- a/app/views/comics/_form.html.erb +++ b/app/views/comics/_form.html.erb @@ -21,7 +21,7 @@
<%= f.label :author_id %>
- <%= h @author.name %> + <%= h @operators.author.name %>
diff --git a/app/views/comics/show.html.erb b/app/views/comics/show.html.erb index 4b73f495..9b7a8d60 100644 --- a/app/views/comics/show.html.erb +++ b/app/views/comics/show.html.erb @@ -40,7 +40,7 @@ <%= l @comic.updated_at %>

-<% 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 %> diff --git a/app/views/stories/_form.html.erb b/app/views/stories/_form.html.erb index d5d80a42..d197e6c1 100644 --- a/app/views/stories/_form.html.erb +++ b/app/views/stories/_form.html.erb @@ -27,7 +27,7 @@
<%= f.label :author_id %>
- <%= h @author.name %> + <%= h @operators.author.name %>
diff --git a/lib/item.rb b/lib/item.rb index 173850c3..e021dfd8 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -6,15 +6,16 @@ class Pettanr::Item < ActiveRecord::Base 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 @@ -61,6 +62,10 @@ class Pettanr::Item < ActiveRecord::Base self.count self.visible_count_options end + def self.visible_count_options + [] + end + #InstanceMethods def item_name diff --git a/lib/manifest/filer.rb b/lib/manifest/filer.rb index 03eea9fe..811435af 100644 --- a/lib/manifest/filer.rb +++ b/lib/manifest/filer.rb @@ -269,9 +269,9 @@ module Pettanr 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 -- 2.11.0