--- /dev/null
+_ = require 'kraken/underscore'
+op = require 'kraken/util/op'
+
+
+BaseView = exports.BaseView = Backbone.View.extend do # {{{
+ # List of methods to bind on initialize; set on subclass
+ __bind__ : []
+
+
+ initialize: ->
+ _.bindAll this, ...@__bind__ if @__bind__.length
+ @__super__ = @constructor.__super__
+
+ @model.view = this
+ @$el.data { @model, view:this }
+ @model.on 'change', @render, this
+ @model.on 'destroy', @remove, this
+
+ toTemplateLocals: ->
+ json = {value:v} = @model.toJSON()
+ if _.isArray(v) or _.isObject(v)
+ json.value = JSON.stringify v
+ { $, _, op, @model, view:this } import json
+
+ $template: (locals={}) ->
+ $ @template @toTemplateLocals() import locals
+
+ build: ->
+ return this unless @template
+
+ outer = @$template()
+ @$el.html outer.html()
+ .attr do
+ id : outer.attr 'id'
+ class : outer.attr('class')
+
+
+ this
+
+ render: ->
+ @build()
+ @trigger 'render', this
+ this
+
+ hide : -> @$el.hide(); this
+ show : -> @$el.show(); this
+ remove : -> @$el.remove(); this
+ clear : -> @model.destroy(); @remove()
+
+
+ # remove : ->
+ # if (p = @$el.parent()).length
+ # @$parent or= p
+ # # @parent_index = p.children().indexOf @$el
+ # @$el.remove()
+ # this
+ #
+ # reparent : (parent=@$parent) ->
+ # parent = $ parent
+ # @$el.appendTo parent if parent?.length
+ # this
+
+ toString : -> "#{@ctorName}(model=#{@model})"
+
+
+# }}}
+
+
_ = require 'kraken/underscore'
-{ Field, FieldList, BaseView, FieldView, Scaffold
+{BaseView} = require 'kraken/baseview'
+{ Field, FieldList, FieldView, Scaffold
} = require 'kraken/scaffold'
o[k] = '' if v!?
o
+ toKVPairs: ->
+ key = @get 'name'
+ value = @get 'value'
+ if value?
+ "#{encodeURIComponent key}=#{encodeURIComponent value}"
+ else
+ ''
+
+
# }}}
GraphOptionList = exports.GraphOptionList = FieldList.extend do # {{{
ctorName : 'GraphOptionList'
model : GraphOption
- categories : {}
+ /**
+ * Transforms this list into form-encoded KV-pairs, excluding null values and
+ * @returns {String}
+ */
+ toKVPairs: (keepDefaults=false) ->
+ @models
+ .filter -> it.get('name') and it.getValue()? and (keepDefaults or not it.isDefault())
+ .map -> "#{encodeURIComponent it.get 'name'}=#{encodeURIComponent it.serializeValue()}"
+ .join '&'
- initialize : ->
- FieldList::initialize ...
- @categories = {}
-
+# }}}
+
+
+/**
+ * Represents a Graph, including its charting options, dataset, annotations, and all
+ * other settings for both its content and presentation.
+ */
+GraphModel = exports.GraphModel = Backbone.Model.extend do # {{{
+ ctorName : 'GraphModel'
+ urlRoot : '/graphs'
+ initialize : ->
+ name = @get 'name'
+ if name and not (@id or @has 'id')
+ @id = @attributes.id = _.underscored name
+
+ defaults : ->
+ {
+ name : 'Kraken Graph'
+ dataset : '/data/page_views_by_language.csv'
+ options : {}
+ }
+
+ toString: -> "#{@ctorName}(id=#{@id}, name=#{@get 'name'}, dataset=#{@get 'dataset'})"
# }}}
_ = require 'kraken/underscore'
-{ Field, FieldList, BaseView, FieldView, Scaffold
+{BaseView} = require 'kraken/baseview'
+{ Field, FieldList, FieldView, Scaffold
} = require 'kraken/scaffold'
-{ GraphOption, GraphOptionList, TagSet,
+{ GraphModel, GraphOption, GraphOptionList, TagSet,
} = require 'kraken/graph/model'
+DEBOUNCE_RENDER = exports.DEBOUNCE_RENDER = 20ms
/**
isCollapsed : true
events :
- 'blur .value' : 'update'
- 'submit .value' : 'update'
- 'click .close' : 'toggleCollapsed'
- 'click h3' : 'toggleCollapsed'
- 'click .collapsed' : 'onClick'
+ 'blur .value' : 'update'
+ 'click input[type="checkbox"].value' : 'update'
+ 'submit .value' : 'update'
+ 'click .close' : 'toggleCollapsed'
+ 'click h3' : 'toggleCollapsed'
+ 'click .collapsed' : 'onClick'
update: ->
initialize : ->
Scaffold::initialize ...
- @render = _.debounce @render.bind(this), 50
+ @render = _.debounce @render.bind(this), DEBOUNCE_RENDER
render: ->
# console.log "#this.render() -> .isotope()"
view.on 'change:collapse render', @render
view
+ toKVPairs: ->
+ @collection.toKVPairs()
+
# }}}
-/**
- * Represents a Graph, including its charting options, dataset, annotations, and all
- * other settings for both its content and presentation.
- */
-GraphModel = exports.GraphModel = Backbone.Model.extend do # {{{
- ctorName : 'GraphModel'
- urlRoot : '/graphs'
-
- initialize : ->
- name = @get 'name'
- if name and not (@id or @has 'id')
- @id = @attributes.id = _.underscored name
-
- defaults : ->
- {
- name : 'Kraken Graph'
- dataset : '/data/page_views_by_language.csv'
- options : {}
- }
-
- toString: -> "#{@ctorName}(id=#{@id}, name=#{@get 'name'}, dataset=#{@get 'dataset'})"
-# }}}
-
-
GraphView = exports.GraphView = BaseView.extend do # {{{
ctorName : 'GraphView'
tagName : 'section'
initialize : (o={}) ->
+ @render = _.debounce @render.bind(this), DEBOUNCE_RENDER
@model or= new GraphModel
BaseView::initialize ...
# console.log "#this.initialize!"
@$el.find 'fieldset' .append @scaffold.el
@scaffold.collection.reset that if o.graph_spec
- setTimeout do
- ~> @render()
- 50
+ _.delay @render, DEBOUNCE_RENDER
chartOptions: (values) ->
@render()
false
+
+ toKVPairs: (keepDefaults=false) ->
+ @scaffold.toKVPairs()
+
toString: -> "#{@ctorName}(#{@model})"
# }}}
-{_, op} = require 'kraken/util'
-{ Field, FieldList, BaseView, FieldView, Scaffold
-} = require 'kraken/scaffold'
+{_, op} = require 'kraken/util'
+{BaseView} = require 'kraken/baseview'
+{ Field, FieldList, FieldView, Scaffold
+} = require 'kraken/scaffold'
{ GraphView, GraphModel, TagSet,
GraphOption, GraphOptionList, GraphOptionView,
GraphOptionsScaffold,
-} = require 'kraken/graph'
+} = require 'kraken/graph'
root = do -> this
_ = require 'kraken/underscore'
op = require 'kraken/util/op'
-Hash = require 'hashish'
}
+ /* * * Parsers * * */
getParser: (type) ->
# XXX: handle 'or' by returning an array of parsers?
null
+ /* * * Serializers * * */
+ serializeValue: ->
+ v = @getValue()
+ if v!?
+ v = ''
+ else if _.isArray(v) or _.isObject(v)
+ v = JSON.stringify v
+ String v
+
+
+ /* * * Value Accessors * * */
getValue: (def) ->
@getParser() @get 'value', def
{id:@id} import do
_.clone(@attributes) import { value:@getValue(), def:@get('default') }
+ toKVPairs: ->
+ key = @get 'name'
+ value = @get 'value'
+ if value?
+ "#{encodeURIComponent key}=#{encodeURIComponent value}"
+ else
+ ''
+
toString: -> "(#{@id}: #{@get 'value'})"
# }}}
@models.filter -> not it.isDefault()
-> [ it.get('name'), it.getValue() ]
+ toJSON: ->
+ @values()
+
+ toKVPairs: ->
+ @models
+ .filter -> it.get('name') and it.getValue()?
+ .map -> "#{encodeURIComponent it.id}=#{encodeURIComponent it.get 'value'}"
+ .join '&'
+
toString: -> "#{@ctorName}(length=#{@length})"
# }}}
-_ = require 'kraken/underscore'
-op = require 'kraken/util/op'
+_ = require 'kraken/underscore'
+op = require 'kraken/util/op'
+{BaseView} = require 'kraken/baseview'
{ Field, FieldList,
-} = require 'kraken/scaffold/model'
-
-
-### Views
-
-BaseView = exports.BaseView = Backbone.View.extend do # {{{
- # List of methods to bind on initialize; set on subclass
- __bind__ : []
-
-
- initialize: ->
- _.bindAll this, ...@__bind__ if @__bind__.length
- @__super__ = @constructor.__super__
-
- @model.view = this
- @$el.data { @model, view:this }
- @model.on 'change', @render, this
- @model.on 'destroy', @remove, this
-
- toTemplateLocals: ->
- json = {value:v} = @model.toJSON()
- if _.isArray(v) or _.isObject(v)
- json.value = JSON.stringify v
- { $, _, op, @model, view:this } import json
-
- $template: (locals={}) ->
- $ @template @toTemplateLocals() import locals
-
- build: ->
- return this unless @template
-
- outer = @$template()
- @$el.html outer.html()
- .attr do
- id : outer.attr 'id'
- class : outer.attr('class')
-
-
- this
-
- render: ->
- @build()
- @trigger 'render', this
- this
-
- hide : -> @$el.hide(); this
- show : -> @$el.show(); this
- remove : -> @$el.remove(); this
- clear : -> @model.destroy(); @remove()
-
-
- # remove : ->
- # if (p = @$el.parent()).length
- # @$parent or= p
- # # @parent_index = p.children().indexOf @$el
- # @$el.remove()
- # this
- #
- # reparent : (parent=@$parent) ->
- # parent = $ parent
- # @$el.appendTo parent if parent?.length
- # this
-
- toString : -> "#{@ctorName}(model=#{@model})"
-
-
-# }}}
-
+} = require 'kraken/scaffold/model'
FieldView = exports.FieldView = BaseView.extend do # {{{
#content
z-index 10
+ padding 1em
min-height 100%
background-color $page_bgcolor
box-shadow 0px 0px 6px 2px rgba(0,0,0,0.4)
& > .inner
position relative
- width 80%
- margin 0 auto
+ // width 80%
+ // min-width 960px
+ // margin 0 auto
// .spacer offsets #content to pad for header
.spacer
- op
- backbone
- index
+ - baseview
- template:
- graph.jade
- graph-option.jade