EnVisageOnline/Main-RMO/Source/EnVisage/Views/Clients/Edit.cshtml

199 lines
7.6 KiB
Plaintext

@model EnVisage.Models.ClientModel
@{
ViewBag.Title = Model != null ? "Edit " + Model.Name : "Add New Client";
}
@section Scripts
{
<script type="text/javascript">
emulateNavUrl = "/Clients";
</script>
<script type="text/javascript">
init.push(function() {
@if (Model.Id != Guid.Empty)
{
@:StartEdit('Clients', '@Model.Id', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
if(Model.CompanyId != null)
{
foreach(var companyId in Model.CompanyId)
{
@:$("#companyId_@companyId")[0].checked = true;
}
}
}
$('#btnsave').click(function () {
if ($(this).parents('form').valid())
blockUI();
});
});
</script>
<script type="text/javascript">
if ('@Model.Id' != '@Guid.Empty') {
$('.assign').click(function () {
$('.divForAssign_@Model.Id').load('@Url.Action("AddContact", "Clients", new {Id = Model.Id})', function () {
$(".innerForm input").removeData("validator");
$(".innerForm input").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parseDynamicContent('.innerForm');
$('#btnaddcontact').click(function () {
if ($(this).parents('form').valid())
blockUI();
});
});
$('#modalAddContact_@Model.Id').modal("show");
});
}
else {
$('.assign').addClass("disabled");
}
</script>
<script type="text/javascript">
function editContact(Id) {
if (Id == null || Id == "")
return "";
var text = "@Url.Action( "EditContact", "Clients", new { Id = "JSVar" })"
text = text.replace("JSVar", Id);
$('.divForAssign_@Model.Id').load(text, function ()
{
$(".innerForm input").removeData("validator");
$(".innerForm input").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parseDynamicContent('.innerForm');
$('#btnaddcontact').click(function () {
if ($(this).parents('form').valid())
blockUI();
});
});
$('#modalAddContact_@Model.Id').modal("show");
};
function deleteContact(Id) {
if (Id == null || Id == "")
return "";
bootbox.confirm({
message: "Are you suse you want to delete this contact?",
callback: function(result) {
if (result) {
var text = "@Url.Action( "DeleteContact", "Clients", new { Id = "JSVar" })";
text = text.replace("JSVar", Id);
blockUI();
$('.divForAssign_@Model.Id').load(text, function(response, status, xhr) {
unblockUI();
if (status == "error") {
showErrorModal('Loading error', 'We are sorry but there was an error, please try again later.');
} else {
window.location.reload();
}
});
}
},
className: "bootbox-sm"
});
return "";
};
</script>
<!--//TODO: TEMPORARY CODE, REMOVE WHEN FULL DYNAMIC VALIDATOR CONTENT IS ADDED-->
<script>
</script>
}
<div id="erorMsgPlaceholder"></div>
@using (Html.BeginForm("Edit", "Clients", FormMethod.Post, new { @class = "panel form-horizontal" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(t => t.Id)
<div class="panel-body">
<div class="form-group">
@Html.LabelFor(model => model.ClientNumber, new { @class = "col-sm-2 control-label" })
<div class="col-sm-10">
@Html.TextBoxFor(model => model.ClientNumber, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ClientNumber)
</div>
@Html.LabelFor(model => model.Name, new { @class = "col-sm-2 control-label" })
<div class="col-sm-10">
@Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name)
</div>
@Html.LabelFor(model => model.GLAccountId, "GL Account Name", new { @class = "control-label col-sm-2" })
<div class="col-sm-10">
@Html.DropDownListFor(model => model.GLAccountId, EnVisage.Code.Utils.GetGLAccounts(true), new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.GLAccountId)
</div>
@Html.LabelFor(model => model.Companies, new { @class = "col-sm-2 control-label" })
<div class="col-sm-10">
@Html.Partial("_companies", Model.Companies)
</div>
</div>
@Html.ValidationSummary(false, "The client could not be saved due to the following errors:")
<div class="form-group" style="margin-bottom: 0;">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-primary" href="@Url.Action("Index", "Clients")"><i class="fa fa-backward"></i> Back to list</a>
<button type="submit" class="btn btn-success" id="btnsave"><i class="fa fa-save"></i> Save</button>
@if (Model != null && Model.Id != Guid.Empty)
{
if (Model.ProjectsCount > 0)
{
<a id="btnDelete" class="btn btn-danger disabled" href="javascript:void(0);"><i class="fa fa-trash-o"></i> Delete</a>
}
else
{
<a id="btnDelete" class="btn btn-danger" href="@Url.Action("Delete", "Clients", new {@id = Model.Id})"><i class="fa fa-trash-o"></i> Delete</a>
}
}
</div>
</div>
</div>
}
<div class="panel colourable">
<div class="panel-heading">
<span class="panel-title">Contacts</span>
</div>
<div class="panel-body" id="contacts">
<div class="table-light table-responsive no-margin" id="contactslist_@Model.Id">
<a class="btn btn-primary assign" href="javascript:;"><i class="fa fa-plus"></i> Add Contact</a>
<h1></h1>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered no-margin">
<thead>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>Phone Number</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var contact in Model.Contacts)
{
<tr>
<td>@(contact.FirstName + " "+ contact.LastName)</td>
<td><a href="mailto:@contact.Email;">@contact.Email</a></td>
<td>@contact.Phone</td>
<td>
<a href="javascript:void(0)" onclick="editContact('@contact.Id');" class="btn btn-primary lockable"><i class="fa fa-edit"></i> Edit</a>
@if (contact.ProjectLinksCount > 0)
{
<a href="javascript:void(0)" class="btn btn-danger lockable disabled"><i class="fa fa-trash-o"></i> Delete</a>
}
else
{
<a href="javascript:void(0)" onclick="deleteContact('@contact.Id');" class="btn btn-danger lockable"><i class="fa fa-trash-o"></i> Delete</a>
}
</td>
</tr>
}
</tbody>
</table>
</div>
<div id="modalAddContact_@Model.Id" class="modal fade" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static">
<div class="modal-dialog divForAssign_@Model.Id">
</div> <!-- / .modal-dialog -->
</div> <!-- / .modal -->
</div>
</div>