Updates to the data tracking app; Updated the VAP list.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<!-- Main Page Content -->
|
||||
<h1><span class="fa fa-users"></span> Manage Subcategories</h1>
|
||||
|
||||
<div class="col-sm-6">
|
||||
<div class="col-sm-12">
|
||||
<div class="dt-buttons btn-group" style="display: inline-block">
|
||||
<a id="createButton" class="btn btn-default buttons-create" tabindex="0" href="javaScript:void(0);"><span>New</span></a>
|
||||
<a id="editButton" class="btn btn-default buttons-selected buttons-edit" tabindex="0" href="javaScript:void(0);"><span>Edit</span></a>
|
||||
@@ -79,6 +79,31 @@
|
||||
var $btnDelete = $page.find("#deleteButton");
|
||||
var $btnRestore = $page.find("#restoreButton");
|
||||
|
||||
$btnEdit.disable(true);
|
||||
$btnDelete.disable(true);
|
||||
$btnRestore.disable(true);
|
||||
|
||||
var selectionChanged = function($tr, model) {
|
||||
if($tr && model) {
|
||||
$btnEdit.disable(false);
|
||||
|
||||
//If the object was deleted (hidden), then allow it to be restored, otherwise allow the model to be deleted.
|
||||
if(model.deletedAt) {
|
||||
$btnRestore.disable(false);
|
||||
$btnDelete.disable(true);
|
||||
}
|
||||
else {
|
||||
$btnRestore.disable(true);
|
||||
$btnDelete.disable(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$btnEdit.disable(true);
|
||||
$btnDelete.disable(true);
|
||||
$btnRestore.disable(true);
|
||||
}
|
||||
};
|
||||
|
||||
var dataTable = new LinkedTable($page.find('#dataTable'), {
|
||||
url: "data/Subcategory/readAll",
|
||||
attr: "data-key-name",
|
||||
@@ -86,26 +111,7 @@
|
||||
parameters: function() {
|
||||
return {paranoid: !$page.find('#includeDeletedToggle').is(":checked")};
|
||||
},
|
||||
selectionChanged: function($tr, model) {
|
||||
if($tr && model) {
|
||||
$btnEdit.show();
|
||||
|
||||
//If the object was deleted (hidden), then allow it to be restored, otherwise allow the model to be deleted.
|
||||
if(model.deletedAt) {
|
||||
$btnRestore.show();
|
||||
$btnDelete.hide();
|
||||
}
|
||||
else {
|
||||
$btnRestore.hide();
|
||||
$btnDelete.show();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$btnEdit.hide();
|
||||
$btnDelete.hide();
|
||||
$btnRestore.hide();
|
||||
}
|
||||
},
|
||||
selectionChanged: selectionChanged,
|
||||
supportingData: [{name: "categories", url: "data/Category/readAll", parameters: {showDeleted: true}, postProcess: function(data) {
|
||||
var byId;
|
||||
|
||||
@@ -115,9 +121,6 @@
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
//Save the categories by id for use when setting the editor dialog's dropdown selection.
|
||||
categoriesById = byId;
|
||||
|
||||
return byId;
|
||||
}}],
|
||||
cellDataHandlers: {category: function($cell, subcategory, supportingData) {
|
||||
@@ -134,11 +137,20 @@
|
||||
if(dataObject.deletedAt) {
|
||||
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
|
||||
}
|
||||
},
|
||||
postUpdateRowHandler: function($row, dataObject) {
|
||||
if(dataObject.deletedAt) {
|
||||
$("td:first", $row).prepend("<span class='glyphicon glyphicon-remove-circle' style='margin-right: 10px;' aria-hidden='true'></span>");
|
||||
}
|
||||
|
||||
if($row.is(dataTable.getSelectedRow())) {
|
||||
selectionChanged($row, dataObject);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Call the refresh user table function once initially.
|
||||
dataTable.refresh();
|
||||
dataTable.build();
|
||||
|
||||
//Refresh the data table if the user toggles the button to show/hide deleted elements.
|
||||
$page.find('#includeDeletedToggle').on('click', function(event) {
|
||||
@@ -165,11 +177,11 @@
|
||||
var $editorDialog = $page.find('#editorDialog');
|
||||
var $deleteDialog = $page.find('#deleteDialog');
|
||||
var $editorForm = $editorDialog.find('form');
|
||||
var queries = [$.get("data/Category/readAll", {order: ['name', ['name']]})];
|
||||
var queries = [$.get("data/Category/readAll", {request: JSON.stringify({order: ['name', ['name']]})})];
|
||||
|
||||
//Update the dialog drop downs when the queries finish.
|
||||
$.when.apply($, queries).then(function(query1) {
|
||||
var categories = query1[0];
|
||||
var categories = query1;
|
||||
var categoriesData = [];
|
||||
|
||||
//Iterate over the categories and their subcategories to build the tree of data for the dropdown.
|
||||
@@ -206,7 +218,7 @@
|
||||
$editorDialog.find(".modal-title").text("Edit Subcategory");
|
||||
//Reset fields to selected values.
|
||||
$editorDialog.find('#DFName').val(dataTable.getSelectedRow().data("model").name);
|
||||
$editorDialog.find('#DFCategory').val(dataTable.getSelectedRow().data("model").categoryId);
|
||||
$editorDialog.find('#DFCategory').val(dataTable.getSelectedRow().data("model").categoryId).trigger("change");
|
||||
//Open the dialog.
|
||||
$editorDialog.modal();
|
||||
}
|
||||
@@ -216,22 +228,15 @@
|
||||
var createFunction = function(close) {
|
||||
$editorForm.data('bs.validator').validate(function(isValid) {
|
||||
if(isValid) {
|
||||
try {
|
||||
$.post("data/Subcategory/create", {
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
categoryId: parseInt($editorForm.find("#DFCategory").val())
|
||||
}, function(data) {
|
||||
if(data.result == "success") {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
}
|
||||
$.ajax({url: "data/Subcategory/create", type: "POST", dataType: "json", data: encodeData({
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
categoryId: parseInt($editorForm.find("#DFCategory").val())
|
||||
})}).done(function(data) {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -245,23 +250,16 @@
|
||||
$editorDialog.find('#DFSave').on('click', function(event) {
|
||||
$editorForm.data('bs.validator').validate(function(isValid) {
|
||||
if(isValid) {
|
||||
try {
|
||||
$.post("data/Subcategory/edit", {
|
||||
id: dataTable.getSelectedRow().data("model").id,
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
categoryId: parseInt($editorForm.find("#DFCategory").val())
|
||||
}, function(data) {
|
||||
if(data.result == "success") {
|
||||
$editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
}
|
||||
$.ajax({url: "data/Subcategory/edit", type: "POST", dataType: "json", data: encodeData({
|
||||
id: dataTable.getSelectedRow().data("model").id,
|
||||
name: $editorForm.find("#DFName").val(),
|
||||
categoryId: parseInt($editorForm.find("#DFCategory").val())
|
||||
})}).done(function(data) {
|
||||
if(close) $editorDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -287,15 +285,12 @@
|
||||
//Delete the element and close the dialog.
|
||||
$deleteDialog.find('#deleteButton').on("click", function(event) {
|
||||
if(dataTable.getSelectedRow() != null) {
|
||||
$.post("data/Subcategory/delete", {where: {id: dataTable.getSelectedRow().data("model").id}}, function(data) {
|
||||
if(data.result == "success") {
|
||||
$deleteDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}
|
||||
else {
|
||||
alert(data.result);
|
||||
}
|
||||
}, "json");
|
||||
$.ajax({url: "data/Subcategory/delete", type: "POST", dataType: "json", data: encodeData({where: {id: dataTable.getSelectedRow().data("model").id}})}).done(function(data) {
|
||||
$deleteDialog.modal("hide");
|
||||
dataTable.refresh();
|
||||
}).fail(function(data) {
|
||||
alert("Server call failed.");
|
||||
});
|
||||
}
|
||||
});
|
||||
$deleteDialog.find('#DFCancelDelete').on('click', function(event) {
|
||||
|
||||
Reference in New Issue
Block a user