Restructure callbacks
This commit is contained in:
@@ -135,7 +135,7 @@ feature -- Execution
|
|||||||
local
|
local
|
||||||
f: WSF_FILE_RESPONSE
|
f: WSF_FILE_RESPONSE
|
||||||
do
|
do
|
||||||
create f.make_html (name)
|
create f.make (name)
|
||||||
response.send (f)
|
response.send (f)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ feature
|
|||||||
create container.make_multi_control ("container")
|
create container.make_multi_control ("container")
|
||||||
container.add_class ("container")
|
container.add_class ("container")
|
||||||
create navbar.make_navbar ("Sample Page")
|
create navbar.make_navbar ("Sample Page")
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
|
navbar.nav.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
navbar.nav.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
navbar.nav.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
||||||
navbar.add_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"#%"", "About"))
|
navbar.nav_right.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"#%"", "About"))
|
||||||
container.add_control (navbar)
|
container.add_control (navbar)
|
||||||
control := container
|
control := container
|
||||||
end
|
end
|
||||||
|
|||||||
1143
examples/widgetapp/typeahead.min.js
vendored
1143
examples/widgetapp/typeahead.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
|
|||||||
|
#IMPORTANT PLEASE COMPILE WITH:: coffee -cbw widget.coffee
|
||||||
cache = {}
|
cache = {}
|
||||||
template = tmpl = (str, data) ->
|
template = tmpl = (str, data) ->
|
||||||
# Simple JavaScript Templating
|
# Simple JavaScript Templating
|
||||||
@@ -10,20 +11,20 @@ Mini =
|
|||||||
{
|
{
|
||||||
render:template(t)
|
render:template(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_callback = (control_name,event,event_parameter)->
|
build_control = (control_name, state, control)->
|
||||||
$.ajax
|
$el = control.$el.find('[data-name='+control_name+']')
|
||||||
data:
|
#get control type
|
||||||
control_name: control_name
|
type = $el.data('type')
|
||||||
event: event
|
#create class
|
||||||
event_parameter: event_parameter
|
typeclass = null
|
||||||
states: JSON.stringify(window.states)
|
try
|
||||||
cache: no
|
typeclass = eval(type)
|
||||||
.done (new_states)->
|
catch e
|
||||||
#Update all classes
|
typeclass = WSF_CONTROL
|
||||||
for name,state of new_states
|
if type? and typeclass?
|
||||||
controls[name]?.update(state)
|
return new typeclass(control, $el, control_name, state)
|
||||||
return
|
return null
|
||||||
|
|
||||||
class WSF_VALIDATOR
|
class WSF_VALIDATOR
|
||||||
constructor: (@parent_control, @settings)->
|
constructor: (@parent_control, @settings)->
|
||||||
@@ -55,21 +56,71 @@ class WSF_MAX_VALIDATOR extends WSF_VALIDATOR
|
|||||||
val = @parent_control.value()
|
val = @parent_control.value()
|
||||||
return (val.length<=@settings.max)
|
return (val.length<=@settings.max)
|
||||||
|
|
||||||
validatormap =
|
|
||||||
"WSF_REGEXP_VALIDATOR":WSF_REGEXP_VALIDATOR
|
|
||||||
"WSF_MIN_VALIDATOR":WSF_MIN_VALIDATOR
|
|
||||||
"WSF_MAX_VALIDATOR":WSF_MAX_VALIDATOR
|
|
||||||
|
|
||||||
class WSF_CONTROL
|
class WSF_CONTROL
|
||||||
constructor: (@control_name, @$el)->
|
constructor: (@parent_control, @$el, @control_name, @fullstate)->
|
||||||
|
@state = @fullstate.state
|
||||||
|
@load_subcontrols()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
load_subcontrols: ()->
|
||||||
|
if @fullstate.controls?
|
||||||
|
@controls=(build_control(control_name, state, @) for control_name, state of @fullstate.controls)
|
||||||
|
else
|
||||||
|
@controls = []
|
||||||
|
|
||||||
|
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
console.log "Attached #{@control_name}"
|
||||||
|
for control in @controls
|
||||||
|
if control?
|
||||||
|
control.attach_events()
|
||||||
return
|
return
|
||||||
|
|
||||||
update: (state)->
|
update: (state)->
|
||||||
return
|
return
|
||||||
|
get_state: ()->
|
||||||
|
@state
|
||||||
|
|
||||||
|
get_control_states:()->
|
||||||
|
result = {}
|
||||||
|
for control in @controls
|
||||||
|
if control?
|
||||||
|
result[control.control_name]=control.get_full_state()
|
||||||
|
result
|
||||||
|
|
||||||
|
get_full_state: ()->
|
||||||
|
{"state":@get_state(),"controls":@get_control_states()}
|
||||||
|
|
||||||
|
process_update: (new_states)->
|
||||||
|
if new_states[@control_name]?
|
||||||
|
@update(new_states[@control_name])
|
||||||
|
for control in @controls
|
||||||
|
if control?
|
||||||
|
control.process_update(new_states)
|
||||||
|
|
||||||
|
get_context_state : ()->
|
||||||
|
if @parent_control?
|
||||||
|
return @parent_control.get_context_state()
|
||||||
|
return @get_full_state()
|
||||||
|
|
||||||
|
trigger_callback: (control_name,event,event_parameter)->
|
||||||
|
if @parent_control?
|
||||||
|
return @parent_control.trigger_callback(control_name,event,event_parameter)
|
||||||
|
self = @
|
||||||
|
$.ajax
|
||||||
|
type: 'POST',
|
||||||
|
url: '?' + $.param
|
||||||
|
control_name: control_name
|
||||||
|
event: event
|
||||||
|
data:
|
||||||
|
JSON.stringify(@get_full_state())
|
||||||
|
processData: false,
|
||||||
|
contentType: 'application/json',
|
||||||
|
cache: no
|
||||||
|
.done (new_states)->
|
||||||
|
#Update all classes
|
||||||
|
self.process_update(new_states)
|
||||||
#Simple event listener
|
#Simple event listener
|
||||||
|
|
||||||
#subscribe to an event
|
#subscribe to an event
|
||||||
@@ -89,36 +140,45 @@ class WSF_CONTROL
|
|||||||
ev.callback.call(ev.context)
|
ev.callback.call(ev.context)
|
||||||
return @
|
return @
|
||||||
|
|
||||||
|
class WSF_PAGE_CONTROL extends WSF_CONTROL
|
||||||
|
constructor: (@fullstate)->
|
||||||
|
@state = @fullstate.state
|
||||||
|
@parent_control=null
|
||||||
|
@$el = $('[data-name='+@state.id+']')
|
||||||
|
@control_name = @state.id
|
||||||
|
@load_subcontrols()
|
||||||
|
|
||||||
controls = {}
|
controls = {}
|
||||||
|
|
||||||
class WSF_BUTTON_CONTROL extends WSF_CONTROL
|
class WSF_BUTTON_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
@$el.click (e)->
|
@$el.click (e)->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
self.click()
|
self.click()
|
||||||
|
|
||||||
click: ()->
|
click: ()->
|
||||||
if window.states[@control_name]['callback_click']
|
if @state['callback_click']
|
||||||
trigger_callback(@control_name, 'click')
|
@trigger_callback(@control_name, 'click')
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.text?
|
if state.text?
|
||||||
window.states[@control_name]['text'] = state.text
|
@state['text'] = state.text
|
||||||
@$el.text(state.text)
|
@$el.text(state.text)
|
||||||
|
|
||||||
class WSF_INPUT_CONTROL extends WSF_CONTROL
|
class WSF_INPUT_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
@$el.change ()->
|
@$el.change ()->
|
||||||
self.change()
|
self.change()
|
||||||
|
|
||||||
change: ()->
|
change: ()->
|
||||||
#update local state
|
#update local state
|
||||||
window.states[@control_name]['text'] = @$el.val()
|
@state['text'] = @$el.val()
|
||||||
if window.states[@control_name]['callback_change']
|
if @state['callback_change']
|
||||||
trigger_callback(@control_name, 'change')
|
@trigger_callback(@control_name, 'change')
|
||||||
@trigger('change')
|
@trigger('change')
|
||||||
|
|
||||||
value:()->
|
value:()->
|
||||||
@@ -126,28 +186,31 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.text?
|
if state.text?
|
||||||
window.states[@control_name]['text'] = state.text
|
@state['text'] = state.text
|
||||||
@$el.val(state.text)
|
@$el.val(state.text)
|
||||||
|
|
||||||
class WSF_TEXTAREA_CONTROL extends WSF_INPUT_CONTROL
|
class WSF_TEXTAREA_CONTROL extends WSF_INPUT_CONTROL
|
||||||
|
|
||||||
class WSF_AUTOCOMPLETE_CONTROL extends WSF_INPUT_CONTROL
|
class WSF_AUTOCOMPLETE_CONTROL extends WSF_INPUT_CONTROL
|
||||||
attach_events: () ->
|
attach_events: () ->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
@$el.typeahead({
|
@$el.typeahead({
|
||||||
name: @control_name
|
name: @control_name
|
||||||
template: window.states[@control_name]['template']
|
template: @state['template']
|
||||||
engine: Mini
|
engine: Mini
|
||||||
remote:
|
remote:
|
||||||
url:""
|
url:""
|
||||||
replace: (url, uriEncodedQuery) ->
|
replace: (url, uriEncodedQuery) ->
|
||||||
window.states[self.control_name]['text'] = self.$el.val()
|
self.state['text'] = self.$el.val()
|
||||||
'?' + $.param
|
'?' + $.param
|
||||||
control_name: self.control_name
|
control_name: self.control_name
|
||||||
event: 'autocomplete'
|
event: 'autocomplete'
|
||||||
states: JSON.stringify(window.states)
|
states: JSON.stringify(self.get_context_state())
|
||||||
filter: (parsedResponse) ->
|
filter: (parsedResponse) ->
|
||||||
parsedResponse[self.control_name]['suggestions']
|
parsedResponse[self.control_name]['suggestions']
|
||||||
|
fn: ()->
|
||||||
|
self.trigger_callback(self.control_name, 'autocomplete')
|
||||||
})
|
})
|
||||||
@$el.on 'typeahead:closed',()->
|
@$el.on 'typeahead:closed',()->
|
||||||
self.change()
|
self.change()
|
||||||
@@ -156,16 +219,17 @@ class WSF_AUTOCOMPLETE_CONTROL extends WSF_INPUT_CONTROL
|
|||||||
|
|
||||||
class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
@checked_value = window.states[@control_name]['checked_value']
|
@checked_value = @state['checked_value']
|
||||||
@$el.change ()->
|
@$el.change ()->
|
||||||
self.change()
|
self.change()
|
||||||
|
|
||||||
change: ()->
|
change: ()->
|
||||||
#update local state
|
#update local state
|
||||||
window.states[@control_name]['checked'] = @$el.is(':checked')
|
@state['checked'] = @$el.is(':checked')
|
||||||
if window.states[@control_name]['callback_change']
|
if @state['callback_change']
|
||||||
trigger_callback(@control_name, 'change')
|
@trigger_callback(@control_name, 'change')
|
||||||
@trigger('change')
|
@trigger('change')
|
||||||
|
|
||||||
value:()->
|
value:()->
|
||||||
@@ -173,23 +237,25 @@ class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.text?
|
if state.text?
|
||||||
window.states[@control_name]['checked'] = state.checked
|
@state['checked'] = state.checked
|
||||||
@$el.prop('checked',state.checked)
|
@$el.prop('checked',state.checked)
|
||||||
|
|
||||||
class WSF_FORM_ELEMENT_CONTROL extends WSF_CONTROL
|
class WSF_FORM_ELEMENT_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
@value_control = controls[window.states[@control_name]['value_control']]
|
@value_control = @controls[0]
|
||||||
if @value_control?
|
if @value_control?
|
||||||
#subscribe to change event on value_control
|
#subscribe to change event on value_control
|
||||||
@value_control.on('change',@change,@)
|
@value_control.on('change',@change,@)
|
||||||
@serverside_validator = false
|
@serverside_validator = false
|
||||||
#Initialize validators
|
#Initialize validators
|
||||||
@validators = []
|
@validators = []
|
||||||
for validator in window.states[@control_name]['validators']
|
for validator in @state['validators']
|
||||||
if validatormap[validator.name]?
|
try
|
||||||
@validators.push new validatormap[validator.name](@,validator)
|
validatorclass = eval(validator.name)
|
||||||
else
|
@validators.push new validatorclass(@,validator)
|
||||||
|
catch e
|
||||||
#Use serverside validator if no js implementation
|
#Use serverside validator if no js implementation
|
||||||
@serverside_validator = true
|
@serverside_validator = true
|
||||||
return
|
return
|
||||||
@@ -203,7 +269,7 @@ class WSF_FORM_ELEMENT_CONTROL extends WSF_CONTROL
|
|||||||
@showerror("")
|
@showerror("")
|
||||||
#If there is validator which is not implemented in js ask server to validate
|
#If there is validator which is not implemented in js ask server to validate
|
||||||
if @serverside_validator
|
if @serverside_validator
|
||||||
trigger_callback(@control_name, 'validate')
|
@trigger_callback(@control_name, 'validate')
|
||||||
return
|
return
|
||||||
|
|
||||||
showerror: (message)->
|
showerror: (message)->
|
||||||
@@ -228,19 +294,16 @@ class WSF_HTML_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.html?
|
if state.html?
|
||||||
window.states[@control_name]['html'] = state.html
|
@state['html'] = state.html
|
||||||
@$el.html(state.html)
|
@$el.html(state.html)
|
||||||
|
|
||||||
class WSF_CHECKBOX_LIST_CONTROL extends WSF_CONTROL
|
class WSF_CHECKBOX_LIST_CONTROL extends WSF_CONTROL
|
||||||
|
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
self = @
|
super
|
||||||
@subcontrols = []
|
|
||||||
#Listen to events of subelements and forward them
|
#Listen to events of subelements and forward them
|
||||||
for name,control of controls
|
for control in @controls
|
||||||
if @$el.has(control.$el).length > 0
|
control.on('change',@change,@)
|
||||||
@subcontrols.push(control)
|
|
||||||
control.on('change',@change,@)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
change:()->
|
change:()->
|
||||||
@@ -248,7 +311,7 @@ class WSF_CHECKBOX_LIST_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
value:()->
|
value:()->
|
||||||
result = []
|
result = []
|
||||||
for subc in @subcontrols
|
for subc in @controls
|
||||||
if subc.value()
|
if subc.value()
|
||||||
result.push(subc.checked_value)
|
result.push(subc.checked_value)
|
||||||
return result
|
return result
|
||||||
@@ -256,20 +319,22 @@ class WSF_CHECKBOX_LIST_CONTROL extends WSF_CONTROL
|
|||||||
class WSF_PROGRESS_CONTROL extends WSF_CONTROL
|
class WSF_PROGRESS_CONTROL extends WSF_CONTROL
|
||||||
|
|
||||||
attach_events:() ->
|
attach_events:() ->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
runfetch= ()->
|
runfetch= ()->
|
||||||
self.fetch()
|
self.fetch()
|
||||||
setInterval(runfetch, 5000)
|
setInterval(runfetch, 5000)
|
||||||
|
|
||||||
fetch: ()->
|
fetch: ()->
|
||||||
trigger_callback(@control_name, 'progress_fetch')
|
@trigger_callback(@control_name, 'progress_fetch')
|
||||||
|
|
||||||
update: (state)->
|
update: (state)->
|
||||||
if state.progress?
|
if state.progress?
|
||||||
window.states[@control_name]['progress'] = state.progress
|
@state['progress'] = state.progress
|
||||||
@$el.children('.progress-bar').attr('aria-valuenow', state.progress).width(state.progress + '%')
|
@$el.children('.progress-bar').attr('aria-valuenow', state.progress).width(state.progress + '%')
|
||||||
|
|
||||||
class WSF_PAGINATION_CONTROL extends WSF_CONTROL
|
class WSF_PAGINATION_CONTROL extends WSF_CONTROL
|
||||||
|
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
self = @
|
self = @
|
||||||
@$el.on 'click', 'a', (e)->
|
@$el.on 'click', 'a', (e)->
|
||||||
@@ -279,11 +344,11 @@ class WSF_PAGINATION_CONTROL extends WSF_CONTROL
|
|||||||
click: (e)->
|
click: (e)->
|
||||||
nr = $(e.target).data('nr')
|
nr = $(e.target).data('nr')
|
||||||
if nr == "next"
|
if nr == "next"
|
||||||
trigger_callback(@control_name, "next")
|
@trigger_callback(@control_name, "next")
|
||||||
else if nr == "prev"
|
else if nr == "prev"
|
||||||
trigger_callback(@control_name, "prev")
|
@trigger_callback(@control_name, "prev")
|
||||||
else
|
else
|
||||||
trigger_callback(@control_name, "goto", nr)
|
@trigger_callback(@control_name, "goto", nr)
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state._html?
|
if state._html?
|
||||||
@@ -291,49 +356,25 @@ class WSF_PAGINATION_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
class WSF_GRID_CONTROL extends WSF_CONTROL
|
class WSF_GRID_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.datasource?
|
if state.datasource?
|
||||||
window.states[@control_name]['datasource'] = state.datasource
|
@state['datasource'] = state.datasource
|
||||||
if state._body?
|
if state._body?
|
||||||
@$el.find('tbody').html(state._body)
|
@$el.find('tbody').html(state._body)
|
||||||
|
|
||||||
class WSF_REPEATER_CONTROL extends WSF_CONTROL
|
class WSF_REPEATER_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
|
super
|
||||||
self = @
|
self = @
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.datasource?
|
if state.datasource?
|
||||||
window.states[@control_name]['datasource'] = state.datasource
|
@state['datasource'] = state.datasource
|
||||||
if state._body?
|
if state._body?
|
||||||
@$el.find('.repeater_content').html(state._body)
|
@$el.find('.repeater_content').html(state._body)
|
||||||
console.log state._body
|
console.log state._body
|
||||||
|
|
||||||
#map class name to effective class
|
|
||||||
typemap =
|
|
||||||
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL
|
|
||||||
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL
|
|
||||||
"WSF_TEXTAREA_CONTROL": WSF_TEXTAREA_CONTROL
|
|
||||||
"WSF_AUTOCOMPLETE_CONTROL": WSF_AUTOCOMPLETE_CONTROL
|
|
||||||
"WSF_CHECKBOX_CONTROL": WSF_CHECKBOX_CONTROL
|
|
||||||
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL
|
|
||||||
"WSF_HTML_CONTROL": WSF_HTML_CONTROL
|
|
||||||
"WSF_CHECKBOX_LIST_CONTROL": WSF_CHECKBOX_LIST_CONTROL
|
|
||||||
"WSF_PROGRESS_CONTROL": WSF_PROGRESS_CONTROL
|
|
||||||
"WSF_PAGINATION_CONTROL": WSF_PAGINATION_CONTROL
|
|
||||||
"WSF_GRID_CONTROL": WSF_GRID_CONTROL
|
|
||||||
"WSF_REPEATER_CONTROL":WSF_REPEATER_CONTROL
|
|
||||||
|
|
||||||
#create a js class for each control
|
|
||||||
for name,state of window.states
|
|
||||||
#find control DOM element
|
|
||||||
$el = $('[data-name='+name+']')
|
|
||||||
#get control type
|
|
||||||
type = $el.data('type')
|
|
||||||
#create class
|
|
||||||
if type? and typemap[type]?
|
|
||||||
controls[name]=new typemap[type](name,$el)
|
|
||||||
for name,state of window.states
|
|
||||||
controls[name]?.attach_events()
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ inherit
|
|||||||
WSF_VALUE_CONTROL [LIST [STRING]]
|
WSF_VALUE_CONTROL [LIST [STRING]]
|
||||||
undefine
|
undefine
|
||||||
load_state,
|
load_state,
|
||||||
read_state,
|
full_state,
|
||||||
read_state_changes
|
read_state_changes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
load_state (new_states: JSON_OBJECT)
|
load_state (new_states: JSON_OBJECT)
|
||||||
-- Select state stored with `control_name` as key
|
-- Select state stored with `control_name` as key
|
||||||
do
|
do
|
||||||
if attached {JSON_OBJECT} new_states.item (control_name) as new_state_obj then
|
if attached {JSON_OBJECT} new_states.item ("state") as new_state_obj then
|
||||||
set_state (new_state_obj)
|
set_state (new_state_obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -45,10 +45,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state (states: JSON_OBJECT)
|
full_state: JSON_OBJECT
|
||||||
-- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value
|
-- Return state of object
|
||||||
do
|
do
|
||||||
states.put (state, control_name)
|
create Result.make
|
||||||
|
Result.put (state, "state")
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state_changes (states: JSON_OBJECT)
|
read_state_changes (states: JSON_OBJECT)
|
||||||
@@ -62,6 +63,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
state: JSON_OBJECT
|
state: JSON_OBJECT
|
||||||
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
|
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
|
||||||
deferred
|
deferred
|
||||||
|
ensure
|
||||||
|
controls_not_defined: not (attached Result.item ("controls"))
|
||||||
end
|
end
|
||||||
|
|
||||||
state_changes: JSON_OBJECT
|
state_changes: JSON_OBJECT
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ inherit
|
|||||||
redefine
|
redefine
|
||||||
read_state_changes,
|
read_state_changes,
|
||||||
load_state,
|
load_state,
|
||||||
read_state
|
full_state
|
||||||
end
|
end
|
||||||
|
|
||||||
WSF_VALIDATABLE
|
WSF_VALIDATABLE
|
||||||
@@ -52,7 +52,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
-- Pass new_states to subcontrols
|
-- Pass new_states to subcontrols
|
||||||
do
|
do
|
||||||
Precursor (new_states)
|
Precursor (new_states)
|
||||||
value_control.load_state (new_states)
|
if attached {JSON_OBJECT} new_states.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state then
|
||||||
|
value_control.load_state (value_state)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set_state (new_state: JSON_OBJECT)
|
set_state (new_state: JSON_OBJECT)
|
||||||
@@ -61,11 +63,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
value_control.set_state (new_state)
|
value_control.set_state (new_state)
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state (states: JSON_OBJECT)
|
full_state: JSON_OBJECT
|
||||||
-- Read states in subcontrols
|
local
|
||||||
|
controls_state: JSON_OBJECT
|
||||||
do
|
do
|
||||||
Precursor (states)
|
Result := Precursor
|
||||||
value_control.read_state (states)
|
create controls_state.make
|
||||||
|
controls_state.put (value_control.full_state, value_control.control_name)
|
||||||
|
Result.put (controls_state, "controls")
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state_changes (states: JSON_OBJECT)
|
read_state_changes (states: JSON_OBJECT)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ inherit
|
|||||||
|
|
||||||
WSF_CONTROL
|
WSF_CONTROL
|
||||||
redefine
|
redefine
|
||||||
read_state,
|
full_state,
|
||||||
read_state_changes,
|
read_state_changes,
|
||||||
load_state
|
load_state
|
||||||
end
|
end
|
||||||
@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
|
|||||||
-- Initialize with specified control name and tag
|
-- Initialize with specified control name and tag
|
||||||
do
|
do
|
||||||
make_control (n, t)
|
make_control (n, t)
|
||||||
controls := create {ARRAYED_LIST [G]}.make(5);
|
controls := create {ARRAYED_LIST [G]}.make (5);
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||||
@@ -40,11 +40,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
-- Pass new_states to subcontrols
|
-- Pass new_states to subcontrols
|
||||||
do
|
do
|
||||||
Precursor (new_states)
|
Precursor (new_states)
|
||||||
across
|
if attached {JSON_OBJECT} new_states.item ("controls") as ct then
|
||||||
controls as c
|
across
|
||||||
loop
|
controls as c
|
||||||
if attached {WSF_CONTROL} c.item as cont then
|
loop
|
||||||
cont.load_state (new_states)
|
if attached {WSF_CONTROL} c.item as cont then
|
||||||
|
if attached {JSON_OBJECT} ct.item (cont.control_name) as value_state then
|
||||||
|
cont.load_state (value_state)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -54,17 +58,21 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state (states: JSON_OBJECT)
|
full_state: JSON_OBJECT
|
||||||
-- Read states in subcontrols
|
-- Read states in subcontrols
|
||||||
|
local
|
||||||
|
controls_state: JSON_OBJECT
|
||||||
do
|
do
|
||||||
Precursor (states)
|
Result := Precursor
|
||||||
|
create controls_state.make
|
||||||
across
|
across
|
||||||
controls as c
|
controls as c
|
||||||
loop
|
loop
|
||||||
if attached {WSF_CONTROL} c.item as cont then
|
if attached {WSF_CONTROL} c.item as cont then
|
||||||
cont.read_state (states)
|
controls_state.put (cont.full_state, cont.control_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Result.put (controls_state, "controls")
|
||||||
end
|
end
|
||||||
|
|
||||||
read_state_changes (states: JSON_OBJECT)
|
read_state_changes (states: JSON_OBJECT)
|
||||||
|
|||||||
@@ -47,21 +47,24 @@ feature -- Implementation
|
|||||||
local
|
local
|
||||||
event: detachable STRING
|
event: detachable STRING
|
||||||
event_parameter: detachable STRING
|
event_parameter: detachable STRING
|
||||||
control_name: detachable STRING
|
event_control_name: detachable STRING
|
||||||
states: detachable STRING
|
states: STRING
|
||||||
states_changes: JSON_OBJECT
|
states_changes: JSON_OBJECT
|
||||||
json_parser: JSON_PARSER
|
json_parser: JSON_PARSER
|
||||||
do
|
do
|
||||||
control_name := get_parameter ("control_name")
|
event_control_name := get_parameter ("control_name")
|
||||||
event := get_parameter ("event")
|
event := get_parameter ("event")
|
||||||
event_parameter := get_parameter ("event_parameter")
|
event_parameter := get_parameter ("event_parameter")
|
||||||
states := get_parameter ("states")
|
if attached event and attached event_control_name and attached control then
|
||||||
if attached event and attached control_name and attached control and attached states then
|
create states.make_empty
|
||||||
|
request.read_input_data_into (states)
|
||||||
create json_parser.make_parser (states)
|
create json_parser.make_parser (states)
|
||||||
if attached {JSON_OBJECT} json_parser.parse_json as sp then
|
if attached {JSON_OBJECT} json_parser.parse_json as sp then
|
||||||
control.load_state (sp)
|
if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then
|
||||||
|
control.load_state (value_state)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
control.handle_callback (control_name, event, event_parameter)
|
control.handle_callback (event_control_name, event, event_parameter)
|
||||||
create states_changes.make
|
create states_changes.make
|
||||||
control.read_state_changes (states_changes)
|
control.read_state_changes (states_changes)
|
||||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json; charset=ISO-8859-1"]>>)
|
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json; charset=ISO-8859-1"]>>)
|
||||||
@@ -82,16 +85,14 @@ feature -- Implementation
|
|||||||
data := "<html><head>"
|
data := "<html><head>"
|
||||||
data.append ("<link href=%"/bootstrap.min.css%" rel=%"stylesheet%">")
|
data.append ("<link href=%"/bootstrap.min.css%" rel=%"stylesheet%">")
|
||||||
data.append ("<link href=%"/widget.css%" rel=%"stylesheet%">")
|
data.append ("<link href=%"/widget.css%" rel=%"stylesheet%">")
|
||||||
data.append ("</head><body>")
|
data.append ("</head><body data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
|
||||||
data.append (control.render)
|
data.append (control.render)
|
||||||
data.append ("<script type=%"text/javascript%">window.states=")
|
|
||||||
create states.make
|
|
||||||
control.read_state (states)
|
|
||||||
data.append (states.representation)
|
|
||||||
data.append (";</script>")
|
|
||||||
data.append ("<script src=%"/jquery.min.js%"></script>")
|
data.append ("<script src=%"/jquery.min.js%"></script>")
|
||||||
data.append ("<script src=%"/typeahead.min.js%"></script>")
|
data.append ("<script src=%"/typeahead.min.js%"></script>")
|
||||||
data.append ("<script src=%"/widget.js%"></script>")
|
data.append ("<script src=%"/widget.js%"></script>")
|
||||||
|
data.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
|
||||||
|
data.append (full_state.representation)
|
||||||
|
data.append (");page.attach_events();});</script>")
|
||||||
data.append ("</body></html>")
|
data.append ("</body></html>")
|
||||||
create page.make
|
create page.make
|
||||||
page.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html; charset=ISO-8859-1"]>>)
|
page.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html; charset=ISO-8859-1"]>>)
|
||||||
@@ -99,6 +100,28 @@ feature -- Implementation
|
|||||||
response.send (page)
|
response.send (page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
control_name: STRING
|
||||||
|
do
|
||||||
|
Result := request.request_time_stamp.out
|
||||||
|
end
|
||||||
|
|
||||||
|
state: JSON_OBJECT
|
||||||
|
do
|
||||||
|
create Result.make
|
||||||
|
Result.put (create {JSON_STRING}.make_json (control_name), "id")
|
||||||
|
end
|
||||||
|
|
||||||
|
full_state: JSON_OBJECT
|
||||||
|
local
|
||||||
|
controls_state: JSON_OBJECT
|
||||||
|
do
|
||||||
|
create Result.make
|
||||||
|
create controls_state.make
|
||||||
|
controls_state.put (control.full_state, control.control_name)
|
||||||
|
Result.put (controls_state, "controls")
|
||||||
|
Result.put (state, "state")
|
||||||
|
end
|
||||||
|
|
||||||
get_parameter (key: STRING): detachable STRING
|
get_parameter (key: STRING): detachable STRING
|
||||||
-- Read query parameter as string
|
-- Read query parameter as string
|
||||||
local
|
local
|
||||||
|
|||||||
Reference in New Issue
Block a user