Module: Engine2::MetaFormSupport

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!, #loc!, #reload_routes!, #render, #show_fields

Methods included from MetaTabSupport

#field_tabs, #lazy_tab, #select_tabs

Methods included from MetaPanelSupport

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

Methods included from MetaMenuSupport

#menu, #menu?

Methods included from MetaAngularSupport

#ng_call, #ng_execute, #ng_info!, #ng_record, #ng_record!

Methods included from MetaOnChangeSupport

#on_change

Instance Method Details

#field_template(template) ⇒ Object



756
757
758
# File 'lib/engine2/meta.rb', line 756

def field_template template
    panel[:field_template] = template
end

#hr_after(field, message = '-') ⇒ Object



820
821
822
# File 'lib/engine2/meta.rb', line 820

def hr_after field, message = '-'
    info! field, hr: message
end

#post_processObject



776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/engine2/meta.rb', line 776

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

        decorate(fields)

        fields.each do |name|
            # type_info = model.type_info.fetch(name)
            type_info = get_type_info(name)

            info[name][:render] ||= begin
                renderer = DefaultFormRenderers[type_info[:type]] # .merge(default: true)
                raise E2Error.new("No form renderer found for field '#{type_info[:name]}' of type '#{type_info[:type]}'") unless renderer
                renderer.(self, type_info)
            end

            proc = FormRendererPostProcessors[type_info[:type]]
            proc.(self, name, type_info) if proc
        end

        assoc = assets[:assoc]
        if assoc && assoc[:type] == :one_to_many
            # fields.select{|f| assoc[:keys].include? f}.each do |key|
            #     # hide_fields(key) if self[:info, key, :hidden] == nil
            #     info! key, disabled: true
            # end
            assoc[:keys].each do |key|
                info! key, disabled: true if fields.include? key
            end
        end
    end

    super
end

#post_runObject



811
812
813
814
# File 'lib/engine2/meta.rb', line 811

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

#pre_runObject



760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/engine2/meta.rb', line 760

def pre_run
    super
    panel_template 'scaffold/form'
    field_template 'scaffold/fields'
    panel_class 'modal-large'

    menu :panel_menu do
        option :approve, icon: "ok", disabled: 'action.action_pending()' # text: true,
        option :cancel, icon: "remove" # text: true,
    end
    # modal_action false
end

#record(handler, record) ⇒ Object



773
774
# File 'lib/engine2/meta.rb', line 773

def record handler, record
end

#templateObject



816
817
818
# File 'lib/engine2/meta.rb', line 816

def template
    Templates
end