GraphOptionList = exports.GraphOptionList = FieldList.extend do # {{{
ctorName : 'GraphOptionList'
model : GraphOption
- # initialize : ->
- # console.log "#this.initialize!"
- # FieldList::initialize ...
# }}}
+/**
+ * The view for a single configurable option.
+ */
GraphOptionView = exports.GraphOptionView = FieldView.extend do # {{{
ctorName : 'GraphOptionView'
tagName : 'div'
className : 'field option'
template : require 'kraken/template/graph-option'
+ isCollapsed : true
+
events :
- 'blur .value' : 'update'
- 'submit .value' : 'update'
+ 'blur .value' : 'update'
+ 'submit .value' : 'update'
- # initialize: ->
- # # console.log "#this.initialize!"
- # FieldView::initialize ...
+
+ initialize: ->
+ # console.log "#this.initialize!"
+ FieldView::initialize ...
+ @$el.on 'click', (evt) ~>
+ target = $ evt.target
+ @toggleCollapsed() if @el is evt.target or not target.is '.value, label, input'
+
update: ->
val = @$el.find('.value').val()
@model.setValue val, {+silent}
render: ->
- @$el.html @template @model.toJSON()
+ outer = $ @template @model.toJSON()
+ @$el.html outer.html()
+ .attr do
+ id : outer.attr 'id'
+ class : outer.attr('class') + if @isCollapsed then ' collapsed' else ''
+ this
+
+ toggleCollapsed: ->
+ @$el.toggleClass 'collapsed'
+ @isCollapsed = @$el.hasClass 'collapsed'
this
# }}}
className : 'options scaffold'
collectionType : GraphOptionList
subviewType : GraphOptionView
+
+ # initialize : ->
+ # Scaffold::initialize ...
+ # @$el.isotope do
+ # itemSelector : '.field.option'
+ # layoutMode : 'masonry'
+ # masonry : columnWidth : 10
+ # animationEngine : 'jquery'
+ #
+
# }}}
+
+
+/**
+ * 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: ->
# console.log "#this.initialize!"
+ @model.view = this
@$el.data { model:@model, view:this }
@model.on 'change', @render, this
@model.on 'destroy', @remove, this
render: ->
if @template
- @$el.html @template @model.toJSON()
+ t = $ @template @model.toJSON()
+ @$el.html t.html()
+ .attr { id:t.attr('id'), class:t.attr('class') }
return this
return @remove() if @model.get 'hidden'
initialize: ->
_.bindAll this, 'addOne', 'addAll'
- # @subviews = []
+ @subviews = []
CollectionType = @collectionType
- @collection or= new CollectionType
+ @model = @collection or= new CollectionType
@collection.on 'add', @addOne
@collection.on 'reset', @addAll
- # @collection.on 'all', @render
@$el.data { model:@collection, view:this } .addClass @className
addOne: (field) ->
+ _.remove @subviews, field.view if field.view
+
SubviewType = @subviewType
view = new SubviewType model:field
- # @subviews.push view
+ @subviews.push view
@$el.append view.render().el
view
@collection.each @addOne
this
- toString: ->
- "#{@ctorName}(collection=#{@collection})"
+ get: (id) ->
+ @collection.get id
+
+ at: (idx) ->
+ @collection.at idx
+
+ pluck: (prop) ->
+ @collection.pluck prop
+
+ values: ->
+ @collection.values()
+
+ toString: -> "#{@ctorName}(collection=#{@collection})"
# }}}
- 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);
+- var type_cls = _.domize('type', type);
.field.option(id=_.domize('option', id), class="#{category_cls} #{tags_cls}")
+ h3.shortname #{_.shortname(name)}
label.name(for=value_id) #{name}
input.value(type="text", id=value_id, name=name, value=value)
_obj = do
/**
+ * In-place removal of a value from an Array or Object.
+ */
+ remove: (obj, v) ->
+ values = [].slice.call arguments, 1
+ if _.isArray obj
+ for v of values
+ idx = obj.indexOf v
+ obj.splice idx, 1 if idx is not -1
+ else
+ for k, v in obj
+ delete obj[k] if -1 is not values.indexOf v
+ obj
+
+ /**
* Searches a heirarchical object for a given subkey specified in dotted-property syntax.
* @param {Object} base The object to serve as the root of the property-chain.
* @param {Array|String} chain The property-chain to lookup.
else
"#{key}_#{_str.trim _str.underscored(value), '_'}"
+ shortname: (s) ->
+ return s if s.length <= 6
+ parts = _ s
+ .chain()
+ .underscored()
+ .trim '_'
+ .value()
+ .replace /_+/g, '_'
+ .split '_'
+ .map -> _.capitalize it.slice 0, 2
+ return s if parts.length is 1 #and s.length <= 8
+ parts.shift().toLowerCase() + parts.join('')
+
_string import do
dropLeft : _string.ldrop
@import 'nib'
@import 'colors'
-
+section.graph
+ .graph-label
+ position relative
+
+ .viewport
+ position relative
+
+ form.details
+ position relative
+
+ fieldset.options
+ legend
+ position relative
+
+ .field.option
+ padding 0.5em
+ margin 0.5em
+
+ .shortname
+ display none
+ .value
+ position relative
+ .type
+ position relative
+ .default
+ position relative
+ .desc
+ position relative
+ .tags
+ .tag
+ position relative
+ .examples
+ .example
+ position relative
+
+
+ &.collapsed
+ float left
+ min-width 2em
+ min-height 2em
+ background-color #ccc
+
+ *
+ display none
+ .shortname
+ display inline
+