add site
This commit is contained in:
376
Site/Inspection/js/modules/importpackages.js
Normal file
376
Site/Inspection/js/modules/importpackages.js
Normal file
@ -0,0 +1,376 @@
|
||||
define([], function () {
|
||||
var imppkg = {};
|
||||
|
||||
var txtfilename;
|
||||
var txtpwd;
|
||||
var btnbrowse;
|
||||
var btnunpackpkg;
|
||||
var txtname;
|
||||
var txtnotes;
|
||||
var grid_templatedt;
|
||||
var grid_sectiondt;
|
||||
var divpkg;
|
||||
|
||||
var tempgridholder;
|
||||
var sectiongridholder;
|
||||
|
||||
var filedata;
|
||||
|
||||
function InitTemplateGridData() {
|
||||
var div_grid = $('<div style="margin-top:5px;"></div>');
|
||||
div_grid.css("height", 200);
|
||||
|
||||
grid_templatedt = new GridView(div_grid);
|
||||
grid_templatedt.lang = {
|
||||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||||
};
|
||||
var list_columns = [
|
||||
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
|
||||
{ name: 'TemplateName', caption: GetTextByKey("P_TEMPLATE", "Template"), valueIndex: 'Name', css: { 'width': 320, 'text-align': 'left' } },
|
||||
{ name: 'AssetName', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 400, '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;
|
||||
col.allowFilter = list_columns[hd].allowFilter;
|
||||
if (list_columns[hd].type) {
|
||||
col.type = list_columns[hd].type;
|
||||
}
|
||||
if (col.name === 'Selected') {
|
||||
col.allcheck = true;
|
||||
col.sortable = false;
|
||||
}
|
||||
|
||||
columns.push(col);
|
||||
}
|
||||
grid_templatedt.canMultiSelect = false;
|
||||
grid_templatedt.columns = columns;
|
||||
grid_templatedt.init();
|
||||
|
||||
return div_grid;
|
||||
}
|
||||
|
||||
function showTemplates(data) {
|
||||
var rows = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var r = data[i];
|
||||
r.Selected = true;
|
||||
var fr = { Values: r };
|
||||
rows.push(fr);
|
||||
}
|
||||
|
||||
grid_templatedt.setData(rows);
|
||||
}
|
||||
|
||||
|
||||
function InitSectionGridData() {
|
||||
var div_grid = $('<div style="margin-top:5px;"></div>');
|
||||
div_grid.css("height", 200);
|
||||
|
||||
grid_sectiondt = new GridView(div_grid);
|
||||
grid_sectiondt.lang = {
|
||||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||||
};
|
||||
var list_columns = [
|
||||
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
|
||||
{ name: 'SectionName', caption: GetTextByKey("P_IPT_SECTION", "Section"), valueIndex: 'ItemName', css: { 'width': 320, 'text-align': 'left' } },
|
||||
{ name: 'AssetName', caption: GetTextByKey("P_IPT_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 400, '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;
|
||||
col.allowFilter = list_columns[hd].allowFilter;
|
||||
if (list_columns[hd].type) {
|
||||
col.type = list_columns[hd].type;
|
||||
}
|
||||
if (col.name === 'Selected') {
|
||||
col.allcheck = true;
|
||||
col.sortable = false;
|
||||
}
|
||||
|
||||
columns.push(col);
|
||||
}
|
||||
grid_sectiondt.canMultiSelect = false;
|
||||
grid_sectiondt.columns = columns;
|
||||
grid_sectiondt.init();
|
||||
|
||||
return div_grid;
|
||||
}
|
||||
|
||||
function showGlobalSections(data) {
|
||||
var rows = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var r = data[i];
|
||||
r.Selected = true;
|
||||
var fr = { Values: r };
|
||||
rows.push(fr);
|
||||
}
|
||||
|
||||
grid_sectiondt.setData(rows);
|
||||
}
|
||||
|
||||
function onImport(_this, overwritten) {
|
||||
var alerttitle = GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package');
|
||||
if (!filedata) {
|
||||
showAlert(GetTextByKey("P_IPT_PLEASESELECTTHEPACKAGEFILE", 'Please select the package file.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
if (txtname.text() == "") {
|
||||
showAlert(GetTextByKey("P_IPT_PLEASEUNPACKTHEPACKAGE", 'Please unpack the package.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
|
||||
var templateids = [];
|
||||
for (var i = 0; i < grid_templatedt.source.length; i++) {
|
||||
var t = grid_templatedt.source[i].Values;
|
||||
if (t.Selected)
|
||||
templateids.push(t.Id);
|
||||
}
|
||||
|
||||
var sectionids = [];
|
||||
for (var i = 0; i < grid_sectiondt.source.length; i++) {
|
||||
var t = grid_sectiondt.source[i].Values;
|
||||
if (t.Selected)
|
||||
sectionids.push(t.ItemId);
|
||||
}
|
||||
if (templateids.length < 1 && sectionids.length < 1) {
|
||||
showAlert(GetTextByKey("P_IPT_PLEASESELECTATLEASTONETEMPLATEORGLOBALSECTIONTOIMPORT", 'Please select at least one template or global section to import.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
|
||||
_this.loading && _this.loading.fadeIn(100);
|
||||
|
||||
var p = [overwritten, JSON.stringify(templateids), JSON.stringify(sectionids)];
|
||||
p = JSON.stringify(p);
|
||||
var formData = new FormData();
|
||||
formData.append("pkgfile", filedata);
|
||||
formData.append("MethodName", "ImportPackage");
|
||||
formData.append("ClientData", htmldecode(p));
|
||||
$.ajax({
|
||||
url: 'Inspection.aspx?tp=ashx',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
processData: false,
|
||||
contentType: false,
|
||||
data: formData,
|
||||
async: true,
|
||||
success: function (data) {
|
||||
if (data === "OK") {
|
||||
showAlert(GetTextByKey("P_IPT_PACKAGEHASBEENIMPORTEDSUCCESSFULLY", 'Package has been imported successfully.'), alerttitle);
|
||||
filedata = null;
|
||||
divpkg.hide();
|
||||
txtfilename.val("");
|
||||
txtpwd.val("");
|
||||
txtname.text("");
|
||||
txtnotes.html("");
|
||||
} else {
|
||||
showAlert(data, alerttitle);
|
||||
}
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
},
|
||||
error: function (err) {
|
||||
showAlert(err.statusText, alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getPackageData(_this) {
|
||||
var alerttitle = GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package');
|
||||
var pwd = txtpwd.val();
|
||||
if (!pwd || pwd == "") {
|
||||
showAlert(GetTextByKey("P_IPT_PASSWORDISREQUIRED", 'Password is required.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
_this.loading && _this.loading.fadeIn(100);
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("pkgfile", filedata);
|
||||
formData.append("MethodName", "GetPackageData");
|
||||
formData.append("ClientData", htmldecode(pwd));
|
||||
$.ajax({
|
||||
url: 'Inspection.aspx?tp=ashx',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
processData: false,
|
||||
contentType: false,
|
||||
data: formData,
|
||||
async: true,
|
||||
success: function (data) {
|
||||
if (typeof (data) === "string") {
|
||||
showAlert(data, alerttitle);
|
||||
} else {
|
||||
showPackageData(data);
|
||||
}
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
},
|
||||
error: function (err) {
|
||||
showAlert(err.statusText, alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showPackageData(pkgdata) {
|
||||
divpkg.show();
|
||||
reshowgrid();
|
||||
txtname.text(pkgdata.PackageName);
|
||||
txtnotes.html(replaceHtmlText(pkgdata.Notes));
|
||||
showTemplates(pkgdata.Templates);
|
||||
showGlobalSections(pkgdata.GlobalSections);
|
||||
}
|
||||
|
||||
imppkg.createContent = function () {
|
||||
var _this = this;
|
||||
setPageTitle(GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'), true);
|
||||
var content = $('<div style="padding-left:10px;padding-right:10px;"></div>');
|
||||
this.content = content;
|
||||
var funcs = $('<div class="function_title"></div>');
|
||||
var btn = $('<span class="sbutton iconsave">' + GetTextByKey('P_IPT_IMPORT', 'Import') + '</span>').click(function () {
|
||||
showConfirm(GetTextByKey("P_IPT_DOYOUWANTTOOVERWRITETHEITEMSWHICHHAVEANEWERVERSION", 'Do you want to overwrite the items which have a higher version?'), GetTextByKey("P_IPT_IMPORTPACKAGE", 'Import Package'), function () {
|
||||
onImport(_this, 1);
|
||||
}, function () {
|
||||
onImport(_this, 0);
|
||||
});
|
||||
});
|
||||
funcs.append(btn);
|
||||
content.append(funcs);
|
||||
|
||||
var tb = $('<table style="line-height:24px;"></table>');
|
||||
content.append(tb);
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
var td = $('<td class="label" style="width:160px;">' + GetTextByKey('P_IPT_IMPORTPACKAGEFILE_COLON', 'Import Package File:') + '</td>');
|
||||
tr.append(td);
|
||||
td = $('<td></td>');
|
||||
tr.append(td);
|
||||
txtfilename = $('<input type="text" maxlength=100 style="width: 500px; height: 21px;margin-top:5px;margin-bottom:5px;" disabled="disabled"></input>');
|
||||
td.append(txtfilename);
|
||||
btnbrowse = $('<input type="button" value="' + GetTextByKey('P_IPT_BROWSE', 'Browse...') + '" style="margin-left:10px;width:80px;"></input>');
|
||||
td.append(btnbrowse);
|
||||
btnbrowse.click(function UpLoadMachineIcon(type, e) {
|
||||
var file = $('<input type="file" style="display: none;" />')
|
||||
file.change(function () {
|
||||
filedata = this.files[0];
|
||||
txtname.text("");
|
||||
txtnotes.html("")
|
||||
if (filedata) {
|
||||
txtfilename.val(filedata.name);
|
||||
btnunpackpkg.prop("disabled", false);
|
||||
}
|
||||
}).click();
|
||||
});
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
td = $('<td class="label" style="width:160px;">Password:</td>');
|
||||
tr.append(td);
|
||||
td = $('<td></td>');
|
||||
tr.append(td);
|
||||
txtpwd = $('<input type="password" maxlength=16 style="width: 500px; height: 21px;margin-top:5px;margin-bottom:5px;"></input>');
|
||||
td.append(txtpwd);
|
||||
btnunpackpkg = $('<input type="button" value="' + GetTextByKey('P_IPT_UNPACK', 'Unpack') + '" style="margin-left:10px;width:80px;" disabled="disabled"></input>');
|
||||
td.append(btnunpackpkg);
|
||||
btnunpackpkg.click(function () {
|
||||
getPackageData(_this);
|
||||
});
|
||||
|
||||
divpkg = $('<div style="display:none;"></div>');
|
||||
content.append(divpkg);
|
||||
|
||||
var tb = $('<table style="line-height:24px;"></table>');
|
||||
divpkg.append(tb);
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
var td = $('<td class="label" style="width:160px;">Name:</td>');
|
||||
tr.append(td);
|
||||
td = $('<td></td>');
|
||||
tr.append(td);
|
||||
txtname = $('<span></span>');
|
||||
td.append(txtname);
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
var td = $('<td class="label" style="width:160px;vertical-align:top;">Notes:</td>');
|
||||
tr.append(td);
|
||||
td = $('<td></td>');
|
||||
tr.append(td);
|
||||
txtnotes = $('<div></div>');
|
||||
td.append(txtnotes);
|
||||
|
||||
var ul = $('<ul class="tab_header" style="padding-top: 5px;"></ul>');
|
||||
divpkg.append(ul);
|
||||
|
||||
var tabName = "tabTemplates";
|
||||
var templi = $('<li></li>').attr('data-href', tabName);
|
||||
ul.append(templi);
|
||||
templi.append($('<span></span>').text(GetTextByKey("P_TEMPLATES", 'Templates')));
|
||||
templi.click(function () {
|
||||
reshowgrid();
|
||||
});
|
||||
tempgridholder = InitTemplateGridData();
|
||||
tempgridholder.attr('data-page', tabName)
|
||||
divpkg.append(tempgridholder);
|
||||
|
||||
tabName = "tabSections";
|
||||
var li = $('<li></li>').attr('data-href', tabName);
|
||||
ul.append(li);
|
||||
li.append($('<span></span>').text(GetTextByKey("P_GLOBALSECTIONS", 'Global Sections')));
|
||||
li.click(function () {
|
||||
reshowgrid();
|
||||
});
|
||||
sectiongridholder = InitSectionGridData();
|
||||
sectiongridholder.attr('data-page', tabName)
|
||||
divpkg.append(sectiongridholder);
|
||||
|
||||
ul.append($('<li style="clear: both;"></li>'));
|
||||
|
||||
divpkg.tab();
|
||||
templi.click();
|
||||
|
||||
//divpkg.append($('<span style="margin-left:5px;font-size:16px;font-weight:bold;">Templates</span>'));
|
||||
//divpkg.append(InitTemplateGridData());
|
||||
|
||||
//divpkg.append($('<span style="margin-left:5px;font-size:16px;font-weight:bold;">Global Sections</span>'));
|
||||
//divpkg.append(InitSectionGridData());
|
||||
|
||||
var loading = $('<div id="mask_bg" style="display:none;"></div>');
|
||||
_this.loading = loading;
|
||||
content.append(loading);
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
function reshowgrid() {
|
||||
setTimeout(function () {
|
||||
tempgridholder.css("height", $(window).height() - tempgridholder.offset().top - 15);
|
||||
grid_templatedt && grid_templatedt.resize();
|
||||
sectiongridholder.css("height", $(window).height() - sectiongridholder.offset().top - 15);
|
||||
grid_sectiondt && grid_sectiondt.resize();
|
||||
});
|
||||
}
|
||||
|
||||
return imppkg;
|
||||
});
|
Reference in New Issue
Block a user