class Peta.Item extends Backbone.Model\r
+ \r
+ initialize: (attr = {}, options = {}) ->\r
+ @url = @default_url()\r
+ super(attr, options)\r
+ @expire_time = options.expire_time\r
+ @boosters = {}\r
+ @templates = {}\r
+ \r
@child_models: () ->\r
@my_manifest().child_models()\r
\r
\r
# ClassMethods\r
\r
+ @default_url: () ->\r
+ '/' + @table_name() + '/'\r
+ \r
@my_class: () ->\r
this\r
\r
my_class: () ->\r
- Pettanr[@constructor.name]\r
+ @constructor\r
\r
@my_peta: () ->\r
return null if not Manifest.manifest().items\r
'Name'\r
\r
@plural: () ->\r
- 'Names'\r
+ table_name = Manifest.manifest().pluralize @item_name()\r
+ Pettanr.camelize(table_name)\r
\r
@class_name: () ->\r
@singular()\r
@parent_model: () ->\r
null\r
\r
+ @has_picture: () ->\r
+ false\r
+ \r
@path_name: (with_engine = false) ->\r
@table_name()\r
\r
- @pickup_item_name: () ->\r
- @item_name()\r
- \r
- @pickup_column_name: () ->\r
- 'id'\r
- \r
@find_boost_name: (column_name) ->\r
@my_peta().find_boost_name column_name\r
\r
\r
#InstanceMethods\r
\r
+ default_url: () ->\r
+ r = @my_class().default_url()\r
+ r = r.concat( @id ) if @id\r
+ r\r
+ \r
singular: () ->\r
- Pettanr[@constructor.name].singular()\r
+ @my_class().singular()\r
\r
plural: () ->\r
- Pettanr[@constructor.name].plural()\r
+ @my_class().plural()\r
\r
item_name: () ->\r
@my_class().item_name()\r
path_name: (with_engine = false) ->\r
@my_class().path_name(with_engine)\r
\r
- pickup_item_name: () ->\r
- @my_class().pickup_item_name()\r
- \r
- pickup_column_name: () ->\r
- @my_class().pickup_column_name()\r
- \r
- pickup_id: () ->\r
- @get(pickup_column_name())\r
- \r
form_template: (with_engine = false) ->\r
@path_name(with_engine) + '/form'\r
\r
else\r
@item_name()\r
\r
+ has_many: (has_many_name) ->\r
+ has_many_manifest = @my_class().my_manifest().associations.has_many[has_many_name]\r
+ action_name = has_many_manifest.list_action_name\r
+ Locmare.ListGroup.list(\r
+ has_many_name, action_name, {id: @get('id')}\r
+ )\r
+ \r
+ has_one: (has_one_name) ->\r
+ has_one_manifest = @my_class().my_manifest().associations.has_one[has_one_name]\r
+ controller_name = has_one_manifest.model().table_name()\r
+ action_name = has_one_manifest.list_action_name\r
+ Locmare.ListGroup.list(\r
+ controller_name, action_name, {id: @get('id')}\r
+ )\r
+ \r
boosts: (level) ->\r
- _this = this\r
c = @my_class().my_peta().boost\r
- _.each c, (boost_manifest, boost_name) ->\r
+ _.each c, (boost_manifest, boost_name) =>\r
return if level == 'read' and boost_manifest.level == 'post'\r
- _this.boost boost_manifest\r
+ @boost boost_manifest\r
\r
boost: (boost_manifest) ->\r
- @boosters ||= {}\r
- @boosters[boost_manifest.name] ||= new Locmare.Booster(boost_manifest, this)\r
- \r
- boosters: () ->\r
- @boosters ||= {}\r
+ @boosters[boost_manifest.name] = new Locmare.Booster(boost_manifest, this)\r
+ # fetched item is not cleared . force write booster\r
+ #@boosters[boost_manifest.name] ||= new Locmare.Booster(boost_manifest, this)\r
\r
is_extend_column: (column_name) ->\r
@is_extend_column column_name\r
\r
- is_visible: (operators) ->\r
+ is_visible: (operators = Pettanr.cache.operators) ->\r
if Manifest.manifest().magic_numbers['run_mode'] == 0\r
return false if not operators.is_guest()\r
else\r
return false if not operators.is_resource_reader()\r
true\r
\r
+ retriever: () ->\r
+ new Pettanr.Cache.Retriever(@my_class(), @get('id'))\r
+ \r
+ @pick_item_name: () ->\r
+ null\r
+ \r
+ @pick_model: () ->\r
+ Manifest.item_name_to_model(@pick_item_name())\r
+ \r
+ @traceable_item_names: () ->\r
+ []\r
+ \r
+ @is_traceable: (item_name) ->\r
+ _.contains(@traceable_item_names(), item_name)\r
+ \r
+ @is_picker_inspire: (item_name) ->\r
+ item_name == @item_name()\r
+ \r
+ @is_picker_trace: (item_name) ->\r
+ @is_traceable(item_name)\r
+ \r
+ @is_picker_pick: (item_name) ->\r
+ item_name == @pick_item_name()\r
+ \r
+ @pick_type: (item_name) ->\r
+ if @is_picker_inspire(item_name)\r
+ 'inspire'\r
+ else if @is_picker_trace(item_name)\r
+ 'trace'\r
+ else if @is_picker_pick(item_name)\r
+ 'pick'\r
+ else\r
+ 'none'\r
+ \r
+ icon_view: (half) ->\r
+ new Pettanr.Views[@my_class().singular()].Icon({item: this, half: half})\r
+ \r
+ @index_url: () ->\r
+ Pettanr.url(@table_name(), 'index', {id: null})\r
+ \r
+ index_url: () ->\r
+ @my_class().index_url()\r
+ \r
+ list_url: (action_name = 'index') ->\r
+ Pettanr.url(@table_name(), action_name, {id: @get('id')})\r
+ \r
+ show_url: () ->\r
+ Pettanr.url(@table_name(), 'show', {id: @get('id')})\r
+ \r
+ prof_url: () ->\r
+ Pettanr.url(@table_name(), 'show', {id: @get('id'), format: 'prof'})\r
+ \r
+ new_url: () ->\r
+ Pettanr.url(@table_name(), 'new', {})\r
+ \r
+ create_url: () ->\r
+ Pettanr.url(@table_name(), 'create', {})\r
+ \r
+ edit_url: () ->\r
+ Pettanr.url(@table_name(), 'edit', {id: @get('id')})\r
+ \r
+ update_url: () ->\r
+ Pettanr.url(@table_name(), 'update', {id: @get('id')})\r
+ \r
+ destroy_url: () ->\r
+ Pettanr.url(@table_name(), 'destroy', {id: @get('id')})\r
+ \r
+ hold: () ->\r
+ Pettanr.cache.hold(this)\r
+ \r
+ fix: () ->\r
+ Pettanr.cache.fix(this)\r
+ \r
+ release: () ->\r
+ Pettanr.cache.release(this)\r
+ \r
+ save: (model_attr) ->\r
+ super(model_attr || @attributes, {\r
+ success: (model, response, options) =>\r
+ @trigger('save:success', model, response)\r
+ error: (model, response, options) =>\r
+ @trigger('save:fail', model, response)\r
+ })\r
+ \r
+ destroy: () ->\r
+ super({\r
+ success: (model, response, options) =>\r
+ @trigger('destroy:success', model, response)\r
+ error: (model, response, options) =>\r
+ @trigger('destroy:fail', model, response)\r
+ })\r
+ \r
is_editize: () ->\r
@editor\r
\r
dom_id: () ->\r
(@get('id') || '').toString()\r
\r
+ cache_key: () ->\r
+ @table_name() + '-' + @dom_id()\r
+ \r
dom_pool_type: () ->\r
@new_record ? 'stored' : 'new'\r
\r