From 258c95f02efd356772c958be60a09a384028bb60 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 21 Mar 2016 21:19:52 +0100 Subject: [PATCH] Remove sync ajax calls in validation callback for forms (#413) Remove jquery-bgiframe (not used anynmore) (#328) Fix bug in receiving form save if supplier was empty Conflicts: application/controllers/Items.php application/views/customers/form.php application/views/items/form.php application/views/partial/header.php application/views/receivings/form.php application/views/sales/form.php bower.json dist/opensourcepos.js dist/opensourcepos.min.js templates/spacelab/views/partial/header.php --- application/controllers/Customers.php | 2 +- application/controllers/Items.php | 2 +- application/controllers/Receivings.php | 4 +-- application/controllers/Sales.php | 3 +-- application/views/customers/form.php | 37 +++++++++++++------------- application/views/items/form.php | 35 ++++++++++++------------ application/views/partial/header.php | 3 +-- application/views/receivings/form.php | 36 +++++++++++-------------- application/views/sales/form.php | 32 ++++++++++------------ bower.json | 1 - dist/opensourcepos.min.js | 2 +- js/jquery.bgiframe.min.js | 10 ------- 12 files changed, 72 insertions(+), 95 deletions(-) delete mode 100644 js/jquery.bgiframe.min.js diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index c75de83e5..df2a955a6 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -102,7 +102,7 @@ class Customers extends Person_controller function check_account_number() { $exists = $this->Customer->account_number_exists($this->input->post('account_number'),$this->input->post('person_id')); - echo json_encode(array('success'=>!$exists,'message'=>$this->lang->line('customers_account_number_duplicate'))); + echo !$exists ? 'true' : 'false'; } /* diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 4e2cc6042..954d10c04 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -492,7 +492,7 @@ class Items extends Secure_area implements iData_controller function check_item_number() { $exists = $this->Item->item_number_exists($this->input->post('item_number'),$this->input->post('item_id')); - echo json_encode(array('success'=>!$exists,'message'=>$this->lang->line('items_item_number_duplicate'))); + echo !$exists ? 'true' : 'false'; } function _handle_image_upload() diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index b7971d08b..9bc16b3ac 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -367,7 +367,7 @@ class Receivings extends Secure_area $receiving_data = array( 'receiving_time' => $date_formatter->format('Y-m-d H:i:s'), - 'supplier_id' => $this->input->post('supplier_id'), + 'supplier_id' => empty($this->input->post('supplier_id')) ? NULL : $this->input->post('supplier_id'), 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), 'invoice_number' => $this->input->post('invoice_number') @@ -402,7 +402,7 @@ class Receivings extends Secure_area $receiving_id=$this->input->post('receiving_id'); $invoice_number=$this->input->post('invoice_number'); $exists=!empty($invoice_number) && $this->Receiving->invoice_number_exists($invoice_number,$receiving_id); - echo json_encode(array('success'=>!$exists,'message'=>$this->lang->line('recvs_invoice_number_duplicate'))); + echo !$exists ? 'true' : 'false'; } } ?> diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index d624aab6a..127dd335f 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -828,8 +828,7 @@ class Sales extends Secure_area $sale_id = $this->input->post('sale_id'); $invoice_number = $this->input->post('invoice_number'); $exists = !empty($invoice_number) && $this->Sale->invoice_number_exists($invoice_number,$sale_id); - - echo json_encode(array('success'=>!$exists, 'message'=>$this->lang->line('sales_invoice_number_duplicate'))); + echo !$exists ? 'true' : 'false'; } } ?> diff --git a/application/views/customers/form.php b/application/views/customers/form.php index 2cfe397f3..2ae58a203 100644 --- a/application/views/customers/form.php +++ b/application/views/customers/form.php @@ -54,23 +54,6 @@ echo form_close(); $(document).ready(function() { - $.validator.addMethod("account_number", function(value, element) - { - return JSON.parse($.ajax( - { - type: 'POST', - url: '', - data: {'person_id' : 'person_id; ?>', 'account_number' : $(element).val() }, - success: function(response) - { - success=response.success; - }, - async:false, - dataType: 'json' - }).responseText).success; - - }, 'lang->line("customers_account_number_duplicate"); ?>'); - $('#customer_form').validate({ submitHandler:function(form) { @@ -91,13 +74,29 @@ $(document).ready(function() first_name: "required", last_name: "required", email: "email", - account_number: { account_number: true } + account_number: + { + remote: + { + url: "", + type: "post", + data: + { + "person_id" : "person_id; ?>", + "account_number" : function() + { + return $("#account_number").val(); + } + } + } + } }, messages: { first_name: "lang->line('common_first_name_required'); ?>", last_name: "lang->line('common_last_name_required'); ?>", - email: "lang->line('common_email_invalid_format'); ?>" + email: "lang->line('common_email_invalid_format'); ?>", + account_number: "lang->line('customers_account_number_duplicate'); ?>" } }); }); diff --git a/application/views/items/form.php b/application/views/items/form.php index f5b37d11a..7fffa1cce 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -282,23 +282,6 @@ $(document).ready(function() - - $.validator.addMethod("item_number", function(value, element) - { - return JSON.parse($.ajax( - { - type: 'POST', - url: '', - data: {'item_id' : 'item_id; ?>', 'item_number' : $(element).val() }, - success: function(response) - { - success=response.success; - }, - async:false, - dataType: 'json' - }).responseText).success; - - }, 'lang->line("items_item_number_duplicate"); ?>'); $('#item_form').validate({ submitHandler:function(form) @@ -332,7 +315,22 @@ $(document).ready(function() { name:"required", category:"required", - item_number: { item_number: true }, + item_number: + { + remote: + { + url: "", + type: "POST", + data: + { + "item_id": "item_id; ?>", + "item_number": function () + { + return $("#item_number").val(); + } + } + } + }, cost_price: { required:true, @@ -359,6 +357,7 @@ $(document).ready(function() messages: { name:"lang->line('items_name_required'); ?>", + item_number:"lang->line('items_item_number_duplicate'); ?>", category:"lang->line('items_category_required'); ?>", cost_price: { diff --git a/application/views/partial/header.php b/application/views/partial/header.php index 9a1b38a0e..8a9c52f0f 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -15,7 +15,6 @@ - @@ -35,7 +34,7 @@ - + diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index d5bfae34c..c468270d7 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -71,24 +71,6 @@