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

710 lines
28 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/Credentials/Credentials.master" AutoEventWireup="true" CodeFile="ManageJDLink.aspx.cs" Inherits="ManageJDLink" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<style type="text/css">
.dialog .dialog-title .dialog-close {
float: right;
margin-right: 6px;
cursor: pointer;
}
.dialog .dialog-title .dialog-close:before {
content: '\e600';
}
.dialog-content table {
border-collapse: collapse;
width: 100%;
}
.dialog-content table td {
padding-top: 30px;
}
.dialog-content table td.label {
width: 130px;
text-align: right;
padding-right: 10px;
line-height: 24px;
height: 24px;
vertical-align: top;
}
.dialog-content table td input,
.dialog-content table td textarea {
border: 1px solid #a9a9a9;
width: 200px;
height: 18px;
padding: 1px;
}
.dialog-content table td input[type="checkbox"] {
border: none;
}
.dialog-content table td textarea {
height: 100px;
max-width: 200px;
}
.icon {
font-family: CalciteWebCoreIcons;
cursor: default;
}
</style>
<script type="text/javascript">
credentialquery = function (method, param, callback, error, nolog) {
_network.request("Credentials/ManageJDLink.aspx?tp=ashx", -1, method, param, callback, error, nolog);
}
//**************************************Begin JD Link***************************************************//
function OnAdd() {
showloading(true);
credentialquery("CreateJDLinkAuthUrl", "", function (data) {
showloading(false);
if (data != "") {
window.open(data);
}
else {
showAlert(GetTextByKey("P_JDL_FAILEDTOCREATETHISJDLINK", "Failed to create this JD link."), GetTextByKey("P_JDL_CREATEJDLINK", 'Create JD Link'));
}
}, function (err) {
showloading(false);
});
}
function OnRefresh() {
showloading(true);
credentialquery("GetJDLinkTokenItems", "", function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_JDL_ERROR", 'Error'));
return;
}
showCredentialList(data);
}, function (err) {
showloading(false);
});
}
function showCredentialList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "RequestTime")
r[j] = { DisplayValue: r["RequestTimeStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_dt.setData(rows);
}
var grid_dt;
function InitGridData() {
grid_dt = new GridView('#jdlinklist');
grid_dt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'AccountName', caption: GetTextByKey("P_JDL_ACCOUNTNAME", "Account Name"), valueIndex: 'AccountName', css: { 'width': 400, 'text-align': 'left' } },
{ name: 'RequestTime', caption: GetTextByKey("P_JDL_REQUESTTIME", "Request Time"), valueIndex: 'RequestTime', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Organization', caption: "", css: { 'width': 110, 'text-align': 'center' } },
{ name: 'ManageOrganization', caption: "", css: { 'width': 120, 'text-align': 'center' } },
{ name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
OnDelete(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': getText("P_JDL_DELETE", 'Delete') };
}
else if (col.name === "Organization") {
col.isurl = true;
col.text = GetTextByKey("P_SET_XXX", "My Organizations");
col.sortable = false;
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 0);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_SET_XXX", "My Organizations") };
}
else if (col.name === "ManageOrganization") {
col.isurl = true;
col.text = GetTextByKey("P_SET_XXX", "Manage Organizations");
col.sortable = false;
col.events = {
onclick: function () {
GetJDOrganizationUrl(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_SET_XXX", "Manage Organizations") };
}
columns.push(col);
}
grid_dt.canMultiSelect = false;
grid_dt.columns = columns;
grid_dt.init();
grid_dt.selectedrowchanged = function (rowindex) {
var rowdata = grid_dt.source[rowindex];
if (rowdata) {
creid = rowdata.Values.ID;
}
}
}
function OnDelete(cr) {
var cre = cr;
if (!cre) {
return;
}
showConfirm(GetTextByKey("P_JDL_DOYOUWANTTODELETETHEJDLINK", 'Do you want to delete the JD link?'), GetTextByKey("P_JDL_DELETEJDLINK", 'Delete JD Link'), function () {
credentialquery("DeleteToken", cre.TokenId, function (data) {
OnRefresh();
}, function (err) {
});
});
}
//**************************************End JD Link***************************************************//
//**************************************Begin MyJohnDeere***************************************************//
function OnAddMyJD() {
showloading(true);
credentialquery("CreateMyJDAPIAuthUrl", "", function (data) {
showloading(false);
if (data != "") {
window.open(data);
}
else {
showAlert(GetTextByKey("P_JDL_FAILEDTOCREATETHISMYJOHNDEERE", "Failed to create this MyJohnDeere."), GetTextByKey("P_JDL_CREATEMYJOHNDEERE", 'Create MyJohnDeere'));
}
}, function (err) {
showloading(false);
});
}
function OnRefreshMyJD() {
showloading(true);
credentialquery("GetMyJDAPITokenItems", "", function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_JDL_ERROR", 'Error'));
return;
}
showMyJDList(data);
}, function (err) {
showloading(false);
});
}
function showMyJDList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "RequestTime")
r[j] = { DisplayValue: r["RequestTimeStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_dtmyjd.setData(rows);
}
var grid_dtmyjd;
function InitGridMyJDData() {
grid_dtmyjd = new GridView('#myjdlist');
grid_dtmyjd.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'AccountName', caption: GetTextByKey("P_JDL_ACCOUNTNAME", "Account Name"), valueIndex: 'AccountName', css: { 'width': 400, 'text-align': 'left' } },
{ name: 'RequestTime', caption: GetTextByKey("P_JDL_REQUESTTIME", "Request Time"), valueIndex: 'RequestTime', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Organization', caption: "", css: { 'width': 110, 'text-align': 'center' } },
{ name: 'ManageOrganization', caption: "", css: { 'width': 120, 'text-align': 'center' } },
{ name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
DeleteMyJDToken(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': getText("P_JDL_DELETE", 'Delete') };
}
else if (col.name === "Organization") {
col.isurl = true;
col.text = GetTextByKey("P_SET_XXX", "My Organizations");
col.sortable = false;
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 1);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_SET_XXX", "My Organizations") };
}
else if (col.name === "ManageOrganization") {
col.isurl = true;
col.text = GetTextByKey("P_SET_XXX", "Manage Organizations");
col.sortable = false;
col.events = {
onclick: function () {
GetJDOrganizationUrl(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_SET_XXX", "Manage Organizations") };
}
columns.push(col);
}
grid_dtmyjd.canMultiSelect = false;
grid_dtmyjd.columns = columns;
grid_dtmyjd.init();
grid_dtmyjd.selectedrowchanged = function (rowindex) {
var rowdata = grid_dtmyjd.source[rowindex];
if (rowdata) {
creid = rowdata.Values.ID;
}
}
}
function DeleteMyJDToken(cr) {
var cre = cr;
if (!cre) {
return;
}
showConfirm(GetTextByKey("P_JDL_DOYOUWANTTODELETETHEMYJOHNDEERE", 'Do you want to delete the MyJohnDeere?'), GetTextByKey("P_JDL_DELETEMYJOHNDEERE", 'Delete MyJohnDeere'), function () {
credentialquery("DeleteToken", cre.TokenId, function (data) {
OnRefreshMyJD();
}, function (err) {
});
});
}
//**************************************End MyJohnDeere***************************************************//
//**************************************Begin JD Notifications***************************************************//
function OnAddNotification() {
$('#dialog_displayname').val('');
$('#mask_bg').show();
$('#dialog_credential')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_credential').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_credential').width()) / 2
})
.showDialogfixed();
$('#dialog_displayname').focus();
}
function CreateJDSubPubAuthUrl() {
var displayname = $.trim($('#dialog_displayname').val());
showloading(true);
credentialquery("CreateJDSubPubAuthUrl", displayname, function (data) {
showloading(false);
if (data != "") {
window.open(data);
$('#dialog_credential').hideDialog();
OnRefreshNotification();
}
else {
showAlert(GetTextByKey("P_JDN_FAILEDTOCREATETHISSUBSCRIPTION", "Failed to create this subscription."), GetTextByKey("P_JDN_CREATEANEWSUBSCRIPTION", 'Create a new subscription'));
}
}, function (err) {
$('#dialog_credential').hideDialog();
showloading(false);
});
}
function OnRefreshNotification() {
showloading(true);
credentialquery("GetNotificationSubscriptions", '', function (data) {
showloading(false);
showNotificationList(data);
}, function (err) {
showloading(false);
});
}
function showNotificationList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "CreateTime")
r[j] = { DisplayValue: r["CreateTimeStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_dtnotification.setData(rows);
}
var grid_dtnotification;
function InitGridNotificationData() {
grid_dtnotification = new GridView('#jdnotificationlist');
grid_dtnotification.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'DisplayName', caption: GetTextByKey("P_JDN_DISPLAYAME", "Display Name"), valueIndex: 'DisplayName', css: { 'width': 400, 'text-align': 'left' } },
{ name: 'AccountName', caption: GetTextByKey("P_JDL_USERNAME", "User Name"), valueIndex: 'AccountName', css: { 'width': 400, 'text-align': 'left' } },
{ name: 'CreateTime', caption: GetTextByKey("P_JDL_SUBSCRIPTIONNDATE", "Subscription Date"), valueIndex: 'CreateTime', css: { 'width': 150, 'text-align': 'left' } },
//{ name: 'Organization', caption: "", css: { 'width': 110, 'text-align': 'center' } },
{ name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
OnDeleteNotification(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': getText("P_JDL_DELETE", 'Delete') };
}
else if (col.name === "Organization") {
col.isurl = true;
col.text = GetTextByKey("P_SET_XXX", "My Organizations");
col.sortable = false;
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 2);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_SET_XXX", "My Organizations") };
}
columns.push(col);
}
grid_dtnotification.canMultiSelect = false;
grid_dtnotification.columns = columns;
grid_dtnotification.init();
grid_dtnotification.selectedrowchanged = function (rowindex) {
var rowdata = grid_dtnotification.source[rowindex];
if (rowdata) {
}
}
}
function OnDeleteNotification(cr) {
var cre = cr;
if (!cre) {
return;
}
showConfirm(GetTextByKey("P_JDL_DOYOUWANTTODELETETHESUBSCRIPTION", 'Do you want to delete the subscription?'), GetTextByKey("P_JDL_DELETESUBSCRIPTION", 'Delete Subscription'), function () {
credentialquery("DeleteNotificationSubscription", cre.Id, function (data) {
OnRefreshNotification();
}, function (err) { });
});
}
//**************************************End JD Notifications***************************************************//
//**************************************Begin My Organizations***************************************************//
function openMyOrganizationsDialog(cr, type) {//0:jdlink;1:MyJohnDeere;2:Notification
var cre = cr;
if (!cre) {
return;
}
var tokenid = "";
if (type == 0 || type == 1)
tokenid = cre.TokenId;
else
tokenid = cre.Id;
GetOrganizations(tokenid);
$('#mask_myorganizationbg').show();
$('#dialog_myorganization')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_myorganization').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_myorganization').width()) / 2
})
.showDialogfixed();
}
function GetOrganizations(tokieid) {
showloading(true);
credentialquery("GetOrganizations", tokieid, function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_JDL_ERROR", 'Error'));
return;
}
showMyOrgList(data);
}, function (err) {
showloading(false);
});
}
function GetJDOrganizationUrl(cr) {
var cre = cr;
if (!cre) {
return;
}
credentialquery("GetJDOrganizationUrl", cre.TokenId, function (data) {
if (data != "")
window.open(data);
}, function (err) {
});
}
function showMyOrgList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "Member")
r[j] = { DisplayValue: r["Member"] ? "Yes" : "", Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_dtmyorgs.setData(rows);
}
var grid_dtmyorgs;
function InitGridMyOrgData() {
grid_dtmyorgs = new GridView('#myorganization_list');
grid_dtmyorgs.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Id', caption: GetTextByKey("P_JDN_XXX", "Id"), valueIndex: 'Id', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'Name', caption: GetTextByKey("P_JDL_XXX", "Name"), valueIndex: 'Name', css: { 'width': 300, 'text-align': 'left' } },
{ name: 'OrgType', caption: GetTextByKey("P_JDL_XXX", "Type"), valueIndex: 'OrgType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Member', caption: GetTextByKey("P_JDL_XXX", "Member"), valueIndex: 'Member', css: { 'width': 100, 'text-align': 'left' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
}
grid_dtmyorgs.canMultiSelect = false;
grid_dtmyorgs.columns = columns;
grid_dtmyorgs.init();
grid_dtmyorgs.selectedrowchanged = function (rowindex) {
var rowdata = grid_dtmyorgs.source[rowindex];
if (rowdata) {
}
}
}
//**************************************End My Organizations***************************************************//
$(function () {
setPageTitle(GetTextByKey("P_JDLINK", 'JD Link'), true);
InitGridData();
InitGridMyJDData();
InitGridNotificationData();
InitGridMyOrgData();
OnRefresh();
OnRefreshMyJD();
OnRefreshNotification();
$('#dialog_credential').dialog(function () {
$('#mask_bg').hide();
});
$('#dialog_myorganization').dialog(function () {
$('#mask_myorganizationbg').hide();
});
$(window).resize(function () {
$("#jdlinklist").css("height", 170);
grid_dt && grid_dt.resize();
$("#myjdlist").css("height", 170);
grid_dtmyjd && grid_dtmyjd.resize();
$("#jdnotificationlist").css("height", 170);
grid_dtnotification && grid_dtnotification.resize();
$("#myorganization_list").css("height", 300);
grid_dtmyorgs && grid_dtmyorgs.resize();
}).resize();
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div style="min-width: 400px;">
<div class="page_title" data-lgid="P_JDLINK">
JD Link
</div>
<div class="function_title">
<span class="sbutton iconadd" onclick="OnAdd();" data-lgid="P_JDL_ADD">Add</span>
<span class="sbutton iconrefresh" onclick="OnRefresh();" data-lgid="P_JDL_REFRESH">Refresh</span>
</div>
<div class="clear"></div>
<div id="jdlinklist"></div>
</div>
<div style="min-width: 400px; margin-top: 10px;">
<div class="page_title" data-lgid="P_JDL_MYJOHNDEERE">MyJohnDeere</div>
<div class="function_title">
<span class="sbutton iconadd" onclick="OnAddMyJD();" data-lgid="P_JDL_ADD">Add</span>
<span class="sbutton iconrefresh" onclick="OnRefreshMyJD();" data-lgid="P_JDL_REFRESH">Refresh</span>
</div>
<div class="clear"></div>
<div id="myjdlist"></div>
</div>
<div style="min-width: 400px; margin-top: 10px;">
<div class="page_title" data-lgid="P_JDL_NOTIFICATIONSUBSCRIPTION">Notification Subscription</div>
<div class="function_title">
<span class="sbutton iconadd" onclick="OnAddNotification();" data-lgid="P_JDL_ADD">Add</span>
<span class="sbutton iconrefresh" onclick="OnRefreshNotification();" data-lgid="P_JDL_REFRESH">Refresh</span>
</div>
<div class="clear"></div>
<div id="jdnotificationlist"></div>
</div>
<div id="mask_bg">
<div class="loading c-spin"></div>
</div>
<div class="dialog" id="dialog_credential" style="display: none; width: 600px;">
<div class="dialog-title"><span class="title" data-lgid="P_JDN_CREATEANEWSUBSCRIPTION">Create a new subscription</span><em class="dialog-close"></em></div>
<div class="dialog-content">
<table>
<tr>
<td class="label" data-lgid="P_JDN_DISPLAYAME_COLON">Display Name:</td>
<td>
<input id="dialog_displayname" maxlength="50" tabindex="2" style="width: 400px;" /></td>
</tr>
</table>
</div>
<div class="dialog-func" style="margin-top: 16px;">
<input type="button" value="Cancel" data-lgid="P_JDN_CANCEL" class="dialog-close" tabindex="5" />
<input type="button" style="width: unset;" onclick="CreateJDSubPubAuthUrl(); return false;" value="Create" data-lgid="P_JDN_CREATE" tabindex="3" />
<div class="clear"></div>
</div>
</div>
<div id="mask_myorganizationbg" class="maskbg" style="display: none;">
<div class="loading c-spin"></div>
</div>
<div class="dialog" id="dialog_myorganization" style="display: none; width: 800px;">
<div class="dialog-title"><span class="title" data-lgid="P_JDN_XXX">My Organizations</span><em class="dialog-close"></em></div>
<div class="dialog-content">
<div id="myorganization_list"></div>
</div>
<div class="dialog-func" style="margin-top: 16px;">
<div class="clear"></div>
</div>
</div>
</asp:Content>