task reminders
This commit is contained in:
@@ -35,6 +35,7 @@ use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Preferences;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Reminder;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Core\FieldProcessing\Saver as SaverInterface;
|
||||
@@ -112,7 +113,7 @@ class Saver implements SaverInterface
|
||||
foreach ($userIdList as $userId) {
|
||||
$reminderList = $userId === $this->user->getId() ?
|
||||
$this->getReminderList($entity, $typeList) :
|
||||
$this->getPreferencesReminderList($typeList, $userId);
|
||||
$this->getPreferencesReminderList($typeList, $userId, $entityType);
|
||||
|
||||
foreach ($reminderList as $item) {
|
||||
$this->createReminder($entity, $userId, $start, $item);
|
||||
@@ -296,7 +297,7 @@ class Saver implements SaverInterface
|
||||
* @param string[] $typeList
|
||||
* @return object{seconds: int, type: string}[]
|
||||
*/
|
||||
private function getPreferencesReminderList(array $typeList, string $userId): array
|
||||
private function getPreferencesReminderList(array $typeList, string $userId, string $entityType): array
|
||||
{
|
||||
$preferences = $this->entityManager->getRepositoryByClass(Preferences::class)->getById($userId);
|
||||
|
||||
@@ -304,8 +305,15 @@ class Saver implements SaverInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
$param = 'defaultReminders';
|
||||
|
||||
// @todo Refactor.
|
||||
if ($entityType === Task::ENTITY_TYPE) {
|
||||
$param = 'defaultRemindersTask';
|
||||
}
|
||||
|
||||
/** @var stdClass[] $list */
|
||||
$list = $preferences->get('defaultReminders') ?? [];
|
||||
$list = $preferences->get($param) ?? [];
|
||||
|
||||
return $this->sanitizeList($list, $typeList);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"signature": "Email Signature",
|
||||
"dashboardTabList": "Tab List",
|
||||
"defaultReminders": "Default Reminders",
|
||||
"defaultRemindersTask": "Default Reminders for Tasks",
|
||||
"theme": "Theme",
|
||||
"useCustomTabList": "Custom Tab List",
|
||||
"addCustomTabs": "Add Custom Tabs",
|
||||
|
||||
@@ -86,11 +86,11 @@
|
||||
"rows": [
|
||||
[
|
||||
{"name": "calendarSlotDuration"},
|
||||
{"name": "defaultReminders"}
|
||||
{"name": "calendarScrollHour"}
|
||||
],
|
||||
[
|
||||
{"name": "calendarScrollHour"},
|
||||
false
|
||||
{"name": "defaultReminders"},
|
||||
{"name": "defaultRemindersTask"}
|
||||
]
|
||||
]
|
||||
},
|
||||
|
||||
@@ -127,6 +127,15 @@
|
||||
"Espo\\Modules\\Crm\\Classes\\FieldValidators\\Event\\Reminders\\MaxCount"
|
||||
]
|
||||
},
|
||||
"defaultRemindersTask": {
|
||||
"type": "jsonArray",
|
||||
"view": "crm:views/meeting/fields/reminders",
|
||||
"default": [],
|
||||
"validatorClassNameList": [
|
||||
"Espo\\Modules\\Crm\\Classes\\FieldValidators\\Event\\Reminders\\Valid",
|
||||
"Espo\\Modules\\Crm\\Classes\\FieldValidators\\Event\\Reminders\\MaxCount"
|
||||
]
|
||||
},
|
||||
"theme": {
|
||||
"type": "enum",
|
||||
"view": "views/preferences/fields/theme",
|
||||
|
||||
@@ -51,6 +51,8 @@ class CalenderEditModalView extends EditModalView {
|
||||
'change .scope-switcher input[name="scope"]': function () {
|
||||
Espo.Ui.notify(' ... ');
|
||||
|
||||
const prevScope = this.scope;
|
||||
|
||||
const scope = $('.scope-switcher input[name="scope"]:checked').val();
|
||||
this.scope = scope;
|
||||
|
||||
@@ -61,7 +63,7 @@ class CalenderEditModalView extends EditModalView {
|
||||
|
||||
attributes = {...attributes, ...this.getRecordView().model.getClonedAttributes()};
|
||||
|
||||
this.filterAttributesForEntityType(attributes, scope);
|
||||
this.filterAttributesForEntityType(attributes, scope, prevScope);
|
||||
|
||||
model.set(attributes);
|
||||
|
||||
@@ -77,7 +79,16 @@ class CalenderEditModalView extends EditModalView {
|
||||
},
|
||||
}
|
||||
|
||||
filterAttributesForEntityType(attributes, entityType) {
|
||||
/**
|
||||
* @param {Record} attributes
|
||||
* @param {string} entityType
|
||||
* @param {string} previousEntityType
|
||||
*/
|
||||
filterAttributesForEntityType(attributes, entityType, previousEntityType) {
|
||||
if (entityType === 'Task' || previousEntityType === 'Task') {
|
||||
delete attributes.reminders;
|
||||
}
|
||||
|
||||
this.getHelper()
|
||||
.fieldManager
|
||||
.getEntityTypeFieldList(entityType, {type: 'enum'})
|
||||
|
||||
@@ -74,13 +74,7 @@ class MeetingRemindersField extends BaseFieldView {
|
||||
}
|
||||
|
||||
setup() {
|
||||
if (this.model.isNew() && !this.model.get(this.name) && this.model.entityType !== 'Preferences') {
|
||||
this.reminderList = this.getPreferences().get('defaultReminders') || [];
|
||||
} else {
|
||||
this.reminderList = this.model.get(this.name) || [];
|
||||
}
|
||||
|
||||
this.reminderList = Espo.Utils.cloneDeep(this.reminderList);
|
||||
this.setupReminderList();
|
||||
|
||||
this.listenTo(this.model, 'change:' + this.name, () => {
|
||||
this.reminderList = Espo.Utils
|
||||
@@ -101,6 +95,22 @@ class MeetingRemindersField extends BaseFieldView {
|
||||
});
|
||||
}
|
||||
|
||||
setupReminderList() {
|
||||
if (this.model.isNew() && !this.model.get(this.name) && this.model.entityType !== 'Preferences') {
|
||||
let param = 'defaultReminders';
|
||||
|
||||
if (this.model.entityType === 'Task') {
|
||||
param = 'defaultRemindersTask';
|
||||
}
|
||||
|
||||
this.reminderList = this.getPreferences().get(param) || [];
|
||||
} else {
|
||||
this.reminderList = this.model.get(this.name) || [];
|
||||
}
|
||||
|
||||
this.reminderList = Espo.Utils.cloneDeep(this.reminderList);
|
||||
}
|
||||
|
||||
afterRender() {
|
||||
if (this.isEditMode()) {
|
||||
this.$container = this.$el.find('.reminders-container');
|
||||
|
||||
Reference in New Issue
Block a user