summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2011-01-01 12:37:39 +0000
committerRichard Wall <richard@largo>2011-01-01 12:37:39 +0000
commiteadfb7138783844ba9c62bad9038cdeac7a1f305 (patch)
treed5df4fbd083de0a7f0052a8ef6682554a89037b5
parent4b91cf5648ebddf60e793cb90ad209439b595dbd (diff)
A reset button
-rw-r--r--jarmon/jarmon.js95
-rw-r--r--jarmon/jarmon.test.js2
2 files changed, 54 insertions, 43 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index 6639382..a9dcac5 100644
--- a/jarmon/jarmon.js
+++ b/jarmon/jarmon.js
@@ -826,9 +826,59 @@ jarmon.RrdChooser.prototype.drawDsSummary = function() {
jarmon.ChartEditor = function($tpl, data) {
this.$tpl = $tpl;
this.data = data;
+
+ $('form', this.$tpl[0]).live(
+ 'submit',
+ {self: this},
+ function(e) {
+ var self = e.data.self;
+ self.data.title = this['title'].value;
+ self.data.datasources = $(this).find('.datasources tbody tr').map(
+ function(i, el) {
+ return $(el).find('input[type=text]').map(
+ function(i, el) {
+ return el.value;
+ }
+ );
+ }
+ );
+ return false;
+ }
+ );
+
+ $('form', this.$tpl[0]).live(
+ 'reset',
+ {self: this},
+ function(e) {
+ var self = e.data.self;
+ self.draw();
+ return false;
+ }
+ );
+
+ $('form input[name=datasource_delete]', this.$tpl[0]).live(
+ 'click',
+ function(e) {
+ $(this).closest('tr').remove();
+ }
+ );
+
+ $('form input[name=datasource_add]', this.$tpl[0]).live(
+ 'click',
+ {self: this},
+ function(e) {
+ var self = e.data.self;
+ self._addDatasourceRow(
+ self._extractRowValues(
+ $(this).closest('tr')
+ )
+ );
+ $(this).closest('tr').find('input[type=text]').val('');
+ }
+ );
};
-jarmon.ChartEditor.prototype.drawChartEditForm = function() {
+jarmon.ChartEditor.prototype.draw = function() {
var self = this;
this.$tpl.empty();
@@ -881,52 +931,13 @@ jarmon.ChartEditor.prototype.drawChartEditForm = function() {
$('<tbody/>')
)
),
- $('<input/>', {type: 'submit', value: 'save'})
+ $('<input/>', {type: 'submit', value: 'save'}),
+ $('<input/>', {type: 'reset', value: 'reset'})
).appendTo(this.$tpl);
for(var i=0; i<this.data.datasources.length; i++) {
this._addDatasourceRow(this.data.datasources[i]);
}
-
- $('form', this.$tpl[0]).live(
- 'submit',
- {self: this},
- function(e) {
- var self = e.data.self;
- self.data.title = this['title'].value;
- self.data.datasources = $(this).find('.datasources tbody tr').map(
- function(i, el) {
- return $(el).find('input[type=text]').map(
- function(i, el) {
- return el.value;
- }
- );
- }
- );
- console.log(self.data);
- return false;
- }
- );
-
- $('form input[name=datasource_delete]', this.$tpl[0]).live('click',
- function(e) {
- $(this).closest('tr').remove();
- }
- );
-
- $('form input[name=datasource_add]', this.$tpl[0]).live(
- 'click',
- {self: this},
- function(e) {
- var self = e.data.self;
- self._addDatasourceRow(
- self._extractRowValues(
- $(this).closest('tr')
- )
- );
- $(this).closest('tr').find('input[type=text]').val('')
- }
- );
};
diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js
index 08ac433..f5b7dae 100644
--- a/jarmon/jarmon.test.js
+++ b/jarmon/jarmon.test.js
@@ -466,7 +466,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) {
]
}
);
- c.drawChartEditForm();
+ c.draw();
},
test_drawInitialForm: function () {