diff options
author | Luke Macken <lmacken@redhat.com> | 2008-06-27 23:08:39 -0400 |
---|---|---|
committer | Luke Macken <lmacken@redhat.com> | 2008-06-27 23:08:39 -0400 |
commit | a1bace833d421f20642d5077a03d769ffb1cd355 (patch) | |
tree | 1e658ec9fe3851c56db1cf3ca04bf719b435c0f7 /manas | |
parent | 5b30509db844bffffbeb61702bbc6917cb2b1170 (diff) | |
download | manas-a1bace833d421f20642d5077a03d769ffb1cd355.tar.gz manas-a1bace833d421f20642d5077a03d769ffb1cd355.tar.xz manas-a1bace833d421f20642d5077a03d769ffb1cd355.zip |
Add our initial widgets module
Diffstat (limited to 'manas')
-rw-r--r-- | manas/widgets.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/manas/widgets.py b/manas/widgets.py new file mode 100644 index 0000000..4c30d9c --- /dev/null +++ b/manas/widgets.py @@ -0,0 +1,69 @@ +import time + +from tw.forms import TableForm, TextField, TextArea, HiddenField +from tw.api import WidgetsList, Widget, js_callback, js_function, JSLink +from tw.jquery import jquery_js +from tw.jquery.activeform import AjaxForm +from formencode.validators import NotEmpty + +manas_js = JSLink(link='/javascript/manas.js') +orbited_js = JSLink(link='http://localhost:8000/_/orbited.js') + + +class LatestIdeas(Widget): + """ A real-time idea displaying widget """ + name = "Latest Ideas" + params = ['id', 'name'] + template = 'genshi:manas.templates.latestideas' + javascript=[orbited_js, jquery_js, manas_js] + include_dynamic_js_calls = True + def update_params(self, d): + super(LatestIdeas, self).update_params(d) + event_cb = js_callback("""function(data) { + $.each(data, function(i, item) { + $('<div/>').hide().append( + $('<a/>') + .attr('href', '#') + .attr('onclick', '$("#main").load("/idea/' + item["id"] + '")') + .text(item['title']) + ).prependTo("#%s_data").slideDown(); + }); + }""" % self.id) + # TODO: use an existing username, if it exists? + self.add_call(js_function('connect')(event_cb, str(time.time()), '/orbited', 0)) + + +class IdeaWidget(Widget): + """ The representation of an Idea """ + template = 'genshi:manas.templates.ideawidget' + params = ['show_comments', 'idea'] + show_comments = False + + +# At the moment we cannot use the JQValidate + AjaxForm. +# The validation occurs just fine, but the form still POST's. I mentioned this +# on the mailing list... +#from tw.jquery.validate import JQValidate +#jquery_validate = JQValidate() +#jQuery = js_function('$') + + +class NewIdeaForm(AjaxForm): + success = js_callback('idea_success') + class fields(WidgetsList): + title = TextField('title', validator=NotEmpty, attrs={'class': 'required'}) + tags = TextField('tags', validator=NotEmpty, attrs={'class': 'required'}) + description = TextArea('description', validator=NotEmpty, + attrs={'class': 'required'}) + js = manas_js + #validate = jquery_validate + #def update_params(self, d): + # super(NewIdeaForm, self).update_params(d) + # self.add_call(jQuery('#%s' % d.id).validate()) + + +class NewCommentForm(AjaxForm): + success = js_callback('comment_success') + class fields(WidgetsList): + text = TextArea(validator=NotEmpty) + js = manas_js |