Commits

Anonymous committed dea026f

[svn] o added urls.current_url
o added confirm option to form_tag.submit

Comments (0)

Files changed (2)

webhelpers/rails/form_tag.py

 """
 Form Tag Helpers
 """
-
+from urls import confirm_javascript_function
 from tags import *
 from webhelpers.util import html_escape
 
 def submit(value="Save changes", name='commit', **options):
     """
     Creates a submit button with the text ``value`` as the caption.
+
+    Options:
+
+    * ``confirm`` - A confirm message displayed when the button is clicked.
+    * ``disable_with`` - The value to be used to rename a disabled version of the submit
+    button.
     
     If options contains a keyword pair with the key of "disable_with", then the value will
     be used to rename a disabled version of the submit button.
     """
+    confirm = options.get('confirm')
+    if confirm:
+        options.pop('confirm')
+        onclick = options.get('onclick', '')
+        if onclick.strip() and not onclick.rstrip().endswith(';'):
+            onclick += ';'
+        options['onclick'] = "%s return %s;" % (onclick, confirm_javascript_function(confirm))
+
     if options.has_key('disable_with'):
         options["onclick"] = "this.disabled=true;this.value='%s';this.form.submit();%s" % (options['disable_with'], options.get("onclick", ''))
     o = {'type': 'submit', 'name_': name, 'value': value }
 #    return tag("input", **o)
 
 __all__ = ['form', 'start_form', 'end_form', 'select', 'text_field', 'hidden_field', 'file_field',
-           'password_field', 'text_area', 'check_box', 'radio_button', 'submit']
+           'password_field', 'text_area', 'check_box', 'radio_button', 'submit']

webhelpers/rails/urls.py

 
 def current_page(url):
     """
-    Returns true if the current page uri is equivilant to ``url``
+    Returns true if the current page uri is equivalent to ``url``
+    """
+    currl = current_url()
+    if callable(url):
+        return url() == currl
+    else:
+        return url == currl
+
+def current_url():
+    """
+    Returns the current page's url.
     """
     config = request_config()
     environ = config.environ
     if environ.get('REQUEST_METHOD', 'GET') == 'GET':
         if environ.has_key('QUERY_STRING'):
             curopts.update(dict(parse_querystring(environ)))
-    currl = url_for(**curopts)
-    if callable(url):
-        return url() == currl
-    else:
-        return url == currl
+    return url_for(**curopts)
 
 def convert_options_to_javascript(confirm=None, popup=None, post=None, **html_options):
     if popup and post:
     return "f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();"
 
 __all__ = ['url', 'link_to', 'button_to', 'link_to_unless_current', 'link_to_unless', 'link_to_if',
-           'current_page']
+           'current_page', 'current_url']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.