OSDN Git Service

clean
[pettanr/pettanr.git] / app / assets / javascripts / manifest / manifest.js.coffee
index c442bc6..1d8e0c7 100644 (file)
@@ -6,24 +6,50 @@ class Manifest
   \r
   init: () ->\r
     # managers can't initialize before load  application.rb\r
+    @inflectors = @global_json.inflectors\r
+    @item_names = {}\r
+    @table_names = {}\r
+    _.each @inflectors, (table_name, item_name) =>\r
+      @item_names[item_name] = table_name  # monkey copy\r
+      @table_names[table_name] = item_name\r
     @items = ManifestBase.load_type_name_args(this, @global_json, 'items', Manifest.ItemFactory)\r
     @controllers = Manifest.Controller.load(this, @global_json, 'controllers', Manifest.Controller)\r
     @models = Manifest.Model.load(this, @global_json, 'models', Manifest.Model)\r
-    @inflectors = {}\r
-    _this = this\r
-    _.each @models, (model_manifest, item_name) ->\r
-      if model_manifest.table_name\r
-        _this.inflectors[model_manifest.table_name] = item_name\r
+    @replace_action_alias()\r
     true\r
   \r
-  @item_name_to_model: (item_name) ->\r
-    Pettanr[Pettanr.camelize(item_name)]\r
+  replace_action_alias: () ->\r
+    replaces = {}\r
+    _.each @controllers, (controller_manifest, controller_name) ->\r
+      _.each controller_manifest.actions, (action_manifest, action_name) ->\r
+        return if not action_manifest.alias\r
+        alias_action = action_manifest.alias_action()\r
+        return if alias_action.type != action_manifest.type\r
+        args = {}\r
+        _.each action_manifest.a_arg_names(), (name) ->\r
+          args[name] = action_manifest[name] || alias_action[name]\r
+        _.each action_manifest.b_arg_names(), (name) ->\r
+          args[name] = alias_action[name] || action_manifest[name]\r
+        args.original = action_manifest\r
+        json = {type: alias_action.type, args: args}\r
+        new_action_manifest = Manifest.ControllerModule.ActionFactory.factory(\r
+          controller_manifest, action_manifest.name, json, \r
+          action_manifest.module_name, Manifest.ControllerModule.ActionFactory\r
+        )\r
+        replaces[controller_name] ||= {}\r
+        replaces[controller_name][action_name] = new_action_manifest\r
+    _.each replaces, (controller, controller_name) ->\r
+      _.each controller, (action_manifest, action_name) ->\r
+        Manifest.manifest().controllers[controller_name].actions[action_name] = action_manifest\r
+  \r
+  pluralize: (item_name) ->\r
+    @item_names[item_name]\r
   \r
-  @pluralize: (name) ->\r
-    name.pluralize\r
+  singularize: (table_name) ->\r
+    @table_names[table_name]\r
   \r
-  @singularize: (name) ->\r
-    @inflectors[name]\r
+  @item_name_to_model: (item_name) ->\r
+    Pettanr[Pettanr.camelize(item_name)]\r
   \r
   @manifest: () ->\r
     @mani\r