sclass HCRUD_Data { new Map renderers; new SS fieldHelp; O currentValue; // current field value held temporarily bool humanizeFieldNames = true; SS rawFormValues; // temporary map with raw form values abstract sclass Renderer { S metaInfo; swappable O preprocessValue(O value) { ret value; } } sclass NotEditable extends Renderer {} srecord TextArea(int cols, int rows) extends Renderer { // star constructor syntax not working here (transpiler bug) TextArea(int cols, int rows, IF1 preprocessValue) { this.cols = cols; this.rows = rows; this.preprocessValue = preprocessValue; } } sclass AceEditor extends TextArea { *() {} *(int *cols, int *rows) {} } srecord TextField(int cols) extends Renderer {} srecord AbstractComboBox extends Renderer { bool editable; // help find item to select swappable S valueToEntry(O value) { ret strOrNull(value); } } srecord ComboBox(LS entries) extends AbstractComboBox { ComboBox(S... entries) { this(asList(entries)); } ComboBox(bool editable, S... entries) { this(entries); this.editable = editable; } ComboBox(bool editable, LS entries) { this(entries); this.editable = editable; } // star constructor syntax not working here (transpiler bug) ComboBox(LS entries, IF1 valueToEntry) { this.entries = entries; this.valueToEntry = valueToEntry; } } srecord DynamicComboBox(S info) extends AbstractComboBox { S url; } srecord CheckBox() extends Renderer { { metaInfo = "Bool"; } } srecord FlexibleLengthList(Renderer itemRenderer) extends Renderer {} S itemName() { ret "object"; } S itemNamePlural() { ret plural(itemName()); } //LS fields() { null; } L list() { null; } L list(IntRange range) { ret subListOrFull(list(), range); } S idField() { ret "id"; } MapSO emptyObject() { null; } MapSO getObject(O id) { null; } MapSO getObjectForEdit(O id) { ret getObject(id); } swappable MapSO getObjectForDuplication(O id) { ret getObject(id); } // return ID O createObject(SS fullMap, S fieldPrefix) { throw unimplemented(); } // return text msg S deleteObject(O id) { throw unimplemented(); } bool objectCanBeDeleted(O id) { true; } swappable bool objectCanBeEdited(O id) { true; } // return text msg S updateObject(O id, SS fullMap, S fieldPrefix) { throw unimplemented(); } // return null for standard input field Renderer getRenderer(S field) { ret renderers.get(field); } final Renderer getRenderer(S field, O value) { this.currentValue = value; try { ret getRenderer(field); } finally { this.currentValue = null; } } // returns HTML S fieldHelp(S field) { ret fieldHelp.get(field); } returnSelf addRenderer(S field, Renderer renderer) { renderers.put(field, renderer); } returnSelf fieldHelp(S field, S help, S... more) { fieldHelp.put(field, help); for (int i = 0; i+1 < l(more); i += 2) fieldHelp.put(more[i], more[i+1]); } S fieldNameToHTML(S name) { S help = fieldHelp.get(name); ret spanTitle(help, htmlencode2( humanizeFieldNames ? humanizeLabel(name) : name)); } Set filteredFields() { null; } LS comboBoxSearch(S info, S query) { null; } // optional page title when showing a single object S titleForObjectID(O id) { null; } // second parameter indicates descending Pair defaultSortField() { null; } abstract class Item extends AbstractMap { O id; MapSO fullMap; *(O *id) {} abstract MapSO calcFullMap(); MapSO fullMap() { if (fullMap == null) fullMap = calcFullMap(); ret fullMap; } replace A with S. replace B with O. public int size() { ret l(fullMap()); } public Set> entrySet() { ret fullMap().entrySet(); } public bool containsKey(O o) { ret fullMap().containsKey(o); } public B get(O o) { if (fullMap == null && eq(o, idField())) ret id; ret fullMap().get(o); } public B put(A key, B value) { ret fullMap().put(key, value); } } }