44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# encoding: utf-8
|
|
class WebLink
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
include OrbitModel::Status
|
|
include OrbitModel::Impression
|
|
include OrbitTag::Taggable
|
|
include OrbitCategory::Categorizable
|
|
|
|
|
|
field :image_description, type: String, localize: true
|
|
mount_uploader :image, ImageUploader
|
|
field :title, localize: true
|
|
field :context, localize: true
|
|
field :order_position, type: Integer, default: -1
|
|
field :url, localize: true
|
|
field :create_user_id
|
|
field :update_user_id
|
|
field :rss2_id, type: String
|
|
|
|
field :link_open, type: String
|
|
LINK_OPEN_TYPES = ["local", "new_window"]
|
|
|
|
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:order_position,:asc])}
|
|
|
|
before_save :add_http
|
|
|
|
protected
|
|
|
|
def add_http
|
|
temp_url = {}
|
|
Site.first.in_use_locales.each do |locale|
|
|
locale = locale.to_s
|
|
tmp = self.url_translations[locale]
|
|
temp_url[locale] = tmp
|
|
unless tmp.match(/^http(s|):\/\//) || tmp.blank? || tmp.start_with?('/')
|
|
temp_url[locale] = 'https://' + tmp
|
|
end
|
|
end
|
|
self.url_translations = temp_url
|
|
end
|
|
|
|
end |