diff --git a/ang/crmContactcats.css b/ang/crmContactcats.css index 4d043bb..7c1b891 100644 --- a/ang/crmContactcats.css +++ b/ang/crmContactcats.css @@ -2,10 +2,44 @@ crm-contact-category-settings ol { padding: 0; } -crm-contact-category-settings ol li { +crm-contact-category-settings li.deleted { + opacity: 0.3; +} +/* @keyframes crm-contact-cats-move { */ +/* 0%, 90% {transform: none;} */ +/* 95% {transform: translateX(0.2em);} */ +/* 100% {transform: none;} */ +/* } */ + +crm-contact-category-settings .crm-contact-cats-move-target { + transition: opacity 0.3s ease, transform 0.3s ease, display 0.001s allow-discrete, max-height 0.3s ease; + transform-origin: top left; + display: none; +} +crm-contact-category-settings .moving .crm-contact-cats-move-target { + display: block; + transform: none; + opacity: 1; + max-height: 5rem; + @starting-style { + transform: scaleY(0); + opacity:0; + max-height: 0; + } +} + +crm-contact-category-settings li.being-moved .panel { + opacity: 0.8; +} +crm-contact-category-settings .panel { + margin-bottom: 0; +} +crm-contact-category-settings .panel-body { display: flex; + box-sizing: border-box; padding: 0.5em 0; - align-items: flex-end; + align-items: center; + justify-content: space-between; gap: 1em; } crm-contact-category-settings li label { diff --git a/ang/crmContactcats.js b/ang/crmContactcats.js index 0405af0..3d7a18f 100644 --- a/ang/crmContactcats.js +++ b/ang/crmContactcats.js @@ -22,11 +22,109 @@ // this.$onInit gets run after the this controller is called, and after the bindings have been applied. this.$onInit = async function() { ctrl.saved = false; + ctrl.view = 'list'; + ctrl.moveIdx = null; + ctrl.categoryToEdit = null; ctrl.categoryDefinitions = null; ctrl.categoryDefinitions = await crmApi4("ContactCategoryDefinition", 'get', { orderBy: { label: 'ASC' }, withLabels: true }); $scope.$digest(); + ctrl.edit = idx => { + if (idx === -1) { + // New item. + + // Create a random dark colour + let [r, g, b] = [Math.random(), Math.random(), Math.random()], + min = Math.min(r, g, b), + range = Math.max(r, g, b) - min, + conv = (x) => ('0' + Math.ceil((x-min)/range * 128).toString(16)).replace(/^.*(..)$/, '$1'); + + // Create a blank + ctrl.categoryToEdit = { + idx: ctrl.categoryDefinitions.length, + label: '', + search_type: 'search', + search_data: { saved_search_id: null }, + color: '#' + [r, g, b].map(conv).join(''), + icon: '', + description: '', + }; + } + else { + ctrl.categoryToEdit = Object.assign({idx}, JSON.parse(JSON.stringify(ctrl.categoryDefinitions[idx]))); + } + ctrl.view = 'edit'; + }; + + ctrl.moveTo = idx => { + let item = ctrl.categoryDefinitions.splice(ctrl.moveIdx, 1)[0]; + if (idx > ctrl.moveIdx) { + idx--; + } + ctrl.categoryDefinitions.splice(idx, 0, item); + ctrl.moveIdx = null; + }; + ctrl.deleteCategory = idx => { + if (!confirm(ts( + 'Confirm deleting category ‘%1’. You will lose history related to this category. Sure?', + {1: ctrl.categoryDefinitions[idx].label} + ))) { + return; + } + ctrl.categoryDefinitions[idx].deleted = true; + ctrl.categoryToEdit = null; + ctrl.view = 'list'; + }; + + ctrl.updateEditedThing = () => { + // @todo validate, e.g. + if (!ctrl.categoryToEdit.label) { + alert("No name"); + return; + } + + const search_data = ctrl.categoryToEdit.search_data; + console.log("search_data", search_data); + if (ctrl.categoryToEdit.search_type === 'group') { + // Only store what we need. + const {group_id} = search_data; + console.log("group_id", group_id, search_data); + ctrl.categoryToEdit.search_data = {group_id}; + } + else if (ctrl.categoryToEdit.search_type === 'search') { + const {saved_search_id} = search_data; + ctrl.categoryToEdit.search_data = {saved_search_id}; + } + + const edited = ctrl.categoryToEdit; + const idx = edited.idx; + delete(edited.idx); + ctrl.categoryDefinitions[idx] = edited; + ctrl.categoryToEdit = null; + ctrl.view = 'list'; + console.log("done editing"); + } + + // We need to ensure the search_data object contains the fields required for the selected search_type + ctrl.fixSearchData = () => { + const search_data = ctrl.categoryToEdit.search_data; + if (ctrl.categoryToEdit.search_type === 'group') { + if (!('group_id' in search_data)) { + search_data.group_id = null; + } + } + else if (ctrl.categoryToEdit.search_type === 'search') { + if (!('saved_search_id' in search_data)) { + search_data.saved_search_id = null; + } + } + }; + + ctrl.save = async () => { + if (!confirm(ts("Confirm saving changes to categories? Note that categories will not be fully applied until tomorrow."))) { return; } + }; + // ctrl.deleteRow = idx => { // ctrl.catmap.splice(idx, 1); // }; diff --git a/ang/crmContactcats/crmContactCategorySettings.html b/ang/crmContactcats/crmContactCategorySettings.html index 70cc933..24f9647 100644 --- a/ang/crmContactcats/crmContactCategorySettings.html +++ b/ang/crmContactcats/crmContactCategorySettings.html @@ -1,11 +1,9 @@