Make csrf token generation more generic using dataFilter in ajaxSetup (#597, #599)

This commit is contained in:
jekkos
2016-07-05 17:53:11 +02:00
parent 5de3f17af8
commit 8002694c96
6 changed files with 12 additions and 8 deletions

View File

@@ -83,11 +83,10 @@ $(document).ready(function()
submitHandler:function(form)
{
$(form).ajaxSubmit({
beforeSerialize: setup_csrf_token(),
success:function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
},
dataType:'json'
});

View File

@@ -331,7 +331,6 @@
$('#item_form').validate($.extend({
submitHandler: function(form, event) {
$(form).ajaxSubmit({
beforeSerialize: setup_csrf_token,
success: function(response) {
var stay_open = dialog_support.clicked_id() != 'submit';
if (stay_open)

View File

@@ -36,5 +36,11 @@
setup_csrf_token();
$(document).ajaxComplete(setup_csrf_token);
$.ajaxSetup({
dataFilter: function(data) {
setup_csrf_token();
return data;
}
});
</script>

View File

@@ -85,7 +85,10 @@ if (isset($success))
<?php echo form_input(array('name'=>'item', 'id'=>'item', 'class'=>'form-control input-sm', 'size'=>'50', 'tabindex'=>'1')); ?>
</li>
<li class="pull-right">
<button id='new_item_button' class='btn btn-info btn-sm pull-right modal-dlg' data-btn-submit='<?php echo $this->lang->line('common_submit') ?>' data-href='<?php echo site_url("items/view"); ?>'
<button id='new_item_button' class='btn btn-info btn-sm pull-right modal-dlg'
data-btn-new='<?php echo $this->lang->line('common_new') ?>'
data-btn-submit='<?php echo $this->lang->line('common_submit') ?>'
data-href='<?php echo site_url("items/view"); ?>'
title='<?php echo $this->lang->line('sales_new_item'); ?>'>
<span class="glyphicon glyphicon-tag">&nbsp</span><?php echo $this->lang->line('sales_new_item'); ?>
</button>
@@ -493,7 +496,6 @@ $(document).ready(function()
{
if(response.success)
{
setup_csrf_token();
if (resource.match(/suppliers$/))
{
$("#supplier").attr("value",response.id);

View File

@@ -164,7 +164,6 @@ $(document).ready(function()
{
$(this).ajaxSubmit(
{
beforeSerialize: setup_csrf_token(),
success: function(response)
{
dialog_support.hide();

View File

@@ -672,7 +672,6 @@ $(document).ready(function()
table_support.handle_submit = function(resource, response, stay_open)
{
if(response.success) {
setup_csrf_token();
if (resource.match(/customers$/))
{
$("#customer").val(response.id);