Module: Engine2::MetaListSupport

Includes:
MetaAPISupport, MetaMenuSupport, MetaModelSupport, MetaOnChangeSupport, MetaPanelSupport, MetaTabSupport
Included in:
ListMeta
Defined in:
lib/engine2/meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MetaModelSupport

#action_defined, #get_type_info, #hide_pk, #show_pk, #unsupported_association

Methods included from MetaAPISupport

#config, #decorate, #field_filter, #hide_fields, #info, #info!, #render, #show_fields

Methods included from MetaTabSupport

#field_tabs, #lazy_tab, #select_tabs

Methods included from MetaPanelSupport

#glyphicon, #modal_action, #panel, #panel_class, #panel_panel_template, #panel_template, #panel_title

Methods included from MetaMenuSupport

#menu

Methods included from MetaOnChangeSupport

#on_change

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



536
537
538
# File 'lib/engine2/meta.rb', line 536

def filters
  @filters
end

#ordersObject (readonly)

Returns the value of attribute orders.



536
537
538
# File 'lib/engine2/meta.rb', line 536

def orders
  @orders
end

Instance Method Details

#filter(name, &blk) ⇒ Object



656
657
658
# File 'lib/engine2/meta.rb', line 656

def filter name, &blk
    (@filters ||= {})[name] = blk
end

#order(name, &blk) ⇒ Object



660
661
662
# File 'lib/engine2/meta.rb', line 660

def order name, &blk
    (@orders ||= {})[name] = blk
end

#post_processObject

def find_renderer type_info

renderer = DefaultSearchRenderers[type_info[:type]] || DefaultSearchRenderers[type_info[:otype]]
raise E2Error.new("No search renderer found for field '#{type_info[:name]}'") unless renderer
renderer.(self, type_info)

end



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
# File 'lib/engine2/meta.rb', line 588

def post_process
    if fields = @meta[:search_fields]
        fields = fields - static.get[:search_fields] if dynamic?

        decorate(fields)
        fields.each do |name|
            type_info = get_type_info(name)

            # render = info[name][:render]
            # if not render
            #     info[name][:render] = find_renderer(type_info)
            # else
            #     info[name][:render].merge!(find_renderer(type_info)){|key, v1, v2|v1}
            # end

            info[name][:render] ||= begin # set before :fields
                renderer = DefaultSearchRenderers[type_info[:type]] || DefaultSearchRenderers[type_info[:otype]]
                raise E2Error.new("No search renderer found for field '#{type_info[:name]}'") unless renderer
                renderer.(self, type_info)
            end

            proc = SearchRendererPostProcessors[type_info[:type]] || ListRendererPostProcessors[type_info[:type]] # ?
            proc.(self, name, type_info) if proc
        end
    end

    if fields = @meta[:fields]
        fields = fields - static.get[:fields] if dynamic?

        decorate(fields)
        fields.each do |name|
            type_info = get_type_info(name)
            proc = ListRendererPostProcessors[type_info[:type]]
            proc.(self, name, type_info) if proc
        end
    end

    super
end

#post_runObject



569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/engine2/meta.rb', line 569

def post_run
    unless panel[:class]
        panel_class case @meta[:fields].size
        when 1..3; ''
        when 4..6; 'modal-large'
        else; 'modal-huge'
        end
    end

    super
    @meta[:primary_fields] = assets[:model].primary_keys
end

#pre_runObject



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/engine2/meta.rb', line 538

def pre_run
    super
    config.merge!(per_page: 10, use_count: false, show_item_menu: true, selectable: true) # search_active: false,

    # modal_action self.class != ListMeta
    panel_template 'scaffold/list'
    panel_panel_template 'panels/menu_m' unless action.parent.*.assets[:model]
    search_template 'scaffold/search'
    panel_title "#{glyphicon('list')} #{LOCS[assets[:model].name.to_sym]}"
    menu(:panel_menu).option :cancel, icon: "remove"
    menu :menu do
        properties break: 2, group_class: "btn-group-xs"
        option :search_toggle, icon: "search", show: "action.meta.search_fields", class: "action.ui_state.search_active && 'active'", button_loc: false

        # divider
        option :refresh, icon: "refresh", button_loc: false
        option :default_order, icon: "signal", button_loc: false
        option :select_toggle, icon: "check", enabled: "action.meta.config.selectable", button_loc: false
        divider
        option :debug_info, icon: "list-alt" do
            option :show_meta, icon: "eye-open"
        end
    end

    menu :item_menu do
        properties break: 1, group_class: "btn-group-xs"
    end

    @meta[:state] = [:query, :ui_state]
end

#search_live(*flds) ⇒ Object



637
638
639
640
# File 'lib/engine2/meta.rb', line 637

def search_live *flds
    flds = @meta[:search_fields] if flds.empty?
    info! *flds, search_live: true
end

#search_template(template) ⇒ Object



628
629
630
# File 'lib/engine2/meta.rb', line 628

def search_template template
    panel[:search_template] = template
end

#searchable(*flds) ⇒ Object



642
643
644
645
# File 'lib/engine2/meta.rb', line 642

def searchable *flds
    @meta.delete(:tabs)
    @meta[:search_fields] = *flds
end

#searchable_tabs(tabs) ⇒ Object



647
648
649
650
# File 'lib/engine2/meta.rb', line 647

def searchable_tabs tabs
    searchable *tabs.map{|name, fields|fields}.flatten
    field_tabs tabs
end

#sortable(*flds) ⇒ Object



632
633
634
635
# File 'lib/engine2/meta.rb', line 632

def sortable *flds
    flds = @meta[:fields] if flds.empty?
    info! *flds, sort: true
end

#templateObject



652
653
654
# File 'lib/engine2/meta.rb', line 652

def template
    SearchTemplates
end