From c2b0cf858e31df2eba3c70c33678cfbacb167659 Mon Sep 17 00:00:00 2001 From: simov Date: Thu, 12 Dec 2013 14:00:31 +0200 Subject: [PATCH] Load static values fomr settings --- lib/core/editview.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/core/editview.js b/lib/core/editview.js index c1852fe..9d12e9e 100644 --- a/lib/core/editview.js +++ b/lib/core/editview.js @@ -34,6 +34,38 @@ var otm = { } }; +// load static values from settings +// modifies `args.config.columns` with `value` +var stc = { + getSelect: function (options) { + var values = []; + for (var i=0; i < options.length; i++) { + values.push({__pk: options[i], __text: options[i]}); + } + return values; + }, + getRadio: function (options) { + return [ + {text: options[0], value: 1}, + {text: options[1], value: 0} + ]; + }, + loopColumns: function (args) { + var columns = args.config.columns; + for (var i=0; i < columns.length; i++) { + var control = columns[i].control; + if (!(control.options instanceof Array)) continue; + + switch (true) { + case control.select: + columns[i].value = stc.getSelect(control.options); break; + case control.radio: + columns[i].value = stc.getRadio(control.options); break; + } + } + } +}; + // get table records var tbl = { getSql: function (args) { @@ -132,6 +164,7 @@ function getData (args, cb) { otm.loopColumns(args, function (err) { if (err) return cb(err); + stc.loopColumns(args); tbl.getRecords(args, function (err, rows) { if (err) return cb(err); mtm.loopRecords(args, rows, function (err) {