# -*- encoding : utf-8 -*- format do def wrap_item item, args={} item #no wrap in base end view :core do |args| pointer_items args[:item], joint=', ' end def pointer_items itemview=nil, joint=' ' args = { :view => ( itemview || (@inclusion_opts && @inclusion_opts[:view]) || default_item_view ) } if type = card.item_type args[:type] = type end card.item_cards.map do |icard| wrap_item process_inclusion(icard, args.clone), args end.join joint end end format :html do view :core do |args| %{
#{ pointer_items args[:item], args[:joint] }
} end view :closed_content do |args| args[:item] = (args[:item] || inclusion_defaults[:view])=='name' ? 'name' : 'link' args[:joint] ||= ', ' _render_core args end view :editor do |args| part_view = (c = card.rule(:input)) ? c.gsub(/[\[\]]/,'') : :list form.hidden_field( :content, :class=>'card-content') + raw(_render(part_view)) end view :list do |args| #this is a permission view. should it go with them? args ||= {} items = args[:item_list] || card.item_names(:context=>:raw) items = [''] if items.empty? options_card_name = (oc = card.options_card) ? oc.cardname.url_key : ':all' extra_css_class = args[:extra_css_class] || 'pointer-list-ul' %{
#{link_to 'Add another','#', :class=>'pointer-item-add'}
} end view :checkbox do |args| options = card.options.map do |option| checked = card.item_names.include?(option.name) id = "pointer-checkbox-#{option.cardname.key}" description = pointer_option_description option %{
#{ check_box_tag "pointer_checkbox", option.name, checked, :id=>id, :class=>'pointer-checkbox-button' } #{ %{
#{ description }
} if description }
} end.join "\n" %{
#{options}
} end view :multiselect do |args| options = options_from_collection_for_select(card.options,:name,:name,card.item_names) select_tag("pointer_multiselect", options, :multiple=>true, :class=>'pointer-multiselect') end view :radio do |args| input_name = "pointer_radio_button-#{card.key}" options = card.options.map do |option| checked = (option.name==card.item_names.first) id = "pointer-radio-#{option.cardname.key}" description = pointer_option_description option %{
#{ radio_button_tag input_name, option.name, checked, :id=>id, :class=>'pointer-radio-button' } #{ %{
#{ description }
} if description }
} end.join("\n") %{
#{options}
} end view :select do |args| options = [["-- Select --",""]] + card.options.map{|x| [x.name,x.name]} select_tag("pointer_select", options_for_select(options, card.item_names.first), :class=>'pointer-select') end def pointer_option_description option pod_name = card.rule(:options_label) || 'description' dcard = Card[ "#{option.name}+#{pod_name}" ] if dcard and dcard.ok? :read subformat(dcard).render_core end end def wrap_item item, args %{
#{item}
} end end def item_cards args={} if args[:complete] #warn "item_card[#{args.inspect}], :complete" Card::Query.new({:referred_to_by=>name}.merge(args)).run else #warn "item_card[#{inspect}], :complete" item_names(args).map do |name| new_args = args[:type] ? { :type=>args[:type] } : {} Card.fetch name, :new=>new_args end.compact # compact? can't be nil, right? end end def item_names args={} context = args[:context] || self.cardname self.raw_content.split(/\n+/).map do |line| item_name = line.gsub /\[\[|\]\]/, '' if context == :raw item_name else item_name.to_name.to_absolute context end end end def item_ids args={} item_names(args).map do |name| Card.fetch_id name end.compact end def item_type opt = options_card if !opt or opt==self #fixme, need better recursion prevention nil else opt.item_type end end def items= array self.content='' array.each { |i| self << i } save! end def << item newname = case item when Card ; item.name when Integer ; c = Card[item] and c.name else item end add_item newname end def add_item newname inames = item_names unless inames.include? newname self.content="[[#{(inames << newname).reject(&:blank?)*"]]\n[["}]]" end end def drop_item name inames = item_names if inames.include? name inames = inames.reject{|n|n==name} self.content= inames.empty? ? '' : "[[#{inames * "]]\n[["}]]" end end def options_card self.rule_card :options end def options if oc = options_card oc.item_cards :default_limit=>50, :context=>name else Card.search :sort=>'alpha', :limit=>50 end end format :css do view :content do |args| %(#{major_comment "STYLE GROUP: \"#{card.name}\"", '='}#{ _render_core }) end view :core do |args| card.item_cards.map do |item| process_inclusion item, :view=>(params[:item] || :content) end.join "\n\n" end end