Communication in both directions (Text control)

Code regrouping
This commit is contained in:
YNH Webdev
2013-08-28 12:52:09 +02:00
parent b72e6871e8
commit b7ab840d71
8 changed files with 255 additions and 70 deletions

View File

@@ -2,13 +2,14 @@ trigger_callback = (control_name,event)->
$.ajax
data:
control_name: control_name
event: event
event: event
states: JSON.stringify(states)
cache: no
.done (new_states)->
#Update all classes
window.states = new_states
for name,state of new_states
controls[name]?.update(state)
states = new_states
return
class WSF_CONTROL
@@ -35,12 +36,26 @@ class WSF_BUTTON_CONTROL extends WSF_CONTROL
update: (state) ->
@$el.text(state.text)
class WSF_TEXT_CONTROL extends WSF_CONTROL
attach_events: ()->
self = @
@$el.change ()->
self.change()
change: ()->
#update local state
window.states[@control_name]['text'] = @$el.val()
trigger_callback(@control_name, 'change')
update: (state) ->
@$el.val(state.text)
#map class name to effectiv class
typemap =
"WSF_BUTTON_CONTROL":WSF_BUTTON_CONTROL
"WSF_TEXT_CONTROL":WSF_TEXT_CONTROL
#create a js class for each control
for name,state of states
for name,state of window.states
#find control DOM element
$el = $('[data-name='+name+']')
#get control type