Update http.js, app/index.js

This commit is contained in:
Namhyeon Go 2020-11-12 13:36:16 +09:00
parent a5f60b1409
commit 4ec0d79860
2 changed files with 30 additions and 9 deletions

View File

@ -106,18 +106,17 @@ var getLocalApplications = function() {
console.log("반영되었습니다.");
}
};
if (applicationId) {
req = $.ajax({
type: "PATCH",
url: apiUrl + "/netsolid/items/applications/" + applicationId,
data: JSON.stringify(data),
contentType: 'application/json-patch+json',
success: onSuccess
});
HTTP.create()
.setContentType("application/json-patch+json")
.setRequestBody(JSON.stringify(data))
.patch(apiUrl + "/netsolid/items/applications/" + applicationId, onSuccess)
;
} else {
HTTP.create()
.setContentType("application/json")
.setBearerAuth(token)
.setRequestBody(data)
.post(apiUrl + "/netsolid/items/applications", onSuccess)
;

View File

@ -143,7 +143,6 @@ var HTTPObject = function() {
break;
case "PATCH":
console.error("Not supported yet: " + method); // TODO
break;
default:
@ -187,6 +186,29 @@ var HTTPObject = function() {
return this.open("GET", url, false).send(callback);
};
this.patch = function(url, callback) {
var options = {
type: "PATCH",
headers: this.headers,
url: url,
data: this.requestBody,
contentType: this.contentType,
success: callback
};
if (typeof(window) !== "undefined") {
if (typeof(window.jQuery) !== "undefined") {
window.jQuery.ajax(options);
} else {
console.error("PATCH is required jQuery library");
}
} else {
console.error("PATCH dose not supported on console mode");
}
return this;
};
this.create();
};