Settings entity

26-05-2019
Important to give "RU" permissions to virtualSettings to make it editable ``` orm.register({ name: "settings", permissions: "", label: "@@Configuración", pluralLabel: "@@Configuración", properties: [ { name: "name", type: "string" }, { name: "value", type: "text" }, ], constraints: [ { type: "unique", columns: ["name"] } ] }) orm.register({ name: "virtualSettings", permissions: "RU", transient: true, idProperty: false, auditProperties: false, label: "@@Configuración", pluralLabel: "@@Configuración", properties: [ { name: "name", type: "string", size: 100, label: "@@Nombre", nullable: true }, ] }) ``` Client side: ``` S.addRoute("/admin/amura/billing/settings", () => { let detail = new admin.EntityDetail("amura.billing.virtualSettings", { singleRowLoadURL: "/amura/billing/loadConfig.api", singleRowSaveURL: "/amura/billing/saveConfig.api", }) detail.load() let view = new admin.AdminView("padding") let tile = new S.Tile() view.content.appendChild(tile.element) tile.element.appendChild(detail.element) S.setView(view) }) ``` Server side: ``` import * as settings from "stdlib/settings"; web.addApi({ url: "/amura/billing/loadConfig.api", handler: loadConfigHandler, }) web.addApi({ url: "/amura/billing/saveConfig.api", handler: saveAppconfigHandler, }) function loadConfigHandler(c: web.Context) { let config = settings.load() as VirtualSettings c.response.writeJSON(config) } function saveAppconfigHandler(c: web.Context) { let entity = orm.getEntityWithCustomFields("amura.billing.virtualSettings") let model = crud.parseValues(c.request.values, entity.properties, c) as VirtualSettings; settings.save(model, entity.properties) } ```

Amura