diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake
index da664bab..b9cbb605 100644
--- a/lib/tasks/migrate.rake
+++ b/lib/tasks/migrate.rake
@@ -156,6 +156,23 @@ namespace :migrate do
end
p 'End PageContext'
+ p '====================================================='
+ p '====================================================='
+
+ p 'Start WebLink'
+ links = WebLink.admin_manager_all
+ i = 1
+ links.each do |link|
+ p "#{i}/#{links.size} - #{link.id}"
+ name = I18nVariable.first(:conditions => {:key => 'name', :language_value_id => link.id, :language_value_type => link.class})
+ link.name_translations = {'en' => name['en'], 'zh_tw' => name['zh_tw']} if name
+ context = I18nVariable.first(:conditions => {:key => 'context', :language_value_id => link.id, :language_value_type => link.class})
+ link.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
+ link.save(:validate => false)
+ i += 1
+ end
+ p 'End WebLink'
+
end
end
diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb
index 40db805f..ef96e7d3 100644
--- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb
+++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb
@@ -161,75 +161,5 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id})
end
-
- def get_sorted_and_filtered_web_links
- web_links = WebLink.all
- case params[:sort]
- when 'category'
- category_ids = web_links.distinct(:web_link_category_id)
- categories = WebLinkCategory.find(category_ids) rescue nil
- if categories
- h = Hash.new
- categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
- sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
- sorted_categorys = sorted.collect {|a| web_links.where(:web_link_category_id => a[1]).entries }
- web_links = sorted_categorys.flatten!
- end
- when 'name'
- h = Array.new
- web_links.each { |web_link| h << [web_link.name[I18n.locale].downcase, web_link] }
- sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
- web_links = sorted.collect {|a| a[1] }
- when 'status'
- web_links = web_links.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction])
- when 'tags'
- a = Array.new
- WebResourceTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.web_links }
- a.flatten!
- a.uniq!
- tmp = Array.new
- web_links.where(:tag_ids => []).each { |web_link| tmp << [web_link.name[I18n.locale].downcase, web_link] }
- sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse!
- sorted_names = sorted.collect {|a| a[1] }
- a = params[:direction].eql?('asc') ? (sorted_names + a) : (a + sorted_names)
- web_links = a.flatten
- end
- # if @filter
- # @filter.each do |key, value|
- # case key
- # when 'status'
- # a = Array.new
- # web_links.each do |web_link|
- # value.each do |v|
- # case v
- # when 'pending'
- # a << web_link if web_link.is_checked.nil?
- # when 'rejected'
- # a << web_link if web_link.is_checked.eql?(false)
- # else
- # a << web_link if web_link[v]
- # end
- # end
- # end
- # web_links = a.uniq
- # when 'categories'
- # a = Array.new
- # web_links.each do |web_link|
- # a << web_link if value.include?(web_link.web_link_category.id.to_s)
- # end
- # web_links = a.uniq
- # when 'tags'
- # a = Array.new
- # web_links.each do |web_link|
- # web_link.tags.each do |tag|
- # a << web_link if value.include?(tag.id.to_s)
- # end
- # end
- # web_links = a.uniq
- # end if value.size > 0
- # end
- # end
- Kaminari.paginate_array(web_links).page(params[:page]).per(10)
- end
end
diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb
index a254c971..9b0698a8 100644
--- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb
+++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb
@@ -12,7 +12,7 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController
date_now = Time.now
- @web_links = WebLink.where( :is_hidden => false ).desc(:is_top, :name).page(params[:page]).per(10)
+ @web_links = WebLink.where( :is_hidden => false ).desc(:is_top, :title).page(params[:page]).per(10)
get_categorys
end
diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb
index fcb0cb1b..a9fe23d8 100644
--- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb
+++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb
@@ -28,7 +28,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
# deadline
- # @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :name).first
+ # @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :title).first
@web_links = WebLink.widget_datas.page(params[:page]).per(5)
diff --git a/vendor/built_in_modules/web_resource/app/models/web_link.rb b/vendor/built_in_modules/web_resource/app/models/web_link.rb
index 4143c38b..be1f9682 100644
--- a/vendor/built_in_modules/web_resource/app/models/web_link.rb
+++ b/vendor/built_in_modules/web_resource/app/models/web_link.rb
@@ -6,8 +6,8 @@ class WebLink
include Mongoid::MultiParameterAttributes
- has_one :name, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
- has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
+ field :title, localize: true
+ field :context, localize: true
has_and_belongs_to_many :tags, :class_name => "WebResourceTag"
@@ -21,19 +21,17 @@ class WebLink
belongs_to :web_link_category
- validates_presence_of :name
-
- before_save :set_key
+ validates_presence_of :title
def self.search( category_id = nil )
if category_id.to_s.size > 0
- find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :name )
+ find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :title )
else
- find(:all).desc( :is_top, :name)
+ find(:all).desc( :is_top, :title)
end
@@ -42,39 +40,16 @@ class WebLink
def self.widget_datas
- where( :is_hidden => false ).desc(:is_top, :name)
+ where( :is_hidden => false ).desc(:is_top, :title)
end
def is_top?
self.is_top
- end
-
- def name
- @name ||= I18nVariable.first(:conditions => {:key => 'name', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
- end
-
- def context
- @context ||= I18nVariable.first(:conditions => {:key => 'context', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
- end
-
- def text
- @text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
- end
+ end
def sorted_tags
tags.order_by(I18n.locale, :asc)
end
- protected
-
- def set_key
- if name && name.new_record?
- name.key = 'name'
- end
- if context && context.new_record?
- context.key = 'context'
- end
- end
-
end
\ No newline at end of file
diff --git a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb
index 53a10a1a..57f01981 100644
--- a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb
+++ b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb
@@ -12,12 +12,12 @@ class WebLinkCategory
field :key
- has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
+ field :title, localize: true
has_many :web_links
def pp_object
- i18n_variable[I18n.locale]
+ title
end
end
\ No newline at end of file
diff --git a/vendor/built_in_modules/web_resource/app/models/web_resource_tag.rb b/vendor/built_in_modules/web_resource/app/models/web_resource_tag.rb
index bb97b351..9a7f3562 100644
--- a/vendor/built_in_modules/web_resource/app/models/web_resource_tag.rb
+++ b/vendor/built_in_modules/web_resource/app/models/web_resource_tag.rb
@@ -3,7 +3,7 @@ class WebResourceTag < Tag
has_and_belongs_to_many :web_links
- def get_visible_links(sort = :name)
+ def get_visible_links(sort = :title)
self.web_links.where(:is_hidden => false).desc(:is_top, sort)
end
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_form.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_form.html.erb
index 2e0f61ff..4b19235d 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_form.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_form.html.erb
@@ -10,12 +10,12 @@
- <%= f.fields_for :i18n_variable, (@web_link_category.new_record? ? @web_link_category.build_i18n_variable : @web_link_category.i18n_variable) do |f| %>
+ <%= f.fields_for :title_translations do |f| %>
<% @site_valid_locales.each do |locale| %>
<%= label_tag "name-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %>
- <%= f.text_field locale, :class => 'input-xxlarge' %>
+ <%= f.text_field locale, :class => 'input-xxlarge', :value => (@web_link_category.title_translations[locale] rescue nil) %>
<% end %>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb
index 8d018df4..4d1198c3 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb
@@ -14,6 +14,6 @@
<% end -%>
<% @site_valid_locales.each do |locale| %>
-
<%= web_link_category.i18n_variable[locale] rescue nil %> |
+
<%= web_link_category.title_translations[locale] rescue nil %> |
<% end %>
\ No newline at end of file
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb
index 60574b94..1274b884 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb
@@ -69,17 +69,17 @@
">
<%= f.label :name ,t("web_resource.name")%>
- <%= f.fields_for :name, (@web_link.new_record? ? @web_link.build_name : @web_link.name ) do |f| %>
+ <%= f.fields_for :title_translations do |f| %>
<%= I18nVariable.from_locale(locale) %>
- <%= f.text_field locale, :class=>'post-title' %>
+ <%= f.text_field locale, :class=>'post-title', :value => (@web_link.title_translations[locale] rescue nil) %>
<% end %>
<%= f.label :describe,t("web_resource.describe") %>
- <%= f.fields_for :context, (@web_link.new_record? ? @web_link.build_context : @web_link.context ) do |f| %>
+ <%= f.fields_for :context_translations do |f| %>
<%= I18nVariable.from_locale(locale) %>
- <%= f.text_area locale, :style=>"width:100%" %>
+ <%= f.text_area locale, :style=>"width:100%", :value => (@web_link.context_translations[locale] rescue nil) %>
<% end %>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb
index 8873ed20..a53e38bd 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb
@@ -1,4 +1,4 @@
<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'],
['category', 'bulletin_category', 'span2', 'bulletin.category'],
- ['name', 'name','span3', 'bulletin.title'],
+ ['title', 'title','span3', 'bulletin.title'],
['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %>
\ No newline at end of file
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb
index 85a6ad93..d34dc2b3 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb
@@ -19,9 +19,9 @@
- <%= web_link.web_link_category.i18n_variable[I18n.locale] rescue nil %> |
+ <%= web_link.web_link_category.title rescue nil %> |
- <%= link_to web_link.name[I18n.locale], panel_web_resource_back_end_web_link_path(web_link) %>
+ <%= link_to web_link.title, panel_web_resource_back_end_web_link_path(web_link) %>
<%if at_least_module_manager || web_link.web_link_category.cur_user_is_sub_manager_of(:edit)%>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/show.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/show.html.erb
index 1eba0646..e69de29b 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/show.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/show.html.erb
@@ -1,57 +0,0 @@
-<% # encoding: utf-8 %>
-
-
-
-
-
-<%= flash_messages %>
-
-
- -
- <%= t('announcement.category') %>
- <%= @bulletin.bulletin_category.i18n_variable[I18n.locale] rescue nil %>
-
- -
- <%= t('announcement.postdate') %>
- <%= display_date(@bulletin.postdate) %>
-
- -
- <%= t('announcement.title') %>
- <%= @bulletin.title %>
-
- -
- <%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
- <%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
-
- -
- <%= t('announcement.subtitle') %>
- <%= @bulletin.subtitle %>
-
- -
- <%= t('announcement.text') %>
- <%= @bulletin.text %>
-
- -
-
-
- <%= t('announcement.link') %>
- <% @bulletin.bulletin_links.each do | blink | %>
- <%= link_to blink.name, blink.url, :target => '_blank' %>
- <% end %>
-
- -
- <%= t('announcement.file') %>
- <% @bulletin.bulletin_files.each do | bfile | %>
- <%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
- <% end %>
-
- -
- <%= t('announcement.張貼者') %>
- <%= User.find(@bulletin.create_user_id).name %>
-
- -
- <%= t('announcement.最後修改時間') %>
- <%= display_date(@bulletin.updated_at) %>
-
-
-
-<%= link_back %>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb
index 0d1626a5..5bb346b1 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/index.html.erb
@@ -15,10 +15,10 @@
<% @web_links.each do |post| %>
- <%= post.web_link_category.i18n_variable[I18n.locale] rescue nil %> |
+ <%= post.web_link_category.title rescue nil %> |
- <%#= link_to post.name[I18n.locale], panel_web_resource_front_end_web_link_path(post) %>
- <%= link_to post.name[I18n.locale], post.url, {:target => '_blank', :title => post.name[I18n.locale]} %>
+ <%#= link_to post.title, panel_web_resource_front_end_web_link_path(post) %>
+ <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %>
|
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/show.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/show.html.erb
index 7e7f2c95..e69de29b 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/show.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/front_end/web_links/show.html.erb
@@ -1,57 +0,0 @@
-<% # encoding: utf-8 %>
-
-
-
-
-
-<%= flash_messages %>
-
-
- -
- <%= t('announcement.category') %>
- <%= @bulletin.bulletin_category.i18n_variable[I18n.locale] rescue nil %>
-
- -
- <%= t('announcement.postdate') %>
- <%= display_date(@bulletin.postdate) %>
-
- -
- <%= t('announcement.title') %>
- <%= @bulletin.title %>
-
- -
- <%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
- <%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
-
- -
- <%= t('announcement.subtitle') %>
- <%= @bulletin.subtitle %>
-
- -
- <%= t('announcement.text') %>
- <%= @bulletin.text %>
-
- -
-
-
- <%= t('announcement.link') %>
- <% @bulletin.bulletin_links.each do | blink | %>
- <%= link_to blink.name, blink.url, :target => '_blank' %>
- <% end %>
-
- -
- <%= t('announcement.file') %>
- <% @bulletin.bulletin_files.each do | bfile | %>
- <%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
- <% end %>
-
- -
- <%= t('announcement.張貼者') %>
- <%= User.find(@bulletin.create_user_id).name %>
-
- -
- <%= t('announcement.最後修改時間') %>
- <%= display_date_time(@bulletin.updated_at) %>
-
-
-
-<%#= link_back %>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_web_links.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_web_links.html.erb
index 93e65230..cc612c5e 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_web_links.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_web_links.html.erb
@@ -1,6 +1,6 @@
<% @web_links.each do |widget| -%>
- - <%= link_to widget.name[I18n.locale], widget.url, {:target => '_blank', :title => widget.name[I18n.locale]} %>
+ - <%= link_to widget.title, widget.url, {:target => '_blank', :title => widget.title} %>
<% end -%>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.html.erb
index 40d70aaa..1c773429 100644
--- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.html.erb
+++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.html.erb
@@ -1,5 +1,5 @@
<% if @current_category %>
- <%= @current_category.i18n_variable[I18n.locale] + " " + t('web_resource.list_lower') %>
+ <%= @current_category.title + " " + t('web_resource.list_lower') %>
<% elsif @tag %>
<%= @tag[I18n.locale] + " " + t('web_resource.list_lower') %>
<% else %>
@@ -14,9 +14,9 @@
<% @web_links.each do |post| %>
- <%= post.web_link_category.i18n_variable[I18n.locale] rescue nil %> |
+ <%= post.web_link_category.title rescue nil %> |
- <%= link_to post.name[I18n.locale], post.url, {:target => '_blank', :title => post.name[I18n.locale]} %>
+ <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %>
|
<% end %>
|