* Field with graph-option-specific handling for validation, parsing, tags, etc.
*/
GraphOption = exports.GraphOption = Field.extend do # {{{
- initialize : ->
- Field..initialize ...
+ ctorName : 'GraphOption'
+ # initialize : ->
+ # # console.log "#this.initialize!"
+ # Field::initialize ...
# }}}
GraphOptionList = exports.GraphOptionList = FieldList.extend do # {{{
- model : GraphOption
- # initialize : -> FieldList..initialize ...
+ ctorName : 'GraphOptionList'
+ model : GraphOption
+ # initialize : ->
+ # console.log "#this.initialize!"
+ # FieldList::initialize ...
# }}}
GraphOptionView = exports.GraphOptionView = FieldView.extend do # {{{
- tagName : 'form'
- className : 'field graph_option'
- template : require 'kraken/template/graph-option'
+ ctorName : 'GraphOptionView'
+ tagName : 'div'
+ className : 'field option'
+ template : require 'kraken/template/graph-option'
events :
- 'blur .value' : 'update'
+ 'blur .value' : 'update'
+ 'submit .value' : 'update'
- initialize: ->
- FieldView..initialize ...
+ # initialize: ->
+ # # console.log "#this.initialize!"
+ # FieldView::initialize ...
update: ->
val = @$el.find('.value').val()
@$el.html @template @model.toJSON()
this
- toString: -> "GraphOptionView(#{@model.id})"
-
# }}}
GraphOptionsScaffold = exports.GraphOptionsScaffold = Scaffold.extend do # {{{
+ ctorName : 'GraphOptionsScaffold'
className : 'options scaffold'
collectionType : GraphOptionList
subviewType : GraphOptionView
-
- toString: -> "GraphOptionsScaffold()"
# }}}
GraphModel = exports.GraphModel = Backbone.Model.extend do # {{{
- urlRoot : '/graphs'
+ ctorName : 'GraphModel'
+ urlRoot : '/graphs'
initialize : ->
name = @get 'name'
defaults : ->
{
name : 'Kraken Graph'
- dataset : 'data/page_views_by_language.csv'
+ dataset : '/data/page_views_by_language.csv'
options : {}
}
+
+ toString: -> "#{@ctorName}(id=#{@id}, name=#{@get 'name'}, dataset=#{@get 'dataset'})"
# }}}
Graph = exports.Graph = Backbone.View.extend do # {{{
+ ctorName : 'Graph'
tagName : 'section'
className : 'graph'
template : require 'kraken/template/graph'
events:
- 'keypress input' : 'onKeypress'
- 'submit form.settings' : 'onSubmit'
+ 'keypress form.options .value' : 'onKeypress'
+ 'submit form.options' : 'onSubmit'
initialize : (o={}) ->
chartOptions: (values) ->
- options = @scaffold.collection
-
- # @chartOptions 'label', 'label value!'
+ # Handle @chartOptions k, v
if arguments.length > 1
[k, v] = arguments
values = { "#k": v }
+ options = @scaffold.collection
if values
for k, v in values
options.get(k)?.setValue v
# Remove old style, as it confuses dygraph after options update
@viewport.attr 'style', ''
+ console.log "#this"
console.log do
- 'viewport.{ width=%s, height=%s, style=%s }'
+ " .viewport.{ width=%s, height=%s, style=%s }"
@viewport.css('width')
@viewport.css('height')
@viewport.attr 'style'
- console.log 'options:', JSON.stringify @chartOptions()
+ console.log ' .options:', JSON.stringify @chartOptions()
@chart?.destroy()
@chart = new Dygraph do
@viewport.0
- 'data/page_views_by_language.csv'
+ @model.get 'dataset'
@chartOptions()
onKeypress: (evt) ->
$(evt.target).submit() if evt.keyCode is 13
onSubmit: ->
- console.log 'Graph.onSubmit!'
+ console.log "#this.onSubmit!"
@render()
false
- toString: ->
- "Graph()"
+ toString: -> "#{@ctorName}(#{@model})"
# }}}
_ = require 'kraken/underscore'
-{ Field, FieldList, FieldView, Scaffold
+{ Field, FieldList, FieldView, Scaffold
} = require 'kraken/scaffold'
-{Graph} = require 'kraken/graph'
+{ Graph, GraphModel,
+ GraphOption, GraphOptionList, GraphOptionView,
+ GraphOptionsScaffold,
+} = require 'kraken/graph'
Field = exports.Field = Backbone.Model.extend do # {{{
+ ctorName : 'Field'
idAttribute : 'name'
initialize: ->
@set 'value', @get('default'), {+silent} if not @has 'value'
+ # console.log "#this.initialize!"
defaults: ->
{
isDefault: ->
@get('value') is @get('default')
+ toJSON: ->
+ {id:@id} import do
+ _.clone(@attributes) import { value:@getValue(), def:@get('default') }
+
+ toString: -> "#{@ctorName}(id=#{@id}, value=#{@get 'value'})"
# }}}
FieldList = exports.FieldList = Backbone.Collection.extend do # {{{
+ ctorName : 'FieldList'
model : Field
/**
@models.filter -> not it.isDefault()
-> [ it.get('name'), it.getValue() ]
+ toString: -> "#{@ctorName}(length=#{@length})"
# }}}
className : 'field'
events :
- 'blur .value' : 'update'
- 'submit .value' : 'update'
-
+ 'blur .value' : 'onUIChange'
+ 'submit .value' : 'onUIChange'
initialize: ->
+ # console.log "#this.initialize!"
@$el.data { model:@model, view:this }
@model.on 'change', @render, this
@model.on 'destroy', @remove, this
- update: ->
+ onUIChange: ->
val = @$el.find('.value').val()
current = @model.get 'value'
return if val is current
-
- console.log "#this.update( #current -> #val )"
+ console.log "#this.onUIChange( #current -> #val )"
@model.setValue val, {+silent}
render: ->
@$el.find '.value' .val @model.get 'value'
this
- remove: ->
- @$el.remove()
- this
-
- clear: ->
- @model.destroy()
- this
-
- toString: ->
- "FieldView(#{@model.id})"
+ remove : -> @$el.remove(); this
+ clear : -> @model.destroy(); this
+ toString : -> "#{@ctorName}(model=#{@model})"
# }}}
@collection.on 'reset', @addAll
# @collection.on 'all', @render
- @$el.addClass @className
- .data { model:@collection, view:this }
- .attr { action:'/save', method:'get' }
+ @$el.data { model:@collection, view:this } .addClass @className
addOne: (field) ->
this
toString: ->
- "Scaffold()"
+ "#{@ctorName}(collection=#{@collection})"
# }}}
+
exports import {
CWD, WWW, VAR, STATIC,
PORT, LOG_LEVEL, NODE_ENV, VERSION,
app, module, require,
}
-
mainfile = path.basename require.main?.filename
if require.main is module or 'Cokefile' is mainfile
app.start()
+- var _ = require('kraken/underscore');
+- var value_id = _.domize('value', id);
+- var category_cls = _.domize('category', category);
+- var tags_cls = tags.map(_.domize('tag')).join(' ');
+- var type_cls = _.domize('type', type);
+
+.field.option(id=_.domize('option', id), class="#{category_cls} #{tags_cls}")
+ label.name(for=value_id) #{name}
+ input.value(type="text", id=value_id, name=name, value=value)
+
+ .type(class=type_cls) #{type}
+ .default(class=type_cls) #{def}
+
+ .desc
+ #{desc}
+ //- != jade.filters.markdown(desc)
+
+ .tags: ul
+ for tag in tags
+ li.tag(class=_.domize('tag', tag)) #{tag}
+ .examples: ul
+ for example in examples
+ li.example
+ a(href="http://dygraphs.com/tests/#{example}.html", target="_blank") #{example}
+
+- var _ = require('kraken/underscore');
section.graph(id=id)
.graph-label
.viewport
while s and s is not starting
s
+ # Converts to snake_case, concatenates the key-value pair (with '_'), normalizing _'s.
+ # If only a key is given, domize auto-curries and waits for a second argument.
+ domize : (key='', value='') ->
+ key = _str.trim _str.underscored(key), '_'
+ if arguments.length <= 1
+ arguments.callee.bind this, key
+ else
+ "#{key}_#{_str.trim _str.underscored(value), '_'}"
+
_string import do
dropLeft : _string.ldrop