finished some method of list and journal
This commit is contained in:
1 parent
024b331cf3
commit
26436395f5
20 files changed
+306
-316
No files matched your search
@@ -1,9 +1,5 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class JournalAuthorType < WritingJournalCategory
|
||||
|
||||
field :title, localize: true
|
||||
|
||||
has_and_belongs_to_many :writing_journals
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,5 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class JournalLevelType < WritingJournalCategory
|
||||
|
||||
field :title, localize: true
|
||||
|
||||
has_and_belongs_to_many :writing_journals
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,3 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class JournalPaperType < WritingJournalCategory
|
||||
|
||||
field :title
|
||||
|
||||
end
|
||||
end
|
||||
+4
-6
@@ -1,9 +1,7 @@
|
||||
class PersonalJournalTag < Tag
|
||||
|
||||
has_and_belongs_to_many :writing_journals
|
||||
|
||||
def get_visible_links(sort = :title)
|
||||
self.writing_journals.where(:is_hidden => false).desc(:is_top, sort)
|
||||
end
|
||||
|
||||
end
|
||||
def get_visible_links(sort = :title)
|
||||
self.writing_journals.where(:is_hidden => false).desc(:is_top, sort)
|
||||
end
|
||||
end
|
||||
@@ -1,26 +1,20 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class WritingJournal
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
field :paper_title, localize: true
|
||||
field :journal_title, localize: true
|
||||
field :authors, localize: true
|
||||
|
||||
|
||||
has_and_belongs_to_many :tags, :class_name => "PersonalJournalTag"
|
||||
|
||||
has_and_belongs_to_many :journal_author_types
|
||||
has_and_belongs_to_many :journal_level_types
|
||||
|
||||
|
||||
belongs_to :journal_paper_type
|
||||
|
||||
|
||||
field :year
|
||||
field :language
|
||||
field :isbn
|
||||
@@ -36,54 +30,36 @@ class WritingJournal
|
||||
field :note
|
||||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
|
||||
has_many :writing_journal_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
|
||||
accepts_nested_attributes_for :writing_journal_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
|
||||
validates :paper_title, :at_least_one => true
|
||||
|
||||
before_validation :add_http
|
||||
|
||||
after_save :save_writing_journal_files
|
||||
|
||||
before_validation :add_http
|
||||
validates :paper_title, :at_least_one => true
|
||||
validates :url, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :unless => Proc.new{self.url.blank?}
|
||||
|
||||
def self.search( category_id = nil )
|
||||
|
||||
if category_id.to_s.size > 0
|
||||
|
||||
find(:all, :conditions => {writing_journal_category_id: category_id}).desc( :is_top, :title )
|
||||
|
||||
else
|
||||
|
||||
find(:all).desc( :is_top, :title)
|
||||
|
||||
end
|
||||
|
||||
if category_id.to_s.size > 0
|
||||
find(:all, :conditions => {writing_journal_category_id: category_id}).desc( :is_top, :title )
|
||||
else
|
||||
find(:all).desc( :is_top, :title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.widget_datas
|
||||
|
||||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
end
|
||||
|
||||
def sorted_tags
|
||||
tags.order_by(I18n.locale, :asc)
|
||||
end
|
||||
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
@@ -93,22 +69,21 @@ class WritingJournal
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def save_writing_journal_files
|
||||
self.writing_journal_files.each do |t|
|
||||
if t.should_destroy
|
||||
t.destroy
|
||||
end
|
||||
self.writing_journal_files.each do |t|
|
||||
if t.should_destroy
|
||||
t.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create_link
|
||||
|
||||
title = ["\"#{self.paper_title}\""]
|
||||
title << self.journal_title
|
||||
title.join(', ')
|
||||
title << ( !self.journal_level_types.blank? ? "(#{self.journal_level_types.collect{|x| x.title}.join(', ')})" : nil)
|
||||
title.join(', ')
|
||||
title = ["\"#{self.paper_title}\""]
|
||||
title << self.journal_title
|
||||
title.join(', ')
|
||||
title << ( !self.journal_level_types.blank? ? "(#{self.journal_level_types.collect{|x| x.title}.join(', ')})" : nil)
|
||||
title.join(', ')
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -124,5 +99,4 @@ class WritingJournal
|
||||
self.journal_author_type_ids.delete('')
|
||||
self.journal_level_type_ids.delete('')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+5
-9
@@ -1,30 +1,26 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class WritingJournalCategory
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include OrbitCoreLib::ObjectAuthable
|
||||
include OrbitCoreLib::ObjectDisable
|
||||
# include Mongoid::MultiParameterAttributes
|
||||
|
||||
AfterObjectAuthUrl = '/panel/personal_journal/back_end/writing_journal_categorys'
|
||||
APP_NAME = 'writing_journal'
|
||||
# ObjectAuthTitlesOptions = %W{edit}
|
||||
ObjectAuthTitlesOptions = %W{submit_new fact_check}
|
||||
|
||||
field :key
|
||||
|
||||
has_many :writing_journals
|
||||
|
||||
|
||||
def pp_object
|
||||
title
|
||||
end
|
||||
|
||||
|
||||
def self.from_id(id)
|
||||
WritingJournalCategory.find(id) rescue nil
|
||||
end
|
||||
|
||||
def self.is_localized?(field_name)
|
||||
self.fields[field_name.to_s].localized?
|
||||
self.fields[field_name.to_s].localized?
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+2
-2
@@ -6,9 +6,9 @@ class WritingJournalFile
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
# field :description, localize: true
|
||||
field :should_destroy, :type => Boolean
|
||||
field :should_destroy, :type => Boolean
|
||||
field :title, localize: true
|
||||
|
||||
|
||||
belongs_to :writing_journal
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user