Fixed excel import notifications (#478)

This commit is contained in:
FrancescoUK
2016-06-08 22:31:25 +01:00
parent 5129ebec0c
commit 53b220b10b
4 changed files with 40 additions and 51 deletions

View File

@@ -227,9 +227,9 @@ class Customers extends Persons
if(count($failCodes) > 0)
{
$msg = 'Most customers imported. But some were not, here is list of their CODE (' . count($failCodes) . '): ' . implode(', ', $failCodes);
$message = 'Most customers imported. But some were not, here is the list (' . count($failCodes) . '): ' . implode(', ', $failCodes);
echo json_encode(array('success' => FALSE, 'message' => $msg));
echo json_encode(array('success' => FALSE, 'message' => $message));
}
else
{

View File

@@ -577,14 +577,9 @@ class Items extends Secure_Controller
public function do_excel_import()
{
$message = 'do_excel_import';
$failCodes = array();
if($_FILES['file_path']['error'] != UPLOAD_ERR_OK)
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_excel_import_failed')));
return;
}
else
{
@@ -592,8 +587,10 @@ class Items extends Secure_Controller
{
// Skip the first row as it's the table description
fgetcsv($handle);
$i = 1;
$failCodes = array();
while(($data = fgetcsv($handle)) !== FALSE)
{
// XSS file data sanity check
@@ -722,27 +719,23 @@ class Items extends Secure_Controller
$i++;
}
if(count($failCodes) > 0)
{
$message = 'Most Items imported. But some were not, here is the list (' . count($failCodes) . '): ' . implode(', ', $failCodes);
echo json_encode(array('success' => FALSE, 'message' => $message));
}
else
{
echo json_encode(array('success' => TRUE, 'message' => 'Import of Items successful'));
}
}
else
{
echo json_encode(array('success' => FALSE, 'message' => 'Your uploaded file has no data or wrong format'));
return;
}
}
$success = TRUE;
if(count($failCodes) > 0)
{
$message = 'Most items imported. But some were not, here is list of their codes (' . count($failCodes) . '): ' . implode(', ', $failCodes);
$success = FALSE;
}
else
{
$message = 'Import of Items successful';
}
echo json_encode(array('success' => $success, 'message' => $message));
}
}
?>

View File

@@ -1,6 +1,6 @@
<ul id="error_message_box" class="error_message_box"></ul>
<?php echo form_open_multipart('customers/do_excel_import/', array('id'=>'item_form', 'class'=>'form-horizontal')); ?>
<?php echo form_open_multipart('customers/do_excel_import/', array('id'=>'excel_form', 'class'=>'form-horizontal')); ?>
<fieldset id="item_basic_info">
<div class="form-group form-group-sm">
<div class="col-xs-12">
@@ -24,28 +24,26 @@
//validation and submit handling
$(document).ready(function()
{
$('#item_form').validate($.extend({
submitHandler:function(form)
{
$('#excel_form').validate($.extend({
submitHandler:function(form) {
$(form).ajaxSubmit({
success:function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url('customers'); ?>', response);
},
dataType:'json'
});
success:function(response)
{
dialog_support.hide();
$.notify(response.message, { type: response.success ? 'success' : 'danger'} );
},
dataType: 'json'
});
},
errorLabelContainer: "#error_message_box",
wrapper: "li",
rules:
{
file_path:"required"
file_path: "required"
},
messages:
{
file_path:"<?php echo $this->lang->line('common_import_full_path'); ?>"
file_path: "<?php echo $this->lang->line('common_import_full_path'); ?>"
}
}, form_support.error));
});

View File

@@ -1,6 +1,6 @@
<ul id="error_message_box" class="error_message_box"></ul>
<?php echo form_open_multipart('items/do_excel_import/', array('id'=>'item_form', 'class'=>'form-horizontal')); ?>
<?php echo form_open_multipart('items/do_excel_import/', array('id'=>'excel_form', 'class'=>'form-horizontal')); ?>
<fieldset id="item_basic_info">
<div class="form-group form-group-sm">
<div class="col-xs-12">
@@ -24,28 +24,26 @@
//validation and submit handling
$(document).ready(function()
{
$('#item_form').validate($.extend({
submitHandler:function(form)
{
$('#excel_form').validate($.extend({
submitHandler:function(form) {
$(form).ajaxSubmit({
success:function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url('items'); ?>', response);
},
dataType:'json'
});
success:function(response)
{
dialog_support.hide();
$.notify(response.message, { type: response.success ? 'success' : 'danger'} );
},
dataType: 'json'
});
},
errorLabelContainer: "#error_message_box",
wrapper: "li",
rules:
{
file_path:"required"
file_path: "required"
},
messages:
{
file_path:"<?php echo $this->lang->line('common_import_full_path'); ?>"
file_path: "<?php echo $this->lang->line('common_import_full_path'); ?>"
}
}, form_support.error));
});