2023-04-28 12:22:26 +08:00

187 lines
7.3 KiB
JavaScript

define(['modules/packages/createpackage'], function (CreatePackageModule) {
var exppkg = {};
exppkg.title = GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages');
exppkg.description = GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages');
exppkg.version = '1.0';
exppkg.status = 0;
var datacontent = null;
var grid_dt;
exppkg.createContent = function (args) {
var _this = this;
if (args && args.length > 0)
exppkg.status = eval(args[0]);
var content = $('<div style="width:100%;" ></div>');
function createHeader() {
var header = $('<div></div>');
header.append($('<div class="page_title"></div>').text(exppkg.title));
setPageTitle(exppkg.title, true);
var func = $('<div class="function_title"></div>');
var iconCreate = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_CREATE", "Create") + '</span>').click(function () {
exppkg.oncreate();
});
func.append(iconCreate);
var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () {
exppkg.refresh();
});
func.append(iconRefresh);
header.append(func)
return header;
}
function InitGridData() {
var div_grid = $('<div style="padding-right:10px;"></div>');
div_grid.css("height", $(window).height() - 145);
grid_dt = new GridView(div_grid);
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: 'PackageName', caption: GetTextByKey("P_IPT_PACKAGENAME", "Package Name"), valueIndex: 'PackageName', css: { 'width': 300, 'text-align': 'left' } },
{ name: 'Notes', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 300, 'text-align': 'left' } },
{ name: 'Creator', caption: GetTextByKey("P_IPT_CREATOR", "Creator"), valueIndex: 'Creator', css: { 'width': 250, 'text-align': 'left' } },
{ name: 'CreatedOnLocal', caption: GetTextByKey("P_IPT_DATETIMECREATED", "Date/Time Created"), valueIndex: 'CreatedOnLocal', css: { 'width': 180, 'text-align': 'left' } },
{ name: 'DownLoad', caption: "", css: { 'width': 30, '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;
if (ReportReadonly && col.name === 'Edit') {
continue;
}
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 === "DownLoad") {
col.isurl = true;
col.text = "\uf019";
col.sortable = false;
col.events = {
onclick: function () {
_this.onDownLoadPackage();
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.attrs = { 'title': GetTextByKey("P_IPT_DOWNLOADPACKAGE", 'Download Package') };
}
else if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.sortable = false;
col.events = {
onclick: function () {
_this.onDeletePackage();
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.attrs = { 'title': GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package') };
}
columns.push(col);
}
grid_dt.canMultiSelect = false;
grid_dt.columns = columns;
grid_dt.init();
grid_dt.rowdblclick = _this.onDownLoad;
grid_dt.selectedrowchanged = function (rowindex) {
var rowdata = grid_dt.source[rowindex];
if (rowdata) {
}
}
return div_grid;
}
content.append(createHeader());
content.append(InitGridData());
datacontent = $('<div></div>');
content.append(datacontent);
_this.refresh();
return content;
}
exppkg.oncreate = function () {
var _this = this;
var ei = new CreatePackageModule.CreatePackage(_this);
$('#right_popup').empty().append(ei.createContent());
showRightPopup(true);
}
exppkg.onDeletePackage = function () {
var _this = this;
var index = grid_dt.selectedIndex;
var package = grid_dt.source[index].Values;
showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISPACKAGE", 'Are you sure you want to delete this package?'), GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package'), function () {
var p = JSON.stringify([teamintelligence, htmlencode(package.PackageId)]);
inspectionrequest("DeletePackage", p, function (data) {
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package'));
return;
}
_this.refresh();
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTODELETEPACKAGE", 'Failed to delete package.'), GetTextByKey("P_IPT_DELETEPACKAGE", 'Delete Package'));
});
});
}
exppkg.onDownLoadPackage = function () {
var index = grid_dt.selectedIndex;
var package = grid_dt.source[index].Values;
window.open("../filesvc.ashx?sourceType=ipackage&attchid=" + package.PackageId);
}
function showPackages(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "CreatedOnLocal") {
r[j] = { DisplayValue: r["CreatedOnLocalStr"], Value: r[j] };
}
}
var fr = { Values: r };
rows.push(fr);
}
grid_dt.setData(rows);
}
exppkg.refresh = function () {
datacontent.empty();
inspectionrequest("GetCreatedPackages", '', function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_IPT_EXPORTPACKAGES", 'Export Packages'));
return;
}
datacontent.empty();
if (data) {
showPackages(data);
}
}, function (err) {
});
}
return exppkg;
});