reset preferences to defaults

This commit is contained in:
Yuri Kuznetsov
2014-10-15 11:55:40 +03:00
parent 3fd2382741
commit 675975f763
4 changed files with 44 additions and 1 deletions
@@ -24,6 +24,7 @@ namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\NotFound;
class Preferences extends \Espo\Core\Controllers\Base
@@ -52,6 +53,17 @@ class Preferences extends \Espo\Core\Controllers\Base
}
}
public function actionDelete($params, $data)
{
$userId = $params['id'];
if (empty($userId)) {
throw new BadRequest();
}
$this->handleUserAccess($userId);
return $this->getEntityManager()->getRepository('Preferences')->resetToDefaults($userId);
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
@@ -120,6 +120,15 @@ class Preferences extends \Espo\Core\ORM\Repository
return true;
}
}
public function resetToDefaults($userId)
{
$fileName = $this->getFilePath($userId);
$this->getFileManager()->unlink($fileName);
if ($entity = $this->get($userId)) {
return $entity->toArray();
}
}
public function find(array $params)
{
@@ -143,9 +143,11 @@
"fieldShouldBeLess": "{field} should be less then {value}",
"fieldShouldBeGreater": "{field} should be greater then {value}",
"fieldBadPasswordConfirm": "{field} confirmed improperly",
"resetPreferencesDone": "Preferences has been reset to defaults",
"assignmentEmailNotificationSubject": "EspoCRM {entityType}: {Entity.name}",
"assignmentEmailNotificationBody": "{assignerUserName} has assigned {entityType} '{Entity.name}' to you\n\n{recordUrl}",
"confirmation": "Are you sure?",
"resetPreferencesConfirmation": "Are you sure you want to reset preferences to defaults?",
"removeRecordConfirmation": "Are you sure you want to remove the record?",
"unlinkRecordConfirmation": "Are you sure you want to unlink relationship?",
"removeSelectedRecordsConfirmation": "Are you sure you want to remove selected records?"
@@ -34,7 +34,12 @@ Espo.define('Views.Preferences.Record.Edit', 'Views.Record.Edit', function (Dep)
{
name: 'cancel',
label: 'Cancel',
}
},
{
name: 'reset',
label: 'Reset',
style: 'danger'
}
],
dependencyDefs: {
@@ -68,6 +73,21 @@ Espo.define('Views.Preferences.Record.Edit', 'Views.Record.Edit', function (Dep)
},
actionReset: function () {
if (confirm(this.translate('resetPreferencesConfirmation', 'messages'))) {
$.ajax({
url: 'Preferences/' + this.model.id,
type: 'DELETE',
}).done(function (data) {
Espo.Ui.success(this.translate('resetPreferencesDone', 'messages'));
this.model.set(data);
this.getPreferences().set(this.model.toJSON());
this.getPreferences().trigger('update');
}.bind(this));
}
},
afterRender: function () {
Dep.prototype.afterRender.call(this);