From 46b1d55ff66febaf3ce15e84733105bad2c31ffa Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Mon, 14 Jan 2013 18:49:23 +0800 Subject: [PATCH] Complete new interface --- .../admin/default_widget_setting.css | 27 ++++++++++++ .../admin/page_parts_controller.rb | 8 +++- app/helpers/admin/page_parts_helper.rb | 12 ++++-- app/models/module_app.rb | 10 +++++ .../_custom_widget_setting.html.erb | 12 ++++++ .../_default_widget_setting.html.erb | 42 +++++++++++++------ .../_default_widget_style_panel.html.erb | 12 +++--- app/views/admin/page_parts/_edit.html.erb | 2 + .../admin/page_parts/_module_widget.html.erb | 2 +- .../_widget_data_source_category.html.erb | 24 +++++------ .../_widget_data_source_tag.html.erb | 22 +++++----- .../page_parts/_widget_ext_options.html.erb | 13 ++++++ .../admin/page_parts/_widget_setting.html.erb | 5 ++- .../page_parts/reload_widget_styles.js.erb | 9 +++- .../admin/page_parts/reload_widgets.js.erb | 18 +++++--- config/locales/zh_tw.yml | 2 + lib/tasks/migrate.rake | 15 +++++++ 17 files changed, 178 insertions(+), 57 deletions(-) create mode 100644 app/assets/stylesheets/admin/default_widget_setting.css create mode 100644 app/views/admin/page_parts/_custom_widget_setting.html.erb create mode 100644 app/views/admin/page_parts/_widget_ext_options.html.erb diff --git a/app/assets/stylesheets/admin/default_widget_setting.css b/app/assets/stylesheets/admin/default_widget_setting.css new file mode 100644 index 00000000..e68bb3aa --- /dev/null +++ b/app/assets/stylesheets/admin/default_widget_setting.css @@ -0,0 +1,27 @@ +.style_switch{} + +.style_switch ul{} + +.style_switch li{ + float: left; + list-style: none outside none; + margin: 0 30px 0 0; + width: 103px; +} +.style_radio{ + margin: 0 0 5px 10px; +} +.style_img{ + display: block; + margin: 0 0 5px; +} + +.style_description{ + color: #6B6B6B; + display: block; + margin: 0 0 0 5px; +} + +label{ +    white-space: nowrap !important ; +} \ No newline at end of file diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index da2de827..af6b0ed8 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -26,6 +26,7 @@ class Admin::PagePartsController < ApplicationController @part = PagePart.find(params[:id]) @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) @module_app = @part.module_app ? @part.module_app : @module_apps[0] + @user_choose = @part.widget_path @r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag @tag_objects = @r_tag.classify.constantize.all rescue nil @@ -41,6 +42,7 @@ class Admin::PagePartsController < ApplicationController @tags = AnnouncementTag.all when 'gallery' @albums = GalleryAlbum.all + @tags = [] when 'web_resource' @categories = WebLinkCategory.all @tags = WebResourceTag.all @@ -103,6 +105,7 @@ class Admin::PagePartsController < ApplicationController @tags = AnnouncementTag.all when 'gallery' @albums = GalleryAlbum.all + @tags = [] when 'web_resource' @categories = WebLinkCategory.all @tags = WebResourceTag.all @@ -119,9 +122,10 @@ class Admin::PagePartsController < ApplicationController def reload_widget_styles @module_app = ModuleApp.find(params[:module_app_id]) - + @part = PagePart.find params[:part_id] + @user_choose =@widget_path= params[:id] @widget_style = @module_app.widgets[params[:id]] - + respond_to do |format| format.js {} end diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 0914939b..e8a1afc4 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -27,7 +27,7 @@ module Admin::PagePartsHelper def category_checked_value(part,radio_value) - part and (part[:tag] == radio_value) ? true : false + part and (part[:category] == radio_value) ? true : false end def style_checked_value(part,radio_value) @@ -36,17 +36,21 @@ module Admin::PagePartsHelper def nil_radio_button(part,tag_or_cate) content_tag :label,:class=>"radio inline" do - op = radio_button("page_part", tag_or_cate, nil, :checked => eval("#{tag_or_cate}_checked_value(part,nil)")) + op = radio_button("page_part", tag_or_cate, '' , :checked => eval("#{tag_or_cate}_checked_value(part,'')")) op << I18n.t("default_widget.no_value") end end def show_default_widget_setting_panel - binding.pry - false + if @module_app.has_default_widget? && (!@user_choose.nil? && @user_choose== 'default_widget') #&& @part.widget_path == 'default_widget' + true + else + false + end end def show_custom_widget_setting_panel + true end end \ No newline at end of file diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 15657b2c..ab88cdea 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -91,6 +91,16 @@ class ModuleApp end end + def has_default_widget? + case self[:widgets] + when Array + false + when Hash + self[:widgets].has_key? 'default_widget' + end + + end + protected def set_key diff --git a/app/views/admin/page_parts/_custom_widget_setting.html.erb b/app/views/admin/page_parts/_custom_widget_setting.html.erb new file mode 100644 index 00000000..a257336e --- /dev/null +++ b/app/views/admin/page_parts/_custom_widget_setting.html.erb @@ -0,0 +1,12 @@ +
+ + <% if @module_app.widgets[@widget_path].blank? %> + <%= t("default_widget.no_support_setting")%> + <%else%> + <%= select('page_part', 'widget_style', @module_app.widgets[@widget_path]) %> + <% end %> + <% if(@module_app.widget_options && @module_app.widget_options.has_key?(@widget_path)) %> + + <%= render :partial=> "widget_ext_options" %> + <% end %> +
\ No newline at end of file diff --git a/app/views/admin/page_parts/_default_widget_setting.html.erb b/app/views/admin/page_parts/_default_widget_setting.html.erb index 5f001851..728bf010 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -1,18 +1,34 @@ - +
- +
+ + + + + + + + +
<% @module_app.widget_fields.each_with_index do |widget_field, i| %> - <%= i+1 %> - <%= select_tag "page_part[widget_field][]", widget_field_options(i), :include_blank => true %> - <%= select_tag "page_part[widget_field_type][]", widget_fiield_type_options(i), :include_blank => true %>
+
+ + <%= i+1 %> + <%= select_tag "page_part[widget_field][]", widget_field_options(i), :include_blank => true %> + + + <%= select_tag "page_part[widget_field_type][]", widget_fiield_type_options(i), :include_blank => true %>
+
+ +
<% end %> -

- - <%= label_tag t("default_widget.widget_data_count") %> - <%= text_field_tag :widget_data_count,@part.widget_data_count %> - -
- - +
+
+ <%= label_tag t("default_widget.widget_data_count") %> +
+
+ <%= text_field_tag :widget_data_count,@part.widget_data_count %> +
+
diff --git a/app/views/admin/page_parts/_default_widget_style_panel.html.erb b/app/views/admin/page_parts/_default_widget_style_panel.html.erb index b6a60139..3a4096b4 100644 --- a/app/views/admin/page_parts/_default_widget_style_panel.html.erb +++ b/app/views/admin/page_parts/_default_widget_style_panel.html.erb @@ -1,9 +1,9 @@ -
+
  • <%=image_tag 'module/default_widgets/style01.png'%> @@ -11,7 +11,7 @@
  • <%=image_tag 'module/default_widgets/style02.png'%> @@ -19,7 +19,7 @@
  • <%=image_tag 'module/default_widgets/style03.png'%> @@ -27,7 +27,7 @@
  • <%=image_tag 'module/default_widgets/style04.png'%> @@ -35,7 +35,7 @@
  • <%=image_tag 'module/default_widgets/style05.png'%> diff --git a/app/views/admin/page_parts/_edit.html.erb b/app/views/admin/page_parts/_edit.html.erb index 78a20b37..0d96516c 100644 --- a/app/views/admin/page_parts/_edit.html.erb +++ b/app/views/admin/page_parts/_edit.html.erb @@ -1,3 +1,5 @@ +<%= stylesheet_link_tag "admin/default_widget_setting" %> + <%= form_for @part, :url => admin_page_part_path(@part) do |f| %> <% LIST[:page_part_kinds].each do |kind| %> diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 77590997..658d2a62 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -32,7 +32,7 @@
- <%= render :partial => 'widget_setting' %> + <%= render :partial => 'widget_setting' ,:locals=>{:f=>f} %>
+ <% end %> + + + <% end %> + diff --git a/app/views/admin/page_parts/_widget_setting.html.erb b/app/views/admin/page_parts/_widget_setting.html.erb index 75ac6a50..a84717b1 100644 --- a/app/views/admin/page_parts/_widget_setting.html.erb +++ b/app/views/admin/page_parts/_widget_setting.html.erb @@ -3,5 +3,8 @@ <%= render :partial => 'default_widget_style_panel',:locals=>{:f=>f} %> <%= render :partial => 'default_widget_setting' %> -<% elsif show_custom_widget_setting_panel %> +<% elsif show_custom_widget_setting_panel %> +
+ <%= render :partial => 'custom_widget_setting' %> +
<% end %> diff --git a/app/views/admin/page_parts/reload_widget_styles.js.erb b/app/views/admin/page_parts/reload_widget_styles.js.erb index 41b2ad9c..333765c9 100644 --- a/app/views/admin/page_parts/reload_widget_styles.js.erb +++ b/app/views/admin/page_parts/reload_widget_styles.js.erb @@ -1 +1,8 @@ -$('#widget_style_list select').html("<%= j options_for_select(@module_app.widgets[params[:id]]) %>") +<% if !@part.widget_path.blank? %> + <% if show_default_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'default_widget_style_panel' %>"); + $('#widget_setting').append("<%= j render :partial => 'default_widget_setting' %>"); + <% elsif show_custom_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'custom_widget_setting' %>"); + <% end %> +<% end %> diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index 76f49d91..e046c1f0 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -1,7 +1,13 @@ -$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>"); -$('#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' %>"); +$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k},@part.widget_path) %>"); +$("#widget_data_source_category").html("<%= j render :partial => 'widget_data_source_category' %>"); +$("#widget_data_source_tag").html("<%= j render :partial => 'widget_data_source_tag' %>"); + +<% if !@part.widget_path.blank? %> + <% if show_default_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'default_widget_style_panel' %>"); + $('#widget_setting').append("<%= j render :partial => 'default_widget_setting' %>"); + <% elsif show_custom_widget_setting_panel %> + $('#widget_setting').html("<%= j render :partial => 'custom_widget_setting' %>"); + <% end %> +<% end %> -$("#widget_options").html("<%= j render 'widget_options'%>"); \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 2ed3225e..a79e7897 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -154,10 +154,12 @@ zh_tw: no_support_setting: 沒有可以使用的設定 no_value: 不設定(全部) fields_order: 輸出欄位順序 + fields_style: 輸出欄位樣式 select_module_app: 外掛模組選擇 select_widget_path: 外掛樣版選擇 select_widget_style: 排版樣式 widget_data_count: 模組輸出則數 + select_widget_ext_option: 模組延伸選項 caption: typeA: 表格式排版,簡單明瞭呈現內容 typeB_style2: 一圖一文式,輸出欄位水平排列 diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index e55ab296..a791b7b6 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -390,4 +390,19 @@ namespace :migrate do end + task :correct_gallery_and_web_resoure_config => :environment do + a = ModuleApp.where(:key=>'web_resource').first + a.widgets = {} + a.widgets[:web_links] = [] + a.widgets[:home_list] = [] + a.save + + a = ModuleApp.where(:key=>'gallery').first + a.widgets = {} + a.widgets[:widget1] = [] + a.widget_options_fields_i18n = {"widget1"=>{"vertical"=>"gallery.widget_option.vertical", "horizontal"=>"gallery.widget_option.horizontal", "album_id"=>"gallery.widget_option.album"}} + a.widget_options = {"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6], "album_id"=>{"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name}}} + a.save + end + end