From ec96a2e0e712b7ca4105844db6e61e01059ce931 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 10:36:18 +0800 Subject: [PATCH 01/11] Add page counter --- app/views/admin/page_parts/_edit.html.erb | 2 +- config/locales/zh_tw.yml | 1 + lib/parsers/parser_back_end.rb | 1 + lib/parsers/parser_common.rb | 2 +- lib/parsers/parser_front_end.rb | 33 ++++++++++++++++++++--- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/views/admin/page_parts/_edit.html.erb b/app/views/admin/page_parts/_edit.html.erb index 828e03a26..78a20b37c 100644 --- a/app/views/admin/page_parts/_edit.html.erb +++ b/app/views/admin/page_parts/_edit.html.erb @@ -12,6 +12,6 @@ <% end %>

- <%= f.submit t(:update) %> <%= link_back %> + <%= f.submit t(:update_) %> <%= link_back %>

<% end %> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c8075b24d..026a43d0a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -389,6 +389,7 @@ zh_tw: paper: Paper was successfully updated. user: User was successfully updated. success_: S使用者已更新成功 + update_: 更新 update_at: 最後更新時間 url: 網址 use_status: '' diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index c3c43fe8d..d0c1eab6d 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -30,6 +30,7 @@ module ParserBackEnd parse_images_edit(body, page) parse_footer_edit(body, page) parse_sub_menu_edit(body, page) + parse_counter_edit(body) public_r_tags.each do |tag| send("parse_#{tag}s_edit", body, page, true) end diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 794fb4fdc..acdd43b85 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -233,7 +233,7 @@ module ParserCommon end # page_counter - def parse_counter(body = nil, page = nil, edit=nil) + def parse_counter_edit(body = nil) body.css('.page_counter').each do |counter| res = '' case counter['option'] diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 119c27061..763eeba75 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -11,6 +11,7 @@ module ParserFrontEnd parse_images(body, page) parse_menu(body, page) parse_sub_menu(body, page, site) + parse_counter(body) i18n.merge!({locale => body.to_html}) end i18n @@ -21,10 +22,14 @@ module ParserFrontEnd tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] body = Nokogiri::HTML(page.content) body.css('orbit_front').each do |front| - ret = '' - part = PagePart.find(front['part_id']) if front['part_id'] - ret << eval("\"#{front['path']}\"") rescue '' - fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + if front['class'] && front['class'].include?('dymanic_load') + ret = '' + part = PagePart.find(front['part_id']) if front['part_id'] + ret << eval("\"#{front['path']}\"") rescue '' + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + else + fragment = Nokogiri::HTML::DocumentFragment.new(body, eval("#{front['value']}").to_s) + end front.swap(fragment) end body.to_html @@ -131,6 +136,26 @@ module ParserFrontEnd end end + def parse_counter(body = nil) + body.css('.page_counter').each do |counter| + ret = '' + case counter['option'] + when 'all' + ret << "display_visitors" + when 'today' + ret << "display_visitors_today" + when 'this_week' + ret << "display_visitors_this_week" + when 'this_month' + ret << "display_visitors_this_month" + when 'this_year' + ret << "display_visitors_this_year" + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, "") + counter.swap(fragment) + end + end + # ad_banners def generate_ad_banners(*args) "
" From bab8328029ca7fd009d952ce850dc31418415b41 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 10:43:48 +0800 Subject: [PATCH 02/11] Put back old tags (don't use the class ProtoTag) --- app/models/tag.rb | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index ad63434bd..758c7899d 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,45 @@ -class Tag < ProtoTag - belongs_to :module_app +# class Tag < ProtoTag +# belongs_to :module_app + +# end + +class Tag + include Mongoid::Document + include Mongoid::Timestamps + include Impressionist::Impressionable + + is_impressionable :counter_cache => { :column_name => :view_count } + + field :key + field :view_count, :type => Integer, :default => 0 + #field :cloud_amper,:type: Integer,:default=> 0 + + def self.sorted_for_cloud + tags = {} + self.all.each{ |tag| + tags.merge!({tag => self.get_impressionist(tag)}) + } + if !tags.blank? + sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse + sorted_tags[0][1] = :hot1 + offset = (sorted_tags.size - 1) / 3 + i = 1 + class_i = 2 + sorted_tags[1..-1].collect!{ |x| + x[1] = "hot#{class_i}" + i == offset ? i = 1 : i += 1 if class_i < 4 + class_i += 1 if i == offset && class_i < 4 + } + sorted_tags + else + [] + end + end + + protected + + def self.get_impressionist(item_tag = self) + item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count + end end From 17d93409b36dbb2fef2bf3a6b453c594bfa48c10 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 11:10:33 +0800 Subject: [PATCH 03/11] Remove extra double quote in sub_menu Fix web link widget pagination --- app/views/front/show_page_sub_menu.html.erb | 2 +- .../widget/web_links/_index.html.erb | 27 +++++++++++++++++ .../widget/web_links/index.html.erb | 29 ++----------------- .../widget/web_links/index.js.erb | 1 + 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.js.erb diff --git a/app/views/front/show_page_sub_menu.html.erb b/app/views/front/show_page_sub_menu.html.erb index 7dfcb0afd..ebe51f73c 100644 --- a/app/views/front/show_page_sub_menu.html.erb +++ b/app/views/front/show_page_sub_menu.html.erb @@ -1,7 +1,7 @@ <% if @menu_page && @menu_page.visible_children.size > 0 %>

