From 182b7b99f488fc6872224d9107247888b33d278d Mon Sep 17 00:00:00 2001 From: dsc Date: Tue, 24 Apr 2012 12:57:22 -0700 Subject: [PATCH] Adds data-binding class. See previous commit -- I'm too lazy to fix the index. --- lib/base/data-binding.co | 64 ++++++++++++++++++++++++++++++++++++++++++++++ www/css/data.styl | 22 +++++++++++----- www/modules.yaml | 4 +++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 lib/base/data-binding.co diff --git a/lib/base/data-binding.co b/lib/base/data-binding.co new file mode 100644 index 0000000..a70103b --- /dev/null +++ b/lib/base/data-binding.co @@ -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 + + + + + + diff --git a/www/css/data.styl b/www/css/data.styl index 42f2b26..cffa1a8 100644 --- a/www/css/data.styl +++ b/www/css/data.styl @@ -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 diff --git a/www/modules.yaml b/www/modules.yaml index 84a8cbb..4e3fb97 100644 --- a/www/modules.yaml +++ b/www/modules.yaml @@ -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 -- 1.7.0.4