diff --git a/application/controllers/widgets/UDF.php b/application/controllers/widgets/UDF.php
index 3ba745a10..26c30293c 100644
--- a/application/controllers/widgets/UDF.php
+++ b/application/controllers/widgets/UDF.php
@@ -36,7 +36,6 @@ class UDF extends FHC_Controller
*/
public function saveUDFs()
{
- $udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID);
$udfs = $this->input->post(UDFLib::UDFS_ARG_NAME);
if (!isEmptyString($udfs))
@@ -44,7 +43,7 @@ class UDF extends FHC_Controller
$jsonDecodedUDF = json_decode($udfs);
if ($jsonDecodedUDF != null)
{
- $this->outputJson($this->udflib->saveUDFs($udfUniqueId, $jsonDecodedUDF));
+ $this->outputJson($this->udflib->saveUDFs($jsonDecodedUDF));
}
else
{
diff --git a/application/libraries/UDFLib.php b/application/libraries/UDFLib.php
index 26ae1ec78..827bdc989 100644
--- a/application/libraries/UDFLib.php
+++ b/application/libraries/UDFLib.php
@@ -371,7 +371,7 @@ class UDFLib
// Loops through the UDFs values that should be stored
foreach ($udfsParameters as $key => $val)
{
- $tmpValidate = success(true); // temporary variable used to store the returned value from _validateUDFs
+ $tmpValidateArray = array(); // temporary variable used to store the returned value from _validateUDFs
// If this is the definition of this UDF
if ($decodedUDFDefinition->{self::NAME} == $key)
@@ -433,7 +433,7 @@ class UDFLib
if ($toBeValidated === true) // Checks if validation should be performed
{
- $tmpValidate = $this->_validateUDFs(
+ $tmpValidateArray = $this->_validateUDFs(
$decodedUDFDefinition->{self::VALIDATION},
$decodedUDFDefinition->{self::NAME},
$val
@@ -443,13 +443,13 @@ class UDFLib
}
// If validation is ok copy the value that is to be stored into $toBeStoredUDFsArray
- if (isSuccess($tmpValidate))
+ if (isEmptyArray($tmpValidateArray))
{
$toBeStoredUDFsArray[$key] = $val;
}
- else // otherwise store the validation error in $notValidUDFsArray
+ else // otherwise store the validation errors in $notValidUDFsArray
{
- $notValidUDFsArray[] = $tmpValidate;
+ $notValidUDFsArray = array_merge($notValidUDFsArray, $tmpValidateArray);
}
}
}
@@ -585,34 +585,14 @@ class UDFLib
/**
* Save UDFs
*/
- public function saveUDFs($udfUniqueId, $udfs)
+ public function saveUDFs($udfs)
{
- $udfToBewritten = array(); // UDFs to be written into database
-
// Read the all session for this udf widget
$session = $this->getSession();
// If session is empty then return an error
if ($session == null) return error('No UDFWidget loaded');
- // Get the required permission from the session
- $requiredPermissions = $session[self::REQUIRED_PERMISSIONS_PARAMETER];
-
- // For each UDF that is trying to save
- foreach ($udfs as $udfName => $udfValue)
- {
- // If the UDFs exists in the requiredPermissions array
- if (array_key_exists($udfName, $requiredPermissions))
- {
- // Then check if the user has the permissions to write such UDF
- if ($this->_writeAllowed($requiredPermissions[$udfName]))
- {
- // If allowed then save the UDF name and value to be stored later into the database
- $udfToBewritten[$udfName] = $udfValue;
- }
- }
- }
-
// Workaround to load CI
$this->_ci->load->model('system/UDF_model', 'UDFModel');
@@ -629,7 +609,7 @@ class UDFLib
// Returns the result of the database update operation to save UDFs
return $dbModel->update(
array($session[self::PRIMARY_KEY_NAME] => $session[self::PRIMARY_KEY_VALUE]),
- $udfToBewritten
+ get_object_vars($udfs)
);
}
@@ -834,9 +814,6 @@ class UDFLib
}
}
- // If no UDF validation errors were raised, it's a success!!
- if (isEmptyArray($returnArrayValidation)) $returnArrayValidation = success(true);
-
return $returnArrayValidation;
}
diff --git a/public/js/UDFWidget.js b/public/js/UDFWidget.js
index b9c3a7386..82c29de35 100644
--- a/public/js/UDFWidget.js
+++ b/public/js/UDFWidget.js
@@ -55,17 +55,27 @@ var FHC_UDFWidget = {
if (FHC_AjaxClient.hasData(data))
{
- FHC_DialogLib.alertSuccess('Done!');
+ FHC_DialogLib.alertSuccess("Successfully saved");
}
else
{
- console.log(FHC_AjaxClient.getError(data));
+ var msgError = "An error occurred while saving these fields:
";
+ var errors = FHC_AjaxClient.getError(data);
+
+ for (var i = 0; i < errors.length; i++)
+ {
+ var error = errors[i];
+
+ msgError += FHC_AjaxClient.getError(error)+ "
";
+ }
+
+ FHC_DialogLib.alertError(msgError);
}
}
},
{
errorCallback: function(data, textStatus, jqXHR) {
- console.log('Contact the administrator');
+ FHC_DialogLib.alertError("A generic error occurred, please contact the support");
}
}
);
@@ -98,3 +108,4 @@ $(document).ready(function() {
FHC_UDFWidget.display();
});
+