add hashtags
This commit is contained in:
parent
f0d783192f
commit
75322232e5
|
|
@ -27,6 +27,7 @@ class Admin::VideoProsController < OrbitAdminController
|
|||
def update
|
||||
video_image = VideoImage.find(params[:id])
|
||||
video_image.update_user_id = current_user.id.to_s
|
||||
create_get_video_tags(video_image)
|
||||
video_image.save
|
||||
video_image.update_attributes(video_image_params)
|
||||
redirect_to params[:referer_url]
|
||||
|
|
@ -43,6 +44,7 @@ class Admin::VideoProsController < OrbitAdminController
|
|||
video_image = VideoImage.new(video_image_params)
|
||||
video_image.update_user_id = current_user.id.to_s
|
||||
video_image.create_user_id = current_user.id.to_s
|
||||
create_get_video_tags(video_image)
|
||||
video_image.save
|
||||
redirect_to params[:referer_url]
|
||||
end
|
||||
|
|
@ -73,4 +75,25 @@ class Admin::VideoProsController < OrbitAdminController
|
|||
def setup_vars
|
||||
@module_app = ModuleApp.where(:key => "video_pro").first
|
||||
end
|
||||
|
||||
def create_get_video_tags(video)
|
||||
new_tags = params["video_tags"].split(",")
|
||||
tags = []
|
||||
video.video_tags = []
|
||||
new_tags.each do |tag|
|
||||
if is_uuid?(tag) === false
|
||||
vt = VideoTag.new
|
||||
vt.title = tag.downcase
|
||||
vt.save
|
||||
video.video_tags << vt
|
||||
else
|
||||
vt = VideoTag.find(tag)
|
||||
video.video_tags << vt
|
||||
end
|
||||
end
|
||||
return tags
|
||||
end
|
||||
def is_uuid?(str)
|
||||
!!(str =~ /\A[\da-f]{24}\z/i || str =~ /\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i)
|
||||
end
|
||||
end
|
||||
|
|
@ -35,6 +35,8 @@ class VideoImage
|
|||
field :view_count, type: Integer, default: 0
|
||||
field :scale, type: Float
|
||||
field :details, type: String, localize: true
|
||||
|
||||
has_and_belongs_to_many :video_tags, inverse_of: :video_images
|
||||
# LINK_OPEN_TYPES = ["local", "new_window"]
|
||||
|
||||
# before_save :add_http
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
class VideoTag
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :title, type: String
|
||||
has_and_belongs_to_many :video_images, inverse_of: :video_tags
|
||||
|
||||
end
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "video_data/jplayer.blue.monday.min" %>
|
||||
<%= stylesheet_link_tag "select2/select2" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<%= javascript_include_tag "validator" %>
|
||||
<%= javascript_include_tag "video_data/jquery.jplayer.min" %>
|
||||
<%= javascript_include_tag "select2/select2.min" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.fileupload .video-thumbnail{
|
||||
|
|
@ -18,6 +20,9 @@
|
|||
width: 30em;
|
||||
height: 20em;
|
||||
}
|
||||
#s2id_video_image_video_tags_{
|
||||
width: 500px;
|
||||
}
|
||||
</style>
|
||||
<%#= f.error_messages %>
|
||||
<%
|
||||
|
|
@ -32,6 +37,7 @@
|
|||
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
|
||||
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
|
||||
<li><a href="#tag" data-toggle="tab"><%= t(:tags) %></a></li>
|
||||
<li><a href="#hashtag" data-toggle="tab"><%= t("video_pro.hashtags") %></a></li>
|
||||
</ul>
|
||||
<!-- Module -->
|
||||
<div class="tab-content module-area">
|
||||
|
|
@ -243,7 +249,17 @@
|
|||
<div class="tab-pane fade" id="tag">
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:tags) %></label>
|
||||
<%#= select_tags(f, @module_app) %>
|
||||
<%= select_tags(f, @module_app) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-------Hash tags---->
|
||||
<div class="tab-pane fade" id="hashtag">
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("video_pro.hashtags") %></label>
|
||||
<div class="controls">
|
||||
<input id="video_image_video_tags_" type="hidden" name="video_tags" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -370,11 +386,24 @@
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
// $("#video_image_video_tags_").select2({
|
||||
// placeholder: "<%= t("video_pro.select_or_add") %>",
|
||||
// matcher: matchCustom
|
||||
// })
|
||||
$("#video_image_video_tags_").select2({
|
||||
tags: true,
|
||||
multiple: true,
|
||||
data : <%= raw(VideoTag.all.map { |tag| { text: tag.title.html_safe, id: tag.id.to_s } }.to_json) %>,
|
||||
createSearchChoice: function(term, data) {
|
||||
if (!data.length)
|
||||
return { id: term, text: "#" + term.trim().toLowerCase() };
|
||||
}
|
||||
// ajax: {
|
||||
// url: '/api/v1.1/locations',
|
||||
// dataType: 'json'
|
||||
// }
|
||||
|
||||
});
|
||||
$("#video_image_video_tags_").val(<%= raw(@video_image.video_tags.collect { |tag| tag.id.to_s }) %>).trigger("change");
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,4 +70,6 @@ en:
|
|||
choose_type: Please Select One Type First
|
||||
select: Please Select One
|
||||
details: Details
|
||||
hashtags: Hashtags
|
||||
select_or_add: Select or add tags
|
||||
video: Video
|
||||
|
|
@ -67,4 +67,6 @@ zh_tw:
|
|||
choose_type: 請先選擇類型
|
||||
select: 請選擇
|
||||
details: 詳細內容
|
||||
hashtags: Hashtags
|
||||
select_or_add: Select or add tags
|
||||
video: 影片
|
||||
Loading…
Reference in New Issue