|
@@ -234,3 +234,86 @@ CardCustomField.register('cardCustomField');
|
|
|
];
|
|
|
}
|
|
|
}.register('cardCustomField-dropdown'));
|
|
|
+
|
|
|
+// cardCustomField-stringtemplate
|
|
|
+(class extends CardCustomField {
|
|
|
+ onCreated() {
|
|
|
+ super.onCreated();
|
|
|
+
|
|
|
+ this.stringtemplateFormat = this.data().definition.settings.stringtemplateFormat;
|
|
|
+ this.stringtemplateSeparator = this.data().definition.settings.stringtemplateSeparator;
|
|
|
+
|
|
|
+ this.stringtemplateItems = new ReactiveVar(this.data().value ?? []);
|
|
|
+ }
|
|
|
+
|
|
|
+ formattedValue() {
|
|
|
+ return (this.data().value ?? [])
|
|
|
+ .filter(value => !!value.trim())
|
|
|
+ .map(value => this.stringtemplateFormat.replace(/%\{value\}/gi, value))
|
|
|
+ .join(this.stringtemplateSeparator ?? '');
|
|
|
+ }
|
|
|
+
|
|
|
+ getItems() {
|
|
|
+ return Array.from(this.findAll('input'))
|
|
|
+ .map(input => input.value)
|
|
|
+ .filter(value => !!value.trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ events() {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ 'submit .js-card-customfield-stringtemplate'(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ const items = this.getItems();
|
|
|
+ this.card.setCustomField(this.customFieldId, items);
|
|
|
+ },
|
|
|
+
|
|
|
+ 'keydown .js-card-customfield-stringtemplate-item'(event) {
|
|
|
+ if (event.keyCode === 13) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ if (event.metaKey || event.ctrlKey) {
|
|
|
+ this.find('button[type=submit]').click();
|
|
|
+ } else if (event.target.value.trim()) {
|
|
|
+ const inputLast = this.find('input.last');
|
|
|
+
|
|
|
+ let items = this.getItems();
|
|
|
+
|
|
|
+ if (event.target === inputLast) {
|
|
|
+ inputLast.value = '';
|
|
|
+ } else if (event.target.nextSibling === inputLast) {
|
|
|
+ inputLast.focus();
|
|
|
+ } else {
|
|
|
+ event.target.blur();
|
|
|
+
|
|
|
+ const idx = Array.from(this.findAll('input'))
|
|
|
+ .indexOf(event.target);
|
|
|
+ items.splice(idx + 1, 0, '');
|
|
|
+
|
|
|
+ Tracker.afterFlush(() => {
|
|
|
+ const element = this.findAll('input')[idx + 1];
|
|
|
+ element.focus();
|
|
|
+ element.value = '';
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ this.stringtemplateItems.set(items);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 'blur .js-card-customfield-stringtemplate-item'(event) {
|
|
|
+ if (!event.target.value.trim() || event.target === this.find('input.last')) {
|
|
|
+ const items = this.getItems();
|
|
|
+ this.stringtemplateItems.set(items);
|
|
|
+ this.find('input.last').value = '';
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 'click .js-close-inlined-form'(event) {
|
|
|
+ this.stringtemplateItems.set(this.data().value ?? []);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+}.register('cardCustomField-stringtemplate'));
|