OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / peta / item.js.coffee
index a166731..22fe57a 100644 (file)
@@ -1,4 +1,10 @@
 class Peta.Item extends Backbone.Model\r
+  \r
+  initialize: (attr = {}, options = {}) ->\r
+    super(attr, options)\r
+    @expire_time = options.expire_time\r
+    @boosters = {}\r
+  \r
   @child_models: () ->\r
     @my_manifest().child_models()\r
   \r
@@ -11,7 +17,7 @@ class Peta.Item extends Backbone.Model
     this\r
   \r
   my_class: () ->\r
-    Pettanr[@constructor.name]\r
+    @constructor\r
   \r
   @my_peta: () ->\r
     return null if not Manifest.manifest().items\r
@@ -25,7 +31,8 @@ class Peta.Item extends Backbone.Model
     '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
@@ -54,6 +61,9 @@ class Peta.Item extends Backbone.Model
   @parent_model: () ->\r
     null\r
   \r
+  @has_picture: () ->\r
+    false\r
+  \r
   @path_name: (with_engine = false) ->\r
     @table_name()\r
   \r
@@ -78,10 +88,10 @@ class Peta.Item extends Backbone.Model
   #InstanceMethods\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
@@ -114,18 +124,15 @@ class Peta.Item extends Backbone.Model
       @item_name()\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
@@ -137,12 +144,64 @@ class Peta.Item extends Backbone.Model
       return false if not operators.is_resource_reader()\r
     true\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
+  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