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_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': 45, '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_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': 45, '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 = $('
'); this.content = content; var funcs = $('
'); var btn = $('' + GetTextByKey('P_IPT_IMPORT', 'Import') + '').click(function () { showConfirmYesNoCancel(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); }, function () { return; }); }); funcs.append(btn); content.append(funcs); var tb = $('
'); content.append(tb); var tr = $(''); tb.append(tr); var td = $('' + GetTextByKey('P_IPT_IMPORTPACKAGEFILE_COLON', 'Import Package File:') + ''); tr.append(td); td = $(''); tr.append(td); txtfilename = $(''); td.append(txtfilename); btnbrowse = $(''); td.append(btnbrowse); btnbrowse.click(function UpLoadMachineIcon(type, e) { var file = $('') file.change(function () { filedata = this.files[0]; txtname.text(""); txtnotes.html("") if (filedata) { txtfilename.val(filedata.name); btnunpackpkg.prop("disabled", false); } }).click(); }); var tr = $(''); tb.append(tr); td = $('Password:'); tr.append(td); td = $(''); tr.append(td); txtpwd = $(''); td.append(txtpwd); btnunpackpkg = $(''); td.append(btnunpackpkg); btnunpackpkg.click(function () { getPackageData(_this); }); divpkg = $('
'); content.append(divpkg); var tb = $('
'); divpkg.append(tb); var tr = $(''); tb.append(tr); var td = $('Name:'); tr.append(td); td = $(''); tr.append(td); txtname = $(''); td.append(txtname); var tr = $(''); tb.append(tr); var td = $('Notes:'); tr.append(td); td = $(''); tr.append(td); txtnotes = $('
'); td.append(txtnotes); var ul = $(''); divpkg.append(ul); var tabName = "tabTemplates"; var templi = $('
  • ').attr('data-href', tabName); ul.append(templi); templi.append($('').text(GetTextByKey("P_TEMPLATES", 'Templates'))); templi.click(function () { reshowgrid(); }); tempgridholder = InitTemplateGridData(); tempgridholder.attr('data-page', tabName) divpkg.append(tempgridholder); tabName = "tabSections"; var li = $('
  • ').attr('data-href', tabName); ul.append(li); li.append($('').text(GetTextByKey("P_GLOBALSECTIONS", 'Global Sections'))); li.click(function () { reshowgrid(); }); sectiongridholder = InitSectionGridData(); sectiongridholder.attr('data-page', tabName) divpkg.append(sectiongridholder); ul.append($('
  • ')); divpkg.tab(); templi.click(); //divpkg.append($('Templates')); //divpkg.append(InitTemplateGridData()); //divpkg.append($('Global Sections')); //divpkg.append(InitSectionGridData()); var loading = $(''); _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; });