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:
gwoo 2008-01-22 07:47:56 +00:00
parent b7aa6ada2c
commit e127d8f86f
3 changed files with 27 additions and 33 deletions

View file

@ -68,7 +68,7 @@ class AjaxHelper extends AppHelper {
*
* @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.
*
@ -290,43 +290,31 @@ class AjaxHelper extends AppHelper {
* @return string JavaScript/HTML code
*/
function form($params = null, $type = 'post', $options = array()) {
$model = false;
if (is_array($params)) {
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(
array(
'id' => 'form' . intval(rand()),
'action' => $action,
'onsubmit' => "event.returnValue = false; return false;",
'type' => $type
),
$this->__getHtmlOptions($options)
array(
'id' => 'form' . intval(rand()),
'onsubmit' => "event.returnValue = false; return false;",
'type' => $type
),
$this->__getHtmlOptions($options, array('model', 'with'))
);
$options = array_merge(
array(
'url' => $htmlOptions['action'],
'model' => false,
'model' => $model,
'with' => "Form.serialize('{$htmlOptions['id']}')"
),
$options
);
foreach (array_keys($options) as $key) {
unset($htmlOptions[$key]);
}
return $this->Form->create($options['model'], $htmlOptions)
. $this->Javascript->event("'" . $htmlOptions['id']. "'", 'submit', $this->remoteFunction($options));

View file

@ -155,11 +155,12 @@ class FormHelper extends AppHelper {
$options);
if (empty($options['url']) || is_array($options['url'])) {
$options = (array)$options;
if (!empty($model) && $model != $defaultModel) {
$controller = Inflector::underscore(Inflector::pluralize($model));
} else {
$controller = Inflector::underscore($this->params['controller']);
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $defaultModel) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
} elseif (!empty($this->params['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->params['controller']);
}
}
if (empty($options['action'])) {
$options['action'] = ife($created, 'edit', 'add');
@ -167,7 +168,7 @@ class FormHelper extends AppHelper {
$actionDefaults = array(
'plugin' => $this->plugin,
'controller' => $controller,
'controller' => $view->viewPath,
'action' => $options['action'],
'id' => $id
);

View file

@ -160,6 +160,10 @@ class AjaxTest extends UnitTestCase {
function testForm() {
$result = $this->Ajax->form('showForm', 'post', array('model' => 'Form', 'url' => array('action' => 'showForm', 'controller' => 'forms'), 'update' => 'form_box'));
$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() {
@ -421,6 +425,7 @@ class AjaxTest extends UnitTestCase {
function tearDown() {
unset($this->Ajax);
ClassRegistry::flush();
}
}
?>