384 lines
16 KiB
Plaintext
384 lines
16 KiB
Plaintext
@using EnVisage.Code
|
|
@model EnVisage.Models.UserModel
|
|
@{
|
|
ViewBag.Title = Model.Id != Guid.Empty ? "Edit " + Model.UserName : "Add New User";
|
|
}
|
|
@section stylesheets
|
|
{
|
|
@Styles.Render(String.Format("{0}/{1}", Constants.C_BUNDLE_STYLES_BASE_PATH, "prevu-permissiontreestyles"))
|
|
}
|
|
@section Scripts
|
|
{
|
|
@Scripts.Render(String.Format("{0}/{1}", Constants.C_BUNDLE_SCRIPTS_BASE_PATH, "prevu-permissiontree"))
|
|
<script type="text/javascript">
|
|
emulateNavUrl = "/User";
|
|
init.push(function () {
|
|
initUser();
|
|
});
|
|
function initUser() {
|
|
@if (Model.Id != Guid.Empty)
|
|
{
|
|
<text>
|
|
StartEdit('User', '@Model.Id.ToString()', "#btnDelete", "#btnsave", "erorMsgPlaceholder");
|
|
</text>
|
|
}
|
|
@if (Model.Id != Guid.Empty)
|
|
{
|
|
<text>
|
|
ProjectTree.buildProjectTree('@Url.Action("GetProjectAccessTree", "User")?userId=@Model.Id.ToString()');
|
|
</text>
|
|
}
|
|
else
|
|
{
|
|
<text>
|
|
ProjectTree.buildProjectTree('@Url.Action("GetProjectAccessTree", "User")?userId=');
|
|
</text>
|
|
}
|
|
$("input[name='areasread']").click(function () {
|
|
readPermissionItemClick(this, true, true);
|
|
});
|
|
$("input[name='areaswrite']").click(function () {
|
|
writePermissionItemClick(this, true, true);
|
|
});
|
|
$("input[name='roleitems']").click(function () {
|
|
var optionTexts = [];
|
|
$("input[name='roleitems']").each(function () {
|
|
if (this.checked)
|
|
optionTexts.push($(this).val());
|
|
});
|
|
var siteRoot = location.protocol + '//' + location.host;
|
|
$.ajax({
|
|
type: "post",
|
|
url: siteRoot + "/User/GetRolePermissions",
|
|
datatype: "json",
|
|
traditional: true,
|
|
data: { "roleId": optionTexts },
|
|
async: false,
|
|
error: function (returnval) {
|
|
console.writeln(returnval);
|
|
},
|
|
success: function (returnval) {
|
|
var arr = $.parseJSON(returnval);
|
|
$.each($("input[name='areasread']"), function (i, o) {
|
|
updatePermissionFormRole($(o), arr[0], 1, false);
|
|
});
|
|
|
|
$.each($("[name='areaswrite']"), function (i, o) {
|
|
updatePermissionFormRole($(o), arr[0], 2, false);
|
|
});
|
|
|
|
$.each($("input[name='projectlistread']"), function (i, o) {
|
|
|
|
updatePermissionFormRole($(o), arr[1], 1, true);
|
|
});
|
|
|
|
$.each($("input[name='projectlistwrite']"), function (i, o) {
|
|
|
|
updatePermissionFormRole($(o), arr[1], 2, true);
|
|
});
|
|
|
|
result = true;
|
|
}
|
|
});
|
|
});
|
|
$('#@Html.IdFor(t=>t.PreferredResourceAllocation)').switcher({
|
|
on_state_content: 'Resources',
|
|
off_state_content: 'Hours'
|
|
}).parent().css("width", "140px");
|
|
$('#@Html.IdFor(t=>t.PreferredTotalsDisplaying)').switcher({
|
|
on_state_content: 'Average',
|
|
off_state_content: 'Sum'
|
|
}).parent().css("width", "140px");
|
|
$('#@Html.IdFor(t=>t.ShowAutomaticViews)').switcher({
|
|
on_state_content: 'Show Views',
|
|
off_state_content: 'Hide Views'
|
|
}).parent().css("width", "140px");
|
|
|
|
$('#@Html.IdFor(model => model.CompaniesWatcher)').select2()
|
|
.on("select2-selecting", function (e) {
|
|
if (e && e.val) {
|
|
filterSelectedCompanies('@Html.IdFor(model => model.CompaniesWatcher)', e.val);
|
|
}
|
|
});
|
|
$('#@Html.IdFor(model => model.CompaniesContributor)').select2()
|
|
.on("select2-selecting", function (e) {
|
|
if (e && e.val) {
|
|
filterSelectedCompanies('@Html.IdFor(model => model.CompaniesContributor)', e.val);
|
|
}
|
|
});
|
|
$('#@Html.IdFor(model => model.WorkFlowRoles)').select2()
|
|
.on("select2-selecting", function (e) {});
|
|
$('#btnsave').click(function () {
|
|
if ($('#frmEditUser').valid()) {
|
|
blockUI();
|
|
beforeSubmit();
|
|
}
|
|
});
|
|
}
|
|
|
|
function filterSelectedCompanies(controlId, selectedVal) {
|
|
var controlSelector = "#" + controlId;
|
|
var controlItem = $(controlSelector);
|
|
var selectedOption = $(controlItem).find('[value="' + selectedVal + '"]');
|
|
var parentItemId = $(selectedOption).attr("data-parent-value");
|
|
var currentSelection;
|
|
var newSelection;
|
|
if (parentItemId) {
|
|
// Child company was selected. Check if it's parent company is already selected.
|
|
// If so, remove parent company from selection
|
|
currentSelection = controlItem.select2('val');
|
|
var selectionToRemoveIndex = currentSelection.indexOf(parentItemId);
|
|
|
|
if (selectionToRemoveIndex >= 0) {
|
|
newSelection = $.extend([], currentSelection);
|
|
newSelection.splice(selectionToRemoveIndex, 1);
|
|
controlItem.select2('val', newSelection);
|
|
}
|
|
}
|
|
else {
|
|
// Parent company was selected. Check and remove it's child companies from selection
|
|
var childCompaniesForCurrent = [];
|
|
$(controlItem).find('[data-parent-value="' + selectedVal + '"]')
|
|
.each(function (index, item) {
|
|
var itemValue = $(item).attr('value');
|
|
childCompaniesForCurrent.push(itemValue);
|
|
});
|
|
|
|
if (childCompaniesForCurrent.length > 0) {
|
|
currentSelection = controlItem.select2('val');
|
|
newSelection = $.extend([], currentSelection);
|
|
var selectionChanged = false;
|
|
|
|
for (var index = newSelection.length - 1; index >= 0; index--) {
|
|
var itemToCheck = newSelection[index];
|
|
|
|
if (childCompaniesForCurrent.indexOf(itemToCheck) >= 0) {
|
|
newSelection.splice(index, 1);
|
|
selectionChanged = true;
|
|
}
|
|
}
|
|
|
|
if (selectionChanged) {
|
|
controlItem.select2('val', newSelection);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function updatePermissionFormRole(chk, arr, propIndx, useTreeObj) {
|
|
var inherited = false;
|
|
|
|
if (arr.length == 0) {
|
|
if (IsInherited(chk)) {
|
|
setInherited(chk, false, useTreeObj);
|
|
}
|
|
}
|
|
else {
|
|
for (var j = 0; j < arr.length; j++) {
|
|
var item = arr[j][0];
|
|
var itemAllow = arr[j][propIndx];
|
|
|
|
//area is inherited from role
|
|
if (item == chk.val() && IsInherited(chk)) {
|
|
setInherited(chk, itemAllow == "True", useTreeObj);
|
|
inherited = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!inherited) {
|
|
if (IsInherited(chk)) {
|
|
setInherited(chk, false, useTreeObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function setInherited(o, checked, useTreeObj) {
|
|
o.attr("inherited", "inherited");
|
|
o.attr("role", checked ? '1' : '0');
|
|
|
|
if (useTreeObj == true) {
|
|
var obj = ProjectTree.setDataValue($(o).val(), $(o).attr("name") == "projectlistwrite" ? 'write' : 'read', $(o).attr("role") == "1", true);
|
|
ProjectTree.setParentValues(obj);
|
|
}
|
|
else {
|
|
o.prop("checked", checked);
|
|
}
|
|
}
|
|
|
|
function IsInherited(o) {
|
|
return o.attr("inherited") != null;
|
|
}
|
|
|
|
function reset() {
|
|
$.each($("input[name='areasread']"), function (i, o) {
|
|
setInherited($(o), false, false);
|
|
});
|
|
|
|
$.each($("[name='areaswrite']"), function (i, o) {
|
|
setInherited($(o), false, false);
|
|
});
|
|
|
|
$.each($("input[name='projectlistread']"), function (i, o) {
|
|
setInherited($(o), false, true);
|
|
});
|
|
|
|
$.each($("input[name='projectlistwrite']"), function (i, o) {
|
|
setInherited($(o), false, true);
|
|
});
|
|
|
|
}
|
|
|
|
var ProjectListArray = [];
|
|
var AreaListArray = [];
|
|
function projectlist(id, read, write) {
|
|
this.id = id;
|
|
this.p = { read: read, write: write }
|
|
}
|
|
function arealist(id, read, write) {
|
|
this.id = id;
|
|
this.p = { read: read, write: write }
|
|
}
|
|
function beforeSubmit() {
|
|
$("input[name='overriden']").remove();
|
|
var form = document.getElementById("frmEditUser");
|
|
$.each($(".custominput"), function (i, o) {
|
|
if ($(o).attr("inherited") == "inherited") {
|
|
var hid = document.createElement('input');
|
|
$(hid).prop("type", "hidden");
|
|
$(hid).prop("name", "overriden");
|
|
$(hid).prop("value", $(o).prop("name") + "|" + $(o).prop("value"));
|
|
form.appendChild(hid);
|
|
}
|
|
});
|
|
var overriden = [];
|
|
var roles = [];
|
|
$.each($("input[name='roleitems']:checked"), function (i, o) {
|
|
var value = $(this).val();
|
|
roles.push(value);
|
|
});
|
|
$.each($("input[name='overriden']"), function (i, o) {
|
|
var value = $(this).val();
|
|
overriden.push(value);
|
|
});
|
|
$.each($("input[name='areasread']:checked"), function (i, o) {
|
|
var value = $(this).val();
|
|
var a = new arealist(value, true, false);
|
|
var results = $.grep(AreaListArray, function (e) { return e.id === value; });
|
|
if (results.length == 1) {
|
|
a = results[0];
|
|
var i = AreaListArray.indexOf(a);
|
|
a.p.read = true;
|
|
AreaListArray[i] = a;
|
|
}
|
|
else
|
|
AreaListArray.push(a);
|
|
});
|
|
$.each($("input[name='areaswrite']:checked"), function (i, o) {
|
|
var value = $(this).val();
|
|
var a = new arealist(value, true, true);
|
|
var results = $.grep(AreaListArray, function (e) { return e.id === value; });
|
|
if (results.length == 1) {
|
|
a = results[0];
|
|
var i = AreaListArray.indexOf(a);
|
|
a.p.write = true;
|
|
AreaListArray[i] = a;
|
|
}
|
|
else
|
|
AreaListArray.push(a);
|
|
});
|
|
$.each($("input[name='projectlistread']:checked"), function (i, o) {
|
|
var value = $(this).val();
|
|
var read = true;
|
|
var pl = new projectlist(value, read, false);
|
|
var results = $.grep(ProjectListArray, function (e) { return e.id === value; });
|
|
if (results.length == 1) {
|
|
pl = results[0];
|
|
var i = ProjectListArray.indexOf(pl);
|
|
pl.p.read = read;
|
|
ProjectListArray[i] = pl;
|
|
}
|
|
else
|
|
ProjectListArray.push(pl);
|
|
});
|
|
$.each($("input[name='projectlistwrite']:checked"), function (i, o) {
|
|
var value = $(this).val();
|
|
var write = true;
|
|
var pl = new projectlist(value, false, write);
|
|
var results = $.grep(ProjectListArray, function (e) { return e.id === value; });
|
|
if (results.length == 1) {
|
|
pl = results[0];
|
|
var i = ProjectListArray.indexOf(pl);
|
|
pl.p.write = write;
|
|
ProjectListArray[i] = pl;
|
|
}
|
|
else
|
|
ProjectListArray.push(pl);
|
|
});
|
|
|
|
var id = $("input[name='Id']").val();
|
|
var username = $("input[name='UserName']").val();
|
|
var firstname = $("input[name='FirstName']").val();
|
|
var lastname = $("input[name='LastName']").val();
|
|
var email = $("input[name='Email']").val();
|
|
var phone = $("input[name='Phone']").val();
|
|
var preferredresourceallocation = $("input#@Html.IdFor(t => t.PreferredResourceAllocation)").prop('checked') == true;
|
|
var preferredTotalsDisplaying = $("input#@Html.IdFor(t => t.PreferredTotalsDisplaying)").prop('checked') == true;
|
|
var showAutomaticViews = $("input#@Html.IdFor(t => t.ShowAutomaticViews)").prop('checked') == true;
|
|
var discriminator = $("input[name='Discriminator']").val();
|
|
|
|
var userWatchCompaniesControl = $('#@Html.IdFor(model => model.CompaniesWatcher)');
|
|
var userContrCompaniesControl = $('#@Html.IdFor(model => model.CompaniesContributor)');
|
|
var userWkflRoleControl = $('#@Html.IdFor(model => model.WorkFlowRoles)');
|
|
var selectedWatchCompanies = userWatchCompaniesControl.select2('val');
|
|
var selectedContrCompanies = userContrCompaniesControl.select2('val');
|
|
var selectedWflRoles = userWkflRoleControl.select2('val');
|
|
|
|
|
|
var projecttree = { ProjectList: ProjectListArray, AreaList: AreaListArray, Overriden: overriden, RoleItems: roles };
|
|
var aspnetuser = {
|
|
Id: id,
|
|
UserName: username,
|
|
FirstName: firstname,
|
|
LastName: lastname,
|
|
Email: email,
|
|
Phone: phone,
|
|
PreferredResourceAllocation: preferredresourceallocation,
|
|
PreferredTotalsDisplaying: preferredTotalsDisplaying,
|
|
ShowAutomaticViews: showAutomaticViews,
|
|
Discriminator: discriminator,
|
|
WorkFlowRoles: selectedWflRoles,
|
|
CompaniesWatcher: selectedWatchCompanies,
|
|
CompaniesContributor: selectedContrCompanies,
|
|
|
|
};
|
|
|
|
var form = $('#frmEditUser');
|
|
var token = $('input[name="__RequestVerificationToken"]', form).val();
|
|
var permissiondata = { projecttree: projecttree, aspnetuser: aspnetuser };
|
|
$.ajax({
|
|
type: "post",
|
|
url: siteRoot + "/User/Edit",
|
|
context: document.body,
|
|
data: { __RequestVerificationToken: token, edituser: permissiondata },
|
|
error: function (xhr) {
|
|
showErrorModal(null, null, '000011');
|
|
},
|
|
success: function (result, statusText, xhr) {
|
|
handleAjaxResponse(result, function () {
|
|
// success callback
|
|
document.location.href = '@Url.Action("Index", "User")';
|
|
}, null, null, $('#frmEditUser'), 'edituser.aspnetuser.');
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
</script>
|
|
}
|
|
<div id="divEdituser">
|
|
@{ Html.RenderPartial("_editUser", Model); }
|
|
</div> |