X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fmanifest%2Fmodel.js.coffee;h=35974b2d53d9dc4981b69c373018b0229b985438;hp=d855c80beb5ae1e5a9e777a6bdd2adb4db7cb577;hb=afa4bb5b1dcd29e3210562bcc12acf8d87f607ee;hpb=ac99a9d7dc6bcff459b17b1aa8d09765fc701fbb diff --git a/app/assets/javascripts/manifest/model.js.coffee b/app/assets/javascripts/manifest/model.js.coffee index d855c80b..35974b2d 100644 --- a/app/assets/javascripts/manifest/model.js.coffee +++ b/app/assets/javascripts/manifest/model.js.coffee @@ -1,8 +1,84 @@ -class Manifest.Model - constructor: (item_name) -> - @item_name = item_name +class Manifest.Model extends ManifestBase.Base + _attributes = null + _associations = null + _list = null + + attributes: () -> + _attributes + + associations: () -> + _associations + + list: () -> + _list + + set_default: () -> + super + @json['attributes'] ||= {} + @json['associations'] ||= {} + @json['list'] ||= {} + @json['attributes']['id'] = { + 'type': 'number', + 'primary_key': 1, + 'rules': { + 'number': true + } + } + @json['attributes']['created_at'] = { + 'type': 'datetime', + } + @json['attributes']['updated_at'] = { + 'type': 'datetime', + } + + init: () -> + super + _attributes = ManifestBase.load_name_values this, @json, 'attributes', Manifest.ModelModule.Attribute + _associations = ManifestBase.load_value this, @json, 'associations', Manifest.ModelModule.Association + _list = ManifestBase.load_value this, @json, 'list', Manifest.ModelModule.List model_name: () -> - header: () -> - paginate: () -> - + _name + + classify: () -> + Manifest.item_name_to_model _name + + table_name: () -> + @classify.table_name + + valid_encode_columns: () -> + r = [] + _.each @attributes, (attribute, attribute_name) -> + next if not attribute.type == 'text' + r.push attribute_name + r + + owner_type: () -> + return 'author' if @attributes['author_id'] + return 'artist' if @attributes['artist_id'] + false + + content_model: () -> + return true if @owner_type + false + + child_model_manifests: () -> + r = [] + _.each Manifest.items, (peta_manifest, peta_name) -> + next if not peta_manifest.is_element + next if not peta_manifest.parent_model_name == @name + r.push Manifest.models[peta_name] + r + + child_models: () -> + _.map @child_model_manifests, (child_model_manifest) -> + child_model_manifest.classify + + child_element_names: () -> + _.map @child_models, (child_model) -> + _associations.child_element_name(child_model) + + child_element_name: (item_name) -> + _associations.child_element_name(child_model_manifest) + +class Manifest.ModelModule