254 lines
10 KiB
Plaintext
254 lines
10 KiB
Plaintext
@using EnVisage.Code
|
|
@{
|
|
ViewBag.Title = "Work Weeks";
|
|
}
|
|
@section scripts
|
|
{
|
|
<script type="text/javascript">
|
|
var ctr = 0;
|
|
|
|
init.push(function () {
|
|
$('#workweeks').dataTable({
|
|
"bProcessing": true,
|
|
"bServerSide": true,
|
|
"bAutoWidth": false,
|
|
"sAjaxSource": document.URL,
|
|
"sServerMethod": "POST",
|
|
"aoColumns": [
|
|
{ "mDataProp": "Name" },
|
|
{
|
|
"bSortable": false,
|
|
"mDataProp": "DaysOfWeek"
|
|
},
|
|
{
|
|
"bSortable": false,
|
|
"mData": function (data, type, full) {
|
|
@if (SecurityManager.CheckSecurityObjectPermission(Areas.WorkWeeks, AccessLevel.Write))
|
|
{
|
|
<text>
|
|
ctr++;
|
|
var btns = '';
|
|
if (data.IsDefault) {
|
|
btns += '<span class="btn btn-sm btn-warning" style="cursor:default;" disabled><i class="fa fa-check-circle-o"></i></span> ';
|
|
} else {
|
|
btns += '<a id="btnActivate' + String(ctr) + '" data-toggle="popover" data-placement="left" class="btn btn-sm ' +
|
|
'btn-primary popover-warning popover-dark" ' +
|
|
'title="Activate Work Week" ' +
|
|
'onclick="return activateWW(\'_rplcmnt_\');"><i class="fa fa-check-circle-o"></i></a> ';
|
|
}
|
|
btns += '<a id="btnEdit' + String(ctr) + '" onclick="return editWW(this.id, \'_rplcmnt_\');" data-toggle="popover" data-placement="left" ' + 'class="btn btn-sm btn-primary popover-warning popover-dark"><i class="fa fa-edit"></i> Edit</a> ' +
|
|
(!data.IsSystem ? '<a id="btnDelete' + String(ctr) + '" ' + (data.CanBeDeleted ? '' : 'disabled') + ' onclick="return deleteWW(this.id, \'_rplcmnt_\', \'_rplcmn1_\');" data-toggle="popover" data-placement="left" ' + 'class="btn btn-sm btn-danger popover-warning popover-dark"><i class="fa fa-trash-o"></i> Delete</a>' : '');
|
|
btns = btns.replace(/_rplcmnt_/g, data.Id).replace(/_rplcmn1_/g, data.Name.replace(/\'/g, "\\'"));
|
|
return btns;
|
|
</text>
|
|
}
|
|
else
|
|
{
|
|
<text>
|
|
return "";
|
|
</text>
|
|
}
|
|
}
|
|
}],
|
|
})
|
|
@if (SecurityManager.CheckSecurityObjectPermission(Areas.WorkWeeks, AccessLevel.Write))
|
|
{
|
|
<text>
|
|
$('#workweeks_wrapper .table-caption').html('<a class="btn btn-primary" onclick="return editWW(this.id, null);"><i class="fa fa-plus"></i> Add Work Week</a>');
|
|
</text>
|
|
}
|
|
$('#workweeks_wrapper .dataTables_processing').addClass("table-caption");
|
|
$('#workweeks_wrapper .dataTables_processing').html('<span class="h3"><img class="valign-middle" src="../Content/images/loadFA.gif"/></span>');
|
|
});
|
|
|
|
function loadWW(wwId) {
|
|
blockUI();
|
|
var url = "";
|
|
var isNew = true;
|
|
|
|
if (wwId && (wwId != null) && (wwId.length > 0) && (wwId != '@Guid.Empty')) {
|
|
url = "?Id=" + wwId;
|
|
isNew = false;
|
|
}
|
|
|
|
$('#editReload').html("");
|
|
|
|
$.ajax({
|
|
url: '@Url.Action("Edit", "WorkWeek")' + url,
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#editReload').html(data);
|
|
initWW();
|
|
|
|
$('#editWorkWeek')
|
|
.on('hidden.bs.modal', function () {
|
|
if (!isNew) {
|
|
StopEdit();
|
|
RemoveLock('WorkWeek', wwId);
|
|
}
|
|
})
|
|
.modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
},
|
|
});
|
|
}
|
|
|
|
function editWW(aId, Id) {
|
|
if (Id && (Id != null) && (Id.length > 0) && (Id != '@Guid.Empty'))
|
|
if (!CheckLock(aId, 'WorkWeek', Id))
|
|
return false;
|
|
|
|
loadWW(Id);
|
|
return true;
|
|
}
|
|
|
|
function activateWW(wwId) {
|
|
bootbox.confirm({
|
|
message: "Are you sure you want to activate this work week?",
|
|
callback: function (result) {
|
|
if (result) {
|
|
blockUI();
|
|
var url = "";
|
|
if (wwId && (wwId != null) && (wwId.length > 0) && (wwId != '@Guid.Empty')) {
|
|
url = "?Id=" + wwId;
|
|
}
|
|
$.ajax({
|
|
url: '@Url.Action("Activate", "WorkWeek")' + url,
|
|
type: "POST",
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
document.location.href = document.location.href;
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
},
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function deleteWW(aId, Id, name) {
|
|
if (Id && (Id != null) && (Id.length > 0) && (Id != '@Guid.Empty')) {
|
|
if (!CheckLock(aId, 'WorkWeek', Id))
|
|
return false;
|
|
|
|
StartEdit('WorkWeek', Id, null, null, 'errorsMessagesPlaceholder');
|
|
}
|
|
else
|
|
// Id not specified
|
|
return false;
|
|
|
|
$("#deleteWorkWeekId").val(Id);
|
|
$("#deleteWWCaption").text("Do you want to delete \"" + name + "\" work week?");
|
|
$('#modal-warning').on('hidden.bs.modal', function () {
|
|
StopEdit();
|
|
RemoveLock('WorkWeek', Id);
|
|
}).modal('show');
|
|
return true;
|
|
}
|
|
|
|
function onFailure(xhr) {
|
|
showErrorModal();
|
|
}
|
|
function onSuccess(result) {
|
|
handleAjaxResponse(result, function () {
|
|
var href = document.location.href;
|
|
if (href.substr(href.length - 1) == '#')
|
|
href = href.substr(0, href.length - 1);
|
|
document.location.href = href;
|
|
}, null, null, $('#deleteWWForm'));
|
|
}
|
|
|
|
$(document).on('hide.bs.modal', '#editWorkWeek', function (e) {
|
|
// skip modal hide event from datepickers
|
|
if ($(e.target).attr('id') != 'editWorkWeek')
|
|
return true; // close modal form
|
|
// check that form has been changed
|
|
if (typeof isWWDataChanged === 'function')
|
|
// if form has been changed
|
|
if (isWWDataChanged()) {
|
|
// ask user for confirmation of form close
|
|
var msg = "Work Week editing form contains unsaved changes, do you really want to close the form?";
|
|
bootbox.confirm(msg, function (result) {
|
|
if (result) {
|
|
if (typeof resetWWDataChanged === 'function') {
|
|
resetWWDataChanged();
|
|
}
|
|
$('#editWorkWeek').modal('hide');
|
|
}
|
|
});
|
|
|
|
return false; // DO NOT close modal form
|
|
}
|
|
return true; // close modal form
|
|
});
|
|
|
|
</script>
|
|
}
|
|
|
|
<div id="errorsMessagesPlaceholder"></div>
|
|
<div class="table-light table-responsive">
|
|
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="workweeks">
|
|
<thead>
|
|
<tr>
|
|
<th>
|
|
Name
|
|
</th>
|
|
<th>
|
|
Days of Work Week
|
|
</th>
|
|
<th style="width:15%"></th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
<!-- Modal -->
|
|
<div id="editWorkWeek" class="modal fade" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content" id="editReload">
|
|
</div>
|
|
<!-- / .modal-content -->
|
|
</div>
|
|
<!-- / .modal-dialog -->
|
|
</div>
|
|
<!-- /.modal -->
|
|
<!-- / Modal -->
|
|
<!-- Warning modal alert -->
|
|
<div id="modal-warning" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
|
|
<div class="modal-dialog">
|
|
@using (Ajax.BeginForm("Delete", "WorkWeek", new AjaxOptions() { OnBegin = "blockUI", OnComplete = "unblockUI", OnSuccess = "onSuccess", OnFailure = "onFailure" }, new { @id = "deleteWWForm" }))
|
|
{
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" id="deleteWorkWeekId" name="deleteWorkWeekId" />
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
|
|
<h4 class="modal-title">Delete Work Week</h4>
|
|
</div>
|
|
<div class="modal-title"></div>
|
|
<div class="modal-body">
|
|
<strong id="deleteWWCaption"></strong>
|
|
@Html.ValidationSummary(false, "Work week cannot be deleted due to the following errors:")
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn btn-danger">OK</button>
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
|
</div>
|
|
</div> <!-- / .modal-content -->
|
|
}
|
|
</div>
|
|
<!-- / .modal-dialog -->
|
|
</div>
|
|
<!-- / .modal -->
|
|
<!-- Modal --> |