2021-10-30 01:39:46 +00:00
|
|
|
<template>
|
2021-11-11 09:53:33 +00:00
|
|
|
<div class="custom-attribute">
|
2021-10-30 01:39:46 +00:00
|
|
|
<div class="title-wrap">
|
|
|
|
<h4 class="text-block-title title error">
|
2021-11-24 03:30:55 +00:00
|
|
|
<div v-if="isAttributeTypeCheckbox" class="checkbox-wrap">
|
|
|
|
<input
|
|
|
|
v-model="editedValue"
|
|
|
|
class="checkbox"
|
|
|
|
type="checkbox"
|
|
|
|
@change="onUpdate"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="name-button__wrap">
|
|
|
|
<span
|
|
|
|
class="attribute-name"
|
|
|
|
:class="{ error: $v.editedValue.$error }"
|
|
|
|
>
|
|
|
|
{{ label }}
|
|
|
|
</span>
|
|
|
|
<woot-button
|
|
|
|
v-if="showActions"
|
|
|
|
v-tooltip.left="$t('CUSTOM_ATTRIBUTES.ACTIONS.DELETE')"
|
|
|
|
variant="link"
|
|
|
|
size="medium"
|
|
|
|
color-scheme="secondary"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="delete"
|
2021-11-24 03:30:55 +00:00
|
|
|
class-names="delete-button"
|
|
|
|
@click="onDelete"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-10-30 01:39:46 +00:00
|
|
|
</h4>
|
|
|
|
</div>
|
2021-11-24 03:30:55 +00:00
|
|
|
<div v-if="notAttributeTypeCheckboxAndList">
|
|
|
|
<div v-show="isEditing">
|
|
|
|
<div class="input-group small">
|
|
|
|
<input
|
|
|
|
ref="inputfield"
|
|
|
|
v-model="editedValue"
|
|
|
|
:type="inputType"
|
|
|
|
class="input-group-field"
|
|
|
|
autofocus="true"
|
|
|
|
:class="{ error: $v.editedValue.$error }"
|
|
|
|
@blur="$v.editedValue.$touch"
|
|
|
|
@keyup.enter="onUpdate"
|
|
|
|
/>
|
|
|
|
<div class="input-group-button">
|
2021-12-01 05:03:18 +00:00
|
|
|
<woot-button size="small" icon="checkmark" @click="onUpdate" />
|
2021-11-24 03:30:55 +00:00
|
|
|
</div>
|
2021-10-30 01:39:46 +00:00
|
|
|
</div>
|
2021-11-24 03:30:55 +00:00
|
|
|
<span v-if="shouldShowErrorMessage" class="error-message">
|
|
|
|
{{ errorMessage }}
|
|
|
|
</span>
|
2021-10-30 01:39:46 +00:00
|
|
|
</div>
|
2021-11-24 03:30:55 +00:00
|
|
|
<div
|
|
|
|
v-show="!isEditing"
|
|
|
|
class="value--view"
|
|
|
|
:class="{ 'is-editable': showActions }"
|
2021-10-30 01:39:46 +00:00
|
|
|
>
|
2021-11-24 03:30:55 +00:00
|
|
|
<a
|
|
|
|
v-if="isAttributeTypeLink"
|
|
|
|
:href="value"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
class="value"
|
|
|
|
>
|
2022-02-07 07:34:27 +00:00
|
|
|
{{ urlValue }}
|
2021-11-24 03:30:55 +00:00
|
|
|
</a>
|
|
|
|
<p v-else class="value">
|
2021-11-24 05:32:45 +00:00
|
|
|
{{ displayValue || '---' }}
|
2021-11-24 03:30:55 +00:00
|
|
|
</p>
|
|
|
|
<div class="action-buttons__wrap">
|
|
|
|
<woot-button
|
|
|
|
v-if="showActions"
|
|
|
|
v-tooltip="$t('CUSTOM_ATTRIBUTES.ACTIONS.COPY')"
|
|
|
|
variant="link"
|
|
|
|
size="small"
|
|
|
|
color-scheme="secondary"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="clipboard"
|
2021-11-24 03:30:55 +00:00
|
|
|
class-names="edit-button"
|
|
|
|
@click="onCopy"
|
|
|
|
/>
|
|
|
|
<woot-button
|
|
|
|
v-if="showActions"
|
|
|
|
v-tooltip.right="$t('CUSTOM_ATTRIBUTES.ACTIONS.EDIT')"
|
|
|
|
variant="link"
|
|
|
|
size="small"
|
|
|
|
color-scheme="secondary"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="edit"
|
2021-11-24 03:30:55 +00:00
|
|
|
class-names="edit-button"
|
|
|
|
@click="onEdit"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="isAttributeTypeList">
|
|
|
|
<multiselect-dropdown
|
|
|
|
:options="listOptions"
|
|
|
|
:selected-item="selectedItem"
|
|
|
|
:has-thumbnail="false"
|
|
|
|
:multiselector-placeholder="
|
|
|
|
$t('CUSTOM_ATTRIBUTES.FORM.ATTRIBUTE_TYPE.LIST.PLACEHOLDER')
|
|
|
|
"
|
|
|
|
:no-search-result="
|
|
|
|
$t('CUSTOM_ATTRIBUTES.FORM.ATTRIBUTE_TYPE.LIST.NO_RESULT')
|
|
|
|
"
|
|
|
|
:input-placeholder="
|
|
|
|
$t(
|
|
|
|
'CUSTOM_ATTRIBUTES.FORM.ATTRIBUTE_TYPE.LIST.SEARCH_INPUT_PLACEHOLDER'
|
|
|
|
)
|
|
|
|
"
|
|
|
|
@click="onUpdateListValue"
|
2021-10-30 01:39:46 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-11-11 09:53:33 +00:00
|
|
|
import format from 'date-fns/format';
|
2021-10-30 01:39:46 +00:00
|
|
|
import { required, url } from 'vuelidate/lib/validators';
|
|
|
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
2021-11-24 03:30:55 +00:00
|
|
|
import MultiselectDropdown from 'shared/components/ui/MultiselectDropdown.vue';
|
2022-02-07 07:34:27 +00:00
|
|
|
import { isValidURL } from '../helper/URLHelper';
|
2021-11-11 09:53:33 +00:00
|
|
|
const DATE_FORMAT = 'yyyy-MM-dd';
|
|
|
|
|
2021-10-30 01:39:46 +00:00
|
|
|
export default {
|
2021-11-24 03:30:55 +00:00
|
|
|
components: {
|
|
|
|
MultiselectDropdown,
|
|
|
|
},
|
2021-10-30 01:39:46 +00:00
|
|
|
props: {
|
|
|
|
label: { type: String, required: true },
|
2021-11-24 03:30:55 +00:00
|
|
|
values: { type: Array, default: () => [] },
|
|
|
|
value: { type: [String, Number, Boolean], default: '' },
|
2021-10-30 01:39:46 +00:00
|
|
|
showActions: { type: Boolean, default: false },
|
|
|
|
attributeType: { type: String, default: 'text' },
|
|
|
|
attributeKey: { type: String, required: true },
|
2021-11-11 09:53:33 +00:00
|
|
|
contactId: { type: Number, default: null },
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isEditing: false,
|
2021-11-24 05:32:45 +00:00
|
|
|
editedValue: null,
|
2021-10-30 01:39:46 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
validations() {
|
|
|
|
if (this.isAttributeTypeLink) {
|
|
|
|
return {
|
|
|
|
editedValue: { required, url },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
editedValue: { required },
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2021-11-24 05:32:45 +00:00
|
|
|
formattedValue() {
|
|
|
|
if (this.isAttributeTypeDate) {
|
|
|
|
return format(new Date(this.value || new Date()), DATE_FORMAT);
|
|
|
|
}
|
|
|
|
if (this.isAttributeTypeCheckbox) {
|
|
|
|
return this.value === 'false' ? false : this.value;
|
|
|
|
}
|
|
|
|
return this.value;
|
|
|
|
},
|
2021-11-24 03:30:55 +00:00
|
|
|
listOptions() {
|
|
|
|
return this.values.map((value, index) => ({
|
|
|
|
id: index + 1,
|
|
|
|
name: value,
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
selectedItem() {
|
|
|
|
const id = this.values.indexOf(this.editedValue) + 1;
|
|
|
|
return { id, name: this.editedValue };
|
|
|
|
},
|
|
|
|
isAttributeTypeCheckbox() {
|
|
|
|
return this.attributeType === 'checkbox';
|
|
|
|
},
|
|
|
|
isAttributeTypeList() {
|
|
|
|
return this.attributeType === 'list';
|
|
|
|
},
|
2021-10-30 01:39:46 +00:00
|
|
|
isAttributeTypeLink() {
|
|
|
|
return this.attributeType === 'link';
|
|
|
|
},
|
2021-11-24 05:32:45 +00:00
|
|
|
isAttributeTypeDate() {
|
|
|
|
return this.attributeType === 'date';
|
|
|
|
},
|
2022-02-07 07:34:27 +00:00
|
|
|
urlValue() {
|
|
|
|
return isValidURL(this.value) ? this.value : '---';
|
|
|
|
},
|
2021-11-24 03:30:55 +00:00
|
|
|
notAttributeTypeCheckboxAndList() {
|
|
|
|
return !this.isAttributeTypeCheckbox && !this.isAttributeTypeList;
|
|
|
|
},
|
2021-10-30 01:39:46 +00:00
|
|
|
inputType() {
|
|
|
|
return this.isAttributeTypeLink ? 'url' : this.attributeType;
|
|
|
|
},
|
|
|
|
shouldShowErrorMessage() {
|
|
|
|
return this.$v.editedValue.$error;
|
|
|
|
},
|
|
|
|
errorMessage() {
|
|
|
|
if (this.$v.editedValue.url) {
|
|
|
|
return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.INVALID_URL');
|
|
|
|
}
|
|
|
|
return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.REQUIRED');
|
|
|
|
},
|
2021-11-24 05:32:45 +00:00
|
|
|
displayValue() {
|
2021-11-11 09:53:33 +00:00
|
|
|
if (this.attributeType === 'date') {
|
|
|
|
return format(new Date(this.editedValue), 'dd-MM-yyyy');
|
|
|
|
}
|
|
|
|
return this.editedValue;
|
|
|
|
},
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2021-11-24 05:32:45 +00:00
|
|
|
this.editedValue = this.formattedValue;
|
2021-10-30 01:39:46 +00:00
|
|
|
bus.$on(BUS_EVENTS.FOCUS_CUSTOM_ATTRIBUTE, focusAttributeKey => {
|
|
|
|
if (this.attributeKey === focusAttributeKey) {
|
|
|
|
this.onEdit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
focusInput() {
|
|
|
|
if (this.$refs.inputfield) {
|
|
|
|
this.$refs.inputfield.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onEdit() {
|
|
|
|
this.isEditing = true;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.focusInput();
|
|
|
|
});
|
|
|
|
},
|
2021-11-24 03:30:55 +00:00
|
|
|
onUpdateListValue(value) {
|
|
|
|
if (value) {
|
|
|
|
this.editedValue = value.name;
|
|
|
|
this.onUpdate();
|
|
|
|
}
|
|
|
|
},
|
2021-10-30 01:39:46 +00:00
|
|
|
onUpdate() {
|
2021-11-11 09:53:33 +00:00
|
|
|
const updatedValue =
|
|
|
|
this.attributeType === 'date'
|
|
|
|
? format(new Date(this.editedValue), DATE_FORMAT)
|
|
|
|
: this.editedValue;
|
|
|
|
|
2021-10-30 01:39:46 +00:00
|
|
|
this.$v.$touch();
|
|
|
|
if (this.$v.$invalid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isEditing = false;
|
2021-11-11 09:53:33 +00:00
|
|
|
this.$emit('update', this.attributeKey, updatedValue);
|
2021-10-30 01:39:46 +00:00
|
|
|
},
|
|
|
|
onDelete() {
|
|
|
|
this.isEditing = false;
|
|
|
|
this.$emit('delete', this.attributeKey);
|
|
|
|
},
|
|
|
|
onCopy() {
|
|
|
|
this.$emit('copy', this.value);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-11-11 09:53:33 +00:00
|
|
|
.custom-attribute {
|
2021-10-30 01:39:46 +00:00
|
|
|
padding: var(--space-slab) var(--space-normal);
|
|
|
|
}
|
|
|
|
|
|
|
|
.title-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin-bottom: var(--space-mini);
|
|
|
|
}
|
|
|
|
.title {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin: 0;
|
2021-11-24 03:30:55 +00:00
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
.checkbox-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
.checkbox {
|
|
|
|
margin: 0 var(--space-small) 0 0;
|
|
|
|
}
|
|
|
|
.name-button__wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
width: 100%;
|
2021-10-30 01:39:46 +00:00
|
|
|
}
|
|
|
|
.attribute-name {
|
2021-11-24 03:30:55 +00:00
|
|
|
width: 100%;
|
2021-10-30 01:39:46 +00:00
|
|
|
&.error {
|
|
|
|
color: var(--r-400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.title--icon {
|
|
|
|
width: var(--space-two);
|
|
|
|
}
|
|
|
|
.edit-button {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-11-24 03:30:55 +00:00
|
|
|
.delete-button {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
width: var(--space-normal);
|
|
|
|
}
|
2021-10-30 01:39:46 +00:00
|
|
|
.value--view {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
&.is-editable:hover {
|
|
|
|
.value {
|
|
|
|
background: var(--color-background);
|
2021-11-24 03:30:55 +00:00
|
|
|
margin-bottom: 0;
|
2021-10-30 01:39:46 +00:00
|
|
|
}
|
|
|
|
.edit-button {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
2021-11-24 03:30:55 +00:00
|
|
|
|
|
|
|
.action-buttons__wrap {
|
|
|
|
display: flex;
|
|
|
|
max-width: var(--space-larger);
|
|
|
|
}
|
2021-10-30 01:39:46 +00:00
|
|
|
}
|
|
|
|
.value {
|
|
|
|
display: inline-block;
|
|
|
|
min-width: var(--space-mega);
|
|
|
|
border-radius: var(--border-radius-small);
|
2021-11-24 03:30:55 +00:00
|
|
|
margin-bottom: 0;
|
2021-10-30 01:39:46 +00:00
|
|
|
word-break: break-all;
|
|
|
|
padding: var(--space-micro) var(--space-smaller);
|
|
|
|
}
|
|
|
|
.error-message {
|
|
|
|
color: var(--r-400);
|
|
|
|
display: block;
|
|
|
|
font-size: 1.4rem;
|
|
|
|
font-size: var(--font-size-small);
|
|
|
|
font-weight: 400;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
margin-top: -1.6rem;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2021-11-24 03:30:55 +00:00
|
|
|
|
|
|
|
::v-deep {
|
|
|
|
.selector-wrap {
|
|
|
|
margin: 0;
|
|
|
|
top: var(--space-smaller);
|
|
|
|
.selector-name {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.name {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
|
|
|
}
|
2021-10-30 01:39:46 +00:00
|
|
|
</style>
|