Skip to content

Commit 80234b8

Browse files
committed
Added Subscription creation RestApi call to EI Backend functionality to UploadSubscription button.
1 parent 139b4a3 commit 80234b8

File tree

1 file changed

+45
-5
lines changed
  • src/main/resources/static/js

1 file changed

+45
-5
lines changed

src/main/resources/static/js/main.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,49 @@ $(document).ready(function() {
361361
event.stopPropagation();
362362
event.preventDefault();
363363

364-
function validateSubscriptionFormat(subscriptionFile) {
364+
function tryToCreateSubscription(subscriptionJson) {
365365
// Send Subscription JSON file to Spring MVC
366-
366+
// AJAX Callback handling
367+
var callback = {
368+
beforeSend : function () {
369+
},
370+
success : function (data, textStatus) {
371+
372+
var returnData = [data];
373+
if (returnData.length > 0) {
374+
$.jGrowl("Successful created subscription " + subscriptionJson.subscriptionName, {
375+
sticky : false,
376+
theme : 'Error'
377+
});
378+
reload_table();
379+
}
380+
381+
},
382+
error : function (XMLHttpRequest, textStatus, errorThrown) {
383+
384+
$.jGrowl("Failed to create Subscription: " + subscriptionJson.subscriptionName + " Error: " + XMLHttpRequest.responseText, {
385+
sticky : false,
386+
theme : 'Error'
387+
});
388+
389+
},
390+
complete : function () {
391+
}
392+
};
393+
394+
// Fetch Date and format
395+
var now = new Date();
396+
var nowStr = now.format("isoDate") + ' ' + now.format("isoTime");
397+
398+
// Update property created with datetime (formatted)
399+
subscriptionJson.created = String(nowStr);
400+
401+
// Perform AJAX
402+
var ajaxHttpSender = new AjaxHttpSender();
403+
ajaxHttpSender.sendAjax(backendServiceUrl + "/subscriptions", "POST", ko.toJSON(subscriptionJson), callback);
367404
}
368405

369-
function validateJsonandSubscriptionFormat(subscriptionFile){
406+
function validateJsonAndCreateSubscriptions(subscriptionFile){
370407

371408
var reader = new FileReader();
372409

@@ -386,7 +423,10 @@ $(document).ready(function() {
386423
theme : 'Notify'
387424
});
388425

389-
validateSubscriptionFormat(subscriptionFile);
426+
var subscriptionJsonList = JSON.parse(fileContent);
427+
for (i=0; i < subscriptionJsonList.length; i++) {
428+
tryToCreateSubscription(subscriptionJsonList[i]);
429+
}
390430
};
391431

392432
reader.readAsText(subscriptionFile);
@@ -411,7 +451,7 @@ $(document).ready(function() {
411451
// All other Web Browser
412452
pom.onchange = function uploadFinished() {
413453
var subscriptionFile = pom.files[0];
414-
validateJsonandSubscriptionFormat(subscriptionFile);
454+
validateJsonAndCreateSubscriptions(subscriptionFile);
415455
};
416456

417457
if (document.createEvent) {

0 commit comments

Comments
 (0)