Module: Engine2::ActionModelSupport

Instance Method Summary collapse

Instance Method Details

#hide_pkObject



317
318
319
# File 'lib/engine2/action.rb', line 317

def hide_pk
    hide_fields *assets[:model].primary_keys
end

#node_definedObject

while prnt && prnt.*.assets == model

    prnt = prnt.parent
end
m = prnt.*.assets[:model]
m ? m.name : nil

end



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/engine2/action.rb', line 336

def node_defined
    super
    # p_model_name = parent_model_name
    model = @assets[:model]

    at = action_type
    case at
    when :list, :star_to_many_list, :star_to_many_link_list, :star_to_many_field, :star_to_many_field_link_list # :many_to_one_list
        model.many_to_one_associations.each do |assoc_name, assoc|
            unless assoc[:propagate] == false # || p_model_name == assoc[:class_name]
                dc = model.type_info[assoc[:keys].first][:decode]
                node.run_scheme :decode, model, assoc_name, dc[:search]
            end
        end
    end

    case at
    when :modify, :create
        model.many_to_one_associations.each do |assoc_name, assoc|
            unless assoc[:propagate] == false # || p_model_name == assoc[:class_name]
                dc = model.type_info[assoc[:keys].first][:decode]
                node.run_scheme :decode, model, assoc_name, dc[:form]
            end
        end
    end

    case at
    when :list #, :star_to_many_list, :many_to_one_list # list dropdowns
        divider = false
        model.one_to_many_associations.merge(model.many_to_many_associations).each do |assoc_name, assoc|
            unless assoc[:propagate] == false
                menu(:item_menu).divider unless divider
                divider ||= true
                menu(:item_menu).option :"#{assoc_name}!", icon: "list" # , click: "action.show_assoc($index, \"#{assoc_name}!\")"
                node.run_scheme :star_to_many, :"#{assoc_name}!", assoc
            end
        end
    end

    case at
    when :modify, :create
        model.type_info.each do |field, info|
            case info[:type]
            when :blob_store
                node.run_scheme :blob_store, model, field
            when :foreign_blob_store
                node.run_scheme :foreign_blob_store, model, field
            when :file_store
                node.run_scheme :file_store, model, field
            when :star_to_many_field
                assoc = model.association_reflections[info[:assoc_name]] # info[:name] ?
                raise E2Error.new("Association '#{info[:assoc_name]}' not found for model '#{model}'") unless assoc
                node.run_scheme :star_to_many_field, assoc, field
            end
        end
    end
end

#pre_runObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/engine2/action.rb', line 292

def pre_run
    if !(mdl = @assets[:model])
        act = node
        begin
            act = act.parent
            raise E2Error.new("Model not found in tree for node: #{node.name}") unless act
            mdl = act.*.assets[:model]
        end until mdl

        if asc = @assets[:assoc]
            @assets[:model] = asc.associated_class
            # raise E2Error.new("Association '#{asc}' for model '#{asc[:class_name]}' not found") unless @assets[:model]
        else
            @assets[:model] = mdl
            asc = act.*.assets[:assoc]
            @assets[:assoc] = asc if asc
        end
    end

    # @meta[:model!] = assets[:model]
    # @meta[:assoc!] = assets[:assoc] ? assets[:assoc][:name] : nil
    # @meta[:action_class!] = self.class
    super
end

#show_pkObject



321
322
323
# File 'lib/engine2/action.rb', line 321

def show_pk
    show_fields *assets[:model].primary_keys
end

#unsupported_association(assoc) ⇒ Object

Raises:



394
395
396
# File 'lib/engine2/action.rb', line 394

def unsupported_association assoc
    raise E2Error.new("Unsupported association: #{assoc}")
end