From 5134fac52f9daa99d2cd5e07ddb386d8e8534963 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 2 Mar 2018 09:42:40 -0500 Subject: [PATCH] CKEditor Advanced Options - Don't allow same option to be selected twice --- css/civicrm.css | 4 ++++ js/wysiwyg/admin.ckeditor-configurator.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/css/civicrm.css b/css/civicrm.css index c459281324..6b2fdcd184 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -3124,6 +3124,10 @@ div.m ul#civicrm-menu, .crm-container .select2-container[class*=" fa-"]:before { display: none; } +.crm-container .select2-results .select2-result.select2-disabled > .select2-result-label { + opacity: .6; + cursor: default; +} /* Restore this property otherwise our css overrides it */ .select2-search input { diff --git a/js/wysiwyg/admin.ckeditor-configurator.js b/js/wysiwyg/admin.ckeditor-configurator.js index 17ac199703..b7ff14825b 100644 --- a/js/wysiwyg/admin.ckeditor-configurator.js +++ b/js/wysiwyg/admin.ckeditor-configurator.js @@ -51,10 +51,22 @@ } } + function getOptionList() { + var list = []; + _.forEach(options, function(option) { + var opt = _.cloneDeep(option); + if ($('[name="config_' + opt.id + '"]').length) { + opt.disabled = true; + } + list.push(opt); + }); + return {results: list, text: 'id'}; + } + function addOption() { $('#crm-custom-config-options').append($(configRowTpl({}))); $('div:last input.crm-config-option-name', '#crm-custom-config-options').crmSelect2({ - data: {results: options, text: 'id'}, + data: getOptionList, formatSelection: function(field) { return '' + field.id + ' (' + field.type + ')'; }, -- 2.25.1