From 561ce9075457cda0253d32874b5989afd051ff7a Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Wed, 18 Sep 2013 21:30:09 +0300 Subject: web client: validation completion handler for status bar object --- web/client.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'web') diff --git a/web/client.js b/web/client.js index 7f779f6..b864997 100644 --- a/web/client.js +++ b/web/client.js @@ -15,12 +15,16 @@ $(function() { $("#commit").prop("disabled", status == "invalid"); } + function setError(msg, mode) { set("invalid", msg, mode); }; + return { - enableCommit: function() { - set("changed", "You have uncommitted changes", "txn"); - }, - setError: function(msg, mode) { set("invalid", msg, mode); }, - reset: function() { set(null, ""); } + reset: function() { set(null, ""); }, + setError: setError, + validationReady: function(txnValid) { + if (txnValid) + set("changed", "You have uncommitted changes", "txn"); + else setError("Some values need checking", "txn"); + } } })(); @@ -528,11 +532,6 @@ $(function() { if (!isTreeNode(data.meta)) return target.append(JSON.stringify(data)); - function validated(txnValid) { - if (txnValid) statusBar.enableCommit(); - else statusBar.setError("Some values need checking", "txn"); - } - var div = $("
"); target.append(div); @@ -569,7 +568,7 @@ $(function() { data.set(name, widget.get()).done(function(txnValid) { widget.setMessage(""); widget.setStatus(data.status(name)); - validated(txnValid); + statusBar.validationReady(txnValid); }).fail(function(xhr) { if (_.isString(xhr)) widget.setMessage(xhr); @@ -591,7 +590,7 @@ $(function() { else widget.setMessage(formatError("Error", xhr)); widget.setStatus("invalid"); - validated(false); + statusBar.validationReady(false); }); } @@ -601,7 +600,7 @@ $(function() { change, removable ? function() { data.delete(name).done(function(txnValid) { - validated(txnValid) + statusBar.validationReady(txnValid) fetchAndRender(path); }); } : null, @@ -677,7 +676,7 @@ $(function() { data.meta ); button.prop("class", null); - validated(txnValid); + statusBar.validationReady(txnValid); }); } -- cgit v1.2.3