Adds data-binding class. See previous commit -- I'm too lazy to fix the index.
authordsc <dsc@wikimedia.org>
Tue, 24 Apr 2012 19:57:22 +0000 (12:57 -0700)
committerdsc <dsc@wikimedia.org>
Tue, 24 Apr 2012 19:57:22 +0000 (12:57 -0700)
lib/base/data-binding.co [new file with mode: 0644]
www/css/data.styl
www/modules.yaml

diff --git a/lib/base/data-binding.co b/lib/base/data-binding.co
new file mode 100644 (file)
index 0000000..a70103b
--- /dev/null
@@ -0,0 +1,64 @@
+Backbone = require 'backbone'
+
+{ _, op,
+} = require 'kraken/util'
+
+
+class exports.DataBinding
+    
+    data    : null
+    context : null
+    el      : null
+    $el     : null
+    bindPoints: null
+    
+    
+    
+    (el, @context=el) ->
+        if el instanceof Backbone.View
+            el = el.$el
+        @$el = $ el
+        @el = @$el.get 0
+        
+        # Find all bind-points under this element, but not under a subview
+        @bindPoints = @$ '[data-bind], [name]' .not @$ '[data-subview] [data-bind], [data-subview] [name]'
+    
+    $: (sel) ->
+        @$el.find sel
+    
+    serialize: ->
+        it
+    
+    update: (@data) ->
+        for key, val in @data
+            @updateBinding key, val
+        this
+    
+    updateBinding: (key, val) ->
+        # if val and _.isPlainObject val
+        #     for k, v in val
+        #         @updateBinding "#key.#k", v
+        #     return this
+        
+        if bp = @findDataBindPoint key
+            if _.isFunction val
+                val.call @context, val, key, bp, @data
+            else if bp.is 'input:checkbox'
+                bp.attr 'checked', !!val
+            else if bp.is 'input, textarea'
+                bp.val @serialize val
+            else
+                bp.text @serialize val
+        else
+            false and console.warn "#this.updateBinding(): Unable to find data bind-point for #key=#val!"
+        this
+    
+    findDataBindPoint: (key) ->
+        bp = @bindPoints.filter "[name='#key'], [data-bind='#key']"
+        return bp.eq(0) if bp.length
+    
+
+
+
+
+
index 42f2b26..cffa1a8 100644 (file)
@@ -15,13 +15,24 @@ section.graph section.data-ui
     h4
         display none
     
+    .data_set_view_pane
+        absolute 0 0
+        width 40%
+        height 100%
+        min-height 500px
+    
+    .metric_edit_view_pane
+        float right
+        width 60%
+        min-height 100%
+    
     .dataset-controls
         padding 1em
     
     /* * * *  DataSet UI  * * * */
     section.dataset-ui
-        absolute 0 0
-        width 40%
+        // absolute 0 0
+        // width 40%
         height 100%
         min-height 500px
         border-right 1px solid #ccc
@@ -92,9 +103,6 @@ section.graph section.data-ui
                     color $boot_red
                     opacity 1
             
-            
-            
-        
         
         .dataset-metrics-empty
             display none
@@ -104,8 +112,8 @@ section.graph section.data-ui
     /* * * *  Edit Metric UI * * * */
     section.metric-edit-ui
         display none
-        float right
-        width 60%
+        // float right
+        // width 60%
         min-height 100%
         
         .inner
index 84a8cbb..4e3fb97 100644 (file)
@@ -52,11 +52,15 @@ dev:
                 - backbone
                 - parser
                 - cascade
+                - index
+            - timeseries:
+                - timeseries
                 - csv
                 - index
             - base:
                 - base-mixin
                 - base-model
+                - data-binding
                 - base-view
                 - model-cache
                 - cascading-model