Implement repeater

This commit is contained in:
YNH Webdev
2013-09-14 18:41:49 +02:00
parent 26ec7d94c6
commit cfe452543a
8 changed files with 266 additions and 71 deletions

View File

@@ -34,6 +34,7 @@ feature {NONE} -- Initialization
-- router.map (create {WSF_URI_MAPPING}.make ("/hello", create {WSF_AGENT_URI_HANDLER}.make (agent execute_hello)))
map_agent_uri ("/", agent execute_hello, Void)
map_agent_uri ("/grid", agent grid_demo, Void)
map_agent_uri ("/repeater", agent repeater_demo, Void)
map_agent_uri ("/widget.js", agent load_js, Void)
map_agent_uri ("/widget.css", agent load_css, Void)
map_agent_uri ("/bootstrap.min.css", agent load_bootstrap, Void)
@@ -68,6 +69,16 @@ feature -- Execution
page.execute
end
repeater_demo (req: WSF_REQUEST; res: WSF_RESPONSE)
local
page: REPEATER_PAGE
do
-- To send a response we need to setup, the status code and
-- the response headers.
create page.make (req, res)
page.execute
end
load_js (req: WSF_REQUEST; res: WSF_RESPONSE)
local
f: WSF_FILE_RESPONSE

View File

@@ -0,0 +1,38 @@
note
description: "Summary description for {GOOGLE_NEWS_REPEATER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
GOOGLE_NEWS_REPEATER
inherit
WSF_REPEATER_CONTROL [GOOGLE_NEWS]
create
make_repeater
feature
render_item (item: GOOGLE_NEWS): STRING
local
body: STRING
do
Result := ""
if attached item.image as image then
Result.append (render_tag_with_tagname ("a", render_tag_with_tagname ("img", "", "style=%"max-width: 200px;%" src=%"" + image + "%"", "media-object"), "href=%"#%"", "pull-left"))
end
body := ""
if attached item.title as title then
body.append (render_tag_with_tagname ("h4", title, "", "media-heading"))
end
if attached item.content as content then
body.append (content)
end
Result.append (render_tag_with_tagname ("div", body, "", "media-body"))
Result := render_tag_with_tagname ("div", Result, "", "media") + "<hr />"
end
end

View File

@@ -0,0 +1,51 @@
note
description: "Summary description for {REPEATER_PAGE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
REPEATER_PAGE
inherit
WSF_PAGE_CONTROL
create
make
feature
initialize_controls
local
container: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
create container.make_multi_control ("container")
create datasource.make_news
create search_query.make_autocomplete ("query", create {GOOGLE_AUTOCOMPLETION}.make)
search_query.add_class ("form-control")
search_query.set_change_event (agent change_query)
container.add_control (search_query)
create repeater.make_repeater ("myrepeater", datasource)
container.add_control (repeater)
control := container
end
change_query
do
datasource.set_query (search_query.value)
datasource.set_page (1)
datasource.update
end
process
do
end
repeater: GOOGLE_NEWS_REPEATER
search_query: WSF_AUTOCOMPLETE_CONTROL
datasource: GOOGLE_NEWS_DATASOURCE
end

View File

@@ -277,7 +277,19 @@ class WSF_GRID_CONTROL extends WSF_CONTROL
if state.datasource?
window.states[@control_name]['datasource'] = state.datasource
if state._body?
@$el.find('tbody').html($(state._body).html())
@$el.find('tbody').html(state._body)
class WSF_REPEATER_CONTROL extends WSF_CONTROL
attach_events: ()->
self = @
update: (state) ->
if state.datasource?
window.states[@control_name]['datasource'] = state.datasource
if state._body?
@$el.find('.repeater_content').html(state._body)
console.log state._body
#map class name to effective class
typemap =
@@ -291,6 +303,7 @@ typemap =
"WSF_CHECKBOX_LIST_CONTROL": WSF_CHECKBOX_LIST_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

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.1
(function() {
var $el, 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_PAGINATION_CONTROL, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, cache, controls, name, state, template, tmpl, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
var $el, 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_PAGINATION_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, cache, controls, name, state, template, tmpl, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
__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; };
@@ -523,7 +523,7 @@
window.states[this.control_name]['datasource'] = state.datasource;
}
if (state._body != null) {
return this.$el.find('tbody').html($(state._body).html());
return this.$el.find('tbody').html(state._body);
}
};
@@ -531,6 +531,33 @@
})(WSF_CONTROL);
WSF_REPEATER_CONTROL = (function(_super) {
__extends(WSF_REPEATER_CONTROL, _super);
function WSF_REPEATER_CONTROL() {
return WSF_REPEATER_CONTROL.__super__.constructor.apply(this, arguments);
}
WSF_REPEATER_CONTROL.prototype.attach_events = function() {
var self;
return self = this;
};
WSF_REPEATER_CONTROL.prototype.update = function(state) {
if (state.datasource != null) {
window.states[this.control_name]['datasource'] = state.datasource;
}
if (state._body != null) {
this.$el.find('.repeater_content').html(state._body);
return console.log(state._body);
}
};
return WSF_REPEATER_CONTROL;
})(WSF_CONTROL);
typemap = {
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL,
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL,
@@ -541,7 +568,8 @@
"WSF_HTML_CONTROL": WSF_HTML_CONTROL,
"WSF_CHECKBOX_LIST_CONTROL": WSF_CHECKBOX_LIST_CONTROL,
"WSF_PAGINATION_CONTROL": WSF_PAGINATION_CONTROL,
"WSF_GRID_CONTROL": WSF_GRID_CONTROL
"WSF_GRID_CONTROL": WSF_GRID_CONTROL,
"WSF_REPEATER_CONTROL": WSF_REPEATER_CONTROL
};
_ref = window.states;