From 4b91cf5648ebddf60e793cb90ad209439b595dbd Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sat, 1 Jan 2011 12:22:51 +0000 Subject: Allow add delete of data source records --- jarmon/jarmon.js | 132 +++++++++++++++++++++++++++++++++++++++----------- jarmon/jarmon.test.js | 15 +++++- 2 files changed, 117 insertions(+), 30 deletions(-) (limited to 'jarmon') diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 5df7cce..6639382 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -823,19 +823,9 @@ jarmon.RrdChooser.prototype.drawDsSummary = function() { }; -jarmon.ChartEditor = function($tpl) { +jarmon.ChartEditor = function($tpl, data) { this.$tpl = $tpl; - this.data = { - title: '', - datasources: [ - ['data/cpu-0/cpu-wait.rrd', 0, 'CPU-0 Wait', '%'], - ['data/cpu-1/cpu-wait.rrd', 0, 'CPU-1 Wait', '%'], - ['data/cpu-0/cpu-system.rrd', 0, 'CPU-0 System', '%'], - ['data/cpu-1/cpu-system.rrd', 0, 'CPU-1 System', '%'], - ['data/cpu-0/cpu-user.rrd', 0, 'CPU-0 User', '%'], - ['data/cpu-1/cpu-user.rrd', 0, 'CPU-1 User', '%'] - ] - }; + this.data = data; }; jarmon.ChartEditor.prototype.drawChartEditForm = function() { @@ -864,29 +854,113 @@ jarmon.ChartEditor.prototype.drawChartEditForm = function() { $('').text('DS Unit'), $('') ) - ) - ), - $('', {type: 'button', value: 'Add'}) + ), + $('').append( + $('').append( + $('').append( + $('', {type: 'text'}) + ), + $('').append( + $('', {type: 'text'}) + ), + $('').append( + $('', {type: 'text'}) + ), + $('').append( + $('', {type: 'text'}) + ), + $('').append( + $('', { + type: 'button', + value: 'add', + name: 'datasource_add' + }) + ) + ) + ), + $('') + ) ), - $('', {type: 'submit', value: 'Save'}), - $('
', {class: 'next'}) - + $('', {type: 'submit', value: 'save'}) ).appendTo(this.$tpl); - $(this.data.datasources).map( - function(i, el) { - return $('').append( - $('').text(el[0]), - $('').text(el[1]), - $('').text(el[2]), - $('').text(el[3]), - $('').append( - $('', {type: 'button', value: 'edit'}), - $('', {type: 'button', value: 'delete'}) + for(var i=0; i').append( + $('').append( + $('', {type: 'text', value: record[0]}) + ), + $('').append( + $('', {type: 'text', value: record[1]}) + ), + $('').append( + $('', {type: 'text', value: record[2]}) + ), + $('').append( + $('', {type: 'text', value: record[3]}) + ), + $('').append( + $('', { + type: 'button', + value: 'delete', + name: 'datasource_delete' + }) + ) + ).appendTo(this.$tpl.find('.datasources tbody')); }; diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index ee9c7bb..08ac433 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -452,7 +452,20 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { setUp: function() { this.$tpl = $('
').appendTo($('body')) - var c = new jarmon.ChartEditor(this.$tpl); + var c = new jarmon.ChartEditor( + this.$tpl, + { + title: 'Foo', + datasources: [ + ['data/cpu-0/cpu-wait.rrd', 0, 'CPU-0 Wait', '%'], + ['data/cpu-1/cpu-wait.rrd', 0, 'CPU-1 Wait', '%'], + ['data/cpu-0/cpu-system.rrd', 0, 'CPU-0 System', '%'], + ['data/cpu-1/cpu-system.rrd', 0, 'CPU-1 System', '%'], + ['data/cpu-0/cpu-user.rrd', 0, 'CPU-0 User', '%'], + ['data/cpu-1/cpu-user.rrd', 0, 'CPU-1 User', '%'] + ] + } + ); c.drawChartEditForm(); }, -- cgit v1.2.3