fleet-contractor/Site/Credentials/ManageJDLink.aspx
2024-03-26 15:56:31 +08:00

610 lines
26 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">
<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] };
}
rows.push(r);
}
grid_dt.setData(rows);
}
var grid_dt;
function InitGridData() {
grid_dt = createGridView('#jdlinklist');
var list_columns = [
{ name: 'AccountName', caption: GetTextByKey("P_JDL_ACCOUNTNAME", "Account Name"), valueIndex: 'AccountName', allowFilter: true, 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', valueIndex: 'Organization', caption: "", css: { 'width': 110, 'text-align': 'center' } },
{ name: 'ManageOrganization', valueIndex: 'ManageOrganization', caption: "", css: { 'width': 140, '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;
col.allowFilter = list_columns[hd].allowFilter;
if (col.name === "Delete") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Icon;
col.text = 'times';
col.iconType = 'fa-light';
col.events = {
onclick: function () {
OnDelete(this);
}
};
col.attrs = { 'title': GetTextByKey("P_JDL_DELETE", 'Delete') };
}
else if (col.name === "Organization") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Common;
col.styleFilter = function () { return { 'color': 'blue', "cursor": "pointer" } };
col.filter = function () { return GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations"); };
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 0);
}
};
col.attrs = { 'title': GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations") };
}
else if (col.name === "ManageOrganization") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Common;
col.styleFilter = function () { return { 'color': 'blue', "cursor": "pointer" } };
col.filter = function () { return GetTextByKey("P_JDL_MANAGEORGANIZATIONS", "Manage Organizations"); };
col.events = {
onclick: function () {
GetJDOrganizationUrl(this);
}
};
col.attrs = { 'title': GetTextByKey("P_JDL_MANAGEORGANIZATIONS", "Manage Organizations") };
}
columns.push(col);
}
grid_dt.canMultiSelect = false;
grid_dt.columns = columns;
grid_dt.init();
}
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] };
}
rows.push(r);
}
grid_dtmyjd.setData(rows);
}
var grid_dtmyjd;
function InitGridMyJDData() {
grid_dtmyjd = createGridView('#myjdlist');
var list_columns = [
{ name: 'AccountName', caption: GetTextByKey("P_JDL_ACCOUNTNAME", "Account Name"), valueIndex: 'AccountName', allowFilter: true, 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', valueIndex: 'Organization', caption: "", css: { 'width': 110, 'text-align': 'center' } },
{ name: 'ManageOrganization', valueIndex: 'ManageOrganization', caption: "", css: { 'width': 140, '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;
col.allowFilter = list_columns[hd].allowFilter;
if (col.name === "Delete") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Icon;
col.text = 'times';
col.iconType = 'fa-light';
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.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Common;
col.styleFilter = function () { return { 'color': 'blue', "cursor": "pointer" } };
col.filter = function () { return GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations"); };
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 1);
}
};
col.attrs = { 'title': GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations") };
}
else if (col.name === "ManageOrganization") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Common;
col.styleFilter = function () { return { 'color': 'blue', "cursor": "pointer" } };
col.filter = function () { return GetTextByKey("P_JDL_MANAGEORGANIZATIONS", "Manage Organizations"); };
col.events = {
onclick: function () {
GetJDOrganizationUrl(this);
}
};
col.attrs = { 'title': GetTextByKey("P_JDL_MANAGEORGANIZATIONS", "Manage Organizations") };
}
columns.push(col);
}
grid_dtmyjd.canMultiSelect = false;
grid_dtmyjd.columns = columns;
grid_dtmyjd.init();
}
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('');
showmaskbg(true);
$('#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] };
}
rows.push(r);
}
grid_dtnotification.setData(rows);
}
var grid_dtnotification;
function InitGridNotificationData() {
grid_dtnotification = createGridView('#jdnotificationlist');
var list_columns = [
{ name: 'DisplayName', caption: GetTextByKey("P_JDN_DISPLAYAME", "Display Name"), valueIndex: 'DisplayName', allowFilter: true, css: { 'width': 400, 'text-align': 'left' } },
{ name: 'AccountName', caption: GetTextByKey("P_JDL_USERNAME", "User Name"), valueIndex: 'AccountName', allowFilter: true, 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;
col.allowFilter = list_columns[hd].allowFilter;
if (col.name === "Delete") {
col.sortable = false;
col.resizable = false;
col.type = GridView.ColumnTypes.Icon;
col.text = 'times';
col.iconType = 'fa-light';
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.text = GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations");
col.sortable = false;
col.events = {
onclick: function () {
openMyOrganizationsDialog(this, 2);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_JDL_MYORGANIZATIONS", "My Organizations") };
}
columns.push(col);
}
grid_dtnotification.canMultiSelect = false;
grid_dtnotification.columns = columns;
grid_dtnotification.init();
}
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] };
}
rows.push(r);
}
grid_dtmyorgs.setData(rows);
}
var grid_dtmyorgs;
function InitGridMyOrgData() {
grid_dtmyorgs = createGridView('#myorganization_list');
var list_columns = [
{ name: 'Id', caption: GetTextByKey("P_JDL_ID", "Id"), valueIndex: 'Id', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'Name', caption: GetTextByKey("P_JDL_NAME", "Name"), valueIndex: 'Name', css: { 'width': 300, 'text-align': 'left' } },
{ name: 'OrgType', caption: GetTextByKey("P_JDL_TYPE", "Type"), valueIndex: 'OrgType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Member', caption: GetTextByKey("P_JDL_MEMBER", "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();
}
//**************************************End My Organizations***************************************************//
$(function () {
setPageTitle(GetTextByKey("P_JDLINK", 'JD Link'), true);
InitGridData();
InitGridMyJDData();
InitGridNotificationData();
InitGridMyOrgData();
OnRefresh();
OnRefreshMyJD();
OnRefreshNotification();
$('#dialog_credential').dialog(function () {
showmaskbg(false);
});
$('#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_JDL_MYORGANIZATIONS">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>