pieforms-commit Mailing List for Pieforms
Status: Alpha
Brought to you by:
oracleshinoda
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(73) |
Dec
(83) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(16) |
Feb
(19) |
Mar
(12) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(45) |
2008 |
Jan
(20) |
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
(5) |
Jul
(1) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(7) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
|
1
(1) |
2
|
3
|
4
|
5
|
6
(3) |
7
(6) |
8
(3) |
9
|
10
(6) |
11
|
12
|
13
|
14
|
15
(6) |
16
|
17
(3) |
18
(3) |
19
|
20
|
21
|
22
|
23
(31) |
24
(8) |
25
(1) |
26
(3) |
27
(9) |
28
|
29
|
30
|
31
|
|
|
|
|
|
|
From: <ora...@us...> - 2006-12-27 12:54:11
|
Revision: 156 http://svn.sourceforge.net/pieforms/?rev=156&view=rev Author: oracleshinoda Date: 2006-12-27 04:54:07 -0800 (Wed, 27 Dec 2006) Log Message: ----------- Allow forms to specify an error message for jsforms. This is a small helper that stops the need to define a _error function if you want to send an error back. The message is completely optional Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-27 12:49:27 UTC (rev 155) +++ pieforms-php5/trunk/src/pieform.php 2006-12-27 12:54:07 UTC (rev 156) @@ -250,6 +250,11 @@ // unknown error code 'globaljserrorcallback' => '', + // The message to pass back as a reason for the form submission failing + // if the form is a jsform. This can be used by your application however + // you choose. + 'jserrormessage' => '', + // Whether this form can be cancelled, regardless of the presence of // 'cancel' buttons or form inputs mischeviously named as to behave // like cancel buttons @@ -558,7 +563,8 @@ foreach ($errors as $element) { $json[$element['name']] = $element['error']; } - $this->json_reply(PIEFORM_ERR, array('errors' => $json)); + $message = $this->get_property('jserrormessage'); + $this->json_reply(PIEFORM_ERR, array('message' => $message, 'errors' => $json)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 12:49:27
|
Revision: 155 http://svn.sourceforge.net/pieforms/?rev=155&view=rev Author: oracleshinoda Date: 2006-12-27 04:49:27 -0800 (Wed, 27 Dec 2006) Log Message: ----------- Changed the i18n function name for the email rule to be correct Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/email.php Modified: pieforms-php5/trunk/src/pieform/rules/email.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/email.php 2006-12-27 09:12:04 UTC (rev 154) +++ pieforms-php5/trunk/src/pieform/rules/email.php 2006-12-27 12:49:27 UTC (rev 155) @@ -42,7 +42,7 @@ } } -function pieform_i18n_rule_email() { +function pieform_rule_email_i18n() { return array( 'en.utf8' => array( 'email' => 'E-mail address is invalid' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 09:12:05
|
Revision: 154 http://svn.sourceforge.net/pieforms/?rev=154&view=rev Author: oracleshinoda Date: 2006-12-27 01:12:04 -0800 (Wed, 27 Dec 2006) Log Message: ----------- Added pieforms.js, which will contain pieforms-specific javascript. Currently includes support for resizable textareas Added Paths: ----------- pieforms-php5/trunk/src/static/core/pieforms.js Added: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js (rev 0) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2006-12-27 09:12:04 UTC (rev 154) @@ -0,0 +1,132 @@ +/** + * Pieforms core javascript + * Author: Nigel McNie + * (C) 2006 Nigel McNie + * Released under the GNU GPL, see the COPYING file + * @todo pack this, provide a source version. Same with MochiKit + */ + +// The resizable textarea code is based on the code from Drupal (http://drupal.org/) + +/** + * Retrieves the absolute position of an element on the screen + * This function (C) 2006 Drupal + */ +function absolutePosition(el) { + var sLeft = 0, sTop = 0; + var isDiv = /^div$/i.test(el.tagName); + if (isDiv && el.scrollLeft) { + sLeft = el.scrollLeft; + } + if (isDiv && el.scrollTop) { + sTop = el.scrollTop; + } + var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop }; + if (el.offsetParent) { + var tmp = absolutePosition(el.offsetParent); + r.x += tmp.x; + r.y += tmp.y; + } + return r; +} + +addLoadEvent(function() { + forEach(getElementsByTagAndClassName('form', 'pieform'), function(form) { + forEach(getElementsByTagAndClassName('textarea', 'resizable', form), function (textarea) { + new TextArea(textarea); + }); + }); +}); + +/** + * This class based on Drupal's textArea class, which is (C) 2006 Drupal + * + * Provides a 'grippie' for resizing a textarea vertically. + */ +function TextArea(element) { + var self = this; + + this.element = element; + this.parent = this.element.parentNode; + this.dimensions = getElementDimensions(element); + + // Prepare wrapper + this.wrapper = DIV({'class':'resizable-textarea'}); + insertSiblingNodesBefore(this.element, this.wrapper); + + // Add grippie and measure it + this.grippie = DIV({'class': 'grippie'}); + appendChildNodes(this.wrapper, this.grippie); + this.grippie.dimensions = getElementDimensions(this.grippie); + + // Set wrapper and textarea dimensions + setElementDimensions(this.wrapper, {'h': this.dimensions.h + this.grippie.dimensions.h + 1}); + setStyle(this.element, { + 'margin-bottom': '0', + 'width': '100%', + 'height': this.dimensions.h + 'px' + }); + + // Wrap textarea + removeElement(this.element); + insertSiblingNodesBefore(this.grippie, this.element); + + // Measure difference between desired and actual textarea dimensions to account for padding/borders + this.widthOffset = getElementDimensions(this.wrapper).w - this.dimensions.w; + + // Make the grippie line up in various browsers + if (window.opera) { + setStyle(this.grippie, {'margin-right': '4px'}); + } + if (document.all && !window.opera) { + this.grippie.style.width = '100%'; + this.grippie.style.paddingLeft = '2px'; + setStyle(this.grippie, { + 'width': '100%', + 'padding-left': '2px' + }); + } + this.element.style.MozBoxSizing = 'border-box'; + + this.heightOffset = absolutePosition(this.grippie).y - absolutePosition(this.element).y - this.dimensions.h; + + + this.handleDrag = function (e) { + // Get coordinates relative to text area + var pos = absolutePosition(this.element); + var y = e.mouse().client.y - pos.y; + + // Set new height + var height = Math.max(32, y - this.dragOffset - this.heightOffset); + setStyle(this.wrapper, {'height': height + this.grippie.dimensions.h + 1 + 'px'}); + setStyle(this.element, {'height': height + 'px'}); + + // Avoid text selection + e.stop(); + } + + this.endDrag = function (e) { + disconnect(this.mouseMoveHandler); + disconnect(this.mouseUpHandler); + document.isDragging = false; + } + + this.beginDrag = function(e) { + if (document.isDragging) { + return; + } + document.isDragging = true; + + self.mouseMoveHandler = connect(document, 'onmousemove', self, 'handleDrag'); + self.mouseUpHandler = connect(document, 'onmouseup', self, 'endDrag'); + + // Store drag offset from grippie top + var pos = absolutePosition(this.grippie); + this.dragOffset = e.mouse().client.y - pos.y; + + // Process + this.handleDrag(e); + } + + connect(this.grippie, 'onmousedown', self, 'beginDrag'); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 09:09:44
|
Revision: 153 http://svn.sourceforge.net/pieforms/?rev=153&view=rev Author: oracleshinoda Date: 2006-12-27 01:09:43 -0800 (Wed, 27 Dec 2006) Log Message: ----------- Add 'class=pieform' to all pieforms, so they can be targetted by javascript routines. Add a class of 'resizable' to textareas if needed, so javascript can target them Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/textarea.php pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform/elements/textarea.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/textarea.php 2006-12-27 06:23:15 UTC (rev 152) +++ pieforms-php5/trunk/src/pieform/elements/textarea.php 2006-12-27 09:09:43 UTC (rev 153) @@ -55,6 +55,10 @@ Pieform::info('No value for cols or width specified for textarea "' . $element['name'] . '"'); } $element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style; + + if (!empty($element['resizable'])) { + $element['class'] = (isset($element['class']) && $element['class']) ? $element['class'] . ' resizable' : 'resizable'; + } return '<textarea' . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-27 06:23:15 UTC (rev 152) +++ pieforms-php5/trunk/src/pieform.php 2006-12-27 09:09:43 UTC (rev 153) @@ -599,7 +599,7 @@ * @return string */ public function get_form_tag() { - $result = '<form'; + $result = '<form class="pieform"'; foreach (array('name', 'method', 'action') as $attribute) { $result .= ' ' . $attribute . '="' . $this->data[$attribute] . '"'; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 06:23:15
|
Revision: 152 http://svn.sourceforge.net/pieforms/?rev=152&view=rev Author: oracleshinoda Date: 2006-12-26 22:23:15 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Added tabindex to fieldset for keyboard navigation Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/fieldset.php Modified: pieforms-php5/trunk/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-27 05:38:39 UTC (rev 151) +++ pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-27 06:23:15 UTC (rev 152) @@ -56,7 +56,7 @@ $id = substr(md5(microtime()), 0, 4); $result .= ' id="' . $id . '">'; $result .= '<script type="text/javascript">'; - $result .= "var a = A({'href':''}, " . json_encode($element['legend']) . "); "; + $result .= "var a = A({'href':'', 'tabindex':{$form->get_property('tabindex')}}, " . json_encode($element['legend']) . "); "; $result .= "connect(a, 'onclick', function(e) { toggleElementClass('collapsed', $('{$id}').parentNode); e.stop(); });"; $result .= "replaceChildNodes('{$id}', a);</script>"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 05:38:53
|
Revision: 151 http://svn.sourceforge.net/pieforms/?rev=151&view=rev Author: oracleshinoda Date: 2006-12-26 21:38:39 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Ignore .swp files Property Changed: ---------------- pieforms-php5/trunk/src/static/core/ Property changes on: pieforms-php5/trunk/src/static/core ___________________________________________________________________ Name: svn:ignore + *.swp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 05:37:33
|
Revision: 150 http://svn.sourceforge.net/pieforms/?rev=150&view=rev Author: oracleshinoda Date: 2006-12-26 21:37:33 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Removed some comments from the javascript output for jsform submissions, comments aren't needed (later on this stuff might be packed). Added a bit of code to handle expanding a fieldset if it contains elements with errors in them. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-27 05:27:58 UTC (rev 149) +++ pieforms-php5/trunk/src/pieform.php 2006-12-27 05:37:33 UTC (rev 150) @@ -895,33 +895,33 @@ $result .= <<<EOF } else { - // Redirect if the form is being cancelled if (data.returnCode == -2) { window.location = data.message; return; } - // Set errors if there are any {$this->name}_remove_all_errors(); if (data.message.errors) { for (error in data.message.errors) { {$this->name}_set_error(data.message.errors[error], error); } + // @todo only output when fieldsets are present + forEach(getElementsByTagAndClassName('fieldset', 'collapsed', '{$this->name}'), function(fieldset) { + if (getFirstElementByTagAndClassName(null, 'error', fieldset)) { + removeElementClass(fieldset, 'collapsed'); + } + }); } if (data.returnCode == -1) { - // The request failed validation EOF; - - // @todo: renumber the PIEFORM_* flags to be 0, -1, -2 to allow users to have the positive numbers to themselves if (!empty($this->data['jserrorcallback'])) { $result .= " {$this->data['jserrorcallback']}('{$this->name}', data);\n"; } $result .= <<<EOF } else { - // A return code we don't know about EOF; if (!empty($this->data['globaljserrorcallback'])) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 05:28:00
|
Revision: 149 http://svn.sourceforge.net/pieforms/?rev=149&view=rev Author: oracleshinoda Date: 2006-12-26 21:27:58 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Added support for 'collapsable' fieldsets (doesn't depend on 'jsform'). Listens to 'collapsable' and 'collapsed' options. If there is an error with form submission in a collapsed fieldset it is expanded. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/fieldset.php Modified: pieforms-php5/trunk/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-27 04:58:00 UTC (rev 148) +++ pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-27 05:27:58 UTC (rev 149) @@ -33,9 +33,37 @@ * @return string The HTML for the element */ function pieform_element_fieldset(Pieform $form, $element) { - $result = "\n<fieldset>\n"; + $result = "\n<fieldset"; + if (!empty($element['collapsable'])) { + $classes = array('collapsable'); + // Work out whether any of the children have errors on them + $error = false; + foreach ($element['elements'] as $subelement) { + if (isset($subelement['error'])) { + $error = true; + break; + } + } + if (!empty($element['collapsed']) && !$error) { + $classes[] = 'collapsed'; + } + $result .= ' class="' . implode(' ', $classes) . '"'; + } + $result .= ">\n"; if (isset($element['legend'])) { - $result .= '<legend>' . Pieform::hsc($element['legend']) . "</legend>\n"; + $result .= '<legend'; + if (!empty($element['collapsable'])) { + $id = substr(md5(microtime()), 0, 4); + $result .= ' id="' . $id . '">'; + $result .= '<script type="text/javascript">'; + $result .= "var a = A({'href':''}, " . json_encode($element['legend']) . "); "; + $result .= "connect(a, 'onclick', function(e) { toggleElementClass('collapsed', $('{$id}').parentNode); e.stop(); });"; + $result .= "replaceChildNodes('{$id}', a);</script>"; + } + else { + $result .= '>' . Pieform::hsc($element['legend']); + } + $result .= "</legend>\n"; } foreach ($element['elements'] as $subname => $subelement) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-27 04:58:00
|
Revision: 148 http://svn.sourceforge.net/pieforms/?rev=148&view=rev Author: oracleshinoda Date: 2006-12-26 20:58:00 -0800 (Tue, 26 Dec 2006) Log Message: ----------- Loosened the check for fieldsets a little bit so that classes can be added to the fieldset. Required for collapsable fieldset support Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-26 00:28:16 UTC (rev 147) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-27 04:58:00 UTC (rev 148) @@ -38,7 +38,7 @@ $formname = $form->get_name(); if ($rawelement['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance - if (0 === strpos($builtelement, "\n<fieldset>\n<legend>")) { + if (0 === strpos($builtelement, "\n<fieldset")) { $closelegendpos = strpos($builtelement, '</legend>') + 9; $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-26 00:28:18
|
Revision: 147 http://svn.sourceforge.net/pieforms/?rev=147&view=rev Author: oracleshinoda Date: 2006-12-25 16:28:16 -0800 (Mon, 25 Dec 2006) Log Message: ----------- Moved MochiKit stuff to the core/ directory Added Paths: ----------- pieforms-php5/trunk/src/static/core/MochiKit/ Removed Paths: ------------- pieforms-php5/trunk/src/static/MochiKit/ Copied: pieforms-php5/trunk/src/static/core/MochiKit (from rev 146, pieforms-php5/trunk/src/static/MochiKit) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-26 00:27:26
|
Revision: 146 http://svn.sourceforge.net/pieforms/?rev=146&view=rev Author: oracleshinoda Date: 2006-12-25 16:27:24 -0800 (Mon, 25 Dec 2006) Log Message: ----------- Moved js/ to static/ Added Paths: ----------- pieforms-php5/trunk/src/static/ pieforms-php5/trunk/src/static/MochiKit/ pieforms-php5/trunk/src/static/core/ pieforms-php5/trunk/src/static/jscalendar/ Removed Paths: ------------- pieforms-php5/trunk/src/static/MochiKit/ pieforms-php5/trunk/src/static/jscalendar/ Copied: pieforms-php5/trunk/src/static (from rev 140, pieforms-php5/trunk/src/js) Copied: pieforms-php5/trunk/src/static/MochiKit (from rev 144, pieforms-php5/trunk/src/js/MochiKit) Copied: pieforms-php5/trunk/src/static/jscalendar (from rev 144, pieforms-php5/trunk/src/js/jscalendar) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-26 00:18:05
|
Revision: 145 http://svn.sourceforge.net/pieforms/?rev=145&view=rev Author: oracleshinoda Date: 2006-12-25 16:18:04 -0800 (Mon, 25 Dec 2006) Log Message: ----------- Moved js/ to static/, as CSS, images and other things may find their way into that directory Removed Paths: ------------- pieforms-php5/trunk/src/js/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-25 23:45:27
|
Revision: 144 http://svn.sourceforge.net/pieforms/?rev=144&view=rev Author: oracleshinoda Date: 2006-12-25 15:45:25 -0800 (Mon, 25 Dec 2006) Log Message: ----------- Forms will now die if execution is continuing after the submit function is called, however this behaviour can be turned off if necessary (the transient login page in Mahara requires it to be off) Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-24 06:29:24 UTC (rev 143) +++ pieforms-php5/trunk/src/pieform.php 2006-12-25 23:45:25 UTC (rev 144) @@ -255,6 +255,12 @@ // like cancel buttons 'iscancellable' => true, + // Whether Pieforms should die after calling a submit function. Generally + // this is a good idea, as it forces the user to reply to the form + // submission. However, there are occasions where you might want to let + // it continue, so this behaviour can be turned off + 'dieaftersubmit' => true, + // Whether to auto-focus either the first field (if the value is true, // or the named field (if the value is a string) when the form is // displayed. If this has any value other than false and the form has @@ -514,14 +520,20 @@ // finished processing the form. // @todo maybe it should do just that... call_user_func_array($function, array($this, $values)); - // This will only work if I can make the login_submit function stuff work in login_validate - //if ($this->ajaxpost) { - // $message = 'Your ' . $this->name . '_submit function should output some json and exit'; - //} - //else { - // $message = 'Your ' . $this->name . '_submit function should redirect when it is finished'; - //} - //throw new PieformException($message); + if ($this->data['dieaftersubmit']) { + // This will only work if I can make the login_submit function stuff work in login_validate + if ($this->data['jsform']) { + $message = 'Your ' . $this->name . '_submit function should use $form->json_reply to send a response'; + } + else { + $message = 'Your ' . $this->name . '_submit function should redirect or exit when it is done'; + } + throw new PieformException($message); + } + else { + // Successful submission, and the user doesn't care about replying, so... + return; + } } else if (!$submitted) { throw new PieformException('No function registered to handle form submission for form "' . $this->name . '"'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 06:29:28
|
Revision: 143 http://svn.sourceforge.net/pieforms/?rev=143&view=rev Author: oracleshinoda Date: 2006-12-23 22:29:24 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Renumbered response constants to be negative numbers, to allow application developers to use the positive numbers Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-24 05:12:32 UTC (rev 142) +++ pieforms-php5/trunk/src/pieform.php 2006-12-24 06:29:24 UTC (rev 143) @@ -26,6 +26,13 @@ $GLOBALS['_PIEFORM_REGISTRY'] = array(); +/** The form was processed successfully */ +define('PIEFORM_OK', 0); +/** The form failed processing/validating */ +define('PIEFORM_ERR', -1); +/** A cancel button was pressed */ +define('PIEFORM_CANCEL', -2); + /** * Builds, validates and processes a form. * @@ -877,7 +884,7 @@ } else { // Redirect if the form is being cancelled - if (data.returnCode == 2) { + if (data.returnCode == -2) { window.location = data.message; return; } @@ -890,7 +897,7 @@ } } - if (data.returnCode == 1) { + if (data.returnCode == -1) { // The request failed validation EOF; @@ -1330,8 +1337,4 @@ return array_unique($htmlelements); } -define('PIEFORM_OK', 0); -define('PIEFORM_ERR', 1); -define('PIEFORM_CANCEL', 2); - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 05:12:34
|
Revision: 142 http://svn.sourceforge.net/pieforms/?rev=142&view=rev Author: oracleshinoda Date: 2006-12-23 21:12:32 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Renamed the *_messages_js functions to *_get_js, which is more appropriate Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/div.php pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php pieforms-php5/trunk/src/pieform/renderers/table.php pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-24 02:32:29 UTC (rev 141) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-24 05:12:32 UTC (rev 142) @@ -78,8 +78,7 @@ } -// @todo needs updating again... need to replace remove_error with remove_all_errors -function pieform_renderer_div_messages_js($id) { +function pieform_renderer_div_get_js($id) { $result = <<<EOF // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-24 02:32:29 UTC (rev 141) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-24 05:12:32 UTC (rev 142) @@ -46,8 +46,7 @@ $formrenderermct->set_form($form); } -function pieform_renderer_multicolumntable_messages_js($id) { - //return pieform_renderer_table_messages_js($id); +function pieform_renderer_multicolumntable_get_js($id) { return <<<EOF function {$id}_set_error (message, element) { element = '{$id}_' + element; Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-24 02:32:29 UTC (rev 141) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-24 05:12:32 UTC (rev 142) @@ -106,7 +106,7 @@ return "</tbody></table>\n"; } -function pieform_renderer_table_messages_js($id) { +function pieform_renderer_table_get_js($id) { $result = <<<EOF function {$id}_set_error(message, element) { element = $('{$id}_' + element + '_container'); Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-24 02:32:29 UTC (rev 141) +++ pieforms-php5/trunk/src/pieform.php 2006-12-24 05:12:32 UTC (rev 142) @@ -928,7 +928,7 @@ EOF; $result .= "});\n\n"; - $function = 'pieform_renderer_' . $this->data['renderer'] . '_messages_js'; + $function = 'pieform_renderer_' . $this->data['renderer'] . '_get_js'; if (!function_exists($function)) { throw new PieformException('No renderer message function "' . $function . '"'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 02:32:38
|
Revision: 141 http://svn.sourceforge.net/pieforms/?rev=141&view=rev Author: oracleshinoda Date: 2006-12-23 18:32:29 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Insert empty table cells in gaps to preserve HTML validation. Disable fieldsets from working, they just make a mess. Fixed up the javascript for inserting errors so it actually works Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-24 00:25:05 UTC (rev 140) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-24 02:32:29 UTC (rev 141) @@ -42,15 +42,47 @@ */ function pieform_renderer_multicolumntable(Pieform $form, $builtelement, $rawelement) { global $formrenderermct; - // Used by the messages javascript function - $form->include_plugin('renderer', 'table'); $formrenderermct->add_element($builtelement, $rawelement); $formrenderermct->set_form($form); } function pieform_renderer_multicolumntable_messages_js($id) { - return pieform_renderer_table_messages_js($id); + //return pieform_renderer_table_messages_js($id); + return <<<EOF +function {$id}_set_error (message, element) { + element = '{$id}_' + element; + var parentRow = $(element + '_container').parentNode; + var nextRow = parentRow.nextSibling; + if (!(nextRow && hasElementClass(nextRow, 'errorRow'))) { + var errorRow = TR({'class': 'errorRow'}); + log(parentRow.cells.length); + for (var i = 0; i < parentRow.cells.length; i++) { + var attrs = null; + if (parentRow.cells[i].id) { + attrs = { + 'id': parentRow.cells[i].id.replace(/_container$/, '_error'), + 'class': 'error' + }; + } + appendChildNodes(errorRow, TD(attrs)); + } + insertSiblingNodesAfter($(element + '_container').parentNode, errorRow); + } + + appendChildNodes(element + '_error', message); + addElementClass(element, 'error'); + addElementClass( element + '_container', 'error'); } +function {$id}_remove_all_errors() { + forEach(getElementsByTagAndClassName('TR', 'errorRow', '{$id}'), function(row) { + removeElement(row); + }); + forEach(getElementsByTagAndClassName(null, 'error', '{$id}'), function(item) { + removeElementClass(item, 'error'); + }); +} +EOF; +} function pieform_renderer_multicolumntable_header() { global $formrenderermct; @@ -68,6 +100,9 @@ private $form; function add_element($builtelement, $rawelement) { + if ($rawelement['type'] == 'fieldset') { + throw new PieformException('The multicolumntable renderer does not support fieldsets'); + } if (!array_key_exists($rawelement['title'], $this->elements)) { $this->elements[$rawelement['title']] = array(); $this->elements[$rawelement['title']]['rawelements'] = array(); @@ -83,6 +118,11 @@ } function build() { + // Find out the maximum number of columns + $columns = 0; + foreach ($this->elements as $data) { + $columns = max($columns, count($data['builtelements'])); + } $result = "<table cellspacing=\"0\" border=\"0\"><tbody>\n"; foreach ($this->elements as $title => $data) { $result .= "\t<tr"; @@ -120,6 +160,9 @@ // @todo description... } + for ($i = count($data['builtelements']); $i < $columns; $i++) { + $result .= "\t<td></td>\n\t"; + } $result .= "</tr>\n"; } $result .= "</tbody></table>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 00:26:03
|
Revision: 140 http://svn.sourceforge.net/pieforms/?rev=140&view=rev Author: oracleshinoda Date: 2006-12-23 16:25:05 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Ignore vim .swp files Property Changed: ---------------- pieforms-php5/trunk/src/js/MochiKit/ pieforms-php5/trunk/src/js/jscalendar/ pieforms-php5/trunk/src/js/jscalendar/lang/ pieforms-php5/trunk/src/js/jscalendar/skins/ pieforms-php5/trunk/src/js/jscalendar/skins/aqua/ pieforms-php5/trunk/src/pieform/elements/ pieforms-php5/trunk/src/pieform/renderers/ pieforms-php5/trunk/src/pieform/rules/ Property changes on: pieforms-php5/trunk/src/js/MochiKit ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/js/jscalendar ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/js/jscalendar/lang ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/js/jscalendar/skins ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/js/jscalendar/skins/aqua ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/pieform/elements ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/pieform/renderers ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/pieform/rules ___________________________________________________________________ Name: svn:ignore + *.swp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 00:25:23
|
Revision: 139 http://svn.sourceforge.net/pieforms/?rev=139&view=rev Author: oracleshinoda Date: 2006-12-23 16:23:51 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Ignore vim .swp files Property Changed: ---------------- pieforms-php5/trunk/src/ pieforms-php5/trunk/src/JSON/ pieforms-php5/trunk/src/js/ pieforms-php5/trunk/src/pieform/ Property changes on: pieforms-php5/trunk/src ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/JSON ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/js ___________________________________________________________________ Name: svn:ignore + *.swp Property changes on: pieforms-php5/trunk/src/pieform ___________________________________________________________________ Name: svn:ignore + *.swp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 00:22:21
|
Revision: 138 http://svn.sourceforge.net/pieforms/?rev=138&view=rev Author: oracleshinoda Date: 2006-12-23 16:20:47 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Updated the expiry element to work with the error javascript stuff. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/expiry.php Modified: pieforms-php5/trunk/src/pieform/elements/expiry.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/expiry.php 2006-12-24 00:19:12 UTC (rev 137) +++ pieforms-php5/trunk/src/pieform/elements/expiry.php 2006-12-24 00:20:47 UTC (rev 138) @@ -33,6 +33,7 @@ * @return string The HTML for the element */ function pieform_element_expiry(Pieform $form, $element) { + $formname = $form->get_name(); $result = ''; $name = $element['name']; if (!isset($element['defaultvalue'])) { @@ -46,9 +47,9 @@ $seconds = $element['value']; $values = pieform_element_expiry_get_expiry_from_seconds($element['value']); } - else if (isset($global[$element['name'] . '_number']) + else if (isset($global[$element['name']]) && isset($global[$element['name'] . '_units'])) { - $values = array('number' => $global[$element['name'] . '_number'], + $values = array('number' => $global[$element['name']], 'units' => $global[$element['name'] . '_units']); $seconds = $values['number'] * pieform_element_expiry_seconds_in($values['units']); } @@ -65,11 +66,12 @@ // Same with the select. And do the events using mochikit signal instead of dom events $numberinput = '<input'; $numberinput .= ($values['units'] == 'noenddate' && empty($element['rules']['required'])) ? ' disabled="disabled"' : ''; - $numberinput .= ' type="text" size="4" name="' . $name . '_number"'; - $numberinput .= ' id="' . $name . '_number" value="' . $values['number'] . '" tabindex="' . $element['tabindex'] . "\">\n"; + $numberinput .= ' type="text" size="4" name="' . $name . '"'; + $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . $values['number'] . '" tabindex="' . $element['tabindex'] . '"'; + $numberinput .= (isset($element['error']) ? ' class="error"' : '') . ">\n"; $uselect = '<select onchange="' . $name . '_change()" '; - $uselect .= 'name="' . $name . '_units" id="' . $name . '_units"' . ' tabindex="' . $element['tabindex'] . "\">\n"; + $uselect .= 'name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . $element['tabindex'] . "\">\n"; foreach (pieform_element_expire_get_expiry_units() as $u) { // Don't allow 'no end date' if the element is required if ($u == 'noenddate' && !empty($element['rules']['required'])) { @@ -85,11 +87,11 @@ $script = <<<EOJS <script type="text/javascript" language="javascript"> function {$name}_change() { - if ($('{$name}_units').value == 'noenddate') { - $('{$name}_number').disabled = true; + if ($('{$formname}_{$name}_units').value == 'noenddate') { + $('{$formname}_{$name}').disabled = true; } else { - $('{$name}_number').disabled = false; + $('{$formname}_{$name}').disabled = false; } } </script> @@ -113,7 +115,7 @@ return null; } $allunits = pieform_element_expire_get_expiry_units(); - $number = $global[$name . '_number']; + $number = $global[$name]; if (!in_array($unit,$allunits) || $number < 0) { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 00:19:37
|
Revision: 137 http://svn.sourceforge.net/pieforms/?rev=137&view=rev Author: oracleshinoda Date: 2006-12-23 16:19:12 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Slight improvements to the javascript for the table renderer Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-24 00:18:11 UTC (rev 136) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-24 00:19:12 UTC (rev 137) @@ -109,11 +109,11 @@ function pieform_renderer_table_messages_js($id) { $result = <<<EOF function {$id}_set_error(message, element) { - element = '{$id}_' + element + '_container'; - var container = getFirstElementByTagAndClassName('TD', null, $(element)); + element = $('{$id}_' + element + '_container'); + var container = getFirstElementByTagAndClassName('TD', null, element); addElementClass(container, 'error'); addElementClass(container.firstChild, 'error'); - insertSiblingNodesAfter($(element), TR({'id': '{$id}_error_' + element}, TD({'colspan': 2, 'class': 'errmsg'}, message))); + insertSiblingNodesAfter(element, TR(null, TD({'colspan': 2, 'class': 'errmsg'}, message))); } function {$id}_remove_all_errors() { forEach(getElementsByTagAndClassName('TD', 'errmsg', $('$id')), function(item) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-24 00:18:47
|
Revision: 136 http://svn.sourceforge.net/pieforms/?rev=136&view=rev Author: oracleshinoda Date: 2006-12-23 16:18:11 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Updated the div javascript for the recent changes made Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/div.php Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-23 13:23:23 UTC (rev 135) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-24 00:18:11 UTC (rev 136) @@ -81,38 +81,21 @@ // @todo needs updating again... need to replace remove_error with remove_all_errors function pieform_renderer_div_messages_js($id) { $result = <<<EOF - // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { - {$id}_remove_error(element); - element += '_container'; - // @todo set error class on input elements... - insertSiblingNodesBefore(DIV({'id': '{$id}_error_' + element, 'class': 'errmsg'}, message), $(element)); + element = '{$id}_' + element; + addElementClass(element + '_container', 'error'); + addElementClass(element, 'error'); + insertSiblingNodesAfter(element + '_container', DIV({'class': 'errmsg'}, message)); } -function {$id}_remove_error(element) { - element += '_container'; - var elem = $('{$id}_error_' + element); - if (elem) { - removeElement(elem); - } +function {$id}_remove_all_errors() { + forEach(getElementsByTagAndClassName('DIV', 'errmsg', '{$id}'), function(div) { + removeElement(div); + }); + forEach(getElementsByTagAndClassName(null, 'error', '{$id}'), function(div) { + removeElementClass(div, 'error'); + }); } -function {$id}_message(message, type) { - var elem = $('{$id}_pieform_message'); - var msg = DIV({'id': '{$id}_pieform_message', 'class': type}, message); - if (elem) { - swapDOM(elem, msg); - } - else { - insertSiblingNodesAfter($('{$id}_' + {$id}_btn + '_container'), msg); - } -} -function {$id}_remove_message() { - var elem = $('{$id}_message'); - if (elem) { - removeElement(elem); - } -} - EOF; return $result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 13:23:23
|
Revision: 135 http://svn.sourceforge.net/pieforms/?rev=135&view=rev Author: oracleshinoda Date: 2006-12-23 05:23:23 -0800 (Sat, 23 Dec 2006) Log Message: ----------- * You can now have a javascript presubmit function non javascript forms. * A bunch of the callbacks have had their names changed for yet more consistency. * Forms that use a hidden iframe to submit to are now known as 'javascript forms' or 'jsforms', not AJAX forms, because they're not using AJAX. A bunch of the callbacks have been renamed based on this. * Support has been added for a PHP callback if a form fails to validate, and a javascript callback if the returnCode is not recognised. * Some function calls were changed to use call_user_func_array, which allows the possibility that they're not just strings (i.e. they could be class/method array pairs) * Reduced the number of parameters for json_reply to two, now the 'errors' index of the 'message' data holds any errors specific to form elements. * The errors sent back will now be set for any nonzero return code. * Broke out the javascript for detecting which button was pressed last into its own method. * Unset the detected last pressed submit button just before the form callback finishes, which prevents randomness when pressing cancel buttons later * Made the get_errors method public, someone else may want access to it. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-23 13:13:02 UTC (rev 134) +++ pieforms-php5/trunk/src/pieform.php 2006-12-23 13:23:23 UTC (rev 135) @@ -73,7 +73,6 @@ // stuff much easier (form_validate_email, form_validate_date etc). // - Collapsible js for fieldsets // - Grippie for textareas - // - javascript validation (probably won't be done as ajax validation is pretty good) // - handle multipage forms? // - handle a tabbed interface type of form? // @@ -188,24 +187,86 @@ // Assign defaults for the form $formdefaults = array( - 'method' => 'get', - 'action' => '', - 'elements' => array(), - 'renderer' => 'table', - 'ajaxform' => false, - 'preajaxsubmitcallback' => '', - 'postajaxsubmitcallback' => '', - 'ajaxsuccesscallback' => '', - 'ajaxfailurecallback' => '', - 'validate' => true, - 'submit' => true, + // The method used to submit the form, should always be 'get' or 'post' + 'method' => 'get', + + // The form target. The vast majority of the time this should be blank, + // as the functions that handle the submit should be in the same script + // as the form definition + 'action' => '', + + // The form elements + 'elements' => array(), + + // The form renderer (see the pieform/renderers directory) + 'renderer' => 'table', + + // Whether to validate the form. Non validated forms have none of the + // validate, success or error callbacks called on them + 'validate' => true, + + // Whether to process the submission of this form. The form will still + // be validated. Handy if the code handling the submission is elsewhere + 'submit' => true, + + // The PHP callback called to validate the form. Optional 'validatecallback' => '', - 'submitcallback' => '', - 'iscancellable' => true, + + // The PHP callback called to process the submission of the form. + // Required, unless a success function is provided for each submit + // button in the form + 'successcallback' => '', + + // The PHP callback called if there is any validation error. Optional + 'errorcallback' => '', + + // Whether this form should submit to a hidden iframe and use DOM + // manipulation to insert error messages (faster than a normal submit, + // supported in less browsers. Most modern browsers should be fine) + 'jsform' => false, + + // The javascript function called before submission of a form + // (regardless of whether the form is a jsform) + 'presubmitcallback' => '', + + // The javascript function called after submission of a form. As non-js + // forms will trigger a page load on submit, this has no effect for them. + 'postsubmitcallback' => '', + + // The javascript function called if the form submission was successful + 'jssuccesscallback' => '', + + // The javascript function called if the form submission was unsuccessful + 'jserrorcallback' => '', + + // The javascript function called if the form submission returned an + // unknown error code + 'globaljserrorcallback' => '', + + // Whether this form can be cancelled, regardless of the presence of + // 'cancel' buttons or form inputs mischeviously named as to behave + // like cancel buttons + 'iscancellable' => true, + + // Whether to auto-focus either the first field (if the value is true, + // or the named field (if the value is a string) when the form is + // displayed. If this has any value other than false and the form has + // been submitted with an error, the first field with an error will + // be focussed. 'autofocus' => false, + + // The directories to search for additional elements, renderers and + // rules 'configdirs' => array(), + + // The language to use for any form strings, such as those found in + // rules. 'language' => 'en.utf8', + + // Any overriding language strings for rules 'rulei18n' => array(), + + // The tabindex for the form (managed automatically by Pieforms) 'tabindex' => false ); $data = array_merge($formdefaults, $formconfig, $data); @@ -218,7 +279,7 @@ } // Make sure that the javascript callbacks are valid - if ($this->data['ajaxform']) { + if ($this->data['jsform']) { $this->validate_js_callbacks(); } @@ -226,8 +287,8 @@ $this->data['validatecallback'] = $this->name . '_validate'; } - if (!$this->data['submitcallback']) { - $this->data['submitcallback'] = $this->name . '_submit'; + if (!$this->data['successcallback']) { + $this->data['successcallback'] = $this->name . '_submit'; } $this->data['configdirs'] = array_map( @@ -405,7 +466,7 @@ if (!isset($element['goto'])) { throw new PieformException('Cancel element "' . $element['name'] . '" has no page to go to'); } - if ($this->data['ajaxform']) { + if ($this->data['jsform']) { $this->json_reply(PIEFORM_CANCEL, $element['goto']); } header('HTTP/1.1 303 See Other'); @@ -422,15 +483,15 @@ $this->validate($values); // Then user specific validation if a function is available for that $function = $this->data['validatecallback']; - if (function_exists($function)) { - $function($this, $values); + if (is_callable($function)) { + call_user_func_array($function, array($this, $values)); } // Submit the form if things went OK if ($this->data['submit'] && !$this->has_errors()) { $submitted = false; foreach ($this->get_elements() as $element) { - if (!empty($element['submitelement']) == true && isset($global[$element['name']])) { + if (!empty($element['submitelement']) && isset($global[$element['name']])) { $function = "{$this->name}_submit_{$element['name']}"; if (function_exists($function)) { $function($this, $values); @@ -439,13 +500,13 @@ } } } - $function = $this->data['submitcallback']; - if (!$submitted && function_exists($function)) { + $function = $this->data['successcallback']; + if (!$submitted && is_callable($function)) { // Call the user defined function for processing a submit // This function should really redirect/exit after it has // finished processing the form. // @todo maybe it should do just that... - $function($this, $values); + call_user_func_array($function, array($this, $values)); // This will only work if I can make the login_submit function stuff work in login_validate //if ($this->ajaxpost) { // $message = 'Your ' . $this->name . '_submit function should output some json and exit'; @@ -464,15 +525,21 @@ if ($this->data['autofocus'] !== false) { $this->auto_focus_first_error(); } + + // Call the user-defined PHP error function, if it exists + $function = $this->data['errorcallback']; + if (is_callable($function)) { + call_user_func_array($function, array($this)); + } - // If the form has been submitted by ajax, return ajax - if ($this->data['ajaxform']) { + // If the form has been submitted by javascript, return json + if ($this->data['jsform']) { $errors = $this->get_errors(); $json = array(); foreach ($errors as $element) { $json[$element['name']] = $element['error']; } - $this->json_reply(PIEFORM_ERR, '@todo allow forms to specify a local error message', $json); + $this->json_reply(PIEFORM_ERR, array('errors' => $json)); } } } @@ -580,9 +647,18 @@ $result .= "</form>\n"; } - if ($this->data['ajaxform']) { + if ($this->data['jsform'] || $this->data['presubmitcallback']) { $result .= '<script type="text/javascript">'; - $result .= "\n" . $this->submit_js(); + $result .= "\n" . $this->whichbutton_js(); + } + if ($this->data['jsform']) { + $result .= $this->submit_js(); + } + else if ($this->data['presubmitcallback']) { + $result .= 'connect(\'' . $this->name . '\', \'onsubmit\', ' + . 'function() { ' . $this->data['presubmitcallback'] . "('{$this->name}', {$this->name}_btn); });"; + } + if ($this->data['jsform'] || $this->data['presubmitcallback']) { $result .= "\n</script>\n"; } @@ -730,9 +806,7 @@ } } - private function submit_js() { - $strprocessingform = get_string('processingform'); - + private function whichbutton_js() { $result = "var {$this->name}_btn = null;\n"; $connecteventadded = false; @@ -742,20 +816,32 @@ $result .= "addLoadEvent(function() {\n"; $connecteventadded = true; } - $result .= " connect($('{$this->name}_{$element['name']}'), 'onclick', function() { {$this->name}_btn = '{$element['name']}'; });\n"; + if (!empty($element['cancelelement'])) { + $cancelstr = 'cancel_'; + } + else { + $cancelstr = ''; + } + $result .= " connect($('{$cancelstr}{$this->name}_{$element['name']}'), 'onclick', function() { {$this->name}_btn = '{$cancelstr}{$this->name}_{$element['name']}'; });\n"; } } if ($connecteventadded) { $result .= "});\n"; } - $result .= <<<EOF + return $result; + } + + private function submit_js() { + $strprocessingform = get_string('processingform'); + + $result = <<<EOF connect($('{$this->name}'), 'onsubmit', function(e) { if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } EOF; - if (!empty($this->data['preajaxsubmitcallback'])) { - $result .= " {$this->data['preajaxsubmitcallback']}();\n"; + if (!empty($this->data['presubmitcallback'])) { + $result .= " {$this->data['presubmitcallback']}('{$this->name}', {$this->name}_btn);\n"; } $result .= <<<EOF @@ -770,60 +856,78 @@ insertSiblingNodesAfter($('{$this->name}'), iframe); window.pieformHandler_{$this->name} = function(data) { - {$this->name}_remove_all_errors(); + +EOF; + if (isset($this->data['processingstopcallback'])) { + $result .= " {$this->data['processingstopcallback']}('{$this->name}', {$this->name}_btn);\n"; + } + + $result .= <<<EOF evalJSONRequest(data); if (data.returnCode == 0) { + {$this->name}_remove_all_errors(); // The request completed successfully - {$this->name}_message(data.message, 'ok'); EOF; - - if (!empty($this->data['ajaxsuccesscallback'])) { - $result .= " {$this->data['ajaxsuccesscallback']}(data);\n"; + if (!empty($this->data['jssuccesscallback'])) { + $result .= " {$this->data['jssuccesscallback']}('{$this->name}', data);\n"; } - $result .= <<<EOF } - else if (data.returnCode == 1) { - // The request failed validation - {$this->name}_message(data.message, 'error'); - for (error in data.errors) { - {$this->name}_set_error(data.errors[error], error); + else { + // Redirect if the form is being cancelled + if (data.returnCode == 2) { + window.location = data.message; + return; } + + // Set errors if there are any + {$this->name}_remove_all_errors(); + if (data.message.errors) { + for (error in data.message.errors) { + {$this->name}_set_error(data.message.errors[error], error); + } + } + if (data.returnCode == 1) { + // The request failed validation + EOF; - if (!empty($this->data['ajaxfailurecallback'])) { - $result .= " {$this->data['ajaxfailurecallback']}(data);\n"; + // @todo: renumber the PIEFORM_* flags to be 0, -1, -2 to allow users to have the positive numbers to themselves + if (!empty($this->data['jserrorcallback'])) { + $result .= " {$this->data['jserrorcallback']}('{$this->name}', data);\n"; } $result .= <<<EOF + } + else { + // A return code we don't know about + +EOF; + if (!empty($this->data['globaljserrorcallback'])) { + $result .= " {$this->data['globaljserrorcallback']}('{$this->name}', data);\n"; + } + else { + $result .= " alert('Developer: got error code ' + data.returnCode + + ', either fix your form to not use this code or define a global js error handler');\n"; + } + $result .= <<<EOF + } } - else if (data.returnCode == 2) { - window.location = data.message; - } - else { - // A return code we don't know about - // @todo call some predefined function passing the data - alert('an unknown error occured (if you are a mahara dev, see Nigel)'); - } EOF; - if (!empty($this->data['postajaxsubmitcallback'])) { - $result .= " {$this->data['postajaxsubmitcallback']}();\n"; + if (!empty($this->data['postsubmitcallback'])) { + $result .= " {$this->data['postsubmitcallback']}('{$this->name}', {$this->name}_btn);\n"; } $result .= <<<EOF + {$this->name}_btn = null; } } - if ({$this->name}_btn) { - {$this->name}_message('{$strprocessingform}', 'info'); - } -}); - - EOF; + $result .= "});\n\n"; $function = 'pieform_renderer_' . $this->data['renderer'] . '_messages_js'; if (!function_exists($function)) { throw new PieformException('No renderer message function "' . $function . '"'); @@ -832,14 +936,11 @@ return $result . $function($this->name); } - public function json_reply($returncode, $message=null, $errors=null) { + public function json_reply($returncode, $message=null) { $data = array( 'returnCode' => intval($returncode), 'message' => $message ); - if ($errors) { - $data['errors'] = $errors; - } $result = json_encode($data); echo <<<EOF @@ -1117,11 +1218,12 @@ } /** - * Makes sure that the ajax callbacks for this form are valid javascript + * Makes sure that the javascript callbacks for this form are valid javascript * function names. */ private function validate_js_callbacks() { - foreach (array('preajaxsubmitcallback', 'postajaxsubmitcallback', 'ajaxsuccesscallback', 'ajaxfailurecallback') as $callback) { + foreach (array('presubmitcallback', 'postsubmitcallback', 'jssuccesscallback', + 'jserrorcallback', 'globaljserrorcallback') as $callback) { if ($this->data[$callback] != '' && !preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $this->data[$callback])) { throw new PieformException("'{$this->data[$callback]}' is not a valid javascript callback name for callback '$callback'"); } @@ -1134,7 +1236,7 @@ * @return array An array of elements with errors on them, the empty array * in the result of no errors. */ - private function get_errors() { + public function get_errors() { $result = array(); foreach ($this->get_elements() as $element) { if (isset($element['error'])) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 13:13:06
|
Revision: 134 http://svn.sourceforge.net/pieforms/?rev=134&view=rev Author: oracleshinoda Date: 2006-12-23 05:13:02 -0800 (Sat, 23 Dec 2006) Log Message: ----------- Removed the messages functions, they are no longer needed. The function itself will later be renamed Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 05:13:18 UTC (rev 133) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 13:13:02 UTC (rev 134) @@ -124,22 +124,6 @@ removeElementClass(item.firstChild, 'error'); }); } -function {$id}_message(message, type) { - var elem = $('{$id}_pieform_message'); - var msg = TR({'id': '{$id}_pieform_message'}, TD({'colspan': 2, 'class': type}, message)); - if (elem) { - swapDOM(elem, msg); - } - else if ({$id}_btn) { - insertSiblingNodesAfter($('{$id}_' + {$id}_btn + '_container'), msg); - } -} -function {$id}_remove_message() { - var elem = $('{$id}_pieform_message'); - if (elem) { - removeElement(elem); - } -} EOF; return $result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 05:13:18
|
Revision: 133 http://svn.sourceforge.net/pieforms/?rev=133&view=rev Author: oracleshinoda Date: 2006-12-22 21:13:18 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Removed mahara-isms that would have prevented anyone else from using it from svnhead Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-23 05:10:44 UTC (rev 132) +++ pieforms-php5/trunk/src/pieform.php 2006-12-23 05:13:18 UTC (rev 133) @@ -674,7 +674,6 @@ private function get_submitted_values() { $result = array(); $global = ($this->data['method'] == 'get') ? $_GET : $_POST; - log_debug($global); foreach ($this->get_elements() as $element) { if ($element['type'] != 'markup') { if ( @@ -842,7 +841,6 @@ $data['errors'] = $errors; } $result = json_encode($data); - log_debug($result); echo <<<EOF <html><head><script type="text/javascript">function sendResult() { parent.pieformHandler_{$this->name}($result); }</script></head><body onload="sendResult(); "></body></html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 05:10:44
|
Revision: 132 http://svn.sourceforge.net/pieforms/?rev=132&view=rev Author: oracleshinoda Date: 2006-12-22 21:10:44 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Make sure the 'error' class is removed from elements when all errors are being removed Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 05:09:20 UTC (rev 131) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 05:10:44 UTC (rev 132) @@ -119,6 +119,10 @@ forEach(getElementsByTagAndClassName('TD', 'errmsg', $('$id')), function(item) { removeElement(item.parentNode); }); + forEach(getElementsByTagAndClassName('TD', 'error', $('$id')), function(item) { + removeElementClass(item, 'error'); + removeElementClass(item.firstChild, 'error'); + }); } function {$id}_message(message, type) { var elem = $('{$id}_pieform_message'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |