Skip to content

Commit 46c1fb3

Browse files
Added view button for each subscription in table (#27)
1 parent 49c0973 commit 46c1fb3

File tree

1 file changed

+48
-31
lines changed

1 file changed

+48
-31
lines changed

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

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,17 @@ jQuery(document).ready(function() {
363363
"orderable": false,
364364
"title": "Action",
365365
"data": null,
366-
"width":"150px",
367366
"render": function ( data, type, row, meta ) {
368367
if(isSecured == true && row.userName == currentUser && row.userName != null) {
369-
return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
370-
+ '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>';
368+
return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button> '
369+
+ '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
370+
+ '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>';
371371
} else if(isSecured == false) {
372-
return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
372+
return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button> '
373+
+ '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
373374
+ '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>';
374375
} else {
375-
return '';
376+
return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button>';
376377
}
377378
}
378379
}
@@ -586,46 +587,50 @@ jQuery(document).ready(function() {
586587

587588

588589
// /Start ## Reload Datatables ###########################################
589-
function reload_table()
590-
{
590+
function reload_table() {
591591
table.ajax.reload(null,false); //reload datatable ajax
592592
}
593593
// /Stop ## Reload Datatables ############################################
594594

595-
596-
// /Start ## Edit Subscription ###########################################
597-
$('#table').on( 'click', 'tbody tr td button.edit_record', function (event) {
598-
event.stopPropagation();
595+
function get_subscription_data(object, mode) {
596+
event.stopPropagation();
599597
event.preventDefault();
600598
// Fetch datatable row -> subscriptionName
601-
var datatable_row_data = table.row( $(this).parents('tr') ).data();
599+
var datatable_row_data = table.row( $(object).parents('tr') ).data();
602600
var id = datatable_row_data.subscriptionName;
603601
// AJAX Callback handling
604602
var callback = {
605-
beforeSend : function () {
606-
},
603+
beforeSend : function () {},
607604
success : function (data, textStatus) {
608-
populate_json(data, "edit");
605+
populate_json(data, mode);
609606
},
610607
error : function (XMLHttpRequest, textStatus, errorThrown) {
611608
$.jGrowl("Error: " + XMLHttpRequest.responseText, {
612609
sticky : true,
613610
theme : 'Error'
614611
});
615612
},
616-
complete : function () {
617-
}
613+
complete : function () {}
618614
};
619615
// Perform AJAX
620616
var ajaxHttpSender = new AjaxHttpSender();
621617
ajaxHttpSender.sendAjax(frontendServiceUrl + "/subscriptions/"+id, "GET", null, callback);
618+
}
619+
620+
// /Start ## Edit Subscription ###########################################
621+
$('#table').on( 'click', 'tbody tr td button.edit_record', function (event) {
622+
get_subscription_data(this, "edit");
622623
});
623624
// /Stop ## Edit Subscription ###########################################
624625

626+
// /Start ## View Subscription ###########################################
627+
$('#table').on( 'click', 'tbody tr td button.view_record', function (event) {
628+
get_subscription_data(this, "view");
629+
});
630+
// /Stop ## View Subscription ###########################################
625631

626632
// /Start ## populate JSON ###########################################
627-
function populate_json(data, save_method_in)
628-
{
633+
function populate_json(data, save_method_in) {
629634
var returnData = [data];
630635
if (returnData.length > 0) {
631636
vm.subscription([]);
@@ -650,18 +655,31 @@ jQuery(document).ready(function() {
650655
// Force update
651656
vm.subscription()[0].restPostBodyMediaType.valueHasMutated();
652657
$('#modal_form').modal('show');
653-
if(save_method_in === "edit")
654-
{
655-
title_ = 'Edit Subscription';
656-
657-
}else
658-
{
659-
title_ = 'Add Subscription';
660-
}
661-
$('.modal-title').text(title_);
658+
if(save_method_in === "edit") {
659+
title_ = 'Edit Subscription';
660+
addEditMode();
661+
} else if(save_method_in === "add") {
662+
title_ = 'Add Subscription';
663+
addEditMode();
664+
} else {
665+
title_ = 'View Subscription';
666+
viewMode();
667+
}
668+
$('.modal-title').text(title_);
662669
save_method = save_method_in;
663670
}
664671
}
672+
673+
function addEditMode() {
674+
$('#modal_form :button').show();
675+
$('#modal_form :input').prop("disabled", false);
676+
}
677+
function viewMode() {
678+
$('#modal_form :button').hide();
679+
$('#modal_form :input').prop("disabled", true);
680+
$('#modal_form .close').show();
681+
$('#modal_form .close').prop("disabled", false);
682+
}
665683
// /Stop ## pupulate JSON ###########################################
666684

667685

@@ -670,8 +688,7 @@ jQuery(document).ready(function() {
670688
event.stopPropagation();
671689
event.preventDefault();
672690
var notificationMessageKeyValuesArray = vm.subscription()[0].notificationMessageKeyValues();
673-
if(!vm.formpostkeyvaluepairs())
674-
{
691+
if(!vm.formpostkeyvaluepairs()) {
675692
notificationMessageKeyValuesArray[0].formkey=""; // OBS must be empty when NOT using REST POST Form key/value pairs
676693
}
677694

@@ -790,7 +807,7 @@ jQuery(document).ready(function() {
790807
url = frontendServiceUrl + "/subscriptions";
791808
type = "POST";
792809

793-
} else { // Update existing
810+
} else if(save_method === 'edit') { // Update existing
794811
url = frontendServiceUrl + "/subscriptions";
795812
type = "PUT";
796813
}

0 commit comments

Comments
 (0)