+ finish task #1433.

This commit is contained in:
wangyidong
2013-06-26 03:42:13 +00:00
parent c43eec4a20
commit a0c3627b8c
5 changed files with 134 additions and 16 deletions
+14
View File
@@ -581,6 +581,20 @@ class control
echo $this->output;
}
/**
* Send data directly, for ajax requests.
*
* @param misc $data
* @param string $type
* @access public
* @return void
*/
public function send($data, $type = 'json')
{
if($type == 'json') echo json_encode($data);
die(removeUTF8Bom(ob_get_clean()));
}
/**
* Create a link to one method of one module.
*
+7
View File
@@ -0,0 +1,7 @@
<?php if($extView = $this->getExtViewFile(__FILE__)){include $extView; return helper::cd();}?>
<?php
if($config->debug)
{
js::import($jsRoot . 'jquery/form/min.js');
js::import($jsRoot . 'jquery/form/zentao.js');
}
+7
View File
File diff suppressed because one or more lines are too long
+102
View File
@@ -0,0 +1,102 @@
$.extend(
{
ajaxForm: function(formID, callback)
{
form = $(formID);
var options =
{
target : null,
timeout : 30000,
dataType:'json',
success:function(response)
{
$.enableForm(formID);
/* The response is not an object, some error occers, alert it. */
if($.type(response) != 'object')
{
if(response) return alert(response);
return alert('No response.');
}
/* The response.result is success. */
if(response.result == 'success')
{
if($.isFunction(callback)) return callback(response);
if(response.message) alert(response.message);
if(response.locate) return location.href = response.locate;
}
/**
* The response.result is fail.
*/
/* The result.message is just a string. */
if($.type(response.message) == 'string')
{
if($('#responser').length == 0) return alert(response.message);
return $('#responser').html(response.message).addClass('text-error').show().delay(3000).fadeOut(100);
}
/* The result.message is just a object. */
if($.type(response.message) == 'object')
{
$.each(response.message, function(key, value)
{
/* Define the id of the error objecjt and it's label. */
var errorOBJ = '#' + key;
var errorLabel = key + 'Label';
/* Create the error message. */
var errorMSG = '<label id="' + errorLabel + '" class="text-error">';
errorMSG += $.type(value) == 'string' ? value : value.join(';');
errorMSG += '</label>';
/* Append error message, set style and set the focus events. */
$('#' + errorLabel).remove();
$(errorOBJ).after(errorMSG);
$(errorOBJ).css('margin-bottom', 0);
$(errorOBJ).css('border-color','#953B39')
$(errorOBJ).focus(function()
{
$(this).removeAttr('style')
$('#' + errorLabel).remove();
});
})
}
},
/* When error occers, alert the response text, status and error. */
error:function(jqXHR, textStatus, errorThrown)
{
$.enableForm(formID);
alert(jqXHR.responseText + textStatus + errorThrown);
}
};
/* Call ajaxSubmit to sumit the form. */
form.submit(function()
{
$(this).ajaxSubmit(options);
return false; // Prevent the submitting event of the browser.
});
},
/* Disable a form. */
disableForm:function(formID)
{
$(formID).find(':submit').attr('disabled', true);
},
/* Enable a form. */
enableForm:function(formID)
{
$(formID).find(':submit').attr('disabled', false);
}
});
$(document).ready(function()
{
$.ajaxForm('.ajaxForm')
})
+4 -16
View File
File diff suppressed because one or more lines are too long