//dashconfig errors return
This commit is contained in:
@@ -340,7 +340,7 @@ class AdminDashboardControllerCore extends AdminController
|
||||
|
||||
public function ajaxProcessSaveDashConfig()
|
||||
{
|
||||
$return = array('has_errors' => false);
|
||||
$return = array('has_errors' => false, 'errors' => array());
|
||||
$module = Tools::getValue('module');
|
||||
$hook = Tools::getValue('hook');
|
||||
$configs = Tools::getValue('configs');
|
||||
@@ -351,8 +351,17 @@ class AdminDashboardControllerCore extends AdminController
|
||||
);
|
||||
|
||||
if (Validate::isModuleName($module) && $module_obj = Module::getInstanceByName($module))
|
||||
if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'saveDashConfig'))
|
||||
$return['has_errors'] = $module_obj->saveDashConfig($configs);
|
||||
{
|
||||
if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'validateDashConfig'))
|
||||
$return['errors'] = $module_obj->validateDashConfig($configs);
|
||||
if (!count($return['errors']))
|
||||
{
|
||||
if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'saveDashConfig'))
|
||||
$return['has_errors'] = $module_obj->saveDashConfig($configs);
|
||||
}
|
||||
else
|
||||
$return['has_errors'] = true;
|
||||
}
|
||||
else if (is_array($configs) && count($configs))
|
||||
foreach ($configs as $name => $value)
|
||||
if (Validate::isConfigName($name))
|
||||
@@ -360,7 +369,7 @@ class AdminDashboardControllerCore extends AdminController
|
||||
|
||||
if (Validate::isHookName($hook) && method_exists($module_obj, $hook))
|
||||
$return['widget_html'] = $module_obj->$hook($params);
|
||||
|
||||
|
||||
die(Tools::jsonEncode($return));
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -251,6 +251,8 @@ function bindCancelDashConfig()
|
||||
|
||||
function saveDashConfig(widget_name)
|
||||
{
|
||||
$('section#'+widget_name+' .form-group').removeClass('has-error');
|
||||
$('#'+widget_name+'_errors').remove();
|
||||
configs = '';
|
||||
$('#'+widget_name+' form input, #'+widget_name+' form textarea , #'+widget_name+' form select').each( function () {
|
||||
if ($(this).attr('type') == 'radio' && !$(this).attr('checked'))
|
||||
@@ -258,12 +260,16 @@ function saveDashConfig(widget_name)
|
||||
configs += '&configs['+$(this).attr('name')+']='+$(this).val();
|
||||
});
|
||||
data = 'ajax=true&action=saveDashConfig&module='+widget_name+configs+'&hook='+$('#'+widget_name).closest('[id^=hook]').attr('id');
|
||||
|
||||
|
||||
$.ajax({
|
||||
url : dashboard_ajax_url,
|
||||
data : data,
|
||||
dataType: 'json',
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
|
||||
},
|
||||
success : function(jsonData){
|
||||
|
||||
if (!jsonData.has_errors)
|
||||
{
|
||||
$('#'+widget_name).find('section').not('.dash_config').remove();
|
||||
@@ -271,6 +277,18 @@ function saveDashConfig(widget_name)
|
||||
refreshDashboard(widget_name);
|
||||
toggleDashConfig(widget_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
errors_str = '<div class="alert alert-danger" id="'+widget_name+'_errors">';
|
||||
for (error in jsonData.errors)
|
||||
{
|
||||
errors_str += jsonData.errors[error]+'<br/>';
|
||||
$('#'+error).closest('.form-group').addClass('has-error');
|
||||
}
|
||||
errors_str += '</div>';
|
||||
$('section#'+widget_name+'_config header').after(errors_str);
|
||||
errors_str += '</div>';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user