fleet-contractor/Site/Security/UserToContractorPage.aspx
2023-04-28 12:22:26 +08:00

348 lines
15 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/Security/Security.master" AutoEventWireup="true" CodeFile="UserToContractorPage.aspx.cs" Inherits="Security_UserToContractorPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link rel="stylesheet" href="<%=GetFileUrlWithVersion("css/controls.css")%>" type="text/css" />
<style type="text/css">
#content_left {
float: left;
width: 200px;
border-top: 1px solid #b0b0b0;
height: 100%;
overflow-y: auto;
}
.ul_menu {
}
.ul_header {
background: rgb(244,244,244);
margin-bottom: 1px;
}
li.subitem {
text-indent: 10px;
}
#content_right {
margin-left: 200px;
border-left: 1px solid #b0b0b0;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
}
.main_table {
table-layout: fixed;
border-top: none;
}
.main_table td {
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script src="<%=GetFileUrlWithVersion("js/controls.js")%>" type="text/javascript"></script>
<script src="<%=GetFileUrlWithVersion("../fic/fic/override.js")%>" type="text/javascript"></script>
<script type="text/javascript">
var lasttimeclickdata = [];//上一次点击的Contractor的原始状态
var lasttimeclicklabelID = "";//上一次点击的用户或组的ID
function dtquery(method, param, callback) {
_network.request("Security/UserToContractorPage.aspx", -1, method, param, callback, function (e) {
console.log(e);
showmaskbg(false);
showAlert(e.statusText, GetTextByKey("P_UTC_ERROR", 'Error'));
});
}
$(function () {
setPageTitle(GetTextByKey("P_UTC_PERMISSIONMANAGEMENT", 'Permission Management'), true);
$('#leftusertitle').click(groupTitleClick);
$('#leftusergrouptitle').click(groupTitleClick);
$('#thcheckall').click(CheckAll);
$('#selectallcheck').click(CheckAll);
GetUsers();
GetGroups();
});
function groupTitleClick(e) {
if ($(this.lastChild).hasClass('collapse')) {
$(this.lastChild).removeClass('collapse').addClass('expand');
$(this).nextAll().show();
} else {
$(this.lastChild).removeClass('expand').addClass('collapse');
$(this).nextAll().hide();
}
}
function GetUsers() {
dtquery('GetUsers', '', function (data) {
$('#leftusertitle').nextAll().remove();
for (var i = 0; i < data.length; i++) {
var li = $('<li class="subitem"></li>').attr('id', data[i].IID).text(data[i].DisplayName).attr('title', data[i].ID).append($('<i></i>').text('(' + data[i].ID + ')'));
li.click(function () { UserAndGroupClick(this, 1) });
$('#usersul').append(li);
}
// default to load the first
$('#leftusertitle').next().click();
});
}
function GetGroups() {
dtquery('GetGroups', '', function (data) {
$('#leftusergrouptitle').nextAll().remove();
for (var i = 0; i < data.length; i++) {
var li = $('<li class="subitem"></li>').attr('id', data[i].ID).text(data[i].Name);
li.click(function () { UserAndGroupClick(this, 2) });
$('#groupsul').append(li);
}
});
}
function UserAndGroupClick(obj, flag) {
$('#selectallcheck').attr('checked', false);
var nochange = true;//默认不改变
if (obj.id != lasttimeclicklabelID && lasttimeclickdata.length > 0) {
$('#user_tbody tr').each(function () {
var checkinput = this.children[0].firstElementChild;
for (var j = 0; j < lasttimeclickdata.length; j++) {
if (checkinput.id == lasttimeclickdata[j].ID && checkinput.checked != lasttimeclickdata[j].IsChecked) {
nochange = false;
break;
}
}
})
}
if (!nochange) {
if (window.parent && typeof window.parent.onmaskbg == 'function') {
window.parent.showconfirm(GetTextByKey("P_UTC_SOMESETTINGSHAVECHANGED", "Some settings have changed.Would you like to save the changes?"), GetTextByKey("P_UTC_SAVEPERMISSION", "Save Permission"), function () {
dosave();
clearSelectFlag(obj);
GetContractors(obj.id, flag);
}, function () {
clearSelectFlag(obj);
GetContractors(obj.id, flag);
});
}
}
else {
clearSelectFlag(obj);
GetContractors(obj.id, flag);
}
}
function GetContractors(i, flag) {
lasttimeclicklabelID = i;
$('#user_tbody').empty();
$.ajax(
{
type: "POST",
async: false,
datatype: "json",
url: "UserToContractorPage.aspx",
data: {
uiid: i,
Flag: flag,
MethodName: "GetContractors"
},
success: function (data) {
if (data != "") {
var contractordata = eval("(" + data + ")");
lasttimeclickdata = [];
for (var i = 0; i < contractordata.length; i++) {
var newselectcontractor = {
ID: contractordata[i].ID,
IsChecked: contractordata[i].IsChecked
}
lasttimeclickdata.push(newselectcontractor);
var tr = $('<tr></tr>');
var tdcheck = $('<td></td>').click(checkInputClick);
var checkinput = $('<input type="checkbox" />').attr('id', contractordata[i].ID);
if (contractordata[i].AuthorizedIngroup && contractordata[i].IsChecked) {
checkinput.attr('disabled', 'disabled');
tdcheck.unbind("click");
}
if (contractordata[i].IsChecked) {
checkinput.attr('checked', 'checked');
}
checkinput.click(checkInputClick);
tdcheck.append(checkinput);
var tdid = $('<td></td>').text(contractordata[i].ID);
var tdname = $('<td></td>').text(contractordata[i].Name);
tr.append(tdcheck, tdid, tdname);
$('#user_tbody').append(tr);
}
}
},
error: function (msg) {
showAlert(msg.statusText, GetTextByKey("P_UTC_ERROR", 'Error'));
}
}
)
}
function clearSelectFlag(obj) {
$($('#usersul')[0].children).each(function () { $(this).removeClass("selected"); });
$($('#groupsul')[0].children).each(function () { $(this).removeClass("selected"); });
$(obj).addClass("selected");
}
function Save() {
if (!$('li.selected')[0]) {
showAlert(GetTextByKey('P_UTC_PLEASESELECTAUSERORGROUP', "Please select a user or group."), GetTextByKey('P_UTC_SAVEUSERTOCONTRACTOR', 'Save user to contractor'));
return false;
}
if (window.parent && typeof window.parent.onmaskbg == 'function') {
window.parent.showconfirm(GetTextByKey('P_UTC_DOYOUWANTTOSAVEPERMISSIONSFORTHIS', "Do you want to save Permissions for this?"), GetTextByKey("P_UTC_SAVEPERMISSION", "Save Permission"), function () { dosave(); OnRefresh(); }, function () { return false; });
}
}
function dosave() {
var current = $('li.selected')[0].id;
var contractorArray = [];
$($('#user_tbody')[0].children).each(
function () {
var checkinputctr = this.cells['0'].children[0];
if (checkinputctr.checked)
contractorArray.push(encodeURIComponent(checkinputctr.id));
}
);
$.ajax(
{
type: "POST",
async: false,
datatype: "json",
url: "UserToContractorPage.aspx",
data: {
id: current,
contractors: JSON.stringify(contractorArray),
MethodName: "SaveContractor"
},
success: function (msg) {
showAlert(msg, GetTextByKey('P_UTC_SAVEUSERTOCONTRACTOR', 'Save user to contractor'));
},
error: function (msg) {
showAlert(msg.statusText, GetTextByKey('P_UTC_ERROR', 'Error'));
}
}
)
}
function OnRefresh() {
$('#selectallcheck').attr('checked', false);
if ($('li.selected')[0]) {
var current = $('li.selected')[0].id;
if ($('li.selected')[0].parentElement.id == "usersul") {
GetContractors(current, 1);
}
else {
GetContractors(current, 2);
}
}
else
return false;
}
function CheckAll(e) {
var obj = e.currentTarget;
if (e.target.tagName == "TH") {
if ($('#user_tbody')[0].children.length > 0) {
if (obj.children[0].checked) {
$($('#user_tbody')[0].children).each(
function () {
var checkinputctr = this.cells['0'].children[0];
if (!checkinputctr.disabled)
checkinputctr.checked = false;
});
obj.children[0].checked = false;
}
else {
$($('#user_tbody')[0].children).each(
function () {
var checkinputctr = this.cells['0'].children[0];
checkinputctr.checked = true;
});
obj.children[0].checked = true;
}
}
}
else {
if (obj.checked != undefined) {
if (obj.checked) {
$($('#user_tbody')[0].children).each(
function () {
var checkinputctr = this.cells['0'].children[0];
checkinputctr.checked = true;
});
obj.checked = true;
}
else {
$($('#user_tbody')[0].children).each(
function () {
var checkinputctr = this.cells['0'].children[0];
if (!checkinputctr.disabled)
checkinputctr.checked = false;
});
obj.checked = false;
}
}
}
e.stopPropagation(); //禁止冒泡
}
function checkInputClick(e) {
var obj = e.currentTarget;
if (e.target.tagName == "TD") {
if ($('#user_tbody')[0].children.length > 0) {
if (obj.children[0].checked) {
obj.children[0].checked = false;
$('#selectallcheck')[0].checked = false;
}
else {
obj.children[0].checked = true;
}
}
}
else {
if (e.target.tagName == "INPUT" && obj.checked != undefined) {
if (obj.checked) {
obj.checked = true;
}
else {
obj.checked = false;
$('#selectallcheck')[0].checked = false;
}
}
}
e.stopPropagation(); //禁止冒泡
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div style="min-width: 400px;">
<div class="page_title" data-lgid="P_UTC_PERMISSIONMANAGEMENT">Permission Management</div>
<div class="function_title">
<span class="sbutton iconsave" onclick="Save();" data-lgid="P_UTC_SAVE">Save</span>
<span class="sbutton iconrefresh" onclick="OnRefresh();" data-lgid="P_UTC_REFRESH">Refresh</span>
</div>
<div class="clear"></div>
<div class="content_main">
<div id="content_left">
<ul id="usersul" class="ul_menu">
<li id="leftusertitle" class="ul_header"><span data-lgid="P_UTC_USERS">Users</span><em class="icn expand"></em></li>
</ul>
<ul id="groupsul" class="ul_menu">
<li id="leftusergrouptitle" class="ul_header"><span data-lgid="P_UTC_USERGROUPS">User Groups</span><em class="icn expand"></em></li>
</ul>
</div>
<div id="content_right">
<div id="permission_tab" class="tab_holder">
<div id="group_table" class="tab_page">
<table class="main_table">
<thead id="datafirsttr">
<tr>
<th style="width: 20px;" id="thcheckall">
<input type="checkbox" id="selectallcheck" /></th>
<th style="width: 100px;" data-lgid="P_UTC_ID">ID</th>
<th style="" data-lgid="P_UTC_NAME">Name</th>
</tr>
</thead>
<tbody id="user_tbody"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="mask_bg" style="display: none;"><div class="loading c-spin"></div></div>
</asp:Content>