2024-02-14 21:18:09 +00:00
|
|
|
import { FieldRulesConfig } from 'app/client/components/Forms/FormConfig';
|
2021-10-13 17:36:55 +00:00
|
|
|
import { fromKoSave } from 'app/client/lib/fromKoSave';
|
|
|
|
import { DataRowModel } from 'app/client/models/DataRowModel';
|
|
|
|
import { ViewFieldRec } from 'app/client/models/entities/ViewFieldRec';
|
2022-08-08 13:32:50 +00:00
|
|
|
import { cssRow } from 'app/client/ui/RightPanelStyles';
|
2022-10-14 10:07:19 +00:00
|
|
|
import { alignmentSelect, cssButtonSelect, makeButtonSelect } from 'app/client/ui2018/buttonSelect';
|
2023-08-04 11:32:53 +00:00
|
|
|
import { testId } from 'app/client/ui2018/cssVars';
|
|
|
|
import { makeLinks } from 'app/client/ui2018/links';
|
2021-10-13 17:36:55 +00:00
|
|
|
import { NewAbstractWidget, Options } from 'app/client/widgets/NewAbstractWidget';
|
2023-08-04 11:32:53 +00:00
|
|
|
import { Computed, dom, DomContents, fromKo, Observable } from 'grainjs';
|
|
|
|
import { makeT } from 'app/client/lib/localization';
|
2022-12-02 20:49:55 +00:00
|
|
|
|
|
|
|
const t = makeT('NTextBox');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TextBox - The most basic widget for displaying text information.
|
|
|
|
*/
|
|
|
|
export class NTextBox extends NewAbstractWidget {
|
|
|
|
protected alignment: Observable<string>;
|
|
|
|
protected wrapping: Observable<boolean>;
|
|
|
|
|
2021-03-02 12:27:08 +00:00
|
|
|
constructor(field: ViewFieldRec, options: Options = {}) {
|
|
|
|
super(field, options);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-10-14 10:07:19 +00:00
|
|
|
this.alignment = fromKo(this.options.prop('alignment'));
|
|
|
|
this.wrapping = fromKo(this.field.wrap);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
this.autoDispose(this.wrapping.addListener(() => {
|
|
|
|
this.field.viewSection().events.trigger('rowHeightChange');
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-10-07 21:58:43 +00:00
|
|
|
public buildConfigDom(): DomContents {
|
2022-10-14 10:07:19 +00:00
|
|
|
const toggle = () => {
|
|
|
|
const newValue = !this.field.config.wrap.peek();
|
|
|
|
this.field.config.wrap.setAndSave(newValue).catch(reportError);
|
|
|
|
};
|
|
|
|
const options = this.field.config.options;
|
|
|
|
// Some options might be disabled, as more than one column is selected.
|
|
|
|
// Prop observable is owned by the options object.
|
|
|
|
const alignmentDisabled = Computed.create(this, use => use(options.disabled('alignment')));
|
|
|
|
const wrapDisabled = Computed.create(this, (use) => use(options.disabled('wrap')));
|
2020-10-07 21:58:43 +00:00
|
|
|
return [
|
2020-10-02 15:10:00 +00:00
|
|
|
cssRow(
|
2022-10-14 10:07:19 +00:00
|
|
|
alignmentSelect(
|
|
|
|
fromKoSave(this.field.config.alignment),
|
|
|
|
cssButtonSelect.cls('-disabled', alignmentDisabled),
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', {style: 'margin-left: 8px;'},
|
2022-10-14 10:07:19 +00:00
|
|
|
makeButtonSelect(
|
|
|
|
fromKo(this.field.config.wrap),
|
|
|
|
[{value: true, icon: 'Wrap'}],
|
|
|
|
toggle,
|
|
|
|
cssButtonSelect.cls('-disabled', wrapDisabled),
|
2024-02-14 21:18:09 +00:00
|
|
|
),
|
|
|
|
testId('tb-wrap-text'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildFormConfigDom(): DomContents {
|
|
|
|
return [
|
|
|
|
dom.create(FieldRulesConfig, this.field),
|
2020-10-07 21:58:43 +00:00
|
|
|
];
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom(row: DataRowModel) {
|
|
|
|
const value = row.cells[this.field.colId.peek()];
|
|
|
|
return dom('div.field_clip',
|
|
|
|
dom.style('text-align', this.alignment),
|
|
|
|
dom.cls('text_wrapping', this.wrapping),
|
2023-08-22 07:17:01 +00:00
|
|
|
dom.domComputed((use) => use(row._isAddRow) || this.isDisposed() ?
|
|
|
|
null :
|
|
|
|
makeLinks(use(this.valueFormatter).formatAny(use(value), t)))
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|