Added dropdown control

This commit is contained in:
severin
2013-11-02 22:36:21 +01:00
parent 10b950a7e7
commit b70450cfe9
4 changed files with 969 additions and 914 deletions

View File

@@ -11,17 +11,61 @@ inherit
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control make as make_multi_control,
make_with_tag_name as make_multi_control_with_tag_name
end end
create create
make make, make_with_tag_name
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (n: STRING) make (n, title: STRING)
-- Make a dropdown control with div tag name and specified menu title
do do
make_multi_control (n) make_with_tag_name (n, title, "div")
end end
make_with_tag_name (n, title, t: STRING)
-- Make a dropdown control with specified tag name and menu title (such as li)
do
make_multi_control_with_tag_name (n, t)
add_class ("dropdown")
create {WSF_BASIC_CONTROL} dropdown_toggle.make_with_body_class ("a", "data-toggle=%"dropdown%" href=%"#%"", "dropdown-toggle", title + " <strong class=%"caret%"></strong>")
create dropdown_menu.make_with_tag_name (n + "_menu", "ul")
dropdown_menu.add_class ("dropdown-menu")
add_control (dropdown_toggle)
add_control (dropdown_menu)
end
feature -- Change
add_item (c: WSF_STATELESS_CONTROL)
local
li: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
create li.make_with_tag_name (control_name + "_item" + dropdown_menu.controls.count.out, "li")
li.add_control (c)
dropdown_menu.add_control (li)
end
add_link_item (label, link: STRING)
local
c: WSF_BASIC_CONTROL
do
create c.make_with_body ("a", "href=%"" + link + "%"", label)
add_item (c)
end
add_divider
do
dropdown_menu.add_control (create {WSF_BASIC_CONTROL}.make_with_body_class ("li", "", "divider", ""))
end
feature -- Properties
dropdown_toggle: WSF_STATELESS_CONTROL
dropdown_menu: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
end end

View File

@@ -10,16 +10,18 @@ class
inherit inherit
WSF_STATELESS_CONTROL WSF_STATELESS_CONTROL
rename
make as make_stateless_control
redefine redefine
attributes attributes
end end
create create
make_control, make_with_body, make_with_body_class make, make_with_body, make_with_body_class
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_control (t: STRING) make (t: STRING)
-- Initialize -- Initialize
do do
make_with_body_class (t, "", "", "") make_with_body_class (t, "", "", "")
@@ -28,7 +30,7 @@ feature {NONE} -- Initialization
make_with_body (t, attr, b: STRING) make_with_body (t, attr, b: STRING)
-- Initialize with specific attributes and body -- Initialize with specific attributes and body
do do
make (t) make_stateless_control (t)
attributes := attr attributes := attr
body := b body := b
end end

View File

@@ -1,11 +1,12 @@
// Generated by CoffeeScript 1.6.1 // Generated by CoffeeScript 1.6.1
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_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_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, show_alert, start_modal, start_modal_big, template, tmpl, (function() {
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_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_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, show_alert, start_modal, start_modal_big, template, tmpl,
__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; };
cache = {}; cache = {};
jQuery.cachedAsset = function(url, options) { jQuery.cachedAsset = function(url, options) {
var head, onload, script, success, successful, timeoutHandle; var head, onload, script, success, successful, timeoutHandle;
if (/\.css$/.test(url)) { if (/\.css$/.test(url)) {
$("<link/>", { $("<link/>", {
@@ -64,9 +65,9 @@ jQuery.cachedAsset = function(url, options) {
} }
}; };
} }
}; };
jQuery.unparam = function(value) { jQuery.unparam = function(value) {
var i, l, pair, params, pieces; var i, l, pair, params, pieces;
params = {}; params = {};
pieces = value.split("&"); pieces = value.split("&");
@@ -81,9 +82,9 @@ jQuery.unparam = function(value) {
i++; i++;
} }
return params; return params;
}; };
template = tmpl = function(str, data) { template = tmpl = function(str, data) {
var fn; var fn;
fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');")); fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');"));
if (data) { if (data) {
@@ -91,19 +92,19 @@ template = tmpl = function(str, data) {
} else { } else {
return fn; return fn;
} }
}; };
Mini = { Mini = {
compile: function(t) { compile: function(t) {
return { return {
render: template(t) render: template(t)
}; };
} }
}; };
loaded = {}; loaded = {};
lazy_load = function(requirements, fn, that) { lazy_load = function(requirements, fn, that) {
if (requirements.length === 0) { if (requirements.length === 0) {
return function() { return function() {
var a; var a;
@@ -137,9 +138,9 @@ lazy_load = function(requirements, fn, that) {
} }
return done(); return done();
}; };
}; };
build_control = function(control_name, state, control) { build_control = function(control_name, state, control) {
var $el, type, typeclass; var $el, type, typeclass;
$el = control.$el.find('[data-name=' + control_name + ']'); $el = control.$el.find('[data-name=' + control_name + ']');
type = $el.data('type'); type = $el.data('type');
@@ -153,9 +154,9 @@ build_control = function(control_name, state, control) {
return new typeclass(control, $el, control_name, state); return new typeclass(control, $el, control_name, state);
} }
return null; return null;
}; };
WSF_VALIDATOR = (function() { WSF_VALIDATOR = (function() {
function WSF_VALIDATOR(parent_control, settings) { function WSF_VALIDATOR(parent_control, settings) {
this.parent_control = parent_control; this.parent_control = parent_control;
@@ -170,9 +171,9 @@ WSF_VALIDATOR = (function() {
return WSF_VALIDATOR; return WSF_VALIDATOR;
})(); })();
WSF_REGEXP_VALIDATOR = (function(_super) { WSF_REGEXP_VALIDATOR = (function(_super) {
__extends(WSF_REGEXP_VALIDATOR, _super); __extends(WSF_REGEXP_VALIDATOR, _super);
@@ -190,9 +191,9 @@ WSF_REGEXP_VALIDATOR = (function(_super) {
return WSF_REGEXP_VALIDATOR; return WSF_REGEXP_VALIDATOR;
})(WSF_VALIDATOR); })(WSF_VALIDATOR);
WSF_MIN_VALIDATOR = (function(_super) { WSF_MIN_VALIDATOR = (function(_super) {
__extends(WSF_MIN_VALIDATOR, _super); __extends(WSF_MIN_VALIDATOR, _super);
@@ -208,9 +209,9 @@ WSF_MIN_VALIDATOR = (function(_super) {
return WSF_MIN_VALIDATOR; return WSF_MIN_VALIDATOR;
})(WSF_VALIDATOR); })(WSF_VALIDATOR);
WSF_MAX_VALIDATOR = (function(_super) { WSF_MAX_VALIDATOR = (function(_super) {
__extends(WSF_MAX_VALIDATOR, _super); __extends(WSF_MAX_VALIDATOR, _super);
@@ -226,9 +227,9 @@ WSF_MAX_VALIDATOR = (function(_super) {
return WSF_MAX_VALIDATOR; return WSF_MAX_VALIDATOR;
})(WSF_VALIDATOR); })(WSF_VALIDATOR);
WSF_CONTROL = (function() { WSF_CONTROL = (function() {
WSF_CONTROL.prototype.requirements = []; WSF_CONTROL.prototype.requirements = [];
@@ -397,9 +398,9 @@ WSF_CONTROL = (function() {
return WSF_CONTROL; return WSF_CONTROL;
})(); })();
WSF_PAGE_CONTROL = (function(_super) { WSF_PAGE_CONTROL = (function(_super) {
__extends(WSF_PAGE_CONTROL, _super); __extends(WSF_PAGE_CONTROL, _super);
@@ -427,9 +428,9 @@ WSF_PAGE_CONTROL = (function(_super) {
return WSF_PAGE_CONTROL; return WSF_PAGE_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_SLIDER_CONTROL = (function(_super) { WSF_SLIDER_CONTROL = (function(_super) {
__extends(WSF_SLIDER_CONTROL, _super); __extends(WSF_SLIDER_CONTROL, _super);
@@ -441,11 +442,11 @@ WSF_SLIDER_CONTROL = (function(_super) {
return WSF_SLIDER_CONTROL; return WSF_SLIDER_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
controls = {}; controls = {};
WSF_BUTTON_CONTROL = (function(_super) { WSF_BUTTON_CONTROL = (function(_super) {
__extends(WSF_BUTTON_CONTROL, _super); __extends(WSF_BUTTON_CONTROL, _super);
@@ -478,9 +479,9 @@ WSF_BUTTON_CONTROL = (function(_super) {
return WSF_BUTTON_CONTROL; return WSF_BUTTON_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_INPUT_CONTROL = (function(_super) { WSF_INPUT_CONTROL = (function(_super) {
__extends(WSF_INPUT_CONTROL, _super); __extends(WSF_INPUT_CONTROL, _super);
@@ -518,9 +519,9 @@ WSF_INPUT_CONTROL = (function(_super) {
return WSF_INPUT_CONTROL; return WSF_INPUT_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_TEXTAREA_CONTROL = (function(_super) { WSF_TEXTAREA_CONTROL = (function(_super) {
__extends(WSF_TEXTAREA_CONTROL, _super); __extends(WSF_TEXTAREA_CONTROL, _super);
@@ -530,9 +531,9 @@ WSF_TEXTAREA_CONTROL = (function(_super) {
return WSF_TEXTAREA_CONTROL; return WSF_TEXTAREA_CONTROL;
})(WSF_INPUT_CONTROL); })(WSF_INPUT_CONTROL);
WSF_CODEVIEW_CONTROL = (function(_super) { WSF_CODEVIEW_CONTROL = (function(_super) {
__extends(WSF_CODEVIEW_CONTROL, _super); __extends(WSF_CODEVIEW_CONTROL, _super);
@@ -560,9 +561,9 @@ WSF_CODEVIEW_CONTROL = (function(_super) {
return WSF_CODEVIEW_CONTROL; return WSF_CODEVIEW_CONTROL;
})(WSF_INPUT_CONTROL); })(WSF_INPUT_CONTROL);
WSF_AUTOCOMPLETE_CONTROL = (function(_super) { WSF_AUTOCOMPLETE_CONTROL = (function(_super) {
__extends(WSF_AUTOCOMPLETE_CONTROL, _super); __extends(WSF_AUTOCOMPLETE_CONTROL, _super);
@@ -608,9 +609,9 @@ WSF_AUTOCOMPLETE_CONTROL = (function(_super) {
return WSF_AUTOCOMPLETE_CONTROL; return WSF_AUTOCOMPLETE_CONTROL;
})(WSF_INPUT_CONTROL); })(WSF_INPUT_CONTROL);
WSF_CHECKBOX_CONTROL = (function(_super) { WSF_CHECKBOX_CONTROL = (function(_super) {
__extends(WSF_CHECKBOX_CONTROL, _super); __extends(WSF_CHECKBOX_CONTROL, _super);
@@ -649,9 +650,9 @@ WSF_CHECKBOX_CONTROL = (function(_super) {
return WSF_CHECKBOX_CONTROL; return WSF_CHECKBOX_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_FORM_ELEMENT_CONTROL = (function(_super) { WSF_FORM_ELEMENT_CONTROL = (function(_super) {
__extends(WSF_FORM_ELEMENT_CONTROL, _super); __extends(WSF_FORM_ELEMENT_CONTROL, _super);
@@ -720,9 +721,9 @@ WSF_FORM_ELEMENT_CONTROL = (function(_super) {
return WSF_FORM_ELEMENT_CONTROL; return WSF_FORM_ELEMENT_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_HTML_CONTROL = (function(_super) { WSF_HTML_CONTROL = (function(_super) {
__extends(WSF_HTML_CONTROL, _super); __extends(WSF_HTML_CONTROL, _super);
@@ -743,9 +744,9 @@ WSF_HTML_CONTROL = (function(_super) {
return WSF_HTML_CONTROL; return WSF_HTML_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_CHECKBOX_LIST_CONTROL = (function(_super) { WSF_CHECKBOX_LIST_CONTROL = (function(_super) {
__extends(WSF_CHECKBOX_LIST_CONTROL, _super); __extends(WSF_CHECKBOX_LIST_CONTROL, _super);
@@ -782,9 +783,9 @@ WSF_CHECKBOX_LIST_CONTROL = (function(_super) {
return WSF_CHECKBOX_LIST_CONTROL; return WSF_CHECKBOX_LIST_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_PROGRESS_CONTROL = (function(_super) { WSF_PROGRESS_CONTROL = (function(_super) {
__extends(WSF_PROGRESS_CONTROL, _super); __extends(WSF_PROGRESS_CONTROL, _super);
@@ -820,9 +821,9 @@ WSF_PROGRESS_CONTROL = (function(_super) {
return WSF_PROGRESS_CONTROL; return WSF_PROGRESS_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_PAGINATION_CONTROL = (function(_super) { WSF_PAGINATION_CONTROL = (function(_super) {
__extends(WSF_PAGINATION_CONTROL, _super); __extends(WSF_PAGINATION_CONTROL, _super);
@@ -859,9 +860,9 @@ WSF_PAGINATION_CONTROL = (function(_super) {
return WSF_PAGINATION_CONTROL; return WSF_PAGINATION_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_GRID_CONTROL = (function(_super) { WSF_GRID_CONTROL = (function(_super) {
__extends(WSF_GRID_CONTROL, _super); __extends(WSF_GRID_CONTROL, _super);
@@ -886,9 +887,9 @@ WSF_GRID_CONTROL = (function(_super) {
return WSF_GRID_CONTROL; return WSF_GRID_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
WSF_REPEATER_CONTROL = (function(_super) { WSF_REPEATER_CONTROL = (function(_super) {
__extends(WSF_REPEATER_CONTROL, _super); __extends(WSF_REPEATER_CONTROL, _super);
@@ -914,13 +915,13 @@ WSF_REPEATER_CONTROL = (function(_super) {
return WSF_REPEATER_CONTROL; return WSF_REPEATER_CONTROL;
})(WSF_CONTROL); })(WSF_CONTROL);
show_alert = function(action) { show_alert = function(action) {
return alert(action.message); return alert(action.message);
}; };
start_modal = lazy_load(['assets/bootstrap.min.js'], function(action) { start_modal = lazy_load(['assets/bootstrap.min.js'], function(action) {
var cssclass, modal; var cssclass, modal;
cssclass = ""; cssclass = "";
if (action.type === "start_modal_big") { if (action.type === "start_modal_big") {
@@ -939,6 +940,8 @@ start_modal = lazy_load(['assets/bootstrap.min.js'], function(action) {
}).done(function(data) { }).done(function(data) {
return modal.find('.modal-body').append(data); return modal.find('.modal-body').append(data);
}); });
}); });
start_modal_big = start_modal; start_modal_big = start_modal;
}).call(this);

View File

@@ -19,14 +19,20 @@ feature
initialize_controls initialize_controls
local local
btn: WSF_BUTTON_CONTROL btn: WSF_BUTTON_CONTROL
dropdown:WSF_DROPDOWN_CONTROL
do do
create control.make ("container") create control.make ("container")
control.add_class ("container") control.add_class ("container")
create dropdown.make_with_tag_name ("mydropdown", "Dropdown", "li")
dropdown.add_link_item ("Example link 1", "#")
dropdown.add_divider
dropdown.add_link_item ("Example link 2", "#")
create navbar.make_with_brand ("navbar1", "Example") create navbar.make_with_brand ("navbar1", "Example")
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home")) navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
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=%"/grid%"", "Grid"))
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater")) navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/slider%"", "Slider")) navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/slider%"", "Slider"))
navbar.add_element (dropdown)
navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/about%"", "About")) navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/about%"", "About"))
create btn.make ("scode", "Show Code") create btn.make ("scode", "Show Code")
btn.set_click_event (agent show_code) btn.set_click_event (agent show_code)