Change parameter type
This commit is contained in:
@@ -48,7 +48,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
|
|
||||||
feature --Event handling
|
feature --Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Handle goto/next/prev events
|
-- Handle goto/next/prev events
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname[1]) then
|
if Current.control_name.same_string (cname[1]) then
|
||||||
@@ -57,7 +57,7 @@ feature --Event handling
|
|||||||
elseif event.same_string ("prev") then
|
elseif event.same_string ("prev") then
|
||||||
datasource.set_page (datasource.page - 1)
|
datasource.set_page (datasource.page - 1)
|
||||||
elseif event.same_string ("goto") then
|
elseif event.same_string ("goto") then
|
||||||
if attached event_parameter as p and then attached p.to_integer as i then
|
if attached {STRING}event_parameter as p and then attached p.to_integer as i then
|
||||||
datasource.set_page (i)
|
datasource.set_page (i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ feature -- State
|
|||||||
|
|
||||||
feature -- Callback
|
feature -- Callback
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
Precursor {WSF_INPUT_CONTROL} (cname, event, event_parameter)
|
Precursor {WSF_INPUT_CONTROL} (cname, event, event_parameter)
|
||||||
if cname[1].same_string (control_name) and event.same_string ("autocomplete") then
|
if cname[1].same_string (control_name) and event.same_string ("autocomplete") then
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ feature --Event handling
|
|||||||
change_event := e
|
change_event := e
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname[1]) and attached change_event as cevent then
|
if Current.control_name.same_string (cname[1]) and attached change_event as cevent then
|
||||||
if event.same_string ("change") then
|
if event.same_string ("change") then
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ feature --Event handling
|
|||||||
change_event := e
|
change_event := e
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname [1]) and attached change_event as cevent then
|
if Current.control_name.same_string (cname [1]) and attached change_event as cevent then
|
||||||
if event.same_string ("change") then
|
if event.same_string ("change") then
|
||||||
@@ -58,6 +58,17 @@ feature --Event handling
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Upload
|
||||||
|
|
||||||
|
start_upload
|
||||||
|
local
|
||||||
|
upload: WSF_JSON_OBJECT
|
||||||
|
do
|
||||||
|
create upload.make
|
||||||
|
upload.put_string ("start_upload", "type")
|
||||||
|
actions.add (upload)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
value: detachable WSF_PENDING_FILE
|
value: detachable WSF_PENDING_FILE
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ feature --Event handling
|
|||||||
change_event := e
|
change_event := e
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname[1]) and attached change_event as cevent then
|
if Current.control_name.same_string (cname[1]) and attached change_event as cevent then
|
||||||
if event.same_string ("change") then
|
if event.same_string ("change") then
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ feature -- State handling
|
|||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
if cname[1].same_string (control_name) and event.same_string ("progress_fetch") then
|
if cname[1].same_string (control_name) and event.same_string ("progress_fetch") then
|
||||||
state_changes.put_integer (progress_value, "progress")
|
state_changes.put_integer (progress_value, "progress")
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ feature -- State handling
|
|||||||
|
|
||||||
feature -- Callback
|
feature -- Callback
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
-- Do nothing here
|
-- Do nothing here
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ feature --Event handling
|
|||||||
click_event := e
|
click_event := e
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname[1]) and attached click_event as cevent then
|
if Current.control_name.same_string (cname[1]) and attached click_event as cevent then
|
||||||
cevent.call (Void)
|
cevent.call (Void)
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ feature -- Actions
|
|||||||
show_alert (message: STRING)
|
show_alert (message: STRING)
|
||||||
--Start a modal window containg an other or the same page
|
--Start a modal window containg an other or the same page
|
||||||
local
|
local
|
||||||
modal: WSF_JSON_OBJECT
|
alert: WSF_JSON_OBJECT
|
||||||
do
|
do
|
||||||
create modal.make
|
create alert.make
|
||||||
modal.put_string ("show_alert", "type")
|
alert.put_string ("show_alert", "type")
|
||||||
modal.put_string (message, "message")
|
alert.put_string (message, "message")
|
||||||
actions.add (modal)
|
actions.add (alert)
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect (url: STRING)
|
redirect (url: STRING)
|
||||||
@@ -154,7 +154,7 @@ feature -- Rendering
|
|||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Method called if any callback received. In this method you can route the callback to the event handler
|
-- Method called if any callback received. In this method you can route the callback to the event handler
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Pass callback to subcontrols
|
-- Pass callback to subcontrols
|
||||||
do
|
do
|
||||||
if cname [1].same_string (control_name) then
|
if cname [1].same_string (control_name) then
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
|
|
||||||
feature --Event handling
|
feature --Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Pass callback to subcontrols
|
-- Pass callback to subcontrols
|
||||||
do
|
do
|
||||||
if equal (cname [1], control_name) then
|
if equal (cname [1], control_name) then
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ feature -- Implementation
|
|||||||
-- If request is not a callback. Run process and render the html page
|
-- If request is not a callback. Run process and render the html page
|
||||||
local
|
local
|
||||||
event: detachable STRING
|
event: detachable STRING
|
||||||
event_parameter: detachable STRING
|
event_parameter: detachable ANY
|
||||||
event_control_name: detachable STRING
|
event_control_name: detachable STRING
|
||||||
states: STRING
|
states: STRING
|
||||||
states_changes: WSF_JSON_OBJECT
|
states_changes: WSF_JSON_OBJECT
|
||||||
@@ -74,6 +74,11 @@ feature -- Implementation
|
|||||||
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
|
||||||
set_state (sp)
|
set_state (sp)
|
||||||
|
else
|
||||||
|
if attached request.form_parameter ("file") as o then
|
||||||
|
response.put_string (o.name)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
handle_callback (event_control_name.split ('-'), event, event_parameter)
|
handle_callback (event_control_name.split ('-'), event, event_parameter)
|
||||||
create states_changes.make
|
create states_changes.make
|
||||||
@@ -147,7 +152,7 @@ feature -- Implementation
|
|||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Forward callback to control
|
-- Forward callback to control
|
||||||
do
|
do
|
||||||
control.handle_callback (cname, event, event_parameter)
|
control.handle_callback (cname, event, event_parameter)
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ feature
|
|||||||
end
|
end
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
-- Pass callback to subcontrols
|
-- Pass callback to subcontrols
|
||||||
do
|
do
|
||||||
across
|
across
|
||||||
|
|||||||
@@ -180,6 +180,12 @@ class WSF_CONTROL
|
|||||||
process_actions: (actions)->
|
process_actions: (actions)->
|
||||||
for action in actions
|
for action in actions
|
||||||
try
|
try
|
||||||
|
fn = null
|
||||||
|
#Check if action exists in class then check global
|
||||||
|
if @[action.type]?
|
||||||
|
fn = @[action.type]
|
||||||
|
fn.call(@, action)
|
||||||
|
else
|
||||||
fn = eval(action.type)
|
fn = eval(action.type)
|
||||||
fn(action)
|
fn(action)
|
||||||
catch e
|
catch e
|
||||||
@@ -187,6 +193,8 @@ class WSF_CONTROL
|
|||||||
|
|
||||||
process_update: (new_states)->
|
process_update: (new_states)->
|
||||||
try
|
try
|
||||||
|
if new_states.actions?
|
||||||
|
@process_actions(new_states.actions)
|
||||||
if new_states[@control_name]?
|
if new_states[@control_name]?
|
||||||
@update(new_states[@control_name])
|
@update(new_states[@control_name])
|
||||||
for control in @controls
|
for control in @controls
|
||||||
@@ -289,8 +297,6 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL
|
|||||||
@load_subcontrols()
|
@load_subcontrols()
|
||||||
|
|
||||||
process_update: (new_states)->
|
process_update: (new_states)->
|
||||||
if new_states.actions?
|
|
||||||
@process_actions(new_states.actions)
|
|
||||||
for control in @controls
|
for control in @controls
|
||||||
if control?
|
if control?
|
||||||
control.process_update(new_states)
|
control.process_update(new_states)
|
||||||
@@ -361,6 +367,50 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
|||||||
@$el.val(state.text)
|
@$el.val(state.text)
|
||||||
|
|
||||||
class WSF_FILE_CONTROL extends WSF_CONTROL
|
class WSF_FILE_CONTROL extends WSF_CONTROL
|
||||||
|
constructor: ()->
|
||||||
|
super
|
||||||
|
@uploading = false
|
||||||
|
start_upload: ()->
|
||||||
|
if @uploading
|
||||||
|
return
|
||||||
|
@uploading = true
|
||||||
|
@$el.hide()
|
||||||
|
@progressbar = $ """<div class="progress"><div rstyle="width: 10%;" class="progress-bar"></div></div>"""
|
||||||
|
@$el.parent().append(@progressbar)
|
||||||
|
|
||||||
|
formData = new FormData();
|
||||||
|
action = @callback_url
|
||||||
|
control_name: @control_name
|
||||||
|
event: "uploadfile"
|
||||||
|
event_parameter: ""
|
||||||
|
file = @$el[0].files[0];
|
||||||
|
formData.append('our-file', file)
|
||||||
|
formData.append('state', JSON.stringify(@get_context_state()))
|
||||||
|
@sendXHRequest(formData, action)
|
||||||
|
|
||||||
|
sendXHRequest: (formData, uri)->
|
||||||
|
#Get an XMLHttpRequest instance
|
||||||
|
xhr = new XMLHttpRequest();
|
||||||
|
self = @
|
||||||
|
onprogressHandler = (evt)->
|
||||||
|
percent = evt.loaded/evt.total*100
|
||||||
|
self.progressbar.find('.progress-bar').css {'width':percent+"%"}
|
||||||
|
onloadHandler = (evt)->
|
||||||
|
alert "DONE"
|
||||||
|
xhr.upload.addEventListener('progress', onprogressHandler, false);
|
||||||
|
xhr.upload.addEventListener('load', onloadHandler, false);
|
||||||
|
|
||||||
|
###Set up events
|
||||||
|
xhr.upload.addEventListener('loadstart', onloadstartHandler, false);
|
||||||
|
|
||||||
|
|
||||||
|
xhr.addEventListener('readystatechange', onreadystatechangeHandler, false);
|
||||||
|
###
|
||||||
|
#Set up request
|
||||||
|
xhr.open('POST', uri, true);
|
||||||
|
#Fire!
|
||||||
|
xhr.send(formData);
|
||||||
|
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
super
|
super
|
||||||
self = @
|
self = @
|
||||||
|
|||||||
@@ -298,8 +298,14 @@ WSF_CONTROL = (function() {
|
|||||||
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
||||||
action = actions[_i];
|
action = actions[_i];
|
||||||
try {
|
try {
|
||||||
|
fn = null;
|
||||||
|
if (this[action.type] != null) {
|
||||||
|
fn = this[action.type];
|
||||||
|
_results.push(fn.call(this, action));
|
||||||
|
} else {
|
||||||
fn = eval(action.type);
|
fn = eval(action.type);
|
||||||
_results.push(fn(action));
|
_results.push(fn(action));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_results.push(console.log("Failed preforming action " + action.type));
|
_results.push(console.log("Failed preforming action " + action.type));
|
||||||
}
|
}
|
||||||
@@ -310,6 +316,9 @@ WSF_CONTROL = (function() {
|
|||||||
WSF_CONTROL.prototype.process_update = function(new_states) {
|
WSF_CONTROL.prototype.process_update = function(new_states) {
|
||||||
var control, _i, _len, _ref;
|
var control, _i, _len, _ref;
|
||||||
try {
|
try {
|
||||||
|
if (new_states.actions != null) {
|
||||||
|
this.process_actions(new_states.actions);
|
||||||
|
}
|
||||||
if (new_states[this.control_name] != null) {
|
if (new_states[this.control_name] != null) {
|
||||||
this.update(new_states[this.control_name]);
|
this.update(new_states[this.control_name]);
|
||||||
_ref = this.controls;
|
_ref = this.controls;
|
||||||
@@ -453,9 +462,6 @@ WSF_PAGE_CONTROL = (function(_super) {
|
|||||||
|
|
||||||
WSF_PAGE_CONTROL.prototype.process_update = function(new_states) {
|
WSF_PAGE_CONTROL.prototype.process_update = function(new_states) {
|
||||||
var control, _i, _len, _ref;
|
var control, _i, _len, _ref;
|
||||||
if (new_states.actions != null) {
|
|
||||||
this.process_actions(new_states.actions);
|
|
||||||
}
|
|
||||||
_ref = this.controls;
|
_ref = this.controls;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
control = _ref[_i];
|
control = _ref[_i];
|
||||||
@@ -601,9 +607,58 @@ WSF_FILE_CONTROL = (function(_super) {
|
|||||||
__extends(WSF_FILE_CONTROL, _super);
|
__extends(WSF_FILE_CONTROL, _super);
|
||||||
|
|
||||||
function WSF_FILE_CONTROL() {
|
function WSF_FILE_CONTROL() {
|
||||||
return WSF_FILE_CONTROL.__super__.constructor.apply(this, arguments);
|
WSF_FILE_CONTROL.__super__.constructor.apply(this, arguments);
|
||||||
|
this.uploading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSF_FILE_CONTROL.prototype.start_upload = function() {
|
||||||
|
var action, file, formData;
|
||||||
|
if (this.uploading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.uploading = true;
|
||||||
|
this.$el.hide();
|
||||||
|
this.progressbar = $("<div class=\"progress\"><div rstyle=\"width: 10%;\" class=\"progress-bar\"></div></div>");
|
||||||
|
this.$el.parent().append(this.progressbar);
|
||||||
|
formData = new FormData();
|
||||||
|
action = this.callback_url({
|
||||||
|
control_name: this.control_name,
|
||||||
|
event: "uploadfile",
|
||||||
|
event_parameter: ""
|
||||||
|
});
|
||||||
|
file = this.$el[0].files[0];
|
||||||
|
formData.append('our-file', file);
|
||||||
|
formData.append('state', JSON.stringify(this.get_context_state()));
|
||||||
|
return this.sendXHRequest(formData, action);
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_FILE_CONTROL.prototype.sendXHRequest = function(formData, uri) {
|
||||||
|
var onloadHandler, onprogressHandler, self, xhr;
|
||||||
|
xhr = new XMLHttpRequest();
|
||||||
|
self = this;
|
||||||
|
onprogressHandler = function(evt) {
|
||||||
|
var percent;
|
||||||
|
percent = evt.loaded / evt.total * 100;
|
||||||
|
return self.progressbar.find('.progress-bar').css({
|
||||||
|
'width': percent + "%"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
onloadHandler = function(evt) {
|
||||||
|
return alert("DONE");
|
||||||
|
};
|
||||||
|
xhr.upload.addEventListener('progress', onprogressHandler, false);
|
||||||
|
xhr.upload.addEventListener('load', onloadHandler, false);
|
||||||
|
/*Set up events
|
||||||
|
xhr.upload.addEventListener('loadstart', onloadstartHandler, false);
|
||||||
|
|
||||||
|
|
||||||
|
xhr.addEventListener('readystatechange', onreadystatechangeHandler, false);
|
||||||
|
*/
|
||||||
|
|
||||||
|
xhr.open('POST', uri, true);
|
||||||
|
return xhr.send(formData);
|
||||||
|
};
|
||||||
|
|
||||||
WSF_FILE_CONTROL.prototype.attach_events = function() {
|
WSF_FILE_CONTROL.prototype.attach_events = function() {
|
||||||
var self;
|
var self;
|
||||||
WSF_FILE_CONTROL.__super__.attach_events.apply(this, arguments);
|
WSF_FILE_CONTROL.__super__.attach_events.apply(this, arguments);
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ feature
|
|||||||
do
|
do
|
||||||
form.validate
|
form.validate
|
||||||
if form.is_valid then
|
if form.is_valid then
|
||||||
|
filebox.start_upload
|
||||||
--progress.set_progress ((textbox1.text.to_integer_64 / textbox2.text.to_integer_64 * 100).ceiling)
|
--progress.set_progress ((textbox1.text.to_integer_64 / textbox2.text.to_integer_64 * 100).ceiling)
|
||||||
text := textbox1.text + " + " + textbox2.text + " = " + (textbox1.text.to_integer_64 + textbox2.text.to_integer_64).out
|
text := textbox1.text + " + " + textbox2.text + " = " + (textbox1.text.to_integer_64 + textbox2.text.to_integer_64).out
|
||||||
text.append ("<ul>")
|
text.append ("<ul>")
|
||||||
|
|||||||
Reference in New Issue
Block a user