diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index 8d2ca97c..29047c7b 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 f78c6ae3..58af08af 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 47e24fe0..8f4b25da 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 669d82aa..50a6c268 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 994424c8..a36c498a 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 44358601..a1cec8d0 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 21196b5b..81b49992 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 c66c44e9..76f49d91 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 794fb4fd..81fde0b4 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 119c2706..edc8e563 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 03de17e5..5ac425d2 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 99956d41..6a57b47b 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 70ae5363..c856c69a 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