Add HTML control
This commit is contained in:
@@ -29,7 +29,7 @@ feature
|
|||||||
create textbox1.make_input ("txtBox1", "1")
|
create textbox1.make_input ("txtBox1", "1")
|
||||||
create textbox2.make_input ("txtBox2", "2")
|
create textbox2.make_input ("txtBox2", "2")
|
||||||
create button1.make_button ("sample_button1", "SUM")
|
create button1.make_button ("sample_button1", "SUM")
|
||||||
create textbox_result.make_textarea ("txtBox3", "")
|
create textbox_result.make_html ("txtBox3","p", "")
|
||||||
button1.set_click_event (agent handle_click)
|
button1.set_click_event (agent handle_click)
|
||||||
button1.add_class ("col-lg-offset-2")
|
button1.add_class ("col-lg-offset-2")
|
||||||
create form.make_form_control ("panel")
|
create form.make_form_control ("panel")
|
||||||
@@ -61,9 +61,9 @@ feature
|
|||||||
across
|
across
|
||||||
cklist.value as s
|
cklist.value as s
|
||||||
loop
|
loop
|
||||||
text.append ("%N-" + s.item)
|
text.append ("<br />-" + s.item)
|
||||||
end
|
end
|
||||||
textbox_result.set_text (text)
|
textbox_result.set_html (text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -80,6 +80,6 @@ feature
|
|||||||
|
|
||||||
cklist: WSF_CHECKBOX_LIST_CONTROL
|
cklist: WSF_CHECKBOX_LIST_CONTROL
|
||||||
|
|
||||||
textbox_result: WSF_TEXTAREA_CONTROL
|
textbox_result: WSF_HTML_CONTROL
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -119,6 +119,26 @@ class WSF_TEXTAREA_CONTROL extends WSF_CONTROL
|
|||||||
window.states[@control_name]['text'] = state.text
|
window.states[@control_name]['text'] = state.text
|
||||||
@$el.val(state.text)
|
@$el.val(state.text)
|
||||||
|
|
||||||
|
class WSF_TEXTAREA_CONTROL extends WSF_CONTROL
|
||||||
|
attach_events: () ->
|
||||||
|
self = @
|
||||||
|
@$el.change () ->
|
||||||
|
self.change()
|
||||||
|
|
||||||
|
change: () ->
|
||||||
|
window.states[@control_name]['text'] = @$el.val()
|
||||||
|
if window.states[@control_name]['callback_change']
|
||||||
|
trigger_callback(@control_name, 'change')
|
||||||
|
@trigger('change')
|
||||||
|
|
||||||
|
value:()->
|
||||||
|
return @$el.val()
|
||||||
|
|
||||||
|
update: (state) ->
|
||||||
|
if state.text?
|
||||||
|
window.states[@control_name]['text'] = state.text
|
||||||
|
@$el.val(state.text)
|
||||||
|
|
||||||
class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
class WSF_CHECKBOX_CONTROL extends WSF_CONTROL
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
self = @
|
self = @
|
||||||
@@ -185,6 +205,16 @@ class WSF_FORM_ELEMENT_CONTROL extends WSF_CONTROL
|
|||||||
value: ()->
|
value: ()->
|
||||||
@value_control.value()
|
@value_control.value()
|
||||||
|
|
||||||
|
class WSF_HTML_CONTROL extends WSF_CONTROL
|
||||||
|
|
||||||
|
value:()->
|
||||||
|
return @$el.html()
|
||||||
|
|
||||||
|
update: (state) ->
|
||||||
|
if state.html?
|
||||||
|
window.states[@control_name]['html'] = state.html
|
||||||
|
@$el.html(state.html)
|
||||||
|
|
||||||
#map class name to effective class
|
#map class name to effective class
|
||||||
typemap =
|
typemap =
|
||||||
"WSF_BUTTON_CONTROL":WSF_BUTTON_CONTROL
|
"WSF_BUTTON_CONTROL":WSF_BUTTON_CONTROL
|
||||||
@@ -192,6 +222,7 @@ typemap =
|
|||||||
"WSF_TEXTAREA_CONTROL":WSF_TEXTAREA_CONTROL
|
"WSF_TEXTAREA_CONTROL":WSF_TEXTAREA_CONTROL
|
||||||
"WSF_CHECKBOX_CONTROL":WSF_CHECKBOX_CONTROL
|
"WSF_CHECKBOX_CONTROL":WSF_CHECKBOX_CONTROL
|
||||||
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL
|
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL
|
||||||
|
"WSF_HTML_CONTROL": WSF_HTML_CONTROL
|
||||||
|
|
||||||
#create a js class for each control
|
#create a js class for each control
|
||||||
for name,state of window.states
|
for name,state of window.states
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript 1.6.1
|
// Generated by CoffeeScript 1.6.1
|
||||||
(function() {
|
(function() {
|
||||||
var $el, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_INPUT_CONTROL, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, controls, name, state, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
|
var $el, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, controls, name, state, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
|
||||||
__hasProp = {}.hasOwnProperty,
|
__hasProp = {}.hasOwnProperty,
|
||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||||
|
|
||||||
@@ -221,6 +221,45 @@
|
|||||||
|
|
||||||
})(WSF_CONTROL);
|
})(WSF_CONTROL);
|
||||||
|
|
||||||
|
WSF_TEXTAREA_CONTROL = (function(_super) {
|
||||||
|
|
||||||
|
__extends(WSF_TEXTAREA_CONTROL, _super);
|
||||||
|
|
||||||
|
function WSF_TEXTAREA_CONTROL() {
|
||||||
|
return WSF_TEXTAREA_CONTROL.__super__.constructor.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
WSF_TEXTAREA_CONTROL.prototype.attach_events = function() {
|
||||||
|
var self;
|
||||||
|
self = this;
|
||||||
|
return this.$el.change(function() {
|
||||||
|
return self.change();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_TEXTAREA_CONTROL.prototype.change = function() {
|
||||||
|
window.states[this.control_name]['text'] = this.$el.val();
|
||||||
|
if (window.states[this.control_name]['callback_change']) {
|
||||||
|
trigger_callback(this.control_name, 'change');
|
||||||
|
}
|
||||||
|
return this.trigger('change');
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_TEXTAREA_CONTROL.prototype.value = function() {
|
||||||
|
return this.$el.val();
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_TEXTAREA_CONTROL.prototype.update = function(state) {
|
||||||
|
if (state.text != null) {
|
||||||
|
window.states[this.control_name]['text'] = state.text;
|
||||||
|
return this.$el.val(state.text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return WSF_TEXTAREA_CONTROL;
|
||||||
|
|
||||||
|
})(WSF_CONTROL);
|
||||||
|
|
||||||
WSF_CHECKBOX_CONTROL = (function(_super) {
|
WSF_CHECKBOX_CONTROL = (function(_super) {
|
||||||
|
|
||||||
__extends(WSF_CHECKBOX_CONTROL, _super);
|
__extends(WSF_CHECKBOX_CONTROL, _super);
|
||||||
@@ -329,12 +368,36 @@
|
|||||||
|
|
||||||
})(WSF_CONTROL);
|
})(WSF_CONTROL);
|
||||||
|
|
||||||
|
WSF_HTML_CONTROL = (function(_super) {
|
||||||
|
|
||||||
|
__extends(WSF_HTML_CONTROL, _super);
|
||||||
|
|
||||||
|
function WSF_HTML_CONTROL() {
|
||||||
|
return WSF_HTML_CONTROL.__super__.constructor.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
WSF_HTML_CONTROL.prototype.value = function() {
|
||||||
|
return this.$el.html();
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_HTML_CONTROL.prototype.update = function(state) {
|
||||||
|
if (state.html != null) {
|
||||||
|
window.states[this.control_name]['html'] = state.html;
|
||||||
|
return this.$el.html(state.html);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return WSF_HTML_CONTROL;
|
||||||
|
|
||||||
|
})(WSF_CONTROL);
|
||||||
|
|
||||||
typemap = {
|
typemap = {
|
||||||
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL,
|
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL,
|
||||||
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL,
|
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL,
|
||||||
"WSF_TEXTAREA_CONTROL": WSF_TEXTAREA_CONTROL,
|
"WSF_TEXTAREA_CONTROL": WSF_TEXTAREA_CONTROL,
|
||||||
"WSF_CHECKBOX_CONTROL": WSF_CHECKBOX_CONTROL,
|
"WSF_CHECKBOX_CONTROL": WSF_CHECKBOX_CONTROL,
|
||||||
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL
|
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL,
|
||||||
|
"WSF_HTML_CONTROL": WSF_HTML_CONTROL
|
||||||
};
|
};
|
||||||
|
|
||||||
_ref = window.states;
|
_ref = window.states;
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ feature {NONE}
|
|||||||
if attached {WSF_INPUT_CONTROL} c or attached {WSF_TEXTAREA_CONTROL} c then
|
if attached {WSF_INPUT_CONTROL} c or attached {WSF_TEXTAREA_CONTROL} c then
|
||||||
c.add_class ("form-control")
|
c.add_class ("form-control")
|
||||||
end
|
end
|
||||||
|
if attached {WSF_HTML_CONTROL} c then
|
||||||
|
c.add_class ("form-control-static")
|
||||||
|
end
|
||||||
|
|
||||||
value_control := c
|
value_control := c
|
||||||
validators := v
|
validators := v
|
||||||
label := a_label
|
label := a_label
|
||||||
|
|||||||
74
library/server/wsf_html/webcontrol/wsf_html_control.e
Normal file
74
library/server/wsf_html/webcontrol/wsf_html_control.e
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {WSF_html_CONTROL}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
WSF_HTML_CONTROL
|
||||||
|
|
||||||
|
inherit
|
||||||
|
|
||||||
|
WSF_VALUE_CONTROL [STRING]
|
||||||
|
|
||||||
|
create
|
||||||
|
make_html
|
||||||
|
|
||||||
|
feature {NONE}
|
||||||
|
|
||||||
|
make_html (n,t,v: STRING)
|
||||||
|
do
|
||||||
|
make (n, t)
|
||||||
|
html := v
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||||
|
|
||||||
|
set_state (new_state: JSON_OBJECT)
|
||||||
|
-- Restore html from json
|
||||||
|
do
|
||||||
|
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("html")) as new_html then
|
||||||
|
html := new_html.unescaped_string_32
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
state: JSON_OBJECT
|
||||||
|
-- Return state which contains the current html and if there is an event handle attached
|
||||||
|
do
|
||||||
|
create Result.make
|
||||||
|
Result.put (create {JSON_STRING}.make_json (html), create {JSON_STRING}.make_json ("html"))
|
||||||
|
end
|
||||||
|
|
||||||
|
feature --EVENT HANDLING
|
||||||
|
|
||||||
|
handle_callback (cname: STRING; event: STRING)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Implementation
|
||||||
|
|
||||||
|
render: STRING
|
||||||
|
do
|
||||||
|
Result := render_tag (html,"")
|
||||||
|
end
|
||||||
|
|
||||||
|
set_html (t: STRING)
|
||||||
|
do
|
||||||
|
if not t.is_equal (html) then
|
||||||
|
html := t
|
||||||
|
state_changes.replace (create {JSON_STRING}.make_json (html), create {JSON_STRING}.make_json ("html"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
value: STRING
|
||||||
|
do
|
||||||
|
Result := html
|
||||||
|
end
|
||||||
|
|
||||||
|
feature
|
||||||
|
|
||||||
|
html: STRING
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user