From d47db97bb6ce36c3a1452031cc3ccdef1803e759 Mon Sep 17 00:00:00 2001 From: Keegan Date: Thu, 12 Nov 2015 09:42:18 -0800 Subject: [PATCH] WIP --- gulpfile.js | 2 +- src/config-page.html | 2 +- src/scripts/config-page.js | 14 +++++++++----- src/scripts/lib/item-types.js | 4 ++++ src/scripts/lib/manipulators.js | 18 ++++++++++++++++++ src/templates/components/radiogroup.mustache | 15 +++++++++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/config-page.html create mode 100644 src/templates/components/radiogroup.mustache diff --git a/gulpfile.js b/gulpfile.js index a6b6952..83fe187 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -15,7 +15,7 @@ gulp.task('clean', function(done) { }); }); -gulp.task('browserify', ['clean'], function(done) { +gulp.task('browserify', ['clean'], function() { return browserify('src/scripts/config-page.js', { debug: false }) .transform(stringify(['.html', '.mustache'])) .bundle() diff --git a/src/config-page.html b/src/config-page.html old mode 100644 new mode 100755 index 917ad92..2419edd --- a/src/config-page.html +++ b/src/config-page.html @@ -15,6 +15,6 @@
- + diff --git a/src/scripts/config-page.js b/src/scripts/config-page.js index 9b93d5f..3d0ed6e 100755 --- a/src/scripts/config-page.js +++ b/src/scripts/config-page.js @@ -10,8 +10,8 @@ * @property {string|boolean} default * @property {string} label * @property {object} attributes - * @property {array} options - * @property {array} items + * @property {Array} options + * @property {Array} items */ var mustache = require('mustache'); @@ -47,8 +47,10 @@ function getSetting(key, defaultValue) { // settings[key] = value; // } +var index = 0; + /** - * @param {Clay~Item} item + * @param {Clay~Item|Array} item * @param {$} $parent */ function processConfigItem(item, $parent) { @@ -73,9 +75,11 @@ function processConfigItem(item, $parent) { var itemType = itemTypes[item.type]; var templateData = $.extend({}, item, { attributes: $.map(item.attributes || [], function(item, key) { + console.log(index); return { key: key, - value: item.toString() + value: item.toString(), + index: index++ }; }) }); @@ -145,7 +149,7 @@ api.getItemsByType = function(type) { }); }; -processConfigItem(config, $mainForm, 0); +processConfigItem(config, $mainForm); $mainForm.on('submit', submit); module.exports = api; diff --git a/src/scripts/lib/item-types.js b/src/scripts/lib/item-types.js index ae4ac50..a93fc3e 100755 --- a/src/scripts/lib/item-types.js +++ b/src/scripts/lib/item-types.js @@ -31,6 +31,10 @@ module.exports = { template: require('../../templates/components/toggle.mustache'), manipulator: manipulators.checked }, + radiogroup: { + template: require('../../templates/components/radiogroup.mustache'), + manipulator: manipulators.radiogroup + }, submit: { template: require('../../templates/components/submit.mustache'), manipulator: manipulators.val diff --git a/src/scripts/lib/manipulators.js b/src/scripts/lib/manipulators.js index e405e96..ddc583a 100755 --- a/src/scripts/lib/manipulators.js +++ b/src/scripts/lib/manipulators.js @@ -43,5 +43,23 @@ module.exports = { return this.$manipulatorTarget.prop('disabled', false) .triggerHandler('change'); } + }, + radiogroup: { + get: function() { + return this.$manipulatorTarget.find('input:checked').val(); + }, + set: function(value) { + this.$manipulatorTarget.find('[value="' + value + '"]') + .prop('checked', true); + return this.$manipulatorTarget.triggerHandler('change'); + }, + disable: function() { + return this.$manipulatorTarget.prop('disabled', true) + .triggerHandler('change'); + }, + enable: function() { + return this.$manipulatorTarget.prop('disabled', false) + .triggerHandler('change'); + } } }; diff --git a/src/templates/components/radiogroup.mustache b/src/templates/components/radiogroup.mustache new file mode 100644 index 0000000..1bb44e2 --- /dev/null +++ b/src/templates/components/radiogroup.mustache @@ -0,0 +1,15 @@ +
+ {{label}} +
+ {{#options}} + + {{/options}} +
+