Author: croberts Date: 2011-06-01 21:23:06 +0000 (Wed, 01 Jun 2011) New Revision: 4796
Modified: trunk/cumin/python/cumin/grid/limit.py trunk/cumin/python/cumin/grid/limit.strings Log: Addressing BZ https://bugzilla.redhat.com/show_bug.cgi?id=697016 . Changing from the "unlimited" button to a checkbox.
Modified: trunk/cumin/python/cumin/grid/limit.py =================================================================== --- trunk/cumin/python/cumin/grid/limit.py 2011-06-01 11:11:42 UTC (rev 4795) +++ trunk/cumin/python/cumin/grid/limit.py 2011-06-01 21:23:06 UTC (rev 4796) @@ -7,7 +7,7 @@ from cumin.qmfadapter import ObjectQmfAdapter from cumin.widgets import CuminView from wooly.forms import StringField, StringInput, IntegerField, RealField, \ - FormButton, FormField, FormError + FormButton, FormField, FormError, CheckboxInput from wooly.util import StringCatalog from wooly.widgets import TabbedModeSet from wooly.parameters import * @@ -181,11 +181,12 @@ self.limit_max.required = True self.add_field(self.limit_max)
- self.reset_button = self.ResetLimitFormButton(app, "resetbutton") - self.add_field(self.reset_button) +# self.reset_button = self.ResetLimitFormButton(app, "resetbutton") +# self.add_field(self.reset_button)
def process_submit(self, session): new_max_value = self.limit_max.input.get(session) + unlimited_check_value = self.limit_max.checkbox.param.get(session)
self.limit_max.validate(session) if not self.errors.get(session): @@ -207,19 +208,32 @@ def render_form_class(self, session): return " ".join((super(NegotiatorLimitForm, self).render_form_class(session), "mform"))
- class ResetLimitFormButton(FormField): + class StringFieldWithCheckbox(StringField): def __init__(self, app, name): - super(NegotiatorLimitForm.ResetLimitFormButton, self).__init__(app, name) - self.button_tmpl = WidgetTemplate(self, "reset_button_html") - + super(NegotiatorLimitForm.StringFieldWithCheckbox, self).__init__(app, name) + self.button_tmpl = WidgetTemplate(self, "input_with_checkbox_html") + + self.checkbox = CheckboxInput(app, "unlimitedcheck") + self.add_child(self.checkbox) + def do_render(self, session): writer = Writer() self.button_tmpl.render(writer, session) - return writer.to_string() + return writer.to_string()
- def render_class(self, session): - return "midformbutton" + def render_field_value(self,session): + return self.input.get(session)
+ def render_field_name(self,session): + return self.input.param.path + + def render_checkbox_name(self,session): + return self.checkbox.param.path + + def render_onclick_attr(self, session, *args): + value = "toggleLimitInput(this, '%s', '%s')" % (self.checkbox.param.path, self.input.param.path) + return "onclick="%s"" % value + class LimitName(StringField): def __init__(self, app, name): super(NegotiatorLimitForm.LimitName, self).__init__(app, name) @@ -234,7 +248,7 @@ # used to override html and css pass
- class LimitMax(StringField): + class LimitMax(StringFieldWithCheckbox): def render_title(self, session): return "Max Allowance"
@@ -262,6 +276,8 @@ title = self.render_title(session) message = "The '%s' field must be either "unlimited", an integer or a float" % title self.form.errors.add(session, FormError(message)) + +
class LimitView(CuminView): def __init__(self, app, name, limit):
Modified: trunk/cumin/python/cumin/grid/limit.strings =================================================================== --- trunk/cumin/python/cumin/grid/limit.strings 2011-06-01 11:11:42 UTC (rev 4795) +++ trunk/cumin/python/cumin/grid/limit.strings 2011-06-01 21:23:06 UTC (rev 4796) @@ -31,15 +31,27 @@ //]]> </script>
-[ResetLimitFormButton.reset_button_html] +[StringFieldWithCheckbox.input_with_checkbox_html] <tr id="{id}"> - <th></th> - <td><button class="{class}" type="button" name="{id}" onclick="return resetLimitMax();">Unlimited</button></td> + <th> + <div class="title">Max Allowance<span style="color: #c33">*</span></div> + <div class="help"></div> + </th> + <td> + <input type="text" name="{field_name}" id="{field_name}" value="{field_value}" tabindex="100" size="30" /> + <input type="checkbox" name="{checkbox_name}" id="{checkbox_name}" {onclick_attr}/><label for="{checkbox_name}">Unlimited</label> + </td> </tr> <script type="text/javascript"> //<![CDATA[ -function resetLimitMax() { - document.forms[0].elements[1].value="Unlimited"; +function toggleLimitInput(form, checkbox, textinput) { + if($(checkbox).checked) { + $(textinput).value = "Unlimited"; + $(textinput).setProperty('readonly', 'readonly'); + } else { + $(textinput).value = "{field_value}"; + $(textinput).setProperty('readonly', null); + } return false; } //]]>
cumin-developers@lists.fedorahosted.org