Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
Got Delete App working
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrence Ryan committed Sep 21, 2012
1 parent de6f28e commit ddc4ea6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 34 additions & 2 deletions main.js
Expand Up @@ -166,6 +166,16 @@ define(function (require, exports, module) {
zipProject(id);
}

function deleteApp(id) {
var id = pendingDelete;
console.log("Delete has been called");
var xhr = new XMLHttpRequest();
xhr.open("DELETE", "https://build.phonegap.com/api/v1/apps/" + id + "?auth_token=" + token, true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.addEventListener("load", function() {eve("pgb.list"); pendingDelete = null;}, false);
xhr.send();
}

function createZipFile(zip, id) {
var zipfile = zip.generate({"base64":false});
var byteArray = new Uint8Array(zipfile.length);
Expand Down Expand Up @@ -242,6 +252,7 @@ define(function (require, exports, module) {
panelOpened,
token,
linkedProjectId,
pendingDelete,
platforms = ["ios", "android", "winphone", "blackberry", "webos", "symbian"];

function ajax(url, name, type, username, password, showProgress) {
Expand Down Expand Up @@ -391,7 +402,8 @@ define(function (require, exports, module) {
row += '<span data-download="{download.'+val+'}" id="pgb-app-'+val+'-{id}" class="icon '+val+'-{status.'+val+'}"></span>';
});
row += '</td><td><progress valie="0" max="100" class="pgb-upload-progress" id="pgb-progress-{id}"></td>';
row += '<td class="pgb-desc" style="width:200px;"><a href="#" class="pgb-rebuild btn btn-mini primary" data-id="{id}" id="rebuild-link-{id}">' + Strings.REBUILD_LINK + '</a><span style="display:none" id="rebuilding-text-{id}">' + Strings.REBUILDING_MESSAGE + '</span></td></tr>';
row += '<td class="pgb-desc" style="width:75px;"><a href="#" class="pgb-rebuild btn btn-mini primary" data-id="{id}" id="rebuild-link-{id}">' + Strings.REBUILD_LINK + '</a><span style="display:none" id="rebuilding-text-{id}">' + Strings.REBUILDING_MESSAGE + '</span></td>';
row += '<td class="pgb-desc" style="width:75px;"><a href="#" class="pgb-delete btn btn-mini danger" data-id="{id}" id="delete-link-{id}">' + Strings.DELETE_LINK + '</a></td></tr>';
html += format(row, app);
}
html += "</table>";
Expand Down Expand Up @@ -425,6 +437,7 @@ define(function (require, exports, module) {

});
eve.on("pgb.click", function (e) {
console.log("click fired.")
var span = e.target;
if (!String(span.id).indexOf("pgb-app")) {
var data = $(span).attr("data-download");
Expand Down Expand Up @@ -459,16 +472,29 @@ define(function (require, exports, module) {
});
});
}
if (span.className == "pgb-rebuild") {
console.log(span.className);
if (span.className.indexOf("pgb-rebuild") > -1) {
eve("pgb.rebuild", null, span.getAttribute("data-id"));
}

if (span.className.indexOf("pgb-delete") > -1) {
eve("pgb.delete", null, span.getAttribute("data-id"));
}
});
eve.on("pgb.success.projectinfo", function (json) {
console.warn(2, json);
});
eve.on("pgb.rebuild", function (id) {
toggleRebuildLabels(id);
ajax("api/v1/apps/" + id, "rebuild", "put", null, null, false);
});
eve.on("pgb.delete", function (id) {
console.log("delete fired.");
pendingDelete = id;
showAlert(Strings.DELETE_CONFIRMATION_MESSAGE, true, "delete", false);



});
eve.on("pgb.error.rebuild", function (error) {
console.log("pgb.error.rebuild", error);
Expand Down Expand Up @@ -523,6 +549,12 @@ define(function (require, exports, module) {
});
eve.on("pgb.alert.bundle.cancel", function() {
// NO-OP
});
eve.on("pgb.alert.delete.ok", function(id) {
deleteApp(id);
});
eve.on("pgb.alert.delete.cancel", function() {
// NO-OP
});
eve.on("pgb.success.status", function(json) {
var finished = true,
Expand Down
4 changes: 3 additions & 1 deletion nls/root/strings.js
Expand Up @@ -50,5 +50,7 @@ define({
"NEW_DIALOG_TITLE" : "New PhoneGap Build Project",
"NEW_DIALOG_MESSAGE" : "Create a new PhoneGap Build project based on the current folder.",
"NEW_DIALOG_APP_NAME" : "App Name",
"NEW_ALERT_MESSAGE" : "Created a new PhoneGap Build project named"
"NEW_ALERT_MESSAGE" : "Created a new PhoneGap Build project named",
"DELETE_LINK" : "Delete",
"DELETE_CONFIRMATION_MESSAGE" : "Are you sure you want to delete this project?"
});

0 comments on commit ddc4ea6

Please sign in to comment.