Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs
Created February 11, 2009 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonroelofs/62081 to your computer and use it in GitHub Desktop.
Save jasonroelofs/62081 to your computer and use it in GitHub Desktop.
// Turn this:
$.post("/cameras/" + cameraId + "/wireless", {
"_method": "delete"
},
function(response) {
$.prompt(
"<h3>Disconnecting from Wireless</h3>" +
"<ul><li class=\"processing\">Sending Request to Camera</li></ul>", {
buttons: { "Close": true }
});
var query = $("#userquery");
var dialog = query.find("div.userquerymessage");
query.find("div#userquerybuttons").hide();
var currentStep = "request";
function addNewStep(msg, itemClass) {
var klass = itemClass || "processing";
dialog.find("li.processing").removeClass("processing").addClass("success");
dialog.find("ul").append("<li class=\"" + klass + "\">" + msg + "</li>");
}
function updateExistingStep(msg){
dialog.find("li.processing").html(msg);
}
transaction(response.key, {
update: function(data) {
if(data.step != currentStep) {
addNewStep(data.message);
currentStep = data.step;
} else {
updateExistingStep(data.message);
}
},
complete: function(data) {
query.find("div#userquerybuttons").slideDown("slow");
},
success: function(data) {
addNewStep(data.message, "success");
$$.connectedTo = null;
var view = $$.parentView.find(".current-network");
view.slideUp("slow", function() {
view.find(".ssid-list").html("");
});
$$.refreshView();
},
error: function(data) {
var previousEntry = dialog.find("li.processing").removeClass("processing");
if(data.type == "camera_failed") {
previousEntry.addClass("success");
} else {
previousEntry.addClass("error");
}
dialog.find("ul").append("<li class=\"error\">" + data.message + "</li>");
}
});
}, "json");
// Into this:
this.__transactionPrompt({
url: "/cameras/" + cameraId + "/wireless",
method: "delete",
url_args: {},
prompt_text: "<h3>Disconnecting from Wireless</h3><ul><li class=\"processing\">Sending Request to Camera</li></ul>",
onSuccess: function() {
$$.connectedTo = null;
var view = $$.parentView.find(".current-network");
view.slideUp("slow", function() {
view.find(".ssid-list").html("");
});
$$.refreshView();
},
onUpdate: function() {},
onError: function() {},
onComplete: function() {}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment