2012-11-29 06:21:46 +00:00
|
|
|
module OrbitApp
|
|
|
|
module Module
|
|
|
|
module WidgetUtility
|
|
|
|
Version = "0.1"
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
@@widgets = []
|
|
|
|
|
|
|
|
def add(var)
|
|
|
|
@@widgets << var
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
return @@widgets
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
extend ClassMethods
|
|
|
|
def self.included( other )
|
|
|
|
other.extend( ClassMethods )
|
|
|
|
end
|
|
|
|
|
|
|
|
class WidgetSet
|
|
|
|
attr_reader :widgets,:categories_query,:tags_query
|
|
|
|
def initialize(&block)
|
|
|
|
@widgets = []
|
|
|
|
@default_widget = nil
|
|
|
|
@categories_query = ''
|
|
|
|
@tags_query = ''
|
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
|
|
end
|
|
|
|
|
|
|
|
%w{categories_query tags_query}.each do |field|
|
|
|
|
define_method(field){|var| instance_variable_set( "@" + field, var)}
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def find_by_path(path)
|
|
|
|
@widgets.each do |widget|
|
|
|
|
return widget if widget.name == path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def get_categories
|
2012-12-03 10:52:36 +00:00
|
|
|
eval(@categories_query) rescue nil
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_tags
|
2012-12-03 10:52:36 +00:00
|
|
|
eval(@tags_query) rescue nil
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_widget(&block)
|
|
|
|
@default_widget = DefaultWidget.new(&block)
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def customize_widget(name,&block)
|
|
|
|
@widgets << Widget.new(name,&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
# def customize_widget(name,label,options ={})
|
|
|
|
# @widgets << Widget.new(name,label,options)
|
|
|
|
# end
|
|
|
|
|
|
|
|
# def customize_widget_options_fields_i18n(settings)
|
|
|
|
# @customize_widget_options_fields_i18n = settings
|
|
|
|
# end
|
2012-11-29 06:21:46 +00:00
|
|
|
|
|
|
|
def to_module_app_format
|
|
|
|
hash = {}
|
|
|
|
@widgets.collect{|t| hash[t.name] = t.to_hash}
|
2012-12-03 10:52:36 +00:00
|
|
|
hash["default_widget"]= DefaultWidget.get_interface_args unless @default_widget.blank?
|
2012-11-29 06:21:46 +00:00
|
|
|
hash
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def get_fields
|
|
|
|
get_default_widget.get_fields
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def get_default_widget
|
|
|
|
return @default_widget
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DefaultWidget
|
2012-12-03 10:52:36 +00:00
|
|
|
STYLE = ["typeA","typeB_style2","typeB_style3","typeB_style4","typeC"]
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def initialize(&block)
|
|
|
|
@query = nil
|
|
|
|
@image = nil
|
2013-01-29 12:33:40 +00:00
|
|
|
@more_link = {}
|
|
|
|
@fields = []
|
2012-11-29 06:21:46 +00:00
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def more_link_to(label_i18n,path_method)
|
|
|
|
@more_link[:label_i18n] = label_i18n
|
|
|
|
@more_link[:path_method] = path_method
|
|
|
|
end
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
def self.get_interface_args
|
|
|
|
#will need to work with design
|
|
|
|
{:name=>"default_widget",:field=>nil,:label=>'label',:style=>STYLE}
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def to_module_app_format
|
|
|
|
{:query=>@query,:image=>@image} rescue nil
|
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def link_field(field_name,setting)
|
|
|
|
@fields << [field_name,setting,:link]
|
|
|
|
end
|
|
|
|
|
|
|
|
def field(field_name)
|
|
|
|
@fields << [field_name,nil,:field]
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_fields
|
|
|
|
@fields
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def query(var)
|
|
|
|
@query = var
|
|
|
|
end
|
|
|
|
|
|
|
|
def image(var)
|
|
|
|
@image = var
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Widget
|
|
|
|
attr_reader :name,:default_template,:fields
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def initialize(name,&block)
|
2012-11-29 06:21:46 +00:00
|
|
|
@name = name
|
2013-01-29 12:33:40 +00:00
|
|
|
@options = {}
|
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
|
|
|
|
|
|
# @fields = options[:fields]
|
|
|
|
# @label = label
|
|
|
|
# @style= options[:style]
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def widget_i18n(str) # "gallery.widget.widget1"
|
|
|
|
@widget_i18n = str
|
|
|
|
end
|
|
|
|
|
|
|
|
def style(ary)# []
|
|
|
|
@style = ary
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_options
|
|
|
|
@options
|
|
|
|
end
|
|
|
|
|
|
|
|
def options(opt_name,*options) # "vertical",
|
|
|
|
option = options[0]
|
|
|
|
@options[opt_name] = {:label_i18n=>option[:i18n] , :opts=>option[:options_item]}
|
|
|
|
# options => :i18n => "gallery.widget_option.vertical",:options_item=>[1, 2]
|
|
|
|
# :i18n =>"gallery.widget_option.album",:options_item => {"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name}
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
def to_hash
|
|
|
|
{:name => @name,:fields=>@fields,:label=>@label,:style=>@style,:i18n=>@widget_i18n}
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
end# of widget
|
|
|
|
end # of WidgetRegisition
|
|
|
|
end # of Module
|
|
|
|
end # of OrbitApp
|