<%= @menu_page.title %>

-
    " +
      <% @menu_page.visible_children.each do |child| %>
    • <%= child.title %> 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 new file mode 100644 index 000000000..543113709 --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/_index.html.erb @@ -0,0 +1,27 @@ +<% if @current_category %> +

      <%= @current_category.title + " " + t(:list_lower) %>

      +<% elsif @tag %> +

      <%= @tag[I18n.locale] + " " + t(:list_lower) %>

      +<% else %> +

      <%= t('list.link') %>

      +<% end %> + + + + + + + + <% @web_links.each do |post| %> + + + + + <% end %> + +
      <%= t(:category) %><%= t(:name) %>
      <%= post.web_link_category.title rescue nil %> + <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %> +
      + +<%#= paginate @web_links, :params => {:inner => 'true'}, :remote => true %> +<%= paginate @web_links, :params => {:inner => 'false'}, :remote => true %> 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 3e22695d8..93e314020 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,26 +1,3 @@ -<% if @current_category %> -

      <%= @current_category.title + " " + t(:list_lower) %>

      -<% elsif @tag %> -

      <%= @tag[I18n.locale] + " " + t(:list_lower) %>

      -<% else %> -

      <%= t('list.link') %>

      -<% end %> - - - - - - - - <% @web_links.each do |post| %> - - - - - <% end %> - -
      <%= t(:category) %><%= t(:name) %>
      <%= post.web_link_category.title rescue nil %> - <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %> -
      - -<%= paginate @web_links, :params => {:inner => 'false'} %> + \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.js.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.js.erb new file mode 100644 index 000000000..4ca2c879c --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/widget/web_links/index.js.erb @@ -0,0 +1 @@ +$('#web_link_widget').html("<%= j render 'index' %>") \ No newline at end of file From 37309a452dbf7db6d686fa804ca6515e4aeaaf20 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 11:37:37 +0800 Subject: [PATCH 04/11] Fix site map and menu order --- app/controllers/front_controller.rb | 2 +- app/models/item.rb | 2 +- lib/parsers/parser_common.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/front_controller.rb b/app/controllers/front_controller.rb index 2f58d9ed0..0ef396336 100644 --- a/app/controllers/front_controller.rb +++ b/app/controllers/front_controller.rb @@ -39,7 +39,7 @@ class FrontController < ApplicationController res << "'>" i = nil i = 1 if menu.values["li_incremental_#{current}"] - children = current == 1 ? page.visible_children.reverse : page.visible_children + children = current == 1 ? page.visible_children : page.visible_children children.each do |child| res << menu_li(child, current_page, current, menu, i) i += 1 if i diff --git a/app/models/item.rb b/app/models/item.rb index 81366a210..1809e2b2a 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -56,7 +56,7 @@ class Item end def show_in_sitemap_for(locale) - if !sitemap_enabled[locale].blank? + if sitemap_enabled && !sitemap_enabled[locale].blank? sitemap_enabled[locale].eql?('true') ? true : false else true diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index acdd43b85..4eb044b1a 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -9,7 +9,7 @@ module ParserCommon res << "'>" i = nil i = 1 if menu.values["li_incremental_#{current}"] - children = current == 1 ? page.visible_children.reverse : page.visible_children + children = current == 1 ? page.visible_children : page.visible_children children.each do |child| res << menu_li(child, current_page, current, menu, i, edit) i += 1 if i From 0a0298aaad95a516dfedad53b3d0d669a995715d Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 11:44:33 +0800 Subject: [PATCH 05/11] Fix counter front-end --- lib/parsers/parser_front_end.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 763eeba75..177143d3d 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -28,7 +28,7 @@ module ParserFrontEnd ret << eval("\"#{front['path']}\"") rescue '' fragment = Nokogiri::HTML::DocumentFragment.new(body, "
      ") else - fragment = Nokogiri::HTML::DocumentFragment.new(body, eval("#{front['value']}").to_s) + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
      eval('#{front['value']}'').to_s
      " ) end front.swap(fragment) end From 974a190eafefa4af1b33cd731a0e980b2dbe4b97 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 11:51:56 +0800 Subject: [PATCH 06/11] Fix orbit_front parser --- lib/parsers/parser_front_end.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 177143d3d..a211412bb 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -22,13 +22,13 @@ module ParserFrontEnd tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] body = Nokogiri::HTML(page.content) body.css('orbit_front').each do |front| - if front['class'] && front['class'].include?('dymanic_load') + if front['value'] + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
      #{eval(front['value']).to_s}
      ") + else ret = '' part = PagePart.find(front['part_id']) if front['part_id'] ret << eval("\"#{front['path']}\"") rescue '' fragment = Nokogiri::HTML::DocumentFragment.new(body, "
      ") - else - fragment = Nokogiri::HTML::DocumentFragment.new(body, "
      eval('#{front['value']}'').to_s
      " ) end front.swap(fragment) end From 455a27437d8e517f0bb1884dadf293d2e5e75970 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 13:47:30 +0800 Subject: [PATCH 07/11] Changes for announcement widget style 2 --- app/assets/stylesheets/default_widget.css | 195 ++++++++++++++++++ .../widget/bulletins/_index.html.erb | 2 +- .../widget/bulletins/index.html.erb | 2 +- 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/default_widget.css diff --git a/app/assets/stylesheets/default_widget.css b/app/assets/stylesheets/default_widget.css new file mode 100644 index 000000000..96e490c4c --- /dev/null +++ b/app/assets/stylesheets/default_widget.css @@ -0,0 +1,195 @@ +body{ + margin:10px; + padding:0; +} +a{ + color:#333; + text-decoration: none; +} +a:hover{ + color:#888; + text-decoration: none; +} +h2{ + margin:0 0 10px; +} + +ul{ + margin:0; + padding:0; +} + +li{ + list-style:none; +} +.eletb{ + border-collapse:collapse; + width:600px; +} +.eletb td{ + border: 1px solid #EEEEEE; + padding: 5px; + vertical-align: middle; + text-align: center; +} +.news{ + font-size:12px; + margin:0 0 20px; + position:relative; + width:600px; +} +.news ul{ + margin:0 0 10px; +} +.news li{ + padding:5px 0; +} +.more{ + background:#eee; + border-radius: 5px; + clear:both; + display:inline; + padding:3px; + text-align: center; +} +.top{ + color:#e21f1f; +} + +.elements{ + background: none repeat scroll 0 0 #f2f2f2; + border-radius: 5px 5px 5px 5px; + display: inline-block; + height: 50px; + padding: 10px; + text-align: center; + vertical-align: top; + width: 50px; + word-wrap: break-word; +} +.elementlist{ + margin:0 0 20px; +} +/* 1 */ + +.newstb{ + border-collapse:collapse; + width:600px; +} + +.newstb th{ + background: none repeat scroll 0 0 #eee; + padding: 5px; + text-align: left; +} +.newstb td{ + border: 1px solid #EEEEEE; + padding: 5px; +} + + +/* 2 */ + +.news2{} + +.news2 li{ + border-bottom:1px solid #eee; +} + +.news2 .newsimg{ + display: inline-block; + margin: 0 10px 0 0; + vertical-align: top; +} + +.news2 .app-pic{ + height:50px; + width:50px; + display: inline-block; +} +.news2 ul{ + display: inline-block; + width:570px; +} + + +/* 3 */ + +.news3{} + +.news3 li{ + border-bottom:1px solid #eee; + overflow: hidden; +} + +.news3 .img{ + float:left; + margin:0 10px 0 0; +} + +.news3 .hot, .news3 .title, .news3 .date, .news3 .tags, .news3 .text{ + display:block; + margin:0 0 5px; + text-align: left; +} + +.news3 .wrap{ + overflow: hidden; +} + + + + +/* 4 */ + +.news4{} + +.news4 li{ + border-bottom:1px solid #eee; + overflow: hidden; +} + +.news4 .img{ + float:right; + margin:0 0 0 10px; +} + +.news4 .hot, .news4 .title, .news4 .date, .news4 .tags, .news4 .text{ + display:block; + margin:0 0 5px; + text-align: left; +} + +.news4 .wrap{ + overflow: hidden; +} + + + +/* 5 */ + +.news5{ + overflow: hidden; +} + +.news5 .img{ + float:left; + margin:0 10px 0 0; +} +.news5 ul{ + float: left; + text-align: left; + width: 540px; +} +.news5 li{ + border-bottom:1px solid #eee; +} + +.news5 .more{} +.news5 .hot, .news5 .title, .news5 .date, .news5 .tags, .news5 .text{ + +} + +.news5 .wrap{ + overflow: hidden; +} \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb index 8d53872bf..79e52de9a 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb @@ -67,7 +67,7 @@
        <% @bulletins.each do |post| %>
      • -
        <%= image_tag(post.image.url) %>
        +
        <%= image_tag(post.image.url) %>
        <% @widget_fields.each do |wf| %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb index 81992d597..a8c8c7587 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb @@ -1,4 +1,4 @@ - +<%= stylesheet_link_tag "default_widget" %> From e8e7c382217506929e018b8382d2b93ed0695ecf Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 14:01:04 +0800 Subject: [PATCH 08/11] Changes for announcement widget style 1 and categories --- .../announcement/widget/bulletins/_index.html.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb index 79e52de9a..410d35e24 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb @@ -17,8 +17,8 @@ <% @bulletins.each do |post| %> - <% @widget_fields.each do |wf| %> + <% @widget_fields.each do |wf| %> <% if wf[1] == 'title' %> @@ -26,7 +26,7 @@ <% elsif wf[1] == 'date' %> <%= display_date(post.send(wf[0])) %> <% elsif wf[1] == 'category' %> - <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %> + <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").title rescue nil %> <% elsif wf[1] == 'img' %>
        <%= image_tag(post.send(wf[0]).url) %>
        <% elsif wf[1] == 'text' %> @@ -49,8 +49,8 @@ <% end %>
        - <% end %> + <% end %> @@ -76,7 +76,7 @@ <% elsif wf[1] == 'date' %> <%= display_date(post.send(wf[0])) %> <% elsif wf[1] == 'category' %> - <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %> + <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").title rescue nil %> <% elsif wf[1] == 'text' %> <%#= post.send("#{wf[0]}[#{I18n.locale}]").html_safe %> <%= post.send("#{wf[0]}").html_safe %> @@ -124,7 +124,7 @@ <% elsif wf[1] == 'date' %> <%= display_date(post.send(wf[0])) %> <% elsif wf[1] == 'category' %> - <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %> + <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").title rescue nil %> <% elsif wf[1] == 'text' %> <%#= post.send("#{wf[0]}[#{I18n.locale}]").html_safe %> <%= post.send("#{wf[0]}").html_safe %> @@ -174,7 +174,7 @@ <% elsif wf[1] == 'date' %> <%= display_date(post.send(wf[0])) %> <% elsif wf[1] == 'category' %> - <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %> + <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").title rescue nil %> <% elsif wf[1] == 'text' %> <%#= post.send("#{wf[0]}[#{I18n.locale}]").html_safe %> <%= post.send("#{wf[0]}").html_safe %> @@ -222,7 +222,7 @@ <% elsif wf[1] == 'date' %> <%= display_date(post.send(wf[0])) %> <% elsif wf[1] == 'category' %> - <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").i18n_variable[I18n.locale] rescue nil %> + <%= post.send("#{post.class.to_s.underscore}_#{wf[0]}").title rescue nil %> <% elsif wf[1] == 'text' %> <%#= post.send("#{wf[0]}[#{I18n.locale}]").html_safe %> <%= post.send("#{wf[0]}").html_safe %> From 4d965d754b75e3959fd4bee24bd5111877b31003 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 28 Dec 2012 15:03:02 +0800 Subject: [PATCH 09/11] Fix urls in tinymce source editor --- app/assets/javascripts/tinymce_orbit.js.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/tinymce_orbit.js.erb b/app/assets/javascripts/tinymce_orbit.js.erb index 975485a3b..d73d77682 100644 --- a/app/assets/javascripts/tinymce_orbit.js.erb +++ b/app/assets/javascripts/tinymce_orbit.js.erb @@ -14,7 +14,6 @@ function load_tinymce() { theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, - relative_urls : false, // Skin options skin : "o2k7", From baf1240b76723eba325877ed06becf451c877861 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Fri, 28 Dec 2012 15:30:46 +0800 Subject: [PATCH 10/11] gallery options --- app/assets/javascripts/page_edit.js.erb | 8 ++++++-- app/controllers/admin/page_parts_controller.rb | 2 ++ app/controllers/orbit_widget_controller.rb | 7 +++++++ app/models/module_app.rb | 13 +++++++++++-- app/models/page_part.rb | 7 +++++++ app/views/admin/page_parts/_module_widget.html.erb | 7 +++---- app/views/admin/page_parts/_widget_fields.html.erb | 3 ++- app/views/admin/page_parts/reload_widgets.js.erb | 4 +++- lib/parsers/parser_common.rb | 2 +- lib/parsers/parser_front_end.rb | 3 +-- lib/tasks/migrate.rake | 9 +++++++++ .../panel/gallery/widget/albums_controller.rb | 8 +++++++- .../panel/gallery/widget/albums/widget1.html.erb | 2 -- .../built_in_modules/gallery/config/locales/en.yml | 3 +++ .../gallery/config/locales/zh_tw.yml | 5 ++++- 15 files changed, 66 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index 8d2ca97c2..29047c7b8 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -1,3 +1,7 @@ +function get_part_id(){ + return $(".edit_page_part").attr("action").split('/').pop(); +} + $("div.editable").live("mouseenter mouseleave", function (event) { $(this).children('.edit_link').toggle(); }); @@ -21,11 +25,11 @@ $("#page_module_app_id").live('change', function() { }); $("#module_app_list select").live('change', function() { - $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets'); + $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets?part_id=' + get_part_id()); }); $("#widget_list select").live('change', function() { - $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widget_styles?module_app_id=' + $("#module_app_list select").val()); + $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widget_styles?module_app_id=' + $("#module_app_list select").val() + '&part_id=' + get_part_id()); }); $("#tag_list select").live('change', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index f78c6ae3a..58af08af9 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -90,6 +90,7 @@ class Admin::PagePartsController < ApplicationController end def reload_widgets + @part = PagePart.find params[:part_id] @categories =[] @module_app = ModuleApp.find(params[:id]) @@ -112,6 +113,7 @@ class Admin::PagePartsController < ApplicationController @tags = ArchiveTag.all end + @part.widget_path = @module_app.widgets.first if @module_app.needs_to_widget_option? respond_to do |format| format.js {} end diff --git a/app/controllers/orbit_widget_controller.rb b/app/controllers/orbit_widget_controller.rb index 47e24fe05..8f4b25da6 100644 --- a/app/controllers/orbit_widget_controller.rb +++ b/app/controllers/orbit_widget_controller.rb @@ -1,3 +1,10 @@ class OrbitWidgetController< OrbitFrontendComponentController +before_filter :get_wiget_options + def get_wiget_options + @wiget_options = {} + if params[:widget_options] + @wiget_options = (eval('{'+ params[:widget_options] +'}') rescue {}) + end + end end \ No newline at end of file diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 669d82aab..50a6c268e 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -12,12 +12,13 @@ class ModuleApp field :update_info field :create_date field :enable_frontend, type: Boolean, :default => true - + field :app_pages ,type: Array # field :widgets ,type: Array field :widgets ,type: Hash field :widget_fields ,type: Array - + field :widget_options,type:Hash + field :widget_options_fields_i18n,type:Hash has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app @@ -79,6 +80,14 @@ class ModuleApp end end + def needs_to_widget_option? + if self.widget_options + self.widget_options.has_key? widgets.first + else + false + end + end + protected def set_key diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 994424c85..a36c498a6 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -14,6 +14,7 @@ class PagePart field :widget_style field :widget_field , :type => Array + field :widget_options ,:type=>Hash field :widget_data_count belongs_to :page @@ -22,6 +23,11 @@ class PagePart before_save :delete_empty_widget_field after_save :update_parent + def widget_options_uri + self.widget_options.map{|t| "#{t[0]}: #{t[1]}"}.join(',') rescue '' + end + + protected def delete_empty_widget_field @@ -35,4 +41,5 @@ class PagePart self.page.save end + end \ No newline at end of file diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 44358601f..a1cec8d07 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -46,7 +46,6 @@ <%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, @part.widget_field.collect{|widget_field| widget_field}), {:multiple => :multiple, :size => 6} %>
        -
        -<%= f.label :widget_data_count %> -<%= f.text_field :widget_data_count %> -
        + + <%= render 'widget_options' %> + diff --git a/app/views/admin/page_parts/_widget_fields.html.erb b/app/views/admin/page_parts/_widget_fields.html.erb index 21196b5bf..81b49992d 100644 --- a/app/views/admin/page_parts/_widget_fields.html.erb +++ b/app/views/admin/page_parts/_widget_fields.html.erb @@ -1,4 +1,3 @@ - <% if (@module_app && @module_app.widget_fields) %> <%= label_tag('widget_field') %> @@ -9,4 +8,6 @@ <%= select_tag "page_part[widget_field_type][]", options_for_select(LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
        <% end %> + <%= label_tag :widget_data_count %> + <%= text_field_tag :widget_data_count,@part.widget_data_count %> <% end %> \ No newline at end of file diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index c66c44e9d..76f49d910 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -2,4 +2,6 @@ $('#widget_list select').html("<%= j options_for_select(@module_app.widgets.coll $('#widget_style_list').html("<%= escape_javascript(select 'page_part', 'widget_style', @module_app.widgets[@widget_path]) if !@widget_path.blank? %>"); $('#widget_field').html("<%= j render 'widget_fields' %>"); $('#widget_category').html("<%= j render 'widget_categories' %>"); -$('#widget_tag').html("<%= j render 'widget_tags' %>"); \ No newline at end of file +$('#widget_tag').html("<%= j render 'widget_tags' %>"); + +$("#widget_options").html("<%= j render 'widget_options'%>"); \ No newline at end of file diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 794fb4fdc..81fde0b41 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -210,7 +210,7 @@ module ParserCommon when 'default_widget' "/panel/orbit_app/widget/#{part.widget_style}?inner=true" else - "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" + "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true&widget_options=#{part.widget_options_uri}" end options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" ret << "
        " diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 119c27061..edc8e5633 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -109,9 +109,8 @@ module ParserFrontEnd when 'default_widget' "/panel/orbit_app/widget/\#{part.widget_style}?inner=true" else - "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" + "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true&widget_options=\#{part.widget_options_uri}" end - options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}" ret << "" diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 03de17e52..5ac425d2e 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -319,4 +319,13 @@ namespace :migrate do end end + + task :add_widget_options_to_gallery => :environment do + a = ModuleApp.where(:key=>'gallery').first + a.widget_options = {"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6]}} + a.widget_options_fields_i18n = {"widget1"=>{"vertical"=>"gallery.widget_option.vertical", "horizontal"=>"gallery.widget_option.horizontal"}} + a.save + + end + end diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb index 99956d41f..6a57b47ba 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb @@ -1,7 +1,13 @@ class Panel::Gallery::Widget::AlbumsController < OrbitWidgetController def widget1 - @settings = {"vertical"=>2,"horizontal"=>6} #[note] horizontal has it's limitation from 2 to 6 + vertical = 2 + horizontal = 6 + + vertical = @wiget_options[:vertical] if (@wiget_options.has_key?(:vertical) && @wiget_options[:vertical] < vertical) + horizontal = @wiget_options[:horizontal] if (@wiget_options.has_key?(:horizontal) && @wiget_options[:horizontal] < horizontal) + + @settings = {"vertical"=>vertical,"horizontal"=>horizontal} #[note] horizontal has it's limitation from 2 to 6 @class = "c" + @settings["horizontal"].to_s @total = @settings["vertical"] * @settings["horizontal"] @rnd = Random.new diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/widget/albums/widget1.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/widget/albums/widget1.html.erb index 70ae5363a..c856c69a0 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/widget/albums/widget1.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/widget/albums/widget1.html.erb @@ -3,8 +3,6 @@ <%#= javascript_include_tag "cycle" %> <%# end %>
        -

        Gallery Widget

        -

        WIDGET 1