mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing issues with ajax forms and mootools. post needs to be lowercase.
Implementing serializeForm() in MootoolsEngine. Updating doc blocks.
This commit is contained in:
parent
2414a43c91
commit
6f10f5de6d
4 changed files with 94 additions and 46 deletions
|
@ -244,6 +244,9 @@ class JsHelper extends AppHelper {
|
|||
* element that is enhanced with Javascript. Options can include
|
||||
* both those for FormHelper::submit() and JsBaseEngine::request(), JsBaseEngine::event();
|
||||
*
|
||||
* Forms submitting with this method, cannot send files. Files do not transfer over XmlHttpRequest
|
||||
* and require an iframe.
|
||||
*
|
||||
* @param string $title The display text of the submit button.
|
||||
* @param array $options Array of options to use.
|
||||
* @return string Completed submit button.
|
||||
|
@ -269,7 +272,7 @@ class JsHelper extends AppHelper {
|
|||
unset($options['url']);
|
||||
}
|
||||
if (!isset($options['method'])) {
|
||||
$options['method'] = 'POST';
|
||||
$options['method'] = 'post';
|
||||
}
|
||||
$options['dataExpression'] = true;
|
||||
$requestString .= $this->request($url, $options);
|
||||
|
@ -718,15 +721,15 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - handle - selector to the handle element.
|
||||
* - snapGrid - The pixel grid that movement snaps to, an array(x, y)
|
||||
* - container - The element that acts as a bounding box for the draggable element.
|
||||
* - `handle` - selector to the handle element.
|
||||
* - `snapGrid` - The pixel grid that movement snaps to, an array(x, y)
|
||||
* - `container` - The element that acts as a bounding box for the draggable element.
|
||||
*
|
||||
* ### Event Options
|
||||
*
|
||||
* - start - Event fired when the drag starts
|
||||
* - drag - Event fired on every step of the drag
|
||||
* - stop - Event fired when dragging stops (mouse release)
|
||||
* - `start` - Event fired when the drag starts
|
||||
* - `drag` - Event fired on every step of the drag
|
||||
* - `stop` - Event fired when dragging stops (mouse release)
|
||||
*
|
||||
* @param array $options Options array see above.
|
||||
* @return string Completed drag script
|
||||
|
@ -740,14 +743,14 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - accept - Selector for elements this droppable will accept.
|
||||
* - hoverclass - Class to add to droppable when a draggable is over.
|
||||
* - `accept` - Selector for elements this droppable will accept.
|
||||
* - `hoverclass` - Class to add to droppable when a draggable is over.
|
||||
*
|
||||
* ### Event Options
|
||||
*
|
||||
* - drop - Event fired when an element is dropped into the drop zone.
|
||||
* - hover - Event fired when a drag enters a drop zone.
|
||||
* - leave - Event fired when a drag is removed from a drop zone without being dropped.
|
||||
* - `drop` - Event fired when an element is dropped into the drop zone.
|
||||
* - `hover` - Event fired when a drag enters a drop zone.
|
||||
* - `leave` - Event fired when a drag is removed from a drop zone without being dropped.
|
||||
*
|
||||
* @return string Completed drop script
|
||||
**/
|
||||
|
@ -759,17 +762,17 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - containment - Container for move action
|
||||
* - handle - Selector to handle element. Only this element will start sort action.
|
||||
* - revert - Whether or not to use an effect to move sortable into final position.
|
||||
* - opacity - Opacity of the placeholder
|
||||
* - distance - Distance a sortable must be dragged before sorting starts.
|
||||
* - `containment` - Container for move action
|
||||
* - `handle` - Selector to handle element. Only this element will start sort action.
|
||||
* - `revert` - Whether or not to use an effect to move sortable into final position.
|
||||
* - `opacity` - Opacity of the placeholder
|
||||
* - `distance` - Distance a sortable must be dragged before sorting starts.
|
||||
*
|
||||
* ### Event Options
|
||||
*
|
||||
* - start - Event fired when sorting starts
|
||||
* - sort - Event fired during sorting
|
||||
* - complete - Event fired when sorting completes.
|
||||
* - `start` - Event fired when sorting starts
|
||||
* - `sort` - Event fired during sorting
|
||||
* - `complete` - Event fired when sorting completes.
|
||||
*
|
||||
*
|
||||
* @param array $options Array of options for the sortable. See above.
|
||||
|
@ -783,17 +786,17 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - handle - The id of the element used in sliding.
|
||||
* - direction - The direction of the slider either 'vertical' or 'horizontal'
|
||||
* - min - The min value for the slider.
|
||||
* - max - The max value for the slider.
|
||||
* - step - The number of steps or ticks the slider will have.
|
||||
* - value - The initial offset of the slider.
|
||||
* - `handle` - The id of the element used in sliding.
|
||||
* - `direction` - The direction of the slider either 'vertical' or 'horizontal'
|
||||
* - `min` - The min value for the slider.
|
||||
* - `max` - The max value for the slider.
|
||||
* - `step` - The number of steps or ticks the slider will have.
|
||||
* - `value` - The initial offset of the slider.
|
||||
*
|
||||
* ### Events
|
||||
*
|
||||
* - change - Fired when the slider's value is updated
|
||||
* - complete - Fired when the user stops sliding the handle
|
||||
* - `change` - Fired when the slider's value is updated
|
||||
* - `complete` - Fired when the user stops sliding the handle
|
||||
*
|
||||
* @return string Completed slider script
|
||||
**/
|
||||
|
@ -808,8 +811,8 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - isForm - is the current selection a form, or an input? (defaults to false)
|
||||
* - inline - is the rendered statement going to be used inside another JS statement? (defaults to false)
|
||||
* - `isForm` - is the current selection a form, or an input? (defaults to false)
|
||||
* - `inline` - is the rendered statement going to be used inside another JS statement? (defaults to false)
|
||||
*
|
||||
* @param array $options options for serialization generation.
|
||||
* @return string completed form serialization script
|
||||
|
|
|
@ -184,25 +184,28 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
$url = $this->url($url);
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = $data = null;
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
$type = '.JSON';
|
||||
if (!empty($options['data'])) {
|
||||
$data = $this->object($options['data']);
|
||||
unset($options['data']);
|
||||
if (isset($options['type']) || isset($options['update'])) {
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
$type = '.JSON';
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
$options['update'] = str_replace('#', '', $options['update']);
|
||||
$type = '.HTML';
|
||||
}
|
||||
unset($options['type']);
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
$options['update'] = str_replace('#', '', $options['update']);
|
||||
$type = '.HTML';
|
||||
if (!empty($options['data'])) {
|
||||
$data = $this->_toQuerystring($options['data']);
|
||||
unset($options['data']);
|
||||
}
|
||||
unset($options['type']);
|
||||
if (!empty($options['data'])) {
|
||||
$data = $options['data'];
|
||||
unset($options['data']);
|
||||
}
|
||||
$options['url'] = $url;
|
||||
$callbacks = array('onComplete', 'onFailure', 'onRequest', 'onSuccess', 'onCancel', 'onException');
|
||||
if (isset($options['dataExpression'])) {
|
||||
$callbacks[] = 'data';
|
||||
unset($options['dataExpression']);
|
||||
} elseif (!empty($data)) {
|
||||
$data = $this->object($data);
|
||||
}
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
return "var jsRequest = new Request$type({{$options}}).send($data);";
|
||||
}
|
||||
|
@ -303,5 +306,24 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
$this->selection = $slider;
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Serialize the form attached to $selector.
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @return string Completed serializeForm() snippet
|
||||
* @see JsHelper::serializeForm()
|
||||
**/
|
||||
function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$selection = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selection = '$(' . $this->selection . '.form)';
|
||||
}
|
||||
$method = '.toQueryString()';
|
||||
if (!$options['inline']) {
|
||||
$method .= ';';
|
||||
}
|
||||
return $selection . $method;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -357,7 +357,7 @@ CODE;
|
|||
|
||||
$params = array(
|
||||
'update' => $options['update'], 'data' => 'serialize-code',
|
||||
'method' => 'POST', 'dataExpression' => true
|
||||
'method' => 'post', 'dataExpression' => true
|
||||
);
|
||||
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
|
||||
'event', array('click', "ajax-code", $params)
|
||||
|
@ -378,7 +378,7 @@ CODE;
|
|||
'/custom/url', array(
|
||||
'update' => '#content',
|
||||
'data' => 'serialize-code',
|
||||
'method' => 'POST',
|
||||
'method' => 'post',
|
||||
'dataExpression' => true
|
||||
)
|
||||
);
|
||||
|
@ -386,7 +386,7 @@ CODE;
|
|||
|
||||
$params = array(
|
||||
'update' => '#content', 'data' => 'serialize-code',
|
||||
'method' => 'POST', 'dataExpression' => true
|
||||
'method' => 'post', 'dataExpression' => true
|
||||
);
|
||||
$this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array(
|
||||
'event', array('click', "ajax-code", $params)
|
||||
|
|
|
@ -278,5 +278,28 @@ class MooEngineHelperTestCase extends CakeTestCase {
|
|||
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete, range:[10,40]});';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test the serializeForm implementation.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testSerializeForm() {
|
||||
$this->Moo->get('#element');
|
||||
$result = $this->Moo->serializeForm(array('isForm' => true));
|
||||
$expected = '$("element").toQueryString();';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Moo->serializeForm(array('isForm' => true, 'inline' => true));
|
||||
$expected = '$("element").toQueryString()';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Moo->serializeForm(array('isForm' => false));
|
||||
$expected = '$($("element").form).toQueryString();';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Moo->serializeForm(array('isForm' => false, 'inline' => true));
|
||||
$expected = '$($("element").form).toQueryString()';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue