From 2ec8579079cdf81a2bb7a972eafb6815457a13b3 Mon Sep 17 00:00:00 2001
From: satish <satish.dvnk@vtiger.com>
Date: Wed, 13 Jul 2016 12:59:35 +0530
Subject: [PATCH] Ajax edit on currency field showing validation error

---
 include/fields/CurrencyField.php                     | 10 +++++-----
 layouts/vlayout/modules/Products/resources/Edit.js   |  8 ++++----
 .../modules/Settings/Webforms/resources/Field.js     |  2 +-
 layouts/vlayout/modules/Users/resources/Edit.js      |  6 +++---
 .../modules/Users/resources/PreferenceDetail.js      |  2 +-
 .../modules/Users/resources/PreferenceEdit.js        | 12 ++++++------
 modules/Vtiger/resources/validator/FieldValidator.js | 10 +++++-----
 .../modules/Webforms/settings/models/ModuleField.php |  4 ++--
 .../modules/Webforms/settings/models/Record.php      |  8 ++++----
 .../Webforms/settings/templates/resources/Field.js   |  2 +-
 10 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/include/fields/CurrencyField.php b/include/fields/CurrencyField.php
index f9409e7f..70546b54 100644
--- a/include/fields/CurrencyField.php
+++ b/include/fields/CurrencyField.php
@@ -430,18 +430,18 @@ class CurrencyField {
                 $value = rtrim($value, '0');
             }
             if($user->currency_decimal_separator == '&nbsp;')
-                $decimalSeperator = ' ';
+                $decimalSeparator = ' ';
             else
-				$decimalSeperator = $user->currency_decimal_separator;
+				$decimalSeparator = $user->currency_decimal_separator;
 
-			$fieldValue = explode(decode_html($decimalSeperator), $value);
+			$fieldValue = explode(decode_html($decimalSeparator), $value);
 			if(strlen($fieldValue[1]) <= 1){
 				if(strlen($fieldValue[1]) == 1) {
-					return $value = $fieldValue[0].$decimalSeperator.$fieldValue[1];
+					return $value = $fieldValue[0].$decimalSeparator.$fieldValue[1];
 				} else if (!strlen($fieldValue[1])) {
 					return $value = $fieldValue[0];
 				} else {
-					return $value = $fieldValue[0].$decimalSeperator;
+					return $value = $fieldValue[0].$decimalSeparator;
 				}
 			}else{
 				return preg_replace("/(?<=\\.[0-9])[0]+\$/","",$value);
diff --git a/layouts/vlayout/modules/Products/resources/Edit.js b/layouts/vlayout/modules/Products/resources/Edit.js
index 001fc31b..8c388f14 100644
--- a/layouts/vlayout/modules/Products/resources/Edit.js
+++ b/layouts/vlayout/modules/Products/resources/Edit.js
@@ -110,7 +110,7 @@ Vtiger_Edit_Js("Products_Edit_Js",{
 			var price = parseFloat(unitPrice) * parseFloat(conversionRate);
 			var userPreferredDecimalPlaces = unitPriceFieldData.numberOfDecimalPlaces;
 			price = price.toFixed(userPreferredDecimalPlaces);
-			var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeperator);
+			var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeparator);
 			jQuery('.convertedPrice',parentElem).val(calculatedPrice);
 		});
 		return this;
@@ -128,9 +128,9 @@ Vtiger_Edit_Js("Products_Edit_Js",{
 				var fieldData = field.data();
 				//As replace is doing replace of single occurence and using regex 
 				//replace has a problem with meta characters  like (.,$),so using split and join
-				var strippedValue = unitPrice.split(fieldData.groupSeperator);
+				var strippedValue = unitPrice.split(fieldData.groupSeparator);
 				strippedValue = strippedValue.join("");
-				strippedValue = strippedValue.replace(fieldData.decimalSeperator, '.');
+				strippedValue = strippedValue.replace(fieldData.decimalSeparator, '.');
 				unitPrice = strippedValue;
 			}
 			return unitPrice;
@@ -176,7 +176,7 @@ Vtiger_Edit_Js("Products_Edit_Js",{
 				jQuery('button.currencyReset', parentRow).attr('disabled', true).removeAttr('disabled');
 				var userPreferredDecimalPlaces = unitPriceFieldData.numberOfDecimalPlaces;
 				price = price.toFixed(userPreferredDecimalPlaces);
-				var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeperator);
+				var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeparator);
 				jQuery('input.convertedPrice',parentRow).val(calculatedPrice)
 			}else{
 				jQuery('input',parentRow).attr('disabled', true);
diff --git a/layouts/vlayout/modules/Settings/Webforms/resources/Field.js b/layouts/vlayout/modules/Settings/Webforms/resources/Field.js
index a8d0027b..3776e312 100755
--- a/layouts/vlayout/modules/Settings/Webforms/resources/Field.js
+++ b/layouts/vlayout/modules/Settings/Webforms/resources/Field.js
@@ -108,7 +108,7 @@ Vtiger_Field_Js('Webforms_Currency_Field_Js',{},{
 	getUi : function() {
 		var html = '<div class="input-prepend">'+
 						'<span class="add-on">'+ this.getCurrencySymbol()+'</span>'+
-						'<input type="text" name="'+ this.getName() +'" value="'+  this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeperator+'" data-group-separator="'+this.getData().groupSeperator+'"/>'+
+						'<input type="text" name="'+ this.getName() +'" value="'+  this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeparator+'" data-group-separator="'+this.getData().groupSeparator+'"/>'+
 					'</div>';
 		var element = jQuery(html);
 		return this.addValidationToElement(element);
diff --git a/layouts/vlayout/modules/Users/resources/Edit.js b/layouts/vlayout/modules/Users/resources/Edit.js
index 2474cbec..9160b2d4 100644
--- a/layouts/vlayout/modules/Users/resources/Edit.js
+++ b/layouts/vlayout/modules/Users/resources/Edit.js
@@ -67,9 +67,9 @@ Vtiger_Edit_Js("Users_Edit_Js",{},{
 	registerRecordPreSaveEvent : function(form){
 		var thisInstance = this;
 		form.on(Vtiger_Edit_Js.recordPreSave, function(e, data) {
-			var groupingSeperatorValue = jQuery('[name="currency_grouping_separator"]', form).val();
-			var decimalSeperatorValue = jQuery('[name="currency_decimal_separator"]', form).val();
-			if(groupingSeperatorValue == decimalSeperatorValue){
+			var groupingSeparatorValue = jQuery('[name="currency_grouping_separator"]', form).val();
+			var decimalSeparatorValue = jQuery('[name="currency_decimal_separator"]', form).val();
+			if(groupingSeparatorValue == decimalSeparatorValue){
 				Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME'));
 				e.preventDefault();
 			}
diff --git a/layouts/vlayout/modules/Users/resources/PreferenceDetail.js b/layouts/vlayout/modules/Users/resources/PreferenceDetail.js
index 49408cc9..bcdfffed 100644
--- a/layouts/vlayout/modules/Users/resources/PreferenceDetail.js
+++ b/layouts/vlayout/modules/Users/resources/PreferenceDetail.js
@@ -14,6 +14,6 @@ Users_Detail_Js("Users_PreferenceDetail_Js",{},{
 	 */
 	registerEvents : function(){
 		this._super();
-		Users_PreferenceEdit_Js.registerChangeEventForCurrencySeperator();
+		Users_PreferenceEdit_Js.registerChangeEventForCurrencySeparator();
 	}
 });
\ No newline at end of file
diff --git a/layouts/vlayout/modules/Users/resources/PreferenceEdit.js b/layouts/vlayout/modules/Users/resources/PreferenceEdit.js
index 344a365c..c1329d50 100644
--- a/layouts/vlayout/modules/Users/resources/PreferenceEdit.js
+++ b/layouts/vlayout/modules/Users/resources/PreferenceEdit.js
@@ -12,13 +12,13 @@ Users_Edit_Js("Users_PreferenceEdit_Js",{
 	/**
 	 * Function to register change event for currency separator
 	 */
-	registerChangeEventForCurrencySeperator : function(){
+	registerChangeEventForCurrencySeparator : function(){
 		var form = jQuery('form');
 		jQuery('[name="currency_decimal_separator"]',form).on('change',function(e){
 			var element = jQuery(e.currentTarget);
 			var selectedValue = element.val();
-			var groupingSeperatorValue = jQuery('[name="currency_grouping_separator"]',form).data('selectedValue');
-			if(groupingSeperatorValue == selectedValue){
+			var groupingSeparatorValue = jQuery('[name="currency_grouping_separator"]',form).data('selectedValue');
+			if(groupingSeparatorValue == selectedValue){
 				var message = app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME');
 				var params = {
 					text: message,
@@ -36,8 +36,8 @@ Users_Edit_Js("Users_PreferenceEdit_Js",{
 		jQuery('[name="currency_grouping_separator"]',form).on('change',function(e){
 			var element = jQuery(e.currentTarget);
 			var selectedValue = element.val();
-			var decimalSeperatorValue = jQuery('[name="currency_decimal_separator"]',form).data('selectedValue');
-			if(decimalSeperatorValue == selectedValue){
+			var decimalSeparatorValue = jQuery('[name="currency_decimal_separator"]',form).data('selectedValue');
+			if(decimalSeparatorValue == selectedValue){
 				var message = app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME');
 				var params = {
 					text: message,
@@ -60,6 +60,6 @@ Users_Edit_Js("Users_PreferenceEdit_Js",{
 	 */
 	registerEvents : function(){
 		this._super();
-		Users_PreferenceEdit_Js.registerChangeEventForCurrencySeperator();
+		Users_PreferenceEdit_Js.registerChangeEventForCurrencySeparator();
 	}
 });
\ No newline at end of file
diff --git a/modules/Vtiger/resources/validator/FieldValidator.js b/modules/Vtiger/resources/validator/FieldValidator.js
index 8d9d5777..317ceb5e 100644
--- a/modules/Vtiger/resources/validator/FieldValidator.js
+++ b/modules/Vtiger/resources/validator/FieldValidator.js
@@ -620,16 +620,16 @@ Vtiger_Base_Validator_Js('Vtiger_Currency_Validator_Js',{
 		var fieldValue = this.getFieldValue();
 		var fieldData = field.data();
 
-		var strippedValue = fieldValue.replace(fieldData.decimalSeperator, '');
+		var strippedValue = fieldValue.replace(fieldData.decimalSeparator, '');
         var spacePattern = /\s/;
-        if(spacePattern.test(fieldData.decimalSeperator) || spacePattern.test(fieldData.groupSeperator))
+        if(spacePattern.test(fieldData.decimalSeparator) || spacePattern.test(fieldData.groupSeparator))
             strippedValue = strippedValue.replace(/ /g, '');
 		var errorInfo;
         
-        if(fieldData.groupSeperator =="$"){
-            fieldData.groupSeperator="\\$"
+        if(fieldData.groupSeparator =="$"){
+            fieldData.groupSeparator="\\$"
         }
-        var regex = new RegExp(fieldData.groupSeperator,'g');
+        var regex = new RegExp(fieldData.groupSeparator,'g');
         strippedValue = strippedValue.replace(regex, '');
 		//Note: Need to review if we should allow only positive values in currencies
 		/*if(strippedValue < 0){
diff --git a/pkg/vtiger/modules/Webforms/settings/models/ModuleField.php b/pkg/vtiger/modules/Webforms/settings/models/ModuleField.php
index 05eb0e1e..cbd263be 100644
--- a/pkg/vtiger/modules/Webforms/settings/models/ModuleField.php
+++ b/pkg/vtiger/modules/Webforms/settings/models/ModuleField.php
@@ -51,8 +51,8 @@ class Settings_Webforms_ModuleField_Model extends Vtiger_Field_Model {
 		if($this->getFieldDataType() == 'currency') {
 			$currentUser = Users_Record_Model::getCurrentUserModel();
 			$fieldInfo['currency_symbol'] = $currentUser->get('currency_symbol');
-			$fieldInfo['decimalSeperator'] = $currentUser->get('currency_decimal_separator');
-			$fieldInfo['groupSeperator'] = $currentUser->get('currency_grouping_separator');
+			$fieldInfo['decimalSeparator'] = $currentUser->get('currency_decimal_separator');
+			$fieldInfo['groupSeparator'] = $currentUser->get('currency_grouping_separator');
 		}
 
 		if($this->getFieldDataType() == 'owner') {
diff --git a/pkg/vtiger/modules/Webforms/settings/models/Record.php b/pkg/vtiger/modules/Webforms/settings/models/Record.php
index 1a67ffac..c9ff65f4 100644
--- a/pkg/vtiger/modules/Webforms/settings/models/Record.php
+++ b/pkg/vtiger/modules/Webforms/settings/models/Record.php
@@ -338,10 +338,10 @@ class Settings_Webforms_Record_Model extends Settings_Vtiger_Record_Model {
 			}
 			
 			if ($dataType === 'currency') {
-				$decimalSeperator = $currentUser->get('currency_decimal_separator');
-				$groupSeperator = $currentUser->get('currency_grouping_separator');
-				$fieldDefaultValue = str_replace($decimalSeperator, '.', $fieldDefaultValue);
-				$fieldDefaultValue = str_replace($groupSeperator, '', $fieldDefaultValue);
+				$decimalSeparator = $currentUser->get('currency_decimal_separator');
+				$groupSeparator = $currentUser->get('currency_grouping_separator');
+				$fieldDefaultValue = str_replace($decimalSeparator, '.', $fieldDefaultValue);
+				$fieldDefaultValue = str_replace($groupSeparator, '', $fieldDefaultValue);
 			}
 
 			array_push($params, $fieldName, $neutralizedField, $fieldDefaultValue, $fieldDetails['required'], $fieldDetails['sequence'], $fieldDetails['hidden']);
diff --git a/pkg/vtiger/modules/Webforms/settings/templates/resources/Field.js b/pkg/vtiger/modules/Webforms/settings/templates/resources/Field.js
index a8d0027b..3776e312 100644
--- a/pkg/vtiger/modules/Webforms/settings/templates/resources/Field.js
+++ b/pkg/vtiger/modules/Webforms/settings/templates/resources/Field.js
@@ -108,7 +108,7 @@ Vtiger_Field_Js('Webforms_Currency_Field_Js',{},{
 	getUi : function() {
 		var html = '<div class="input-prepend">'+
 						'<span class="add-on">'+ this.getCurrencySymbol()+'</span>'+
-						'<input type="text" name="'+ this.getName() +'" value="'+  this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeperator+'" data-group-separator="'+this.getData().groupSeperator+'"/>'+
+						'<input type="text" name="'+ this.getName() +'" value="'+  this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeparator+'" data-group-separator="'+this.getData().groupSeparator+'"/>'+
 					'</div>';
 		var element = jQuery(html);
 		return this.addValidationToElement(element);
-- 
GitLab