/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
jQuery.Class("Settings_Vtiger_Tax_Js",{},{
//Stored history of TaxName and duplicate check result
duplicateCheckCache : {},
/**
* This function will show the model for Add/Edit tax
*/
editTax : function(url, currentTrElement) {
var aDeferred = jQuery.Deferred();
var thisInstance = this;
var progressIndicatorElement = jQuery.progressIndicator({
'position' : 'html',
'blockInfo' : {
'enabled' : true
}
});
AppConnector.request(url).then(
function(data) {
var callBackFunction = function(data) {
//cache should be empty when modal opened
thisInstance.duplicateCheckCache = {};
var form = jQuery('#editTax');
var params = app.validationEngineOptions;
params.onValidationComplete = function(form, valid){
if(valid) {
thisInstance.saveTaxDetails(form, currentTrElement);
return valid;
}
}
form.validationEngine(params);
form.submit(function(e) {
e.preventDefault();
})
}
progressIndicatorElement.progressIndicator({'mode':'hide'});
app.showModalWindow(data,function(data){
if(typeof callBackFunction == 'function'){
callBackFunction(data);
}
}, {'width':'500px'});
},
function(error) {
//TODO : Handle error
aDeferred.reject(error);
}
);
return aDeferred.promise();
},
/*
* Function to Save the Tax Details
*/
saveTaxDetails : function(form, currentTrElement) {
var thisInstance = this;
var params = form.serializeFormData();
if(typeof params == 'undefined' ) {
params = {};
}
thisInstance.validateTaxName(params).then(
function(data) {
var progressIndicatorElement = jQuery.progressIndicator({
'position' : 'html',
'blockInfo' : {
'enabled' : true
}
});
params.module = app.getModuleName();
params.parent = app.getParentModuleName();
params.action = 'TaxAjax';
AppConnector.request(params).then(
function(data) {
progressIndicatorElement.progressIndicator({'mode':'hide'});
app.hideModalWindow();
//Adding or update the tax details in the list
if(form.find('.addTaxView').val() == "true") {
thisInstance.addTaxDetails(data['result']);
} else {
thisInstance.updateTaxDetails(data['result'], currentTrElement);
}
//show notification after tax details saved
var params = {
text: app.vtranslate('JS_TAX_SAVED_SUCCESSFULLY')
};
Settings_Vtiger_Index_Js.showMessage(params);
}
);
},
function(data,err) {
}
);
},
/*
* Function to add the Tax Details in the list after saving
*/
addTaxDetails : function(details) {
var container = jQuery('#TaxCalculationsContainer');
//Based on tax type, we will add the tax details row
if(details.type == '0') {
var taxTable = jQuery('.inventoryTaxTable', container);
} else {
var taxTable = jQuery('.shippingTaxTable', container);
}
var trElementForTax =
jQuery('