OSDN Git Service

fix layout default
[pettanr/pettanr.git] / app / assets / javascripts / pettanr.js.coffee
index 4a7a0a3..eab863b 100644 (file)
@@ -94,24 +94,18 @@ class Pettanr
       I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])\r
     \r
     @distance_of_time_in_words_to_now: (datetime) ->\r
-      datetime\r
+      if Pettanr.is_blank(datetime)\r
+        ''\r
+      else\r
+        $.timeago(datetime)\r
   \r
   @cache = {}\r
   @credits = {}\r
   \r
-  class Pettanr.FilerCollection extends Backbone.Collection\r
-    \r
-    initialize: (models, options) ->\r
-      @model = options['model']\r
-      @action = options['action']\r
-      @params = options['params']\r
-      \r
-      @url = '/' + @action.url(@params)\r
-  \r
   class Pettanr.AppController\r
-    constructor: () ->\r
+    constructor: (@operators) ->\r
       @params = {}\r
-      @operators = window.operators\r
+      _.extend(this, Backbone.Events)\r
       \r
     set_model: () ->\r
       @my_controller = Manifest.manifest().controllers[@params['controller']]\r
@@ -133,48 +127,43 @@ class Pettanr
     \r
     filer_list: () ->\r
       @set_list()\r
-      _this = this\r
-      @list.open((page_status) ->\r
-        pager = new Locmare.FilerModule.DefaultPager({page_status: page_status})\r
-        f = new Locmare.Filer({\r
-          el: "#pettanr",\r
-          item_name: _this.my_list_model_class.item_name(), \r
-          items: _this.list.items(), \r
+      @list.open(() =>\r
+        pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, @params)\r
+        filer = new Locmare.Filer({\r
+          item_name: @list.item_name, \r
+          items: @list.items(), \r
           pager: pager, \r
-          operators: _this.operators\r
+          operators: @operators\r
         })\r
+        @trigger('ready', filer)\r
       )\r
       false\r
     \r
     set_play: () ->\r
       @set_list()\r
-      @binder_controller = Manifest.manifest().controllers[@params['controller']]\r
-      @binder_action = @my_controller.actions[params['action']]\r
+      @binder_action = @my_action.original\r
+      @binder_controller = @binder_action.controller()\r
       @binder_model = Manifest.manifest().models[@binder_action.item_name]\r
       @binder_model_class = @binder_model.classify()\r
       @item = new @binder_model_class({id: @params['id']})\r
     \r
     play_list: () ->\r
-      _this = this\r
-      @options = @params\r
-      @options['my_play'] = @item.is_own?(@operators)\r
-      @item.fetch({cache: true}).done ->\r
-        _this.list.open((page_status) ->\r
-          console.log _this.list.models\r
-        )\r
-        false\r
+      @list.open(() =>\r
+        console.log @list.items()\r
+      )\r
+      false\r
     \r
-    show_prof: () ->\r
-      _this = this\r
-      @item.fetch({cache: true}).done ->\r
-        _this.item.boosts 'post'\r
+    show_prof: (el) ->\r
+      @item.fetch({cache: true}).done =>\r
+        @item.boosts 'post'\r
         profiler = new Locmare.Profiler({\r
-          item_name: _this.item.item_name(), \r
-          item: _this.item, \r
-          operators: _this.operators\r
+          item_name: @item.item_name(), \r
+          item: @item, \r
+          operators: @operators\r
         })\r
-        $("#pettanr").html(profiler.render().el)\r
-        _this.redraw_title(_this.params)\r
+        el ||= $("#pettanr")\r
+        el.html(profiler.render().el)\r
+        @trigger('retitle', @params)\r
     \r
     set_new: () ->\r
       @set_model()\r
@@ -186,13 +175,12 @@ class Pettanr
     set_edit: () ->\r
       @set_model()\r
       @item = new @my_model_class({id: @params['id']})\r
-      _this = this\r
-      @item.fetch({cache: true}).done ->\r
-        _this.item.boosts 'post'\r
-        _this.render_form()\r
+      @item.fetch({cache: true}).done =>\r
+        @item.boosts 'post'\r
+        @render_form()\r
     \r
     render_form: () ->\r
-      @form = new Locmare.Form({\r
+      @form = Locmare.Form.factory({\r
         form_name: @item.item_name(), \r
         item: @item, \r
         mounted: true, \r
@@ -209,32 +197,32 @@ class Pettanr
     form_edit: () ->\r
       @set_edit()\r
     \r
-    redraw_title: (params, str = null) ->\r
-      t = str || I18n.t(params['controller'] + '.' + params['action'] + '.title')\r
-      site_caption = Manifest.manifest().magic_numbers.profile.users.caption\r
-      $(document).attr('title', t + ' - ' + site_caption)\r
+  class Pettanr.Dialog extends Backbone.View\r
     \r
-  class Pettanr.FilerRender\r
-    constructor: (item_name, list_result, pager_type, operators) ->\r
-      @item_name = item_name\r
-      @list_result = list_result\r
-      @pager_type = pager_type\r
-      @operators = operators\r
-      _this = this\r
-      @list_result.fetch({cache: true}).done () ->\r
-        _this.render()\r
+    initialize: (options) ->\r
+      super(options)\r
     \r
     render: () ->\r
-      items = @list_result.models\r
-      f = new Locmare.Filer({\r
-        item_name: @item_name, \r
-        items: items, \r
-        list_result: @list_result, \r
-        pager_type: @pager_type, \r
-        operators: @operators\r
-      })\r
-      $("#pettanr").html(f.render().el)\r
-\r
+      this.$el.html('')\r
+      this\r
+    \r
+    refresh: (body) ->\r
+      @listenTo(body, 'navigate', @navigate)\r
+      this.$el.html(body.render().el)\r
+    \r
+    fire: (params) ->\r
+      c = Pettanr[Pettanr.camelize(params['controller']) + 'Controller']\r
+      controller = new c\r
+      controller.params = params\r
+      @listenTo(controller, 'ready', @refresh)\r
+      # ignore retitle message\r
+      # @listenTo(controller, 'retitle', @retitle)\r
+      controller[params['action']]()\r
+    \r
+    local_navigate: (url) ->\r
+      window.router.local_navigate(url, true)\r
+    \r
+  \r
   #>> https://gist.github.com/davidjbeveridge/3813724\r
   @xeach: (arr, func, index=0) ->\r
     if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []\r