now default options can be chosen by developer at init

This commit is contained in:
Fu Matthew 2013-03-13 14:09:10 +08:00 committed by Matt K. Fu
parent 50449b55e8
commit 9815950083
4 changed files with 58 additions and 48 deletions

View File

@ -12,47 +12,57 @@
</label> </label>
<div class="controls well"> <div class="controls well">
<ul class="clear"> <ul class="clear">
<li> <% if @module_app.get_default_widget["enabled_styles"].include?("typeA") %>
<label class="radio style_radio"> <li>
<%= radio_button_tag field_name,"typeA",style_checked_value(object,"typeA") %> <label class="radio style_radio">
1 <%= radio_button_tag field_name,"typeA",style_checked_value(object,"typeA") %>
<span class="style_img"><%=image_tag 'module/default_widgets/style01.png'%></span> 1
<span class="style_description"><%= t("default_widget.caption.typeA") %></span> <span class="style_img"><%=image_tag 'module/default_widgets/style01.png'%></span>
</label> <span class="style_description"><%= t("default_widget.caption.typeA") %></span>
</label>
</li> </li>
<li> <% end %>
<label class="radio style_radio"> <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style2") %>
<%= radio_button_tag field_name,"typeB_style2",style_checked_value(object,"typeB_style2") %> <li>
2 <label class="radio style_radio">
<span class="style_img"><%=image_tag 'module/default_widgets/style02.png'%></span> <%= radio_button_tag field_name,"typeB_style2",style_checked_value(object,"typeB_style2") %>
<span class="style_description"><%= t("default_widget.caption.typeB_style2") %></span> 2
</label> <span class="style_img"><%=image_tag 'module/default_widgets/style02.png'%></span>
</li> <span class="style_description"><%= t("default_widget.caption.typeB_style2") %></span>
<li> </label>
<label class="radio style_radio"> </li>
<%= radio_button_tag field_name,"typeB_style3",style_checked_value(object,"typeB_style3") %> <% end %>
3 <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style3") %>
<span class="style_img"><%=image_tag 'module/default_widgets/style03.png'%></span> <li>
<span class="style_description"><%= t("default_widget.caption.typeB_style3") %></span> <label class="radio style_radio">
</label> <%= radio_button_tag field_name,"typeB_style3",style_checked_value(object,"typeB_style3") %>
</li> 3
<li> <span class="style_img"><%=image_tag 'module/default_widgets/style03.png'%></span>
<label class="radio style_radio"> <span class="style_description"><%= t("default_widget.caption.typeB_style3") %></span>
<%= radio_button_tag field_name,"typeB_style4",style_checked_value(object,"typeB_style4") %> </label>
4 </li>
<span class="style_img"><%=image_tag 'module/default_widgets/style04.png'%></span> <% end %>
<span class="style_description"><%= t("default_widget.caption.typeB_style4") %></span> <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style4") %>
</label> <li>
</li> <label class="radio style_radio">
<li> <%= radio_button_tag field_name,"typeB_style4",style_checked_value(object,"typeB_style4") %>
<label class="radio style_radio"> 4
<%= radio_button_tag field_name,"typeC",style_checked_value(object,"typeC") %> <span class="style_img"><%=image_tag 'module/default_widgets/style04.png'%></span>
5 <span class="style_description"><%= t("default_widget.caption.typeB_style4") %></span>
<span class="style_img"><%=image_tag 'module/default_widgets/style05.png'%></span> </label>
<span class="style_description"><%= t("default_widget.caption.typeC") %></span> </li>
</label> <% end %>
</li> <% if @module_app.get_default_widget["enabled_styles"].include?("typeC") %>
<li>
<label class="radio style_radio">
<%= radio_button_tag field_name,"typeC",style_checked_value(object,"typeC") %>
5
<span class="style_img"><%=image_tag 'module/default_widgets/style05.png'%></span>
<span class="style_description"><%= t("default_widget.caption.typeC") %></span>
</label>
</li>
<% end %>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -40,12 +40,7 @@ module OrbitApp
# include ApplicationHelper # include ApplicationHelper
# include AdminHelper # include AdminHelper
include SideBarRenderer include SideBarRenderer
# def is_admin?
# binding.pry
# end
# def is_manager?
# binding.pry
# end
def initialize(name = '',key,get_module_app,&block) def initialize(name = '',key,get_module_app,&block)
@head_label = name @head_label = name
@context_links = [] @context_links = []

View File

@ -101,9 +101,13 @@ module OrbitApp
@image = nil @image = nil
@more_link = {} @more_link = {}
@fields = [] @fields = []
@enabled_styles = STYLE
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end end
def enable(args)
@enabled_styles = args
end
def link_to_more(*args) def link_to_more(*args)
@more_link[:label_i18n] = (args[1] ? args[1][:title_i18n] : 'default_widget.default_link_to_more' ) @more_link[:label_i18n] = (args[1] ? args[1][:title_i18n] : 'default_widget.default_link_to_more' )
@ -112,11 +116,11 @@ module OrbitApp
def self.get_interface_args def self.get_interface_args
#will need to work with design #will need to work with design
{:name=>"default_widget",:field=>@fields,:style=>STYLE,:i18n=>'default_widget.default_widget'} {:name=>"default_widget",:field=>@fields,:style=>@enabled_styles,:i18n=>'default_widget.default_widget'}
end end
def to_module_app_format def to_module_app_format
{"query"=>@query,"image"=>@image,"more_link"=>@more_link} rescue nil {"query"=>@query,"image"=>@image,"more_link"=>@more_link,"enabled_styles"=>@enabled_styles} rescue nil
end end
def link_field(field_name,setting) def link_field(field_name,setting)

View File

@ -24,6 +24,7 @@ module Announcement
widgets do widgets do
default_widget do default_widget do
query 'Bulletin.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )' query 'Bulletin.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )'
enable ["typeA","typeC"]
image :image image :image
field :postdate field :postdate
link_field :title,{:method => 'panel_announcement_front_end_bulletin_path',:args=>:self} link_field :title,{:method => 'panel_announcement_front_end_bulletin_path',:args=>:self}