Libraryless. Click here for Pure Java version (17760L/109K).
1 | sclass HCRUD_Data {
|
2 | new Map<S, Renderer> renderers; |
3 | new SS fieldHelp; |
4 | O currentValue; // current field value held temporarily |
5 | bool humanizeFieldNames = true; |
6 | |
7 | SS rawFormValues; // temporary map with raw form values |
8 | |
9 | abstract sclass Renderer {
|
10 | S metaInfo; |
11 | |
12 | swappable O preprocessValue(O value) { ret value; }
|
13 | } |
14 | |
15 | sclass NotEditable extends Renderer {}
|
16 | |
17 | srecord TextArea(int cols, int rows) extends Renderer {
|
18 | // star constructor syntax not working here (transpiler bug) |
19 | TextArea(int cols, int rows, IF1 preprocessValue) {
|
20 | this.cols = cols; |
21 | this.rows = rows; |
22 | this.preprocessValue = preprocessValue; |
23 | } |
24 | } |
25 | |
26 | sclass AceEditor extends TextArea {
|
27 | *() {}
|
28 | *(int *cols, int *rows) {}
|
29 | } |
30 | |
31 | srecord TextField(int cols) extends Renderer {}
|
32 | |
33 | srecord AbstractComboBox extends Renderer {
|
34 | bool editable; |
35 | |
36 | // help find item to select |
37 | swappable S valueToEntry(O value) { ret strOrNull(value); }
|
38 | } |
39 | |
40 | srecord ComboBox(LS entries) extends AbstractComboBox {
|
41 | ComboBox(S... entries) { this(asList(entries)); }
|
42 | ComboBox(bool editable, S... entries) { this(entries); this.editable = editable; }
|
43 | ComboBox(bool editable, LS entries) { this(entries); this.editable = editable; }
|
44 | |
45 | // star constructor syntax not working here (transpiler bug) |
46 | ComboBox(LS entries, IF1<O, S> valueToEntry) {
|
47 | this.entries = entries; |
48 | this.valueToEntry = valueToEntry; |
49 | } |
50 | } |
51 | |
52 | srecord DynamicComboBox(S info) extends AbstractComboBox {
|
53 | S url; |
54 | } |
55 | |
56 | srecord CheckBox() extends Renderer {
|
57 | { metaInfo = "Bool"; }
|
58 | } |
59 | |
60 | srecord FlexibleLengthList(Renderer itemRenderer) extends Renderer {}
|
61 | |
62 | S itemName() { ret "object"; }
|
63 | S itemNamePlural() { ret plural(itemName()); }
|
64 | |
65 | //LS fields() { null; }
|
66 | |
67 | L<MapSO> list() { null; }
|
68 | L<MapSO> list(IntRange range) { ret subListOrFull(list(), range); }
|
69 | |
70 | S idField() { ret "id"; }
|
71 | MapSO emptyObject() { null; }
|
72 | MapSO getObject(O id) { null; }
|
73 | MapSO getObjectForEdit(O id) { ret getObject(id); }
|
74 | swappable MapSO getObjectForDuplication(O id) { ret getObject(id); }
|
75 | |
76 | // return ID |
77 | O createObject(SS fullMap, S fieldPrefix) { throw unimplemented(); }
|
78 | |
79 | // return text msg |
80 | S deleteObject(O id) { throw unimplemented(); }
|
81 | |
82 | bool objectCanBeDeleted(O id) { true; }
|
83 | swappable bool objectCanBeEdited(O id) { true; }
|
84 | |
85 | |
86 | // return text msg |
87 | S updateObject(O id, SS fullMap, S fieldPrefix) { throw unimplemented(); }
|
88 | |
89 | // return null for standard input field |
90 | Renderer getRenderer(S field) { ret renderers.get(field); }
|
91 | |
92 | final Renderer getRenderer(S field, O value) {
|
93 | this.currentValue = value; |
94 | try {
|
95 | ret getRenderer(field); |
96 | } finally {
|
97 | this.currentValue = null; |
98 | } |
99 | } |
100 | |
101 | // returns HTML |
102 | S fieldHelp(S field) { ret fieldHelp.get(field); }
|
103 | |
104 | returnSelf addRenderer(S field, Renderer renderer) { renderers.put(field, renderer); }
|
105 | |
106 | returnSelf fieldHelp(S field, S help, S... more) {
|
107 | fieldHelp.put(field, help); |
108 | for (int i = 0; i+1 < l(more); i += 2) |
109 | fieldHelp.put(more[i], more[i+1]); |
110 | } |
111 | |
112 | S fieldNameToHTML(S name) {
|
113 | S help = fieldHelp.get(name); |
114 | ret spanTitle(help, htmlencode2( |
115 | humanizeFieldNames ? humanizeLabel(name) : name)); |
116 | } |
117 | |
118 | Set<S> filteredFields() { null; }
|
119 | |
120 | LS comboBoxSearch(S info, S query) { null; }
|
121 | |
122 | // optional page title when showing a single object |
123 | S titleForObjectID(O id) { null; }
|
124 | |
125 | // second parameter indicates descending |
126 | Pair<S, Bool> defaultSortField() { null; }
|
127 | |
128 | abstract class Item extends AbstractMap<S, O> {
|
129 | O id; |
130 | MapSO fullMap; |
131 | |
132 | *(O *id) {}
|
133 | |
134 | abstract MapSO calcFullMap(); |
135 | |
136 | MapSO fullMap() { if (fullMap == null) fullMap = calcFullMap(); ret fullMap; }
|
137 | |
138 | replace A with S. |
139 | replace B with O. |
140 | |
141 | public int size() { ret l(fullMap()); }
|
142 | public Set<Map.Entry<A, B>> entrySet() { ret fullMap().entrySet(); }
|
143 | public bool containsKey(O o) { ret fullMap().containsKey(o); }
|
144 | public B get(O o) {
|
145 | if (fullMap == null && eq(o, idField())) ret id; |
146 | ret fullMap().get(o); |
147 | } |
148 | |
149 | public B put(A key, B value) {
|
150 | ret fullMap().put(key, value); |
151 | } |
152 | } |
153 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1026000 |
| Snippet name: | HCRUD_Data |
| Eternal ID of this version: | #1026000/60 |
| Text MD5: | 2036abdf77fef15bd1834e9e4f9a311a |
| Transpilation MD5: | c4e662864d7c8cd597889742677fe64c |
| Author: | stefan |
| Category: | javax / html |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-07-20 18:04:52 |
| Source code size: | 4385 bytes / 153 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 741 / 1378 |
| Version history: | 59 change(s) |
| Referenced in: | [show references] |