@idevs/corelib 0.0.90 → 0.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editors/checkboxButtonEditor.d.ts +5 -3
- package/dist/editors/checkboxButtonEditor.js +33 -33
- package/dist/editors/checkboxButtonEditor.js.map +1 -1
- package/dist/editors/dateMonthEditor.d.ts +3 -3
- package/dist/editors/dateMonthEditor.js +3 -4
- package/dist/editors/dateMonthEditor.js.map +1 -1
- package/dist/formatters/formatters.d.ts +20 -8
- package/dist/formatters/formatters.js +20 -31
- package/dist/formatters/formatters.js.map +1 -1
- package/package.json +9 -8
- package/src/editors/checkboxButtonEditor.ts +55 -31
- package/src/editors/dateMonthEditor.ts +4 -5
- package/src/formatters/formatters.ts +22 -31
- package/src/tsconfig.json +3 -3
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EditorProps, EditorWidget, IReadOnly } from '@serenity-is/corelib';
|
|
2
2
|
export type CheckboxButtonEditorOptions = {
|
|
3
3
|
enumKey?: string;
|
|
4
4
|
enumType?: any;
|
|
5
5
|
lookupKey?: string;
|
|
6
6
|
isStringId?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare class CheckboxButtonEditor extends
|
|
8
|
+
export declare class CheckboxButtonEditor<P extends CheckboxButtonEditorOptions = CheckboxButtonEditorOptions> extends EditorWidget<P> implements IReadOnly {
|
|
9
9
|
private _items;
|
|
10
10
|
private readonly _idField;
|
|
11
11
|
private readonly _textField;
|
|
12
12
|
private readonly _isStringId;
|
|
13
|
-
|
|
13
|
+
static createDefaultElement(): HTMLDivElement;
|
|
14
|
+
readonly domNode: HTMLElement;
|
|
15
|
+
constructor(props: EditorProps<P>);
|
|
14
16
|
protected renderCheckboxes(): void;
|
|
15
17
|
protected addCheckbox(value: string, text: string): void;
|
|
16
18
|
get_items(): Array<{
|
|
@@ -7,13 +7,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
8
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
9
|
};
|
|
10
|
-
import { Decorators, EnumKeyAttribute, EnumTypeRegistry,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
import { Decorators, EditorWidget, Enum, EnumKeyAttribute, EnumTypeRegistry, Fluent, getCustomAttributes, getLookup, isEmptyOrNull, toId, tryGetText, } from '@serenity-is/corelib';
|
|
11
|
+
let CheckboxButtonEditor = class CheckboxButtonEditor extends EditorWidget {
|
|
12
|
+
static createDefaultElement() {
|
|
13
|
+
return Fluent('div').getNode();
|
|
14
|
+
}
|
|
15
|
+
constructor(props) {
|
|
15
16
|
var _a;
|
|
16
|
-
super(
|
|
17
|
+
super(props);
|
|
17
18
|
if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
@@ -28,7 +29,7 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
28
29
|
const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey);
|
|
29
30
|
let enumKey = this.options.enumKey;
|
|
30
31
|
if (enumKey == null && enumType != null) {
|
|
31
|
-
const enumKeyAttr =
|
|
32
|
+
const enumKeyAttr = getCustomAttributes(enumType, EnumKeyAttribute, false);
|
|
32
33
|
if (enumKeyAttr.length > 0) {
|
|
33
34
|
enumKey = enumKeyAttr[0].value;
|
|
34
35
|
}
|
|
@@ -39,10 +40,13 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
39
40
|
this.addCheckbox(x.toString(), (_a = tryGetText('Enums.' + enumKey + '.' + name)) !== null && _a !== void 0 ? _a : name);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
this.
|
|
43
|
+
this.domNode.classList.add('d-flex', 'flex-wrap');
|
|
43
44
|
}
|
|
44
45
|
renderCheckboxes() {
|
|
45
|
-
this.
|
|
46
|
+
const childDivs = this.domNode.querySelectorAll('div');
|
|
47
|
+
childDivs.forEach(function (child) {
|
|
48
|
+
this.domNode.removeChild(child);
|
|
49
|
+
});
|
|
46
50
|
for (const item of this._items) {
|
|
47
51
|
const textValue = item[this._textField];
|
|
48
52
|
const text = textValue == null ? '' : textValue.toString();
|
|
@@ -60,7 +64,7 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
60
64
|
.attr('value', value)
|
|
61
65
|
.prependTo(label);
|
|
62
66
|
label.appendTo(div);
|
|
63
|
-
div.appendTo(this.
|
|
67
|
+
div.appendTo(this.domNode);
|
|
64
68
|
}
|
|
65
69
|
get_items() {
|
|
66
70
|
return this._items;
|
|
@@ -77,8 +81,9 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
77
81
|
}
|
|
78
82
|
get_value() {
|
|
79
83
|
const val = [];
|
|
80
|
-
this.
|
|
81
|
-
|
|
84
|
+
const inputs = this.domNode.querySelectorAll('input:checked');
|
|
85
|
+
inputs.forEach((input) => {
|
|
86
|
+
val.push(this._isStringId ? input.value : toId(input.value));
|
|
82
87
|
});
|
|
83
88
|
return val.join(',');
|
|
84
89
|
}
|
|
@@ -91,49 +96,44 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
91
96
|
if (!isEmptyOrNull(value)) {
|
|
92
97
|
values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p));
|
|
93
98
|
}
|
|
94
|
-
const inputs = this.
|
|
95
|
-
inputs.
|
|
96
|
-
;
|
|
97
|
-
e.checked = false;
|
|
99
|
+
const inputs = this.domNode.querySelectorAll('input');
|
|
100
|
+
inputs.forEach(input => {
|
|
101
|
+
input.checked = false;
|
|
98
102
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const checks = inputs.filter('[value=' + v + ']');
|
|
102
|
-
if (checks.length > 0) {
|
|
103
|
-
;
|
|
104
|
-
checks[0].checked = true;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const checks = inputs.filter('[value=' + values + ']');
|
|
103
|
+
values.forEach(v => {
|
|
104
|
+
const checks = Array.from(inputs).filter(input => input.value === v);
|
|
110
105
|
if (checks.length > 0) {
|
|
111
106
|
;
|
|
112
107
|
checks[0].checked = true;
|
|
113
108
|
}
|
|
114
|
-
}
|
|
109
|
+
});
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
112
|
set value(v) {
|
|
118
113
|
this.set_value(v);
|
|
119
114
|
}
|
|
120
115
|
get_readOnly() {
|
|
121
|
-
return this.
|
|
116
|
+
return this.domNode.getAttribute('disabled') != null;
|
|
122
117
|
}
|
|
123
118
|
set_readOnly(value) {
|
|
124
119
|
if (this.get_readOnly() !== value) {
|
|
125
120
|
if (value) {
|
|
126
|
-
this.
|
|
121
|
+
this.domNode.setAttribute('disabled', 'disabled');
|
|
122
|
+
this.domNode.querySelectorAll('input').forEach(input => {
|
|
123
|
+
input.setAttribute('disabled', 'disabled');
|
|
124
|
+
});
|
|
127
125
|
}
|
|
128
126
|
else {
|
|
129
|
-
this.
|
|
127
|
+
this.domNode.removeAttribute('disabled');
|
|
128
|
+
this.domNode.querySelectorAll('input').forEach(input => {
|
|
129
|
+
input.removeAttribute('disabled');
|
|
130
|
+
});
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
};
|
|
134
135
|
CheckboxButtonEditor = __decorate([
|
|
135
|
-
Decorators.registerEditor('CheckboxButtonEditor')
|
|
136
|
-
Element('<div/>')
|
|
136
|
+
Decorators.registerEditor('CheckboxButtonEditor')
|
|
137
137
|
], CheckboxButtonEditor);
|
|
138
138
|
export { CheckboxButtonEditor };
|
|
139
139
|
export class idevsEditors {
|
|
@@ -1 +1 @@
|
|
|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AAsB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC;GACL,oBAAoB,CAyIhC;;AAED,MAAM,OAAO,YAAY;IACvB,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/adjacent-overload-signatures */\n// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor\n\nimport { Decorators, EnumKeyAttribute, EnumTypeRegistry, IReadOnly, Widget } from '@serenity-is/corelib'\nimport { Enum, getAttributes, getLookup, isArray, isEmptyOrNull, toId, tryGetText } from '@serenity-is/corelib'\nimport Element = Decorators.element\n\nexport type CheckboxButtonEditorOptions = {\n enumKey?: string\n enumType?: any\n lookupKey?: string\n isStringId?: boolean\n}\n\n@Decorators.registerEditor('CheckboxButtonEditor')\n@Element('<div/>')\nexport class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> implements IReadOnly {\n private _items: Array<{ [key: string]: any }>\n private readonly _idField: string\n private readonly _textField: string\n private readonly _isStringId: boolean\n\n constructor(input: JQuery, opt: CheckboxButtonEditorOptions) {\n super(input, opt)\n\n if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {\n return\n }\n\n this._isStringId = this.options.isStringId\n\n if (!isEmptyOrNull(this.options.lookupKey)) {\n const lookup = getLookup(this.options.lookupKey)\n this._idField = lookup.idField\n this._textField = lookup.textField\n this.set_items(lookup.items as Array<{ [key: string]: any }>)\n } else {\n const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)\n let enumKey = this.options.enumKey\n\n if (enumKey == null && enumType != null) {\n const enumKeyAttr = getAttributes(enumType, EnumKeyAttribute, false)\n if (enumKeyAttr.length > 0) {\n enumKey = enumKeyAttr[0].value\n }\n }\n const values = Enum.getValues(enumType)\n for (const x of values) {\n const name = Enum.toString(enumType, x)\n this.addCheckbox(x.toString(), tryGetText('Enums.' + enumKey + '.' + name) ?? name)\n }\n }\n\n this.element.addClass('d-flex flex-wrap')\n }\n\n protected renderCheckboxes() {\n this.element.children('div').remove()\n\n for (const item of this._items) {\n const textValue = item[this._textField]\n const text = textValue == null ? '' : textValue.toString()\n const idValue = item[this._idField]\n const id = idValue == null ? '' : idValue.toString()\n this.addCheckbox(id, text)\n }\n }\n\n protected addCheckbox(value: string, text: string) {\n const div = $('<div class=\"col-12 col-sm-6 col-md-4 col-xl-3\" />')\n const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))\n $('<input type=\"checkbox\" class=\"me-2\" />')\n .attr('name', this.uniqueName)\n .attr('id', this.uniqueName + '_' + value)\n .attr('value', value)\n .prependTo(label)\n label.appendTo(div)\n div.appendTo(this.element)\n }\n\n get_items(): Array<{ [key: string]: any }> {\n return this._items\n }\n\n get items(): Array<{ [key: string]: any }> {\n return this.get_items()\n }\n\n set_items(value: Array<{ [key: string]: any }>) {\n this._items = value\n this.renderCheckboxes()\n }\n\n set items(v: Array<{ [key: string]: any }>) {\n this.set_items(v)\n }\n\n get_value(): string {\n const val: unknown[] = []\n this.element.find('input:checked').each((i, e) => {\n val.push(this._isStringId ? $(e).val() : toId($(e).val()))\n })\n return val.join(',')\n }\n\n get value(): string {\n return this.get_value()\n }\n\n set_value(value: string): void {\n if (value !== this.get_value()) {\n let values: unknown[] = []\n if (!isEmptyOrNull(value)) {\n values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))\n }\n const inputs = this.element.find('input')\n inputs.each((i, e) => {\n ;(e as HTMLInputElement).checked = false\n })\n\n if (isArray(values)) {\n values.forEach(v => {\n const checks = inputs.filter('[value=' + v + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n })\n } else {\n const checks = inputs.filter('[value=' + values + ']')\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n }\n }\n }\n\n set value(v: string) {\n this.set_value(v)\n }\n\n get_readOnly(): boolean {\n return this.element.attr('disabled') != null\n }\n\n set_readOnly(value: boolean): void {\n if (this.get_readOnly() !== value) {\n if (value) {\n this.element.attr('disabled', 'disabled').find('input').attr('disabled', 'disabled')\n } else {\n this.element.removeAttr('disabled').find('input').removeAttr('disabled')\n }\n }\n }\n}\n\nexport class idevsEditors {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"checkboxButtonEditor.js","sourceRoot":"","sources":["../../src/editors/checkboxButtonEditor.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oEAAoE;AACpE,4FAA4F;;;;;;;AAE5F,OAAO,EACL,UAAU,EAEV,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EAEN,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,sBAAsB,CAAA;AAUtB,IAAM,oBAAoB,GAA1B,MAAM,oBACX,SAAQ,YAAe;IAQvB,MAAM,CAAU,oBAAoB;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAA;IAChC,CAAC;IAGD,YAAY,KAAqB;;QAC/B,KAAK,CAAC,KAAK,CAAC,CAAA;QAEZ,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAClH,OAAM;QACR,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAA;QAE1C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAChD,IAAI,CAAC,QAAQ,GAA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Ae,CAAC,UAAU,CAAC,CAAA;gBACxC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAmB,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACvE,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA;gBACnC,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAtJY,oBAAoB;IADhC,UAAU,CAAC,cAAc,CAAC,sBAAsB,CAAC;GACrC,oBAAoB,CAsJhC;;AAED,MAAM,OAAO,YAAY;IACvB,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/adjacent-overload-signatures */\n// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor\n\nimport {\n Decorators,\n EditorProps,\n EditorWidget,\n Enum,\n EnumKeyAttribute,\n EnumTypeRegistry,\n Fluent,\n IReadOnly,\n getCustomAttributes,\n getLookup,\n isEmptyOrNull,\n toId,\n tryGetText,\n} from '@serenity-is/corelib'\n\nexport type CheckboxButtonEditorOptions = {\n enumKey?: string\n enumType?: any\n lookupKey?: string\n isStringId?: boolean\n}\n\n@Decorators.registerEditor('CheckboxButtonEditor')\nexport class CheckboxButtonEditor<P extends CheckboxButtonEditorOptions = CheckboxButtonEditorOptions>\n extends EditorWidget<P>\n implements IReadOnly\n{\n private _items: Array<{ [key: string]: any }>\n private readonly _idField: string\n private readonly _textField: string\n private readonly _isStringId: boolean\n\n static override createDefaultElement() {\n return Fluent('div').getNode()\n }\n declare readonly domNode: HTMLElement\n\n constructor(props: EditorProps<P>) {\n super(props)\n\n if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {\n return\n }\n\n this._isStringId = this.options.isStringId\n\n if (!isEmptyOrNull(this.options.lookupKey)) {\n const lookup = getLookup(this.options.lookupKey)\n this._idField = lookup.idField\n this._textField = lookup.textField\n this.set_items(lookup.items as Array<{ [key: string]: any }>)\n } else {\n const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)\n let enumKey = this.options.enumKey\n\n if (enumKey == null && enumType != null) {\n const enumKeyAttr = getCustomAttributes(enumType, EnumKeyAttribute, false)\n if (enumKeyAttr.length > 0) {\n enumKey = enumKeyAttr[0].value\n }\n }\n const values = Enum.getValues(enumType)\n for (const x of values) {\n const name = Enum.toString(enumType, x)\n this.addCheckbox(x.toString(), tryGetText('Enums.' + enumKey + '.' + name) ?? name)\n }\n }\n\n this.domNode.classList.add('d-flex', 'flex-wrap')\n }\n\n protected renderCheckboxes() {\n const childDivs = this.domNode.querySelectorAll('div')\n childDivs.forEach(function (child) {\n this.domNode.removeChild(child)\n })\n\n for (const item of this._items) {\n const textValue = item[this._textField]\n const text = textValue == null ? '' : textValue.toString()\n const idValue = item[this._idField]\n const id = idValue == null ? '' : idValue.toString()\n this.addCheckbox(id, text)\n }\n }\n\n protected addCheckbox(value: string, text: string) {\n const div = $('<div class=\"col-12 col-sm-6 col-md-4 col-xl-3\" />')\n const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))\n $('<input type=\"checkbox\" class=\"me-2\" />')\n .attr('name', this.uniqueName)\n .attr('id', this.uniqueName + '_' + value)\n .attr('value', value)\n .prependTo(label)\n label.appendTo(div)\n div.appendTo(this.domNode)\n }\n\n get_items(): Array<{ [key: string]: any }> {\n return this._items\n }\n\n get items(): Array<{ [key: string]: any }> {\n return this.get_items()\n }\n\n set_items(value: Array<{ [key: string]: any }>) {\n this._items = value\n this.renderCheckboxes()\n }\n\n set items(v: Array<{ [key: string]: any }>) {\n this.set_items(v)\n }\n\n get_value() {\n const val: string[] = []\n const inputs = this.domNode.querySelectorAll('input:checked')\n\n inputs.forEach((input: HTMLInputElement) => {\n val.push(this._isStringId ? input.value : toId(input.value))\n })\n\n return val.join(',')\n }\n\n get value(): string {\n return this.get_value()\n }\n\n set_value(value: string): void {\n if (value !== this.get_value()) {\n let values: unknown[] = []\n if (!isEmptyOrNull(value)) {\n values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))\n }\n const inputs = this.domNode.querySelectorAll<HTMLInputElement>('input')\n inputs.forEach(input => {\n input.checked = false\n })\n\n values.forEach(v => {\n const checks = Array.from(inputs).filter(input => (input as HTMLInputElement).value === v)\n if (checks.length > 0) {\n ;(checks[0] as HTMLInputElement).checked = true\n }\n })\n }\n }\n\n set value(v: string) {\n this.set_value(v)\n }\n\n get_readOnly(): boolean {\n return this.domNode.getAttribute('disabled') != null\n }\n\n set_readOnly(value: boolean): void {\n if (this.get_readOnly() !== value) {\n if (value) {\n this.domNode.setAttribute('disabled', 'disabled')\n this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {\n input.setAttribute('disabled', 'disabled')\n })\n } else {\n this.domNode.removeAttribute('disabled')\n this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {\n input.removeAttribute('disabled')\n })\n }\n }\n }\n}\n\nexport class idevsEditors {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SelectEditor, SelectEditorOptions } from '@serenity-is/corelib';
|
|
2
|
-
export declare class DateMonthEditor extends SelectEditor {
|
|
1
|
+
import { EditorProps, SelectEditor, SelectEditorOptions } from '@serenity-is/corelib';
|
|
2
|
+
export declare class DateMonthEditor<P extends DateMonthEditorOptions = DateMonthEditorOptions> extends SelectEditor<P> {
|
|
3
3
|
private months;
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(props: EditorProps<P>);
|
|
5
5
|
get valueAsMonth(): number;
|
|
6
6
|
getItems(): any[];
|
|
7
7
|
}
|
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Decorators, SelectEditor } from '@serenity-is/corelib';
|
|
8
|
-
import { indexOf } from '@serenity-is/corelib';
|
|
7
|
+
import { Decorators, SelectEditor, indexOf } from '@serenity-is/corelib';
|
|
9
8
|
let DateMonthEditor = class DateMonthEditor extends SelectEditor {
|
|
10
|
-
constructor(
|
|
11
|
-
super(
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
12
11
|
this.updateItems();
|
|
13
12
|
}
|
|
14
13
|
get valueAsMonth() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateMonthEditor.js","sourceRoot":"","sources":["../../src/editors/dateMonthEditor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"dateMonthEditor.js","sourceRoot":"","sources":["../../src/editors/dateMonthEditor.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAe,YAAY,EAAuB,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAGnG,IAAM,eAAe,GAArB,MAAM,eAA2E,SAAQ,YAAe;IAG7G,YAAY,KAAqB;QAC/B,KAAK,CAAC,KAAK,CAAC,CAAA;QAEZ,IAAI,CAAC,WAAW,EAAE,CAAA;IACpB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED,QAAQ;;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,OAAiC,CAAA;QAElD,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAC/C,OAAO,GAAG,CAAC,KAAK,CAAA;QAClB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAChB,MAAM,MAAM,GAAG,MAAA,GAAG,CAAC,MAAM,mCAAI,IAAI,CAAA;QACjC,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,MAAA,GAAG,CAAC,OAAO,mCAAI,SAAS,EAAE,CAAA;QACnD,MAAM,SAAS,GAAG,MAAA,GAAG,CAAC,SAAS,mCAAI,KAAK,CAAA;QAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YAC/E,IAAI,SAAS,EAAE,CAAC;gBACd,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;YACrB,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF,CAAA;AApCY,eAAe;IAD3B,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC;GAChC,eAAe,CAoC3B","sourcesContent":["import { Decorators, EditorProps, SelectEditor, SelectEditorOptions, indexOf } from '@serenity-is/corelib'\n\n@Decorators.registerEditor('DateMonthEditor')\nexport class DateMonthEditor<P extends DateMonthEditorOptions = DateMonthEditorOptions> extends SelectEditor<P> {\n private months: string[]\n\n constructor(props: EditorProps<P>) {\n super(props)\n\n this.updateItems()\n }\n\n get valueAsMonth() {\n return indexOf(this.months, x => x == this.value)\n }\n\n getItems() {\n const opt = this.options as DateMonthEditorOptions\n\n if (opt.items != null && opt.items.length >= 1) {\n return opt.items\n }\n\n const today = new Date()\n this.months = []\n const locale = opt.locale ?? 'en'\n const options = { month: opt.display ?? '2-digit' }\n const upperCase = opt.upperCase ?? false\n\n for (let i = 0; i <= 11; i++) {\n let m = new Date(today.getFullYear(), i, 1).toLocaleDateString(locale, options)\n if (upperCase) {\n m = m.toUpperCase()\n }\n this.months.push(m)\n }\n\n return this.months\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DateMonthEditorOptions extends SelectEditorOptions {\n display?: '2-digit' | 'short' | 'long'\n locale?: 'en' | 'th'\n upperCase?: boolean\n}\n"]}
|
|
@@ -3,17 +3,29 @@ export type Formatter = {
|
|
|
3
3
|
format(ctx: FormatterContext): string;
|
|
4
4
|
};
|
|
5
5
|
export declare class ZeroDisplayFormatter implements Formatter {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
readonly props: {
|
|
7
|
+
displayText?: string;
|
|
8
|
+
};
|
|
9
|
+
constructor(props?: {
|
|
10
|
+
displayText?: string;
|
|
11
|
+
});
|
|
8
12
|
format(ctx: FormatterContext): string;
|
|
9
13
|
}
|
|
10
14
|
export declare class CheckboxFormatter implements Formatter {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
readonly props: {
|
|
16
|
+
trueText?: string;
|
|
17
|
+
falseText?: string;
|
|
18
|
+
cssClass?: string;
|
|
19
|
+
trueValueIcon?: string;
|
|
20
|
+
falseValueIcon?: string;
|
|
21
|
+
};
|
|
22
|
+
constructor(props: {
|
|
23
|
+
trueText?: string;
|
|
24
|
+
falseText?: string;
|
|
25
|
+
cssClass?: string;
|
|
26
|
+
trueValueIcon?: string;
|
|
27
|
+
falseValueIcon?: string;
|
|
28
|
+
});
|
|
17
29
|
format(ctx: FormatterContext): string;
|
|
18
30
|
}
|
|
19
31
|
export declare class LookupFormatter implements Formatter {
|
|
@@ -7,61 +7,50 @@
|
|
|
7
7
|
import { Decorators } from '@serenity-is/corelib';
|
|
8
8
|
import { getLookup, htmlEncode } from '@serenity-is/corelib';
|
|
9
9
|
let ZeroDisplayFormatter = class ZeroDisplayFormatter {
|
|
10
|
-
constructor() {
|
|
11
|
-
|
|
10
|
+
constructor(props = {}) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
var _c;
|
|
13
|
+
this.props = props;
|
|
14
|
+
(_a = this.props) !== null && _a !== void 0 ? _a : (this.props = {});
|
|
15
|
+
(_b = (_c = this.props).displayText) !== null && _b !== void 0 ? _b : (_c.displayText = '');
|
|
12
16
|
}
|
|
13
17
|
format(ctx) {
|
|
14
18
|
const src = ctx.value;
|
|
15
19
|
const value = parseFloat(String(src || '0').replace(',', ''));
|
|
16
20
|
if (value == 0) {
|
|
17
|
-
return htmlEncode(this.displayText);
|
|
21
|
+
return htmlEncode(this.props.displayText);
|
|
18
22
|
}
|
|
19
23
|
return htmlEncode(src);
|
|
20
24
|
}
|
|
21
25
|
};
|
|
22
|
-
__decorate([
|
|
23
|
-
Decorators.option()
|
|
24
|
-
], ZeroDisplayFormatter.prototype, "displayText", void 0);
|
|
25
26
|
ZeroDisplayFormatter = __decorate([
|
|
26
27
|
Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')
|
|
27
28
|
], ZeroDisplayFormatter);
|
|
28
29
|
export { ZeroDisplayFormatter };
|
|
29
30
|
let CheckboxFormatter = class CheckboxFormatter {
|
|
30
|
-
constructor() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
31
|
+
constructor(props) {
|
|
32
|
+
var _a, _b, _c, _d, _e;
|
|
33
|
+
var _f, _g, _h, _j, _k;
|
|
34
|
+
this.props = props;
|
|
35
|
+
(_a = (_f = this.props).cssClass) !== null && _a !== void 0 ? _a : (_f.cssClass = 'text-center fs-2 text-gray-1');
|
|
36
|
+
(_b = (_g = this.props).trueText) !== null && _b !== void 0 ? _b : (_g.trueText = '1');
|
|
37
|
+
(_c = (_h = this.props).falseText) !== null && _c !== void 0 ? _c : (_h.falseText = '0');
|
|
38
|
+
(_d = (_j = this.props).trueValueIcon) !== null && _d !== void 0 ? _d : (_j.trueValueIcon = 'mdi mdi-checkbox-marked-outline');
|
|
39
|
+
(_e = (_k = this.props).falseValueIcon) !== null && _e !== void 0 ? _e : (_k.falseValueIcon = 'mdi mdi-checkbox-blank-outline');
|
|
36
40
|
}
|
|
37
41
|
format(ctx) {
|
|
38
42
|
const src = ctx.value;
|
|
39
|
-
if (src == this.trueText) {
|
|
40
|
-
return `<i class="${this.trueValueIcon} ${this.cssClass}"></i>`;
|
|
43
|
+
if (src == this.props.trueText) {
|
|
44
|
+
return `<i class="${this.props.trueValueIcon} ${this.props.cssClass}"></i>`;
|
|
41
45
|
}
|
|
42
|
-
else if (src == this.falseText) {
|
|
43
|
-
return `<i class="${this.falseValueIcon} ${this.cssClass}"></i>`;
|
|
46
|
+
else if (src == this.props.falseText) {
|
|
47
|
+
return `<i class="${this.props.falseValueIcon} ${this.props.cssClass}"></i>`;
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
46
50
|
return htmlEncode(src);
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
|
-
__decorate([
|
|
51
|
-
Decorators.option()
|
|
52
|
-
], CheckboxFormatter.prototype, "trueText", void 0);
|
|
53
|
-
__decorate([
|
|
54
|
-
Decorators.option()
|
|
55
|
-
], CheckboxFormatter.prototype, "falseText", void 0);
|
|
56
|
-
__decorate([
|
|
57
|
-
Decorators.option()
|
|
58
|
-
], CheckboxFormatter.prototype, "cssClass", void 0);
|
|
59
|
-
__decorate([
|
|
60
|
-
Decorators.option()
|
|
61
|
-
], CheckboxFormatter.prototype, "trueValueIcon", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
Decorators.option()
|
|
64
|
-
], CheckboxFormatter.prototype, "falseValueIcon", void 0);
|
|
65
54
|
CheckboxFormatter = __decorate([
|
|
66
55
|
Decorators.registerFormatter('Idevs.CheckboxFormatter')
|
|
67
56
|
], CheckboxFormatter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters/formatters.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAOrD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B;
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters/formatters.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAOrD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,YAA4B,QAAkC,EAAE;;;QAApC,UAAK,GAAL,KAAK,CAA+B;QAC9D,MAAA,IAAI,CAAC,KAAK,oCAAV,IAAI,CAAC,KAAK,GAAK,EAAE,EAAA;QACjB,YAAA,IAAI,CAAC,KAAK,EAAC,WAAW,uCAAX,WAAW,GAAK,EAAE,EAAA;IAC/B,CAAC;IAED,MAAM,CAAC,GAAqB;QAC1B,MAAM,GAAG,GAAG,GAAG,CAAC,KAAe,CAAA;QAE/B,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;QAC7D,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAC3C,CAAC;QAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;CACF,CAAA;AAhBY,oBAAoB;IADhC,UAAU,CAAC,iBAAiB,CAAC,4BAA4B,CAAC;GAC9C,oBAAoB,CAgBhC;;AAGM,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACk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AC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC;CACF,CAAA;AAdQ;IADN,UAAU,CAAC,MAAM,EAAE;mDACwB;AAGrC;IADN,UAAU,CAAC,MAAM,EAAE;kDACM;AALf,kBAAkB;IAD9B,UAAU,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;GAC5C,kBAAkB,CAgB9B;;AAED,MAAM,OAAO,eAAe;IAC1B,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAI,CAAC;CACxB","sourcesContent":["import { Decorators } from '@serenity-is/corelib'\nimport { FormatterContext } from '@serenity-is/sleekgrid'\nimport { getLookup, htmlEncode } from '@serenity-is/corelib'\n\nexport type Formatter = {\n format(ctx: FormatterContext): string\n}\n\n@Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')\nexport class ZeroDisplayFormatter implements Formatter {\n constructor(public readonly props: { displayText?: string } = {}) {\n this.props ??= {}\n this.props.displayText ??= ''\n }\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n\n const value = parseFloat(String(src || '0').replace(',', ''))\n if (value == 0) {\n return htmlEncode(this.props.displayText)\n }\n\n return htmlEncode(src)\n }\n}\n\n@Decorators.registerFormatter('Idevs.CheckboxFormatter')\nexport class CheckboxFormatter implements Formatter {\n constructor(\n public readonly props: {\n trueText?: string\n falseText?: string\n cssClass?: string\n trueValueIcon?: string\n falseValueIcon?: string\n },\n ) {\n this.props.cssClass ??= 'text-center fs-2 text-gray-1'\n this.props.trueText ??= '1'\n this.props.falseText ??= '0'\n this.props.trueValueIcon ??= 'mdi mdi-checkbox-marked-outline'\n this.props.falseValueIcon ??= 'mdi mdi-checkbox-blank-outline'\n }\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (src == this.props.trueText) {\n return `<i class=\"${this.props.trueValueIcon} ${this.props.cssClass}\"></i>`\n } else if (src == this.props.falseText) {\n return `<i class=\"${this.props.falseValueIcon} ${this.props.cssClass}\"></i>`\n } else {\n return htmlEncode(src)\n }\n }\n}\n\n@Decorators.registerFormatter('Idevs.LookupFormatter')\nexport class LookupFormatter implements Formatter {\n @Decorators.option()\n public lookupKey: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (!src) return ''\n\n if (!this.lookupKey) return src\n\n const lookup = getLookup(this.lookupKey)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items = lookup.items as Array<{ [key: string]: any }>\n const idField = lookup.idField\n const textField = lookup.textField\n const idList = src.toString().split(',')\n\n return idList\n .map(x => {\n const g = items.find(i => i[idField] == x)\n if (!g) return x\n\n return htmlEncode(g[textField])\n })\n .join(', ')\n }\n}\n\n@Decorators.registerFormatter('Idevs.DateMonthFormatter')\nexport class DateMonthFormatter implements Formatter {\n @Decorators.option()\n public display: '2-digit' | 'short' | 'long'\n\n @Decorators.option()\n public locale: 'en' | 'th'\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as number\n if (!src) return ''\n\n const locale = this.locale ?? 'en'\n const options = { month: this.display ?? '2-digit' }\n\n return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)\n }\n}\n\nexport class idevsFormatters {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() {}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idevs/corelib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.92",
|
|
4
4
|
"description": "Extended library for Serenity Framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,20 +30,21 @@
|
|
|
30
30
|
"url": "git+https://github.com/klomkling/idevs.corelib"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@serenity-is/corelib": "^8.
|
|
34
|
-
"@serenity-is/sleekgrid": "^1.
|
|
33
|
+
"@serenity-is/corelib": "^8.4.3",
|
|
34
|
+
"@serenity-is/sleekgrid": "^1.7.0",
|
|
35
35
|
"@types/jquery": "^3.5.29",
|
|
36
36
|
"@types/jquery.validation": "^1.16.10",
|
|
37
|
-
"@types/jqueryui": "^1.12.
|
|
38
|
-
"@types/toastr": "^2.1.43"
|
|
39
|
-
"bootstrap": "^5.3.2"
|
|
37
|
+
"@types/jqueryui": "^1.12.22",
|
|
38
|
+
"@types/toastr": "^2.1.43"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
41
|
+
"@serenity-is/tsbuild": "^8.0.1",
|
|
42
42
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
43
43
|
"@typescript-eslint/parser": "^5.62.0",
|
|
44
|
-
"
|
|
44
|
+
"bootstrap": "^5.3.3",
|
|
45
|
+
"eslint": "^8.57.0",
|
|
45
46
|
"eslint-config-prettier": "^8.10.0",
|
|
46
47
|
"prettier": "^2.8.8",
|
|
47
|
-
"typescript": "^5.
|
|
48
|
+
"typescript": "^5.4.4"
|
|
48
49
|
}
|
|
49
50
|
}
|
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/adjacent-overload-signatures */
|
|
3
3
|
// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
Decorators,
|
|
7
|
+
EditorProps,
|
|
8
|
+
EditorWidget,
|
|
9
|
+
Enum,
|
|
10
|
+
EnumKeyAttribute,
|
|
11
|
+
EnumTypeRegistry,
|
|
12
|
+
Fluent,
|
|
13
|
+
IReadOnly,
|
|
14
|
+
getCustomAttributes,
|
|
15
|
+
getLookup,
|
|
16
|
+
isEmptyOrNull,
|
|
17
|
+
toId,
|
|
18
|
+
tryGetText,
|
|
19
|
+
} from '@serenity-is/corelib'
|
|
8
20
|
|
|
9
21
|
export type CheckboxButtonEditorOptions = {
|
|
10
22
|
enumKey?: string
|
|
@@ -14,15 +26,22 @@ export type CheckboxButtonEditorOptions = {
|
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
@Decorators.registerEditor('CheckboxButtonEditor')
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
export class CheckboxButtonEditor<P extends CheckboxButtonEditorOptions = CheckboxButtonEditorOptions>
|
|
30
|
+
extends EditorWidget<P>
|
|
31
|
+
implements IReadOnly
|
|
32
|
+
{
|
|
19
33
|
private _items: Array<{ [key: string]: any }>
|
|
20
34
|
private readonly _idField: string
|
|
21
35
|
private readonly _textField: string
|
|
22
36
|
private readonly _isStringId: boolean
|
|
23
37
|
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
static override createDefaultElement() {
|
|
39
|
+
return Fluent('div').getNode()
|
|
40
|
+
}
|
|
41
|
+
declare readonly domNode: HTMLElement
|
|
42
|
+
|
|
43
|
+
constructor(props: EditorProps<P>) {
|
|
44
|
+
super(props)
|
|
26
45
|
|
|
27
46
|
if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {
|
|
28
47
|
return
|
|
@@ -40,7 +59,7 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
40
59
|
let enumKey = this.options.enumKey
|
|
41
60
|
|
|
42
61
|
if (enumKey == null && enumType != null) {
|
|
43
|
-
const enumKeyAttr =
|
|
62
|
+
const enumKeyAttr = getCustomAttributes(enumType, EnumKeyAttribute, false)
|
|
44
63
|
if (enumKeyAttr.length > 0) {
|
|
45
64
|
enumKey = enumKeyAttr[0].value
|
|
46
65
|
}
|
|
@@ -52,11 +71,14 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
52
71
|
}
|
|
53
72
|
}
|
|
54
73
|
|
|
55
|
-
this.
|
|
74
|
+
this.domNode.classList.add('d-flex', 'flex-wrap')
|
|
56
75
|
}
|
|
57
76
|
|
|
58
77
|
protected renderCheckboxes() {
|
|
59
|
-
this.
|
|
78
|
+
const childDivs = this.domNode.querySelectorAll('div')
|
|
79
|
+
childDivs.forEach(function (child) {
|
|
80
|
+
this.domNode.removeChild(child)
|
|
81
|
+
})
|
|
60
82
|
|
|
61
83
|
for (const item of this._items) {
|
|
62
84
|
const textValue = item[this._textField]
|
|
@@ -76,7 +98,7 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
76
98
|
.attr('value', value)
|
|
77
99
|
.prependTo(label)
|
|
78
100
|
label.appendTo(div)
|
|
79
|
-
div.appendTo(this.
|
|
101
|
+
div.appendTo(this.domNode)
|
|
80
102
|
}
|
|
81
103
|
|
|
82
104
|
get_items(): Array<{ [key: string]: any }> {
|
|
@@ -96,11 +118,14 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
96
118
|
this.set_items(v)
|
|
97
119
|
}
|
|
98
120
|
|
|
99
|
-
get_value()
|
|
100
|
-
const val:
|
|
101
|
-
this.
|
|
102
|
-
|
|
121
|
+
get_value() {
|
|
122
|
+
const val: string[] = []
|
|
123
|
+
const inputs = this.domNode.querySelectorAll('input:checked')
|
|
124
|
+
|
|
125
|
+
inputs.forEach((input: HTMLInputElement) => {
|
|
126
|
+
val.push(this._isStringId ? input.value : toId(input.value))
|
|
103
127
|
})
|
|
128
|
+
|
|
104
129
|
return val.join(',')
|
|
105
130
|
}
|
|
106
131
|
|
|
@@ -114,24 +139,17 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
114
139
|
if (!isEmptyOrNull(value)) {
|
|
115
140
|
values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))
|
|
116
141
|
}
|
|
117
|
-
const inputs = this.
|
|
118
|
-
inputs.
|
|
119
|
-
|
|
142
|
+
const inputs = this.domNode.querySelectorAll<HTMLInputElement>('input')
|
|
143
|
+
inputs.forEach(input => {
|
|
144
|
+
input.checked = false
|
|
120
145
|
})
|
|
121
146
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const checks = inputs.filter('[value=' + v + ']')
|
|
125
|
-
if (checks.length > 0) {
|
|
126
|
-
;(checks[0] as HTMLInputElement).checked = true
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
} else {
|
|
130
|
-
const checks = inputs.filter('[value=' + values + ']')
|
|
147
|
+
values.forEach(v => {
|
|
148
|
+
const checks = Array.from(inputs).filter(input => (input as HTMLInputElement).value === v)
|
|
131
149
|
if (checks.length > 0) {
|
|
132
150
|
;(checks[0] as HTMLInputElement).checked = true
|
|
133
151
|
}
|
|
134
|
-
}
|
|
152
|
+
})
|
|
135
153
|
}
|
|
136
154
|
}
|
|
137
155
|
|
|
@@ -140,15 +158,21 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
get_readOnly(): boolean {
|
|
143
|
-
return this.
|
|
161
|
+
return this.domNode.getAttribute('disabled') != null
|
|
144
162
|
}
|
|
145
163
|
|
|
146
164
|
set_readOnly(value: boolean): void {
|
|
147
165
|
if (this.get_readOnly() !== value) {
|
|
148
166
|
if (value) {
|
|
149
|
-
this.
|
|
167
|
+
this.domNode.setAttribute('disabled', 'disabled')
|
|
168
|
+
this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
|
|
169
|
+
input.setAttribute('disabled', 'disabled')
|
|
170
|
+
})
|
|
150
171
|
} else {
|
|
151
|
-
this.
|
|
172
|
+
this.domNode.removeAttribute('disabled')
|
|
173
|
+
this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
|
|
174
|
+
input.removeAttribute('disabled')
|
|
175
|
+
})
|
|
152
176
|
}
|
|
153
177
|
}
|
|
154
178
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Decorators, SelectEditor, SelectEditorOptions } from '@serenity-is/corelib'
|
|
2
|
-
import { indexOf } from '@serenity-is/corelib'
|
|
1
|
+
import { Decorators, EditorProps, SelectEditor, SelectEditorOptions, indexOf } from '@serenity-is/corelib'
|
|
3
2
|
|
|
4
3
|
@Decorators.registerEditor('DateMonthEditor')
|
|
5
|
-
export class DateMonthEditor extends SelectEditor {
|
|
4
|
+
export class DateMonthEditor<P extends DateMonthEditorOptions = DateMonthEditorOptions> extends SelectEditor<P> {
|
|
6
5
|
private months: string[]
|
|
7
6
|
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
7
|
+
constructor(props: EditorProps<P>) {
|
|
8
|
+
super(props)
|
|
10
9
|
|
|
11
10
|
this.updateItems()
|
|
12
11
|
}
|
|
@@ -8,19 +8,17 @@ export type Formatter = {
|
|
|
8
8
|
|
|
9
9
|
@Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')
|
|
10
10
|
export class ZeroDisplayFormatter implements Formatter {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.
|
|
11
|
+
constructor(public readonly props: { displayText?: string } = {}) {
|
|
12
|
+
this.props ??= {}
|
|
13
|
+
this.props.displayText ??= ''
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
@Decorators.option()
|
|
16
|
-
public displayText: string
|
|
17
|
-
|
|
18
16
|
format(ctx: FormatterContext): string {
|
|
19
17
|
const src = ctx.value as string
|
|
20
18
|
|
|
21
19
|
const value = parseFloat(String(src || '0').replace(',', ''))
|
|
22
20
|
if (value == 0) {
|
|
23
|
-
return htmlEncode(this.displayText)
|
|
21
|
+
return htmlEncode(this.props.displayText)
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
return htmlEncode(src)
|
|
@@ -29,35 +27,28 @@ export class ZeroDisplayFormatter implements Formatter {
|
|
|
29
27
|
|
|
30
28
|
@Decorators.registerFormatter('Idevs.CheckboxFormatter')
|
|
31
29
|
export class CheckboxFormatter implements Formatter {
|
|
32
|
-
constructor(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
constructor(
|
|
31
|
+
public readonly props: {
|
|
32
|
+
trueText?: string
|
|
33
|
+
falseText?: string
|
|
34
|
+
cssClass?: string
|
|
35
|
+
trueValueIcon?: string
|
|
36
|
+
falseValueIcon?: string
|
|
37
|
+
},
|
|
38
|
+
) {
|
|
39
|
+
this.props.cssClass ??= 'text-center fs-2 text-gray-1'
|
|
40
|
+
this.props.trueText ??= '1'
|
|
41
|
+
this.props.falseText ??= '0'
|
|
42
|
+
this.props.trueValueIcon ??= 'mdi mdi-checkbox-marked-outline'
|
|
43
|
+
this.props.falseValueIcon ??= 'mdi mdi-checkbox-blank-outline'
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
@Decorators.option()
|
|
41
|
-
public trueText: string
|
|
42
|
-
|
|
43
|
-
@Decorators.option()
|
|
44
|
-
public falseText: string
|
|
45
|
-
|
|
46
|
-
@Decorators.option()
|
|
47
|
-
public cssClass: string
|
|
48
|
-
|
|
49
|
-
@Decorators.option()
|
|
50
|
-
public trueValueIcon: string
|
|
51
|
-
|
|
52
|
-
@Decorators.option()
|
|
53
|
-
public falseValueIcon: string
|
|
54
|
-
|
|
55
46
|
format(ctx: FormatterContext): string {
|
|
56
47
|
const src = ctx.value as string
|
|
57
|
-
if (src == this.trueText) {
|
|
58
|
-
return `<i class="${this.trueValueIcon} ${this.cssClass}"></i>`
|
|
59
|
-
} else if (src == this.falseText) {
|
|
60
|
-
return `<i class="${this.falseValueIcon} ${this.cssClass}"></i>`
|
|
48
|
+
if (src == this.props.trueText) {
|
|
49
|
+
return `<i class="${this.props.trueValueIcon} ${this.props.cssClass}"></i>`
|
|
50
|
+
} else if (src == this.props.falseText) {
|
|
51
|
+
return `<i class="${this.props.falseValueIcon} ${this.props.cssClass}"></i>`
|
|
61
52
|
} else {
|
|
62
53
|
return htmlEncode(src)
|
|
63
54
|
}
|
package/src/tsconfig.json
CHANGED
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"forceConsistentCasingInFileNames": true,
|
|
13
13
|
"noImplicitAny": true,
|
|
14
14
|
"sourceMap": true,
|
|
15
|
-
"module": "
|
|
15
|
+
"module": "ESNext",
|
|
16
16
|
"moduleResolution": "Node",
|
|
17
17
|
"skipLibCheck": true,
|
|
18
18
|
"types": ["jquery", "jquery.validation", "jqueryui", "toastr"],
|
|
19
19
|
"outDir": "../dist",
|
|
20
|
-
"target": "
|
|
21
|
-
"lib": ["ES6", "ES2020", "DOM"],
|
|
20
|
+
"target": "ES2015",
|
|
21
|
+
"lib": ["ES6", "ES2015", "ES2020", "DOM"],
|
|
22
22
|
"noEmitHelpers": false,
|
|
23
23
|
"importHelpers": false,
|
|
24
24
|
"jsx": "react",
|