--- /dev/null
+_ = require 'kraken/underscore'
+op = require 'kraken/util/op'
+
+
+BaseModel = exports.BaseModel = Backbone.Model.extend do # {{{
+ ctorName : 'BaseModel'
+ # List of methods to bind on initialize; set on subclass
+ __bind__ : []
+
+ idAttribute : 'id'
+ valueAttribute : 'value'
+
+
+ initialize: ->
+ _.bindAll this, ...@__bind__ if @__bind__.length
+ @__super__ = @constructor.__super__
+
+
+ toKVPairs: (kv_delimiter='=') ->
+ idAttr = @idAttribute or 'id'
+ key = @[idAttr] or @get idAttr
+ valAttr = @valueAttribute or 'value'
+ value = @get 'value'
+ if key and value?
+ "#{encodeURIComponent key}#kv_delimiter#{encodeURIComponent value}"
+ else
+ ''
+
+ toString: -> "#{@ctorName}(id=#{@id}, value=#{@get 'value'})"
+
+
+# Class Methods
+BaseModel import do
+
+ fromKVPairs: (o) ->
+ o = _.fromKVPairs o if typeof o is 'string'
+ Cls = if typeof this is 'function' then this else this.constructor
+ new Cls o
+
+# }}}
+
+
+/**
+ * @class Base View, used by scaffold and others.
+ */
+BaseView = exports.BaseView = Backbone.View.extend do # {{{
+ ctorName : 'BaseView'
+
+ # 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})"
+
+
+# }}}
+
+
+++ /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'
-{BaseView} = require 'kraken/baseview'
+{ BaseModel, BaseView,
+} = require 'kraken/base'
{ Field, FieldList, FieldView, Scaffold
} = require 'kraken/scaffold'
indices = ( for tag of tags then @get tag )
if is_single then indices[0] else indices
- toString: -> "Tags(length=#{@length}, values=[\"#{@join '", "'}\"])"
+ toString: -> "TagSet(length=#{@length}, values=[\"#{@join '", "'}\"])"
KNOWN_TAGS = exports.KNOWN_TAGS = new TagSet()
* 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 # {{{
+GraphModel = exports.GraphModel = BaseModel.extend do # {{{
ctorName : 'GraphModel'
urlRoot : '/graphs'
options : {}
}
+
+ hasOption: (key) ->
+ options = @get 'options', {}
+ key in options
+
+ setOption: (key, value, opts) ->
+ options = @get 'options', {}
+ options[key] = value
+ @set 'options', options, opts
+
+ getOption: (key, def) ->
+ options = @get 'options', {}
+ if key in options then options[key] else def
+
+ unsetOption: (key, opts) ->
+ options = @get 'options', {}
+ delete options[key]
+ @set 'options', options, opts
+
+
+ toKVPairs: ->
+ ...
+
toString: -> "#{@ctorName}(id=#{@id}, name=#{@get 'name'}, dataset=#{@get 'dataset'})"
# }}}
_ = require 'kraken/underscore'
op = require 'kraken/util/op'
+{BaseModel} = require 'kraken/base'
### Scaffold Models
-Field = exports.Field = Backbone.Model.extend do # {{{
- ctorName : 'Field'
- idAttribute : 'name'
+Field = exports.Field = BaseModel.extend do # {{{
+ ctorName : 'Field'
+ idAttribute : 'name'
+ valueAttribute : 'value'
initialize: ->
{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'})"
# }}}