EnVisageOnline/Main/Source/EnVisage/Views/UserQuickLink/_editQuickLink.cshtml

149 lines
6.0 KiB
Plaintext

@using System.Diagnostics
@model EnVisage.Models.UserQuickLinkModel
@{
ViewBag.Title = Model != null ? "Edit " + Model.Name : "Add QuickLink";
Debug.Assert(Model != null, "Model != null");
}
<script type="text/javascript">
var _qlDataChanged = false;
function onQLDataChanged() {
_qlDataChanged = true;
}
function resetQLDataChanged() {
_qlDataChanged = false;
}
function isQLDataChanged() {
return _qlDataChanged;
}
//init.push(function () {
function initQuickLink() {
@if (Model.Id != Guid.Empty)
{
<text>
StartEdit('UserQuickLink', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
</text>
}
else
{
<text>
if ($('#editUserQuickLinkForm #Name').val().length === 0) {
$('#editUserQuickLinkForm #Name').val(document.title.replace(' - Prevu', ''));
}
$('#@Html.IdFor(m => m.UserId)').val('@User.Identity.GetID()');
var href = document.location.href;
if (href.substr(href.length - 1) === '#') {
href = href.substr(0, href.length - 1);
}
href = URI(href).removeQuery("linkId");
$('#@Html.IdFor(m => m.Url)').val(href);
var data = {};
var tasks = [];
var sections = [];
var sectionElements = $("*[data-section]");
if (sectionElements && sectionElements.length) {
for (var sIndex = 0; sIndex < sectionElements.length; sIndex++) {
var elem = sectionElements[sIndex];
var sectionName = $(elem).data('section');
sections.push(sectionName);
tasks.push(loadUserPagePreferencesAsync(sectionName, null, true));
}
}
$.when.apply($, tasks)
.then(function () {
for (var i = 0; i < arguments.length; i++) {
data[sections[i]] = arguments[i];
}
$('#@Html.IdFor(m => m.PageState)').val(JSON.stringify(data));
})
.then(null, function (response) {
console.error('An error occurred while loading page preferences');
showErrorModal();
}).always(function () {
unblockUI();
});
</text>
}
$('#editUserQuickLinkForm').find('input[type=checkbox],input[type=text],select,textarea').on("change", function () {
if (typeof onQLDataChanged === 'function')
onQLDataChanged();
});
$(document).ready(function () {
$.validator.unobtrusive.parse($(this));
});
}
function onFailureQuickLinkEdit(xhr) {
showErrorModal('Oops!', 'An error occurred while saving quick link. ErrorCode = 000004');
}
function onSuccessQuickLinkEdit(result) {
handleAjaxResponse(result, function (result) {
onSuccessQuickLinkEditCallback(result.Content);
}, null, null, $('#editUserQuickLinkForm'));
}
function onSuccessQuickLinkEditCallback(data) {
if (typeof resetQLDataChanged === 'function')
resetQLDataChanged();
var span;
if ($('li #' + data.Id).length > 0) {
span = $('li #' + data.Id + ' span.mm-text');
span.attr('title', htmlEncode(data.Name));
span.text(data.Name);
$('#editQuickLink').modal('hide');
}
else if ($('#quicklinksContainer').length > 0) {
var li = '<li id=\'' + data.Id + '\'><a href="javascript:void(0);">' +
'<span class="mm-text" onclick="linkTo(this);" data-link-id="' + data.Id + '"></span>' +
'<span class="label label-danger" onclick="LoadDeleteQLModal(\'' + data.Id + '\');"><i class="fa fa-trash-o"></i></span>' +
'<span class="label label-info" onclick="editQuickLink(event, \'@User.Identity.GetID()\', \'' + data.Id + '\');"><i class="fa fa-edit"></i></span>' +
'</a></li>';
$('#quicklinksContainer').append(li);
span = $('li #' + data.Id + ' span.mm-text');
span.attr('title', htmlEncode(data.Name));
span.data('link-url', htmlEncode(data.Url));
span.text(data.Name);
$('#editQuickLink').modal('hide');
}
else {
reloadPage();
}
}
</script>
<div id="erorMsgPlaceholder"></div>
@using (Ajax.BeginForm("Edit", "UserQuickLink", new AjaxOptions { HttpMethod = "Post", OnBegin = "blockUI", OnSuccess = "onSuccessQuickLinkEdit", OnFailure = "onFailureQuickLinkEdit(xhr)", OnComplete = "unblockUI" }, new { id = "editUserQuickLinkForm" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.UserId)
@Html.HiddenFor(model => model.Url)
@Html.HiddenFor(model => model.PageState)
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">@(Model.Id != Guid.Empty ? "Edit " + Model.Name : "Add QuickLink")</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group no-margin-hr">
@Html.LabelFor(model => model.Name, new { @class = "control-label" })
@Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name)
</div>
</div>
</div>
@Html.ValidationSummary(false, "The Quick Link could not be saved due to the following errors:")
</div> <!-- / .modal-body -->
<div class="modal-footer">
<button type="submit" class="btn btn-success" id="btnsave"><i class="fa fa-save"></i> Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
}