mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
updating ajax and form closes #3582, tests added
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6401 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b7aa6ada2c
commit
e127d8f86f
3 changed files with 27 additions and 33 deletions
|
@ -68,7 +68,7 @@ class AjaxHelper extends AppHelper {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $ajaxOptions = array('after', 'asynchronous', 'before', 'confirm', 'condition', 'contentType', 'encoding', 'evalScripts', 'failure', 'fallback', 'form', 'indicator', 'insertion', 'interactive', 'loaded', 'loading', 'method', 'onCreate', 'onComplete', 'onException', 'onFailure', 'onInteractive', 'onLoaded', 'onLoading', 'onSuccess', 'onUninitialized', 'parameters', 'position', 'postBody', 'requestHeaders', 'success', 'type', 'update', 'url', 'with');
|
var $ajaxOptions = array('after', 'asynchronous', 'before', 'confirm', 'condition', 'contentType', 'encoding', 'evalScripts', 'failure', 'fallback', 'form', 'indicator', 'insertion', 'interactive', 'loaded', 'loading', 'method', 'onCreate', 'onComplete', 'onException', 'onFailure', 'onInteractive', 'onLoaded', 'onLoading', 'onSuccess', 'onUninitialized', 'parameters', 'position', 'postBody', 'requestHeaders', 'success', 'type', 'update', 'with');
|
||||||
/**
|
/**
|
||||||
* Options for draggable.
|
* Options for draggable.
|
||||||
*
|
*
|
||||||
|
@ -290,43 +290,31 @@ class AjaxHelper extends AppHelper {
|
||||||
* @return string JavaScript/HTML code
|
* @return string JavaScript/HTML code
|
||||||
*/
|
*/
|
||||||
function form($params = null, $type = 'post', $options = array()) {
|
function form($params = null, $type = 'post', $options = array()) {
|
||||||
|
$model = false;
|
||||||
if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
extract($params, EXTR_OVERWRITE);
|
extract($params, EXTR_OVERWRITE);
|
||||||
|
|
||||||
if (!isset($action)) {
|
|
||||||
$action = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($type)) {
|
|
||||||
$type = 'post';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($options)) {
|
|
||||||
$options = array();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$action = $params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($options['url'])) {
|
||||||
|
$options['url'] = array('action' => $params);
|
||||||
|
}
|
||||||
|
|
||||||
$htmlOptions = array_merge(
|
$htmlOptions = array_merge(
|
||||||
array(
|
array(
|
||||||
'id' => 'form' . intval(rand()),
|
'id' => 'form' . intval(rand()),
|
||||||
'action' => $action,
|
'onsubmit' => "event.returnValue = false; return false;",
|
||||||
'onsubmit' => "event.returnValue = false; return false;",
|
'type' => $type
|
||||||
'type' => $type
|
),
|
||||||
),
|
$this->__getHtmlOptions($options, array('model', 'with'))
|
||||||
$this->__getHtmlOptions($options)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
array(
|
array(
|
||||||
'url' => $htmlOptions['action'],
|
'model' => $model,
|
||||||
'model' => false,
|
|
||||||
'with' => "Form.serialize('{$htmlOptions['id']}')"
|
'with' => "Form.serialize('{$htmlOptions['id']}')"
|
||||||
),
|
),
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
foreach (array_keys($options) as $key) {
|
|
||||||
unset($htmlOptions[$key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->Form->create($options['model'], $htmlOptions)
|
return $this->Form->create($options['model'], $htmlOptions)
|
||||||
. $this->Javascript->event("'" . $htmlOptions['id']. "'", 'submit', $this->remoteFunction($options));
|
. $this->Javascript->event("'" . $htmlOptions['id']. "'", 'submit', $this->remoteFunction($options));
|
||||||
|
|
|
@ -155,11 +155,12 @@ class FormHelper extends AppHelper {
|
||||||
$options);
|
$options);
|
||||||
|
|
||||||
if (empty($options['url']) || is_array($options['url'])) {
|
if (empty($options['url']) || is_array($options['url'])) {
|
||||||
$options = (array)$options;
|
if (empty($options['url']['controller'])) {
|
||||||
if (!empty($model) && $model != $defaultModel) {
|
if (!empty($model) && $model != $defaultModel) {
|
||||||
$controller = Inflector::underscore(Inflector::pluralize($model));
|
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
|
||||||
} else {
|
} elseif (!empty($this->params['controller'])) {
|
||||||
$controller = Inflector::underscore($this->params['controller']);
|
$options['url']['controller'] = Inflector::underscore($this->params['controller']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (empty($options['action'])) {
|
if (empty($options['action'])) {
|
||||||
$options['action'] = ife($created, 'edit', 'add');
|
$options['action'] = ife($created, 'edit', 'add');
|
||||||
|
@ -167,7 +168,7 @@ class FormHelper extends AppHelper {
|
||||||
|
|
||||||
$actionDefaults = array(
|
$actionDefaults = array(
|
||||||
'plugin' => $this->plugin,
|
'plugin' => $this->plugin,
|
||||||
'controller' => $controller,
|
'controller' => $view->viewPath,
|
||||||
'action' => $options['action'],
|
'action' => $options['action'],
|
||||||
'id' => $id
|
'id' => $id
|
||||||
);
|
);
|
||||||
|
|
|
@ -160,6 +160,10 @@ class AjaxTest extends UnitTestCase {
|
||||||
function testForm() {
|
function testForm() {
|
||||||
$result = $this->Ajax->form('showForm', 'post', array('model' => 'Form', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
|
$result = $this->Ajax->form('showForm', 'post', array('model' => 'Form', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
|
||||||
$this->assertNoPattern('/model=/', $result);
|
$this->assertNoPattern('/model=/', $result);
|
||||||
|
|
||||||
|
$result = $this->Ajax->form('showForm', 'post', array('id' => 'MyFormID', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
|
||||||
|
$this->assertPattern('/id="MyFormID"/', $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSortable() {
|
function testSortable() {
|
||||||
|
@ -421,6 +425,7 @@ class AjaxTest extends UnitTestCase {
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
unset($this->Ajax);
|
unset($this->Ajax);
|
||||||
|
ClassRegistry::flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue