Author: eallen
Date: 2008-11-08 12:56:12 -0500 (Sat, 08 Nov 2008)
New Revision: 2772
Modified:
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/cumin/python/cumin/widgets.strings
Log:
Added class SubmitSwitch to submit the form when changing states. This is so other form
values get submitted and remembered.
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2008-11-08 17:53:18 UTC (rev 2771)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2008-11-08 17:56:12 UTC (rev 2772)
@@ -524,11 +524,13 @@
self.__states = list()
self.__titles = dict()
self.__hover = dict()
+ self.__bookmark = dict()
- def add_state(self, state, title, hover=""):
+ def add_state(self, state, title, hover="", bm=None):
self.__states.append(state)
self.__titles[state] = title
self.__hover[state] = hover
+ self.__bookmark[state] = bm
if self.__param.default is None:
self.__param.default = state
@@ -546,15 +548,28 @@
def get_title(self, state):
return state in self.__titles and self.__titles[state]
- def render_item_link(self, session, state, id="", bm=""):
+ def get_hover(self, state):
+ return state in self.__hover and self.__hover[state]
+
+ def get_bookmark(self, state):
+ return state in self.__bookmark and self.__bookmark[state]
+
+ def get_param_id(self):
+ """ needed because the SubmitSwitch class uses
+ a hidden input to set the param value instead
+ of a link name/value pair """
+ return self.__param.path
+
+ def render_item_link(self, session, state):
branch = session.branch()
self.set(branch, state)
- title = self.__titles[state]
- hover = self.__hover[state]
+ title = self.get_title(state)
+ hover = self.get_hover(state)
class_ = self.get(session) == state and "selected"
+ bm = self.get_bookmark(state)
- return fmt_link(branch.marshal(), title, class_, id=id, link_title=hover, bm=bm)
+ return fmt_link(branch.marshal(), title, class_, link_title=hover, bm=bm)
class GroupSwitch(StateSwitch):
def __init__(self, app, name):
@@ -603,6 +618,30 @@
return sql
+class SubmitSwitch(StateSwitch):
+ """ Clicking on the link will submit the form.
+
+ This uses javascript and a hidden input to
+ submit the form when the link is clicked. This
+ allows other fields on the form to "remember"
+ their values. """
+ def render_value(self, session, *args):
+ return str(self.get(session))
+
+ def render_name(self, session, *args):
+ """ this needs to be the path of the param """
+ return self.get_param_id()
+
+ def render_item_link(self, session, state):
+ title = self.get_title(state)
+ hover = self.get_hover(state)
+ class_ = self.get(session) == state and "selected"
+ bm = self.get_bookmark(state)
+ name = self.get_param_id()
+ click = "submit_state('%s', '%s'); return false;" %
(name, state)
+
+ return fmt_link("", title, class_, link_title=hover, bm=bm,
click=click)
+
class CuminTable(SqlTable):
def __init__(self, app, name):
super(CuminTable, self).__init__(app, name)
@@ -1069,6 +1108,8 @@
return
class AjaxField(Widget):
+ """ Update a single span or div after the page loads
"""
+
def render_script(self, session):
script = """
<script type="text/javascript">
@@ -1112,6 +1153,20 @@
return self.render_id(session)
class MoreFieldSet(FieldForm, FormField):
+ """ Displays a button that opens and closes a set of fields
+
+ Used in a FieldForm as a FormField. Instead of calling
+ add_field on the FieldForm, call add_field on this.
+ For example:
+ self.more = MoreFieldSet(app, "more")
+ self.add_field(self.more)
+
+ self.name = NameField(app, "name")
+ self.more.add_field(self.name)
+
+ self.port = StringField(app, "port")
+ self.more.add_field(self.port)
+ """
def __init__(self, app, name):
super(MoreFieldSet, self).__init__(app, name)
@@ -1140,4 +1195,3 @@
def render_open_display(self, session, *args):
return self.input.get(session) and "block" or "none"
-
\ No newline at end of file
Modified: mgmt/trunk/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.strings 2008-11-08 17:53:18 UTC (rev 2771)
+++ mgmt/trunk/cumin/python/cumin/widgets.strings 2008-11-08 17:56:12 UTC (rev 2772)
@@ -849,6 +849,26 @@
[StateSwitch.item_html]
<li>{item_link}</li>
+[SubmitSwitch.javascript]
+function submit_state(id, state) {
+ var oHidden = document.forms[0].elements[id];
+ if (oHidden) {
+ if (oHidden.length) {
+ for (var i=0; i<oHidden.length; i++) {
+ oHidden[i].value = state;
+ }
+ } else {
+ oHidden.value = state;
+ }
+ document.forms[0].submit();
+ }
+}
+
+[SubmitSwitch.html]
+<ul class="radiotabs">
+ {items}
+</ul><input type="hidden" name="{name}"
value="{value}" />
+
[CuminEditableProperties.html]
<table class="PropertySet Editable">
<thead>
@@ -1004,7 +1024,11 @@
div.more_field_set {
margin-bottom: 1em;
}
+div.more_field_set ul.actions {
+ margin-bottom: 0.5em;
+}
+
[MoreFieldSet.html]
<div class="more_field_set">
<ul class="actions">