Permalink
Browse files

various bug fixes, about to rip out embedded properties

  • Loading branch information...
collin committed Apr 24, 2012
1 parent 60cc30f commit 1e31fe163df721da2710339d9e15c73fa21f5fe4
Showing with 611 additions and 202 deletions.
  1. +3 −2 lib/alpha_simprini/client.coffee
  2. +5 −1 lib/alpha_simprini/client/application.coffee
  3. +8 −8 lib/alpha_simprini/client/binding.coffee
  4. +21 −0 lib/alpha_simprini/client/binding/container.coffee
  5. +15 −12 lib/alpha_simprini/client/binding/field.coffee
  6. +14 −0 lib/alpha_simprini/client/binding/file.coffee
  7. +6 −6 lib/alpha_simprini/client/binding/input.coffee
  8. +20 −9 lib/alpha_simprini/client/binding/many.coffee
  9. +3 −6 lib/alpha_simprini/client/binding/model.coffee
  10. +5 −9 lib/alpha_simprini/client/binding/one.coffee
  11. +1 −0 lib/alpha_simprini/client/binding/select.coffee
  12. +7 −4 lib/alpha_simprini/client/binding_group.coffee
  13. +3 −4 lib/alpha_simprini/client/dom.coffee
  14. +5 −5 lib/alpha_simprini/client/models/targets.coffee
  15. +27 −8 lib/alpha_simprini/client/view.coffee
  16. +2 −1 lib/alpha_simprini/client/view_events.coffee
  17. +9 −3 lib/alpha_simprini/client/view_model.coffee
  18. +3 −1 lib/alpha_simprini/core.coffee
  19. +1 −2 lib/alpha_simprini/core/logging.coffee
  20. +15 −2 lib/alpha_simprini/core/model.coffee
  21. +6 −3 lib/alpha_simprini/core/model/dendrite.coffee
  22. +22 −23 lib/alpha_simprini/core/model/share.coffee
  23. +9 −2 lib/alpha_simprini/core/model/synapse.coffee
  24. +114 −0 lib/alpha_simprini/core/models/file.coffee
  25. +6 −1 lib/alpha_simprini/core/models/radio_selection_model.coffee
  26. +12 −6 lib/alpha_simprini/core/properties/embeds_many.coffee
  27. +19 −11 lib/alpha_simprini/core/properties/field.coffee
  28. +12 −2 lib/alpha_simprini/core/properties/has_many.coffee
  29. +8 −4 lib/alpha_simprini/core/properties/has_one.coffee
  30. +8 −6 lib/alpha_simprini/core/properties/virtual_property.coffee
  31. +10 −4 test/client/binding/check_box.coffee
  32. +4 −4 test/client/binding/input.coffee
  33. +16 −6 test/client/binding/model.coffee
  34. +10 −3 test/client/binding/one.coffee
  35. +3 −3 test/client/binding_group.coffee
  36. +98 −7 test/client/view.coffee
  37. +6 −6 test/core/callbacks.coffee
  38. +7 −3 test/core/collection.coffee
  39. +1 −1 test/core/model.coffee
  40. +42 −8 test/core/model/share.coffee
  41. +15 −14 test/core/properties/belongs_to.coffee
  42. +1 −2 test/core/properties/field.coffee
  43. +9 −0 test/core/properties/has_many.coffee
@@ -6,8 +6,9 @@ Client.require """
dom view view_model binding_group view_events
binding
-
- binding/model binding/field binding/input binding/select
+ binding/container
+
+ binding/model binding/field binding/input binding/select binding/file
binding/check_box binding/edit_line binding/one binding/many
views/panel views/region views/dialog
@@ -23,7 +23,7 @@ AS.Application = AS.Object.extend ({def, include}) ->
handlers =
'': 'escape'
'⌘+↩': 'accept'
- '': 'delete'
+ # 'backspace': 'delete'
#TODO: add to test suite
"": "open"
@@ -41,6 +41,10 @@ AS.Application = AS.Object.extend ({def, include}) ->
each handlers, (trigger, key) =>
jwerty.key key, ( (event) => @trigger(trigger, event) ), @el
+ jwerty.key "backspace", (event) =>
+ event.preventDefault()
+ @trigger("delete", event)
+
def view: (constructor, options={}) ->
options.application = this
constructor.new options
@@ -5,23 +5,23 @@ AS.Binding = AS.Object.extend ({def}) ->
def initialize: (@context, @model, @field, @options={}, @fn=undefined) ->
if _.isString(@field)
@field = @model[@field]
-
- @event = "change:#{field}"
-
+
if _.isFunction(@options)
[@fn, @options] = [@options, {}]
@container ?= @context.$ @context.currentNode
@bindingGroup = @context.bindingGroup
- @content = @context.$ []
+ @content = @makeContent()
if @willGroupBindings()
- @context.groupBindings (bindingGroup) ->
+ @context.groupBindings (bindingGroup) =>
@bindingGroup = bindingGroup
- @setup()
- else
- @setup()
+
+ @setup()
+
+ def makeContent: ->
+ @context.$ []
def willGroupBindings: ->
@constructor.willGroupBindings or _.isFunction(@fn)
@@ -0,0 +1,21 @@
+AS = require "alpha_simprini"
+jQuery = require "jquery"
+
+AS.Binding.Container = AS.Object.extend ({delegate, include, def, defs}) ->
+ delegate 'find', 'html', to: 'el'
+
+ def initialize: (@domElement) ->
+ @el = jQuery(@domElement)
+ @containerChildren = []
+
+ def appendChild: (child) ->
+ if child instanceof jQuery
+ @containerChildren = @containerChildren.concat child
+ child.appendTo(@domElement)
+ else
+ @containerChildren.push child
+ @domElement.appendChild(child)
+
+ def empty: ->
+ jQuery(@containerChildren).remove()
+ @containerChildren = []
@@ -3,41 +3,44 @@ _ = require "underscore"
jQuery = require "jquery"
AS.Binding.Field = AS.Binding.extend ({def}) ->
-
def initialize: ->
@_super.apply this, arguments
- @content = @makeContent()
- @bindContent()
@setContent()
+ @bindContent()
def bindContent: ->
+ # don't go thinking ou want to @withingBindingGroup @bindingGroup this.
+ # you want this binding to take place in the context of the @context
@context.binds @field, "change", @setContent, this
def setContent: ->
if @fn
- @content.remove()
- @container.empty()
+ @content.empty()
+ @bindingGroup.unbind()
fieldValue = @fieldValue()
# FIXME: this turned into a string :(
return if fieldValue is null
return if fieldValue is undefined
return if fieldValue is "null"
return if fieldValue is "undefined"
- @bindingGroup.unbind()
@context.withinBindingGroup @bindingGroup, =>
- @context.withinNode @container, =>
- made = if _.include(fieldValue.model?.constructor.ancestors, AS.Model)
+ @context.withinNode @content, =>
+ if _.include(fieldValue.model?.constructor.ancestors, AS.Model)
value = AS.ViewModel.build(@context, fieldValue.model)
- made = @fn.call(@context, value, AS.Binding.Model.new(@context, value, @container))
+ @fn.call(@context, value, AS.Binding.Model.new(@context, value, @container))
+
+ else if _.include(fieldValue.model?.constructor.ancestors, AS.ViewModel)
+ value = AS.ViewModel.build(@context, fieldValue.model.model)
+ @fn.call(@context, value, AS.Binding.Model.new(@context, value, @container))
+
else
@fn.call(@context)
- @content.push if made instanceof jQuery then made[0] else made
else
@content.text @fieldValue()
def makeContent: ->
- @content = if @fn
- @context.$ []
+ if @fn
+ AS.Binding.Container.new(@container[0])
else
@context.$ @context.span()
@@ -0,0 +1,14 @@
+_ = require("underscore")
+AS = require "alpha_simprini"
+AS.Binding.File = AS.Binding.Input.extend ({delegate, include, def, defs}) ->
+ def makeContent: ->
+ options = _.clone(@options)
+ options.type = "file"
+ @context.$ @context.input(options)
+
+ def fieldValue: -> # FALSE. Cannot set value of a file input.
+ def setContent: -> # FALSE. Cannot set value of a file input.
+ def readField: ->
+ AS.Models.File.new file: @content[0].files[0]
+
+
@@ -13,16 +13,16 @@ AS.Binding.Input = AS.Binding.Field.extend ({def}) ->
@context.$ @context.input(@options)
def bindContent: ->
- if _.isArray @field
- @context.binds @model, @field, @setField, this
- else
- @context.binds @content, "change", @setField, this
+ @context.binds @content, "change", @setField, this
def setContent: () ->
@content.val @fieldValue()
+ def readField: ->
+ @content.val()
+
def setField: () ->
if _.isArray @field
- @model.writePath @field, @content.val()
+ @model.writePath @field, @readField()
else
- @field.set @content.val()
+ @field.set @readField()
@@ -9,17 +9,16 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@collection = @field
@contents = {}
- @bindings = {}
+ @bindingGroups = {}
@sorting = @sortedModels()
-
@makeAll()
@context.binds @collection, "add", @insertItem, this
@context.binds @collection, "remove", @removeItem, this
@context.binds @collection, "change", @changeItem, this
def makeAll: ->
- @sortedModels().each _.bind @makeContent, this
+ @sortedModels().each _.bind @makeItemContent, this
def sortedModels: ->
if sortField = @options.order_by
@@ -39,24 +38,31 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
def insertItem: (item) ->
return if @skipItem(item)
- content = @context.danglingContent => @makeContent(item)
+
+ content = @context.danglingContent => @makeItemContent(item)
index = @sortedModels().indexOf(item).value?()
index ?= 0
siblings = @container.children()
- if siblings.get(0) is undefined or siblings.get(index) is undefined
+
+ unless siblings.get(0)
@container.append(content)
+
+ else unless siblings.get(index)
+ @container.append(content)
+
else
@context.$(siblings.get(index)).before(content)
+ debugger if window.DEBUG
@sorting = @sortedModels()
def removeItem: (item) ->
if @contents[item.cid]
@contents[item.cid].remove()
delete @contents[item.cid]
- @bindings[item.cid].unbind()
- delete @bindings[item.cid]
+ @bindingGroups[item.cid].unbind()
+ delete @bindingGroups[item.cid]
@sorting = @sortedModels()
@@ -81,12 +87,13 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
else if @contents[item.cid] is undefined
@insertItem(item)
- def makeContent: (item) ->
+ def makeItemContent: (item) ->
+ return unless item
return if @skipItem(item)
content = @context.$ []
@context.withinBindingGroup @bindingGroup, =>
@context.groupBindings =>
- @bindings[item.cid] = @context.bindingGroup
+ @bindingGroups[item.cid] = @context.bindingGroup
binding = AS.Binding.Model.new(@context, item, content)
made = @fn.call(@context, AS.ViewModel.build(@context, item), binding)
if made?.jquery
@@ -99,3 +106,7 @@ AS.Binding.Many = AS.Binding.extend ({def}) ->
@contents[item.cid] = content
return content
+
+ def makeContent: ->
+ AS.Binding.Container.new(@container[0])
+
@@ -16,13 +16,11 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
value = @styles[property]()
@content.css property, value
- bindingPath = options
- @context.binds @model, bindingPath, painter, this
+ @context.binds @model, options, painter, this
else
@styles[property] = => options.fn(@model)
painter = => _.defer => @content.css property, @styles[property]()
- for field in options.field.split(" ")
- @context.binds @model, "change:#{field}", painter, this
+ @context.binds @model, options.field, painter, this
def attr: (attrs) ->
for property, options of attrs
@@ -52,8 +50,7 @@ AS.Binding.Model = AS.Object.extend ({def}) ->
painter = => _.defer =>
@content.attr property, @attrs[property]()
- for field in options.field.split(" ")
- @context.binds @model, "change:#{field}", painter, this
+ @context.binds @model, options.field, painter, this
def paint: ->
attrs = {}
@@ -4,18 +4,14 @@ jQuery = require "jquery"
AS.Binding.One = AS.Binding.Field.extend ({delegate, include, def, defs}) ->
def makeContent: ->
- @content = @context.$ []
+ AS.Binding.Container.new(@container[0])
def setContent: ->
- @content.remove()
+ @content.empty()
+ @bindingGroup.unbind()
if (value = @fieldValue()) and @fn
value = AS.ViewModel.build(@context, value) if _.include(value.constructor.ancestors, AS.Model)
- @bindingGroup.unbind()
@context.withinBindingGroup @bindingGroup, =>
- @context.withinNode @container, =>
- made = @fn.call(@context, value, AS.Binding.Model.new(@context, @model, @container))
- @content.push if made instanceof jQuery then made[0] else made
-
- else
- @bindingGroup.unbind()
+ @context.withinNode @content, =>
+ @fn.call(@context, value, AS.Binding.Model.new(@context, @model, @container))
@@ -7,6 +7,7 @@ AS.Binding.Select = AS.Binding.Input.extend ({def}) ->
@require_option "options"
def makeContent: ->
+ @select?.remove()
options = @options.options
@select = @context.$ @context.select ->
if _.isArray options
@@ -3,16 +3,19 @@ _ = require "underscore"
AS.BindingGroup = AS.Object.extend ({def}) ->
- def initialize: ->
+ def initialize: (@parentGroup) ->
@namespace = _.uniqueId("bg")
@children = []
@boundObjects = []
# Unbind all bindings, and then unbind all children binding groups
def unbind: ->
- object.unbind(@namespace) for object in @boundObjects
+ object.unbind("."+@namespace) for object in @boundObjects
+ @unbindChildren()
+
+ def unbindChildren: ->
child.unbind() for child in @children
- @initialize()
+ @children = []
def binds: (object, event, handler, context) ->
@boundObjects.push object
@@ -28,7 +31,7 @@ AS.BindingGroup = AS.Object.extend ({def}) ->
handler: handler
context: context
- def addChild: (child=AS.BindingGroup.new())->
+ def addChild: (child=AS.BindingGroup.new(this))->
@children.push child
return child
@@ -71,8 +71,7 @@ AS.DOM = AS.Object.extend ({delegate, include, def, defs}) ->
else if content
@withinNode node, ->
last = content.call(this)
- if _.isString(last)
- @text(last)
+ @text(last) if _.isString(last)
return node
@@ -94,7 +93,7 @@ SVG_ELEMENTS.each (element) ->
htmlSvgConflict = ~DOM_ELEMENTS.value().indexOf(element)
methodConflict = AS.DOM::[element]?
if htmlSvgConflict or methodConflict
- element = "svg_#{element}"
+ safeElement = "svg_#{element}"
- AS.DOM::[element] = -> @svgTag.apply this, _(arguments).unshift(element)
+ AS.DOM::[safeElement or element] = -> @svgTag.apply this, _(arguments).unshift(element)
@@ -2,11 +2,11 @@ AS = require("alpha_simprini")
$ = require("jquery")
Taxi = require "taxi"
-TOP = name:"TOP"
-MIDDLE = name:"MIDDLE"
-BOTTOM = name:"BOTTOM"
-LEFT = name: "LEFT"
-RIGHT = name: "RIGHT"
+TOP = name:"TOP", toString: -> @name
+MIDDLE = name:"MIDDLE", toString: -> @name
+BOTTOM = name:"BOTTOM", toString: -> @name
+LEFT = name: "LEFT", toString: -> @name
+RIGHT = name: "RIGHT", toString: -> @name
AS.Models.Targets = AS.Object.extend ({def, defs, include}) ->
include Taxi.Mixin
Oops, something went wrong.

0 comments on commit 1e31fe1

Please sign in to comment.