summaryrefslogtreecommitdiffstats
path: root/web/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/client.js')
-rw-r--r--web/client.js94
1 files changed, 50 insertions, 44 deletions
diff --git a/web/client.js b/web/client.js
index 9b47bec..2e5c86e 100644
--- a/web/client.js
+++ b/web/client.js
@@ -24,6 +24,8 @@ $(function() {
}
var changed, invalid;
+ var statusBar = $("#status p");
+ var buttons = $("#status div");
function startTxn() {
var def = $.Deferred();
@@ -32,13 +34,22 @@ $(function() {
txn = xhr.getResponseHeader("X-ACF-Transaction-ID");
changed = {};
invalid = {};
- $("#status").empty();
+ $("#status").prop("class", "");
+ statusBar.empty();
+ buttons.prop("class", "hidden");
def.resolve();
});
return def;
}
+ function showError(el, msg, xhr) {
+ msg += " " + xhr.statusCode().status;
+ if (xhr.responseText) msg += ': ' + xhr.responseText;
+ el.text(msg);
+ }
+
+
var Field = {
format: function(value, status) {
var el = this.staticRender(value);
@@ -292,49 +303,16 @@ $(function() {
invalid[path] = newValue;
msg.text("[checking]");
-
- function showError(el, msg, xhr) {
- msg += " " + xhr.statusCode().status;
- if (xhr.responseText)
- msg += ': ' + xhr.responseText;
- el.text(msg);
- }
-
- function newTxn() {
- return startTxn().done(render);
- }
-
- function abortTxn() {
- request("/", {type: "DELETE"});
- return newTxn();
+ if ($("#status").prop("class") != "invalid")
+ statusBar.text("Validating changes");
+
+ function setStatus(status, msg, commit) {
+ $("#status").prop("class", status);
+ statusBar.text(msg);
+ $("#commit").prop("disabled", !commit);
+ buttons.prop("class", "");
}
- var statusBar = $("#status");
- statusBar.html(
- "You have uncommitted changes.<br/>"
- );
- statusBar.append($("<input>").attr({
- id: "commit",
- type: "submit",
- value: "Commit",
- disabled: true
- }).click(function() {
- request("/", {type: "PUT"})
- .done(newTxn)
- .fail(function(xhr) {
- abortTxn().done(function() {
- showError(
- statusBar,
- "Commit failed",
- xhr
- );
- });
- });
- }));
- statusBar.append($("<input>").attr({
- type: "submit", value: "Revert"
- }).click(abortTxn));
-
task.done(function() {
msg.empty();
widget.setStatus(
@@ -343,11 +321,21 @@ $(function() {
delete invalid[path];
if (!(_.size(invalid)))
- $("#commit").prop("disabled", false);
-
+ setStatus(
+ "changed",
+ "You have uncommitted changes",
+ true
+ );
+
}).fail(function(xhr) {
showError(msg, "Error", xhr);
widget.setStatus("invalid");
+
+ setStatus(
+ "invalid",
+ "Some values need checking",
+ false
+ );
});
});
@@ -414,6 +402,24 @@ $(function() {
});
}
+
+ function newTxn() { return startTxn().done(render); }
+
+ function abortTxn() {
+ request("/", {type: "DELETE"});
+ return newTxn();
+ }
+
+ $("#commit").click(function() {
+ request("/", {type: "PUT"}).done(newTxn).fail(function(xhr) {
+ abortTxn().done(function() {
+ showError(statusBar, "Commit failed", xhr);
+ });
+ });
+ });
+ $("#revert").click(abortTxn);
+
+
startTxn().done(function() {
$(window).bind("hashchange", render);
$.bbq.pushState("#/");