From 4ec0d79860984c3b64e2d521139cff79c77ffe73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=82=A8=ED=98=84?= Date: Thu, 12 Nov 2020 13:36:16 +0900 Subject: [PATCH] Update http.js, app/index.js --- app/index.js | 15 +++++++-------- lib/http.js | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/index.js b/app/index.js index de42c12..9295d87 100644 --- a/app/index.js +++ b/app/index.js @@ -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) ; diff --git a/lib/http.js b/lib/http.js index db7663b..72eeb18 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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(); };