salix/front/core/components/label-value/label-value.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
2018-04-17 12:49:55 +00:00
import './style.scss';
export default class Controller {
constructor($element, $translate, $attrs) {
2018-06-29 07:46:14 +00:00
this.element = $element[0];
this._ = $translate;
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
}
2019-02-18 11:54:33 +00:00
2018-06-29 07:46:14 +00:00
set label(value) {
let label = this.element.querySelector('vn-label');
2019-01-20 15:47:04 +00:00
label.textContent = this._.instant(value);
2018-06-29 07:46:14 +00:00
this._label = value;
}
2019-02-18 11:54:33 +00:00
2018-06-29 07:46:14 +00:00
get label() {
return this._label;
}
2019-02-18 11:54:33 +00:00
get state() {
return this._state;
}
set state(value) {
this._state = value;
this.applyTextContent();
2018-06-29 07:46:14 +00:00
}
2019-02-18 11:54:33 +00:00
2018-06-29 07:46:14 +00:00
get value() {
return this._value;
}
2019-02-18 11:54:33 +00:00
set value(value) {
this._value = value;
this.applyTextContent();
}
2019-02-18 11:54:33 +00:00
get title() {
return this._title;
}
set title(value) {
let span = this.element.querySelector('span');
span.title = value;
this._title = value;
}
applyTextContent() {
const targetElement = this.state ? 'a' : 'span';
const element = this.element.querySelector(targetElement);
const hasValue = this.value && this.value != '';
element.title = this.value;
element.textContent = hasValue ? this.value : '-';
}
}
Controller.$inject = ['$element', '$translate', '$attrs'];
ngModule.component('vnLabelValue', {
controller: Controller,
2018-06-29 07:46:14 +00:00
template: require('./label-value.html'),
bindings: {
2019-02-18 11:54:33 +00:00
title: '@?',
label: '@',
value: '@',
state: '@?',
stateParams: '<?'
}
});