2012-02-15 07:38:27 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
class WebLink
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include Mongoid::MultiParameterAttributes
|
2013-04-26 03:18:57 +00:00
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
include OrbitModel::LanguageRestrict
|
|
|
|
include OrbitModel::Status
|
|
|
|
include OrbitTag::Taggable
|
2012-08-01 07:24:55 +00:00
|
|
|
|
2012-07-25 20:10:15 +00:00
|
|
|
field :title, localize: true
|
|
|
|
field :context, localize: true
|
2012-02-15 07:38:27 +00:00
|
|
|
|
2013-04-10 07:26:57 +00:00
|
|
|
field :url, localize: true
|
2012-02-15 07:38:27 +00:00
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
|
|
|
|
|
|
|
belongs_to :web_link_category
|
|
|
|
|
2013-07-02 08:46:44 +00:00
|
|
|
before_save :clean_tags
|
2012-08-01 07:24:55 +00:00
|
|
|
|
2012-07-31 06:25:46 +00:00
|
|
|
validates :title, :at_least_one => true
|
2012-02-15 07:38:27 +00:00
|
|
|
|
2012-08-04 08:29:31 +00:00
|
|
|
before_validation :add_http
|
2013-04-10 07:26:57 +00:00
|
|
|
# validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?/i
|
2012-08-04 08:29:31 +00:00
|
|
|
|
2012-02-16 03:30:54 +00:00
|
|
|
def self.search( category_id = nil )
|
2012-02-15 07:38:27 +00:00
|
|
|
|
2012-02-16 03:30:54 +00:00
|
|
|
if category_id.to_s.size > 0
|
2012-02-15 07:38:27 +00:00
|
|
|
|
2012-07-25 20:10:15 +00:00
|
|
|
find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :title )
|
2012-02-16 03:30:54 +00:00
|
|
|
|
2012-02-15 07:38:27 +00:00
|
|
|
else
|
|
|
|
|
2012-07-25 20:10:15 +00:00
|
|
|
find(:all).desc( :is_top, :title)
|
2012-02-15 07:38:27 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.widget_datas
|
|
|
|
|
2012-08-01 07:24:55 +00:00
|
|
|
where( :is_hidden => false ).desc(:is_top, :created_at)
|
2012-02-15 07:38:27 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-08-04 08:29:31 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
|
|
|
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
|
|
|
|
self.url = 'http://' + self.url
|
|
|
|
end
|
|
|
|
end
|
2012-08-14 06:38:21 +00:00
|
|
|
|
|
|
|
def clean_tags
|
2013-05-03 04:11:48 +00:00
|
|
|
self.tagged_ids.delete('')
|
2012-08-14 06:38:21 +00:00
|
|
|
end
|
2012-08-01 07:24:55 +00:00
|
|
|
|
2012-02-15 07:38:27 +00:00
|
|
|
end
|