Change link to array.
This commit is contained in:
parent
3ad002bdf1
commit
56bee2dab0
|
@ -41,12 +41,14 @@ class ArchivesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if archive.url.present?
|
if archive.urls.present?
|
||||||
|
archive.urls.each_with_index do |url,i|
|
||||||
files << {
|
files << {
|
||||||
"file-name" => archive.title,
|
"file-name" => archive.title,
|
||||||
"file-type" => "link",
|
"file-type" => archive.get_url_text(i),
|
||||||
"file-url" => archive.url
|
"file-url" => url
|
||||||
}
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
archives << {
|
archives << {
|
||||||
"archive-title" => archive.title,
|
"archive-title" => archive.title,
|
||||||
|
@ -127,14 +129,16 @@ class ArchivesController < ApplicationController
|
||||||
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if archive.url.present?
|
if archive.urls.present?
|
||||||
|
archive.urls.each_with_index do |url,i|
|
||||||
files << {
|
files << {
|
||||||
"file-name" => archive.title,
|
"file-name" => archive.title,
|
||||||
"file-type" => "link",
|
"file-type" => archive.get_url_text(i),
|
||||||
"file-url" => archive.url
|
"file-url" => url
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
{
|
{
|
||||||
"archive-title" => archive.title,
|
"archive-title" => archive.title,
|
||||||
"description" => archive.description,
|
"description" => archive.description,
|
||||||
|
@ -184,12 +188,14 @@ class ArchivesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if archive.url.present?
|
if archive.urls.present?
|
||||||
|
archive.urls.each_with_index do |url,i|
|
||||||
files << {
|
files << {
|
||||||
"file-name" => archive.title,
|
"file-name" => archive.title,
|
||||||
"file-type" => "link",
|
"file-type" => archive.get_url_text(i),
|
||||||
"file-url" => archive.url
|
"file-url" => url
|
||||||
}
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"archive-title" => archive.title,
|
"archive-title" => archive.title,
|
||||||
|
|
|
@ -24,7 +24,9 @@ class ArchiveFile
|
||||||
|
|
||||||
field :title, as: :slug_title, localize: true
|
field :title, as: :slug_title, localize: true
|
||||||
field :description, localize: true
|
field :description, localize: true
|
||||||
field :url, localize: true
|
field :urls, localize: true, type: Array
|
||||||
|
field :url, localize: true #Old field
|
||||||
|
field :url_texts, localize: true, type: Array, default: []
|
||||||
field :create_user_id
|
field :create_user_id
|
||||||
field :update_user_id
|
field :update_user_id
|
||||||
field :postdate , :type => DateTime, :default => Time.now
|
field :postdate , :type => DateTime, :default => Time.now
|
||||||
|
@ -48,18 +50,41 @@ class ArchiveFile
|
||||||
|
|
||||||
before_save :add_http
|
before_save :add_http
|
||||||
|
|
||||||
protected
|
after_initialize do
|
||||||
|
unless self.new_record?
|
||||||
|
if self.urls.nil? && self.url.present?
|
||||||
|
self.urls_translations = self.url_translations.map{|k,v| [k,[v]]}.to_h
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_url_text(idx=0,org=false)
|
||||||
|
url_text = self.url_texts[idx] rescue nil
|
||||||
|
if org
|
||||||
|
url_text
|
||||||
|
else
|
||||||
|
url_text.present? ? url_text : "link"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
protected
|
||||||
def add_http
|
def add_http
|
||||||
temp_url = {}
|
in_use_locales = Site.first.in_use_locales
|
||||||
Site.first.in_use_locales.each do |locale|
|
temp_urls = {}
|
||||||
|
in_use_locales.each do |locale|
|
||||||
locale = locale.to_s
|
locale = locale.to_s
|
||||||
temp_url[locale] = self.url_translations[locale]
|
temp_urls[locale] = []
|
||||||
unless /https?:\/\/[\S]+/.match(self.url_translations[locale]) || self.url_translations[locale].blank?
|
self.urls_translations[locale].each do |tmp_url|
|
||||||
temp_url[locale] = 'http://' + self.url_translations[locale]
|
tmp = tmp_url
|
||||||
|
if tmp.present?
|
||||||
|
unless /^(http|https|ftp):\/\/[\S]+/.match(tmp_url) || url.include?("mailto:")
|
||||||
|
tmp = 'http://' + tmp_url
|
||||||
end
|
end
|
||||||
|
temp_urls[locale] << tmp
|
||||||
end
|
end
|
||||||
self.url_translations = temp_url
|
end rescue nil
|
||||||
|
end
|
||||||
|
self.urls_translations = temp_urls
|
||||||
end
|
end
|
||||||
|
|
||||||
# def to_indexed_json
|
# def to_indexed_json
|
||||||
|
@ -115,5 +140,4 @@ class ArchiveFile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -161,16 +161,20 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- url -->
|
<!-- urls -->
|
||||||
<div class="control-group input-title">
|
<div class="control-group input-title">
|
||||||
<label class="control-label muted"><%= t(:url) %></label>
|
<label class="control-label muted"><%= t(:link) %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.fields_for :url_translations do |f| %>
|
<div class="link_append_target">
|
||||||
<%= f.text_field locale, class: "input-block-level", placeholder: t(:url), value: (@archive_file.url_translations[locale] rescue nil) %>
|
<% I18n.with_locale(locale) do %>
|
||||||
|
<% f.object.urls.each_with_index do |url,i| %>
|
||||||
|
<%= render :partial => "form_link", :locals=>{:f=>f,:locale=>locale,:url=>url,:url_text=>f.object.get_url_text(i,true)} %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<a class="trigger btn btn-small btn-primary add_link" data-locale="<%=locale%>"><i class="icons-plus"></i> <%= t(:add) %></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -410,7 +414,13 @@
|
||||||
});
|
});
|
||||||
$('.main-forms .add-on').tooltip();
|
$('.main-forms .add-on').tooltip();
|
||||||
$(document).on('click', '#add_file', add_file_field);
|
$(document).on('click', '#add_file', add_file_field);
|
||||||
$(document).on('click', '.delete_file', function(){
|
$(document).on('click', '.add_link', function(){
|
||||||
|
var form_link_url = "<%= escape_javascript(render(:partial => "form_link", :locals=>{:f=>f,:locale=>"new_locale",:url=>nil,:url_text=>nil} )) %>"
|
||||||
|
var old_locale = new RegExp("new_locale", "g"),
|
||||||
|
new_locale = $(this).data("locale");
|
||||||
|
$(this).siblings(".link_append_target").append(form_link_url.replace(old_locale,new_locale));
|
||||||
|
})
|
||||||
|
$(document).on('click', '.delete_file, .delete_link', function(){
|
||||||
$(this).parents('.input-prepend').remove();
|
$(this).parents('.input-prepend').remove();
|
||||||
});
|
});
|
||||||
$(document).on('click',"[type='file']",function(){
|
$(document).on('click',"[type='file']",function(){
|
||||||
|
@ -422,6 +432,12 @@
|
||||||
$(this).parents('.start-line').hide();
|
$(this).parents('.start-line').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$(document).on('click', '.remove_existing_link', function(){
|
||||||
|
if(confirm("<%= I18n.t(:sure?)%>")){
|
||||||
|
$(this).parents('.input-prepend').remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<div class="input-prepend input-append start-line" data-locale="<%=locale%>">
|
||||||
|
<span class="add-on icons-link" title="<%= t(:url) %>"></span>
|
||||||
|
<%= text_field_tag "#{f.object_name}[urls_translations][#{locale}][]", url , class: "input-large", placeholder: t(:url) %>
|
||||||
|
<span class="add-on icons-pencil" title="<%= t("archive.url_text") %>"></span>
|
||||||
|
<%= text_field_tag "#{f.object_name}[url_texts_translations][#{locale}][]", url_text , class: "input-large", placeholder: t("archive.url_text_hint") %>
|
||||||
|
<% if locale == "new_locale" %>
|
||||||
|
<span class="delete_link add-on btn" title="<%= t(:delete_) %>">
|
||||||
|
<a class="icon-trash"></a>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<span class="remove_existing_link add-on btn" title="<%= t(:remove) %>">
|
||||||
|
<a class="icon-remove"></a>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
|
@ -2,6 +2,8 @@ en:
|
||||||
restful_actions:
|
restful_actions:
|
||||||
categories_order: Categories Order
|
categories_order: Categories Order
|
||||||
archive:
|
archive:
|
||||||
|
url_text: "URL Text"
|
||||||
|
url_text_hint: "URL Text, default: link"
|
||||||
updated_at: Updated At
|
updated_at: Updated At
|
||||||
download_file: Download file
|
download_file: Download file
|
||||||
drag_file_to_here: Drag file to here
|
drag_file_to_here: Drag file to here
|
||||||
|
|
|
@ -2,6 +2,8 @@ zh_tw:
|
||||||
restful_actions:
|
restful_actions:
|
||||||
categories_order: 類別排序
|
categories_order: 類別排序
|
||||||
archive:
|
archive:
|
||||||
|
url_text: "連結文字"
|
||||||
|
url_text_hint: "連結文字,預設為link"
|
||||||
updated_at: 上傳日期
|
updated_at: 上傳日期
|
||||||
download_file: 檔案下載
|
download_file: 檔案下載
|
||||||
drag_file_to_here: 拖移檔案到此
|
drag_file_to_here: 拖移檔案到此
|
||||||
|
|
Loading…
Reference in New Issue