Introduce actions
First working modal
This commit is contained in:
@@ -87,6 +87,7 @@ feature -- Router and Filter
|
||||
-- this way, it handles the caching and so on
|
||||
map_agent_uri ("/widget.js", agent load_file("widget.js", ?, ?), Void)
|
||||
map_agent_uri ("/jquery.min.js", agent load_file("jquery.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/bootstrap.min.js", agent load_file("bootstrap.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/typeahead.min.js", agent load_file("typeahead.min.js", ?, ?), Void)
|
||||
map_agent_uri ("/widget.css", agent load_file("widget.css", ?, ?), Void)
|
||||
map_agent_uri ("/bootstrap.min.css", agent load_file("bootstrap.min.css", ?, ?), Void)
|
||||
|
||||
@@ -24,7 +24,9 @@ feature
|
||||
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
||||
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
||||
navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"#%"", "About"))
|
||||
container.add_control (navbar)
|
||||
if not attached get_parameter ("ajax") then
|
||||
container.add_control (navbar)
|
||||
end
|
||||
control := container
|
||||
end
|
||||
|
||||
|
||||
6
examples/widgetapp/bootstrap.min.js
vendored
Normal file
6
examples/widgetapp/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -69,27 +69,37 @@ feature
|
||||
button1.set_click_event (agent handle_click)
|
||||
button1.add_class ("col-lg-offset-2")
|
||||
form.add_control (button1)
|
||||
--Button 2
|
||||
create button2.make_button ("sample_button2", "Start Modal Grid")
|
||||
button2.set_click_event (agent handle_click2)
|
||||
button2.add_class ("col-lg-offset-2")
|
||||
form.add_control (button2)
|
||||
--Result
|
||||
create result_html.make_html ("txtBox3", "p", "")
|
||||
form.add_control (create {WSF_FORM_ELEMENT_CONTROL [STRING]}.make_form_element ("Result", result_html))
|
||||
container.add_control (form)
|
||||
|
||||
--Progress bar
|
||||
container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h4","","Autoincrementing progressbar"))
|
||||
container.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h4", "", "Autoincrementing progressbar"))
|
||||
create source.make
|
||||
create progress.make_progress_with_source ("progress1", source)
|
||||
source.set_control (progress)
|
||||
progress.set_isolation(true)
|
||||
progress.set_isolation (true)
|
||||
container.add_control (progress)
|
||||
end
|
||||
|
||||
handle_click2
|
||||
do
|
||||
start_modal ("/")
|
||||
end
|
||||
|
||||
handle_click
|
||||
local
|
||||
text: STRING
|
||||
do
|
||||
form.validate
|
||||
if form.is_valid then
|
||||
--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.append ("<ul>")
|
||||
across
|
||||
@@ -100,7 +110,7 @@ feature
|
||||
text.append ("</ul>")
|
||||
result_html.set_html (text)
|
||||
else
|
||||
result_html.set_html ("VALIDATION ERROR")
|
||||
show_alert ("VALIDATION ERROR")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -110,6 +120,8 @@ feature
|
||||
|
||||
button1: WSF_BUTTON_CONTROL
|
||||
|
||||
button2: WSF_BUTTON_CONTROL
|
||||
|
||||
textbox1: WSF_INPUT_CONTROL
|
||||
|
||||
textbox2: WSF_INPUT_CONTROL
|
||||
|
||||
@@ -93,6 +93,13 @@ class WSF_CONTROL
|
||||
|
||||
update: (state)->
|
||||
return
|
||||
process_actions: (actions)->
|
||||
for action in actions
|
||||
try
|
||||
fn = eval(action.type)
|
||||
fn(action)
|
||||
catch e
|
||||
console.log "Failed preforming action #{action.type}"
|
||||
|
||||
process_update: (new_states)->
|
||||
if new_states[@control_name]?
|
||||
@@ -136,6 +143,8 @@ class WSF_CONTROL
|
||||
cache: no
|
||||
.done (new_states)->
|
||||
#Update all classes
|
||||
if new_states.actions?
|
||||
self.process_actions(new_states.actions)
|
||||
self.process_update(new_states)
|
||||
#Simple event listener
|
||||
|
||||
@@ -165,7 +174,7 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL
|
||||
@url = @state['url']
|
||||
@url_params = jQuery.unparam(@state['url_params'])
|
||||
@load_subcontrols()
|
||||
|
||||
|
||||
wrap : (cname,state)->
|
||||
state
|
||||
|
||||
@@ -398,4 +407,37 @@ class WSF_REPEATER_CONTROL extends WSF_CONTROL
|
||||
@$el.find('.repeater_content').html(state._body)
|
||||
console.log state._body
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### actions
|
||||
|
||||
show_alert = (action)->
|
||||
alert(action.message)
|
||||
|
||||
start_modal = (action)->
|
||||
modal = $("""<div class="modal fade">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">Modal title</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->""")
|
||||
modal.appendTo('body')
|
||||
modal.modal()
|
||||
$.get( action.url, { ajax: 1 } )
|
||||
.done (data) ->
|
||||
modal.find('.modal-body').append(data)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, template, tmpl,
|
||||
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, show_alert, start_modal, template, tmpl,
|
||||
__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; };
|
||||
|
||||
@@ -174,6 +174,21 @@ WSF_CONTROL = (function() {
|
||||
|
||||
WSF_CONTROL.prototype.update = function(state) {};
|
||||
|
||||
WSF_CONTROL.prototype.process_actions = function(actions) {
|
||||
var action, fn, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
||||
action = actions[_i];
|
||||
try {
|
||||
fn = eval(action.type);
|
||||
_results.push(fn(action));
|
||||
} catch (e) {
|
||||
_results.push(console.log("Failed preforming action " + action.type));
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
WSF_CONTROL.prototype.process_update = function(new_states) {
|
||||
var control, _i, _len, _ref, _results;
|
||||
if (new_states[this.control_name] != null) {
|
||||
@@ -238,6 +253,9 @@ WSF_CONTROL = (function() {
|
||||
contentType: 'application/json',
|
||||
cache: false
|
||||
}).done(function(new_states) {
|
||||
if (new_states.actions != null) {
|
||||
self.process_actions(new_states.actions);
|
||||
}
|
||||
return self.process_update(new_states);
|
||||
});
|
||||
};
|
||||
@@ -731,3 +749,19 @@ WSF_REPEATER_CONTROL = (function(_super) {
|
||||
return WSF_REPEATER_CONTROL;
|
||||
|
||||
})(WSF_CONTROL);
|
||||
|
||||
show_alert = function(action) {
|
||||
return alert(action.message);
|
||||
};
|
||||
|
||||
start_modal = function(action) {
|
||||
var modal;
|
||||
modal = $("<div class=\"modal fade\">\n<div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>\n <h4 class=\"modal-title\">Modal title</h4>\n </div>\n <div class=\"modal-body\">\n \n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n <button type=\"button\" class=\"btn btn-primary\">Save changes</button>\n </div>\n </div><!-- /.modal-content -->\n</div><!-- /.modal-dialog -->\n</div><!-- /.modal -->");
|
||||
modal.appendTo('body');
|
||||
modal.modal();
|
||||
return $.get(action.url, {
|
||||
ajax: 1
|
||||
}).done(function(data) {
|
||||
return modal.find('.modal-body').append(data);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user