Skip to content
Browse files

Added Controller template, Event encode_references function

  • Loading branch information...
1 parent d81acb6 commit 767ab76998d6f5020e66b5919e8e88ad77833f81 @onewland onewland committed Mar 23, 2012
Showing with 58 additions and 1 deletion.
  1. +52 −0 lib/bb/template/Controller.coffee
  2. +6 −1 lib/bb/template/Event.coffee
View
52 lib/bb/template/Controller.coffee
@@ -0,0 +1,52 @@
+$a = window.aurora
+
+window.aurora.Controller::initialize = ->
+ @set 'parameters', {}
+ @set 'planlist', new $a.PlanList()
+ @set 'plansequence', new $a.PlanSequence()
+
+window.aurora.Controller::display_point = ->
+ if(not @has('display_position'))
+ display_position = new $a.Display_position()
+ @set 'display_position', display_position
+ p = new $a.Point()
+ display_position.get('point').push(p)
+ pos_elt = null
+ if(@has('link'))
+ pos_elt = @get('link').get('begin').get('node')
+ else if(@has('node'))
+ pos_elt = @get('node')
+ else if(network)
+ pos_elt = @get('network')
+
+ if(pos_elt and pos_elt.has('position') and
+ pos_elt.get('position').has('point') and
+ pos_elt.get('position').get('point')[0])
+ elt_pt = pos_elt.get('position').get('point')[0]
+ p.set 'lat', elt_pt.get('lat')
+ p.set 'lng', elt_pt.get('lng')
+ else
+ p.set 'lat', 0
+ p.set 'lng', 0
+
+ display_position.get('point')[0]
+
+window.aurora.Controller::resolve_references = (deferred, object_with_id) ->
+ deferred.push =>
+ node_id = @get('node_id')
+ link_id = @get('link_id')
+ network_id = @get('network_id')
+ node = object_with_id.node[node_id]
+ link = object_with_id.link[link_id]
+ network = object_with_id.network[network_id]
+ @set 'node', node
+ @set 'link', link
+ @set 'network', network
+
+ if !node_id and !link_id and !network_id
+ throw "Controller must have node_id, link_id, or network_id"
+
+window.aurora.Controller::encode_references = ->
+ @set('node_id', @get('node').id) if @has('node')
+ @set('link_id', @get('link').id) if @has('link')
+ @set('network_id', @get('network').id) if @has('network')
View
7 lib/bb/template/Event.coffee
@@ -36,4 +36,9 @@ window.aurora.Event::resolve_references = (deferred, object_with_id) ->
@set 'network', network
if !node_id and !link_id and !network_id
- throw "Event must have node_id, link_id, or network_id"
+ throw "Event must have node_id, link_id, or network_id"
+
+window.aurora.Event::encode_references = ->
+ @set('node_id', @get('node').id) if @has('node')
+ @set('link_id', @get('link').id) if @has('link')
+ @set('network_id', @get('network').id) if @has('network')

0 comments on commit 767ab76

Please sign in to comment.
Something went wrong with that request. Please try again.