@idevs/corelib 0.0.84 → 0.0.86
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.
|
@@ -3,11 +3,13 @@ export type CheckboxButtonEditorOptions = {
|
|
|
3
3
|
enumKey?: string;
|
|
4
4
|
enumType?: any;
|
|
5
5
|
lookupKey?: string;
|
|
6
|
+
isStringId?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> implements IReadOnly {
|
|
8
9
|
private _items;
|
|
9
|
-
private _idField;
|
|
10
|
-
private _textField;
|
|
10
|
+
private readonly _idField;
|
|
11
|
+
private readonly _textField;
|
|
12
|
+
private readonly _isStringId;
|
|
11
13
|
constructor(input: JQuery, opt: CheckboxButtonEditorOptions);
|
|
12
14
|
protected renderCheckboxes(): void;
|
|
13
15
|
protected addCheckbox(value: string, text: string): void;
|
|
@@ -16,6 +16,7 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
16
16
|
if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
+
this._isStringId = this.options.isStringId;
|
|
19
20
|
if (!isEmptyOrNull(this.options.lookupKey)) {
|
|
20
21
|
const lookup = getLookup(this.options.lookupKey);
|
|
21
22
|
this._idField = lookup.idField;
|
|
@@ -51,8 +52,8 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
51
52
|
}
|
|
52
53
|
addCheckbox(value, text) {
|
|
53
54
|
const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />');
|
|
54
|
-
const label = $('<label/>').text(text);
|
|
55
|
-
$('<input type="checkbox" class="me-2"/>')
|
|
55
|
+
const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '));
|
|
56
|
+
$('<input type="checkbox" class="me-2" />')
|
|
56
57
|
.attr('name', this.uniqueName)
|
|
57
58
|
.attr('id', this.uniqueName + '_' + value)
|
|
58
59
|
.attr('value', value)
|
|
@@ -76,7 +77,7 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
76
77
|
get_value() {
|
|
77
78
|
const val = [];
|
|
78
79
|
this.element.find('input:checked').each((i, e) => {
|
|
79
|
-
val.push(toId($(e).val()));
|
|
80
|
+
val.push(this._isStringId ? $(e).val() : toId($(e).val()));
|
|
80
81
|
});
|
|
81
82
|
return val.join(',');
|
|
82
83
|
}
|
|
@@ -86,8 +87,9 @@ let CheckboxButtonEditor = class CheckboxButtonEditor extends Widget {
|
|
|
86
87
|
set_value(value) {
|
|
87
88
|
if (value !== this.get_value()) {
|
|
88
89
|
let values = [];
|
|
89
|
-
if (!isEmptyOrNull(value))
|
|
90
|
-
values = value.split(',').map(p => Number(p));
|
|
90
|
+
if (!isEmptyOrNull(value)) {
|
|
91
|
+
values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p));
|
|
92
|
+
}
|
|
91
93
|
const inputs = this.element.find('input');
|
|
92
94
|
inputs.each((i, e) => {
|
|
93
95
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkboxButtonEditor.js","sourceRoot":"","sources":["../../src/editors/checkboxButtonEditor.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oEAAoE;AACpE,4FAA4F;;;;;;;AAE5F,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAa,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,IAAO,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AAUnC,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,MAAmC;IAK3E,YAAY,KAAa,EAAE,GAAg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;gBACL,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF,CAAA;AApIY,oBAAoB;IAFhC,UAAU,CAAC,cAAc,CAAC,sBAAsB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC;GACL,oBAAoB,CAoIhC;SApIY,oBAAoB;AAsIjC,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 {\n coalesce,\n Enum,\n getAttributes,\n getLookup,\n isArray,\n isEmptyOrNull,\n toId,\n tryGetText,\n} from '@serenity-is/corelib/q'\nimport Element = Decorators.element\n\nexport type CheckboxButtonEditorOptions = {\n enumKey?: string\n enumType?: any\n lookupKey?: string\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 _idField: string\n private _textField: string\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 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(), coalesce(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)\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: number[] = []\n this.element.find('input:checked').each((i, e) => {\n val.push(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: number[] = []\n if (!isEmptyOrNull(value)) values = value.split(',').map(p => Number(p))\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,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAa,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,IAAO,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AAWnC,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,MAAmC;IAM3E,YAAY,KAAa,EAAE,GAAgC;QACzD,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAEjB,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;YACjH,OAAM;SACP;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAA;QAE1C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,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CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF,CAAA;AAzIY,oBAAoB;IAFhC,UAAU,CAAC,cAAc,CAAC,sBAAsB,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC;GACL,oBAAoB,CAyIhC;SAzIY,oBAAoB;AA2IjC,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 {\n coalesce,\n Enum,\n getAttributes,\n getLookup,\n isArray,\n isEmptyOrNull,\n toId,\n tryGetText,\n} from '@serenity-is/corelib/q'\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(), coalesce(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"]}
|
package/package.json
CHANGED
|
@@ -19,14 +19,16 @@ export type CheckboxButtonEditorOptions = {
|
|
|
19
19
|
enumKey?: string
|
|
20
20
|
enumType?: any
|
|
21
21
|
lookupKey?: string
|
|
22
|
+
isStringId?: boolean
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
@Decorators.registerEditor('CheckboxButtonEditor')
|
|
25
26
|
@Element('<div/>')
|
|
26
27
|
export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> implements IReadOnly {
|
|
27
28
|
private _items: Array<{ [key: string]: any }>
|
|
28
|
-
private _idField: string
|
|
29
|
-
private _textField: string
|
|
29
|
+
private readonly _idField: string
|
|
30
|
+
private readonly _textField: string
|
|
31
|
+
private readonly _isStringId: boolean
|
|
30
32
|
|
|
31
33
|
constructor(input: JQuery, opt: CheckboxButtonEditorOptions) {
|
|
32
34
|
super(input, opt)
|
|
@@ -35,6 +37,8 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
35
37
|
return
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
this._isStringId = this.options.isStringId
|
|
41
|
+
|
|
38
42
|
if (!isEmptyOrNull(this.options.lookupKey)) {
|
|
39
43
|
const lookup = getLookup(this.options.lookupKey)
|
|
40
44
|
this._idField = lookup.idField
|
|
@@ -74,8 +78,8 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
74
78
|
|
|
75
79
|
protected addCheckbox(value: string, text: string) {
|
|
76
80
|
const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />')
|
|
77
|
-
const label = $('<label/>').text(text)
|
|
78
|
-
$('<input type="checkbox" class="me-2"/>')
|
|
81
|
+
const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))
|
|
82
|
+
$('<input type="checkbox" class="me-2" />')
|
|
79
83
|
.attr('name', this.uniqueName)
|
|
80
84
|
.attr('id', this.uniqueName + '_' + value)
|
|
81
85
|
.attr('value', value)
|
|
@@ -102,9 +106,9 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
get_value(): string {
|
|
105
|
-
const val:
|
|
109
|
+
const val: unknown[] = []
|
|
106
110
|
this.element.find('input:checked').each((i, e) => {
|
|
107
|
-
val.push(toId($(e).val()))
|
|
111
|
+
val.push(this._isStringId ? $(e).val() : toId($(e).val()))
|
|
108
112
|
})
|
|
109
113
|
return val.join(',')
|
|
110
114
|
}
|
|
@@ -115,8 +119,10 @@ export class CheckboxButtonEditor extends Widget<CheckboxButtonEditorOptions> im
|
|
|
115
119
|
|
|
116
120
|
set_value(value: string): void {
|
|
117
121
|
if (value !== this.get_value()) {
|
|
118
|
-
let values:
|
|
119
|
-
if (!isEmptyOrNull(value))
|
|
122
|
+
let values: unknown[] = []
|
|
123
|
+
if (!isEmptyOrNull(value)) {
|
|
124
|
+
values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))
|
|
125
|
+
}
|
|
120
126
|
const inputs = this.element.find('input')
|
|
121
127
|
inputs.each((i, e) => {
|
|
122
128
|
;(e as HTMLInputElement).checked = false
|