1 class Peta.ElementNestableContent extends Peta.Content
\r
2 element_items: (element_model) ->
\r
3 n = @my_class().my_manifest().associations.child_element_name(element_model)
\r
6 elements_items: () ->
\r
7 r = _.map @my_class().child_models(), (element_model) =>
\r
8 @element_items(element_model)
\r
9 _.compact(_.flatten(r))
\r
13 _.each @elements_items(), (item) =>
\r
14 item.boosts(level) if item
\r
16 replaced_attributes: () ->
\r
18 _.each @attributes, (attribute, name) =>
\r
19 replaced = if _.isArray(attribute)
\r
20 # has many association
\r
21 model = @my_class().my_manifest().associations.has_many[name].model()
\r
22 _.map attribute, (attr) =>
\r
23 child = @replace_element(model, attr)
\r
24 child.attributes = child.replaced_attributes()
\r
26 else if _.isObject(attribute)
\r
27 # has one association
\r
28 model = @my_class().my_manifest().associations.has_one[name].model()
\r
29 child = @replace_element(model, attribute)
\r
30 child.attributes = child.replaced_attributes()
\r
34 attributes[name] = replaced
\r
37 replace_element: (model, attr) ->
\r
38 empty_child = new model(attr)
\r
39 cached_child = Pettanr.cache.restore(empty_child)
\r
40 Pettanr.cache.store(empty_child) if !cached_child
\r
41 cached_child || empty_child
\r