Fixes and tidies

This commit is contained in:
Rich Lott / Artful Robot 2025-02-27 18:10:48 +00:00
parent e56be4ce31
commit 69d4c6b2e8
11 changed files with 191 additions and 40 deletions

View file

@ -27,6 +27,10 @@
ctrl.categoryToEdit = null;
ctrl.categoryDefinitions = null;
ctrl.categoryDefinitions = await crmApi4("ContactCategoryDefinition", 'get', { orderBy: { execution_order: 'ASC' }, withLabels: true });
if (ctrl.categoryDefinitions.count === 0) {
// First time.
ctrl.categoryDefinitions = [];
}
// Ensure we have the minimum of what we need.
if (!ctrl.categoryDefinitions.find(c => c.search_type === 'default')) {
// There's no default one.
@ -80,7 +84,7 @@
// Create a blank
ctrl.categoryToEdit = {
id: 0,
execution_order: ctrl.categoryDefinitions.length,
execution_order: -1,
label: '',
search_type: 'search',
search_data: { saved_search_id: null },
@ -139,8 +143,14 @@
edited.search_data = {saved_search_id};
}
const idx = edited.execution_order;
ctrl.categoryDefinitions[idx] = edited;
if (edited.execution_order === -1) {
// This is a new category, we need to insert it before the default one.
const newIdx = ctrl.categoryDefinitions.length - 1;
ctrl.categoryDefinitions.splice(newIdx, 0, edited);
}
else {
ctrl.categoryDefinitions[edited.execution_order] = edited;
}
ctrl.categoryToEdit = null;
updateOrders();
ctrl.dirty = 'dirty';