1 | from tw.api import Widget, JSLink, CSSLink, js_function, js_callback, js_symbol |
---|
2 | from tw.forms.fields import TextField |
---|
3 | from tw.forms.validators import Pipe, Int |
---|
4 | |
---|
5 | class UISlider(TextField): |
---|
6 | javascript = [ |
---|
7 | JSLink(modname="sipbmp3web",filename="public/jquery/jquery-1.3.2.js"), |
---|
8 | JSLink(modname="sipbmp3web",filename="public/jquery/jquery-ui-personalized-1.6rc6.js"), |
---|
9 | ] |
---|
10 | template = "genshi:sipbmp3web.widgets.templates.slider" |
---|
11 | def __init__(self, *args, **kw): |
---|
12 | self.min = kw.pop("min") |
---|
13 | self.max = kw.pop("max") |
---|
14 | validator = Int(min=self.min, max=self.max) |
---|
15 | try: |
---|
16 | validator = Pipe(kw["validator"], validator) |
---|
17 | except KeyError: |
---|
18 | pass |
---|
19 | kw["validator"] = validator |
---|
20 | super(UISlider, self).__init__(*args, **kw) |
---|
21 | def update_params(self, d): |
---|
22 | super(TextField, self).update_params(d) |
---|
23 | if not getattr(d, "id", None): |
---|
24 | raise ValueError, "Slider must have id" |
---|
25 | container = '%s_container' % d.id |
---|
26 | self.add_call(js_callback('$("#%s").slider({ \ |
---|
27 | min: %d, max: %d, step: 1, range: false, \ |
---|
28 | value: $("#%s").val(), \ |
---|
29 | slide: function (event, ui) { \ |
---|
30 | jQuery("#%s").val(ui.value);\ |
---|
31 | } \ |
---|
32 | })' % (container, self.min, self.max, d.id, d.id))) |
---|
33 | jQuery = js_function('jQuery') |
---|
34 | input = jQuery("#%s" % d.id) |
---|
35 | self.add_call(input.css("display", "none")) |
---|
36 | |
---|