361 lines
14 KiB
TypeScript
361 lines
14 KiB
TypeScript
import { Global } from "../../Core/Globals"
|
|
import { EventManager } from "../../Core/Events"
|
|
import { Ui } from "../../Core/Ui"
|
|
import * as Events from "../../Core/EventDefinitions"
|
|
import { LocalizationManager } from "../../Core/Localization"
|
|
import { Grid, Sort, Filter, Page, RowSelectEventArgs, Resize, ColumnChooser, Reorder } from "@syncfusion/ej2-grids"
|
|
import { Query, DataManager, UrlAdaptor } from "@syncfusion/ej2-data";
|
|
import * as Models from "../../Common/Models";
|
|
import * as Utility from "../../Core/Utility";
|
|
import { setValue, getValue } from "@syncfusion/ej2-base";
|
|
import ProductCountryItem = Models.ProductCountryItem;
|
|
import ShopVisibility = Models.ShopVisibility;
|
|
import ProductType = Models.ProductType;
|
|
|
|
|
|
class ProductCountriesModule {
|
|
private _moduleName = "ProductCountriesModule";
|
|
private _component = "#productCountriesContainer";
|
|
private _global: Global;
|
|
private _eventManager: EventManager;
|
|
private _uiManager: Ui;
|
|
private _localizationMananger: LocalizationManager;
|
|
private _data: any;
|
|
private _grid: Grid;
|
|
private _dataManager: DataManager;
|
|
|
|
constructor() {
|
|
this._global = Global.getInstance();
|
|
this._eventManager = EventManager.getInstance();
|
|
this._uiManager = Ui.getInstance();
|
|
this._localizationMananger = LocalizationManager.getInstance();
|
|
Grid.Inject(Sort, Filter, Page, Resize, ColumnChooser, Reorder);
|
|
}
|
|
|
|
/**
|
|
* Stellt einen Prefix vor einen Selektor
|
|
* @param selector
|
|
*/
|
|
private prefix(selector: string): string {
|
|
const self = this;
|
|
if ($(`${self._component} ${selector}`).length > 0)
|
|
return `${self._component} ${selector}`;
|
|
return `html ${selector}`;
|
|
}
|
|
|
|
/**
|
|
* Einstellungen für die Liste machen
|
|
*/
|
|
private setupList(): void {
|
|
var self = this;
|
|
|
|
self._dataManager = new DataManager({
|
|
url: <string>$(self.prefix("#jsGetUrl")).val(),
|
|
adaptor: new UrlAdaptor(),
|
|
crossDomain: true,
|
|
headers: [{ "X-Requested-With": "XmlHttpRequest" }]
|
|
});
|
|
|
|
self._uiManager.blockUi(self.prefix("#listCountriesContainer"));
|
|
var query = new Query().addParams("searchValue", $(self.prefix("#search")).valForSearch());
|
|
self._grid = new Grid({
|
|
dataSource: self._dataManager,
|
|
query: query,
|
|
height: 450,
|
|
enablePersistence: true,
|
|
allowSorting: true,
|
|
allowFiltering: true,
|
|
allowPaging: true,
|
|
allowResizing: true,
|
|
allowReordering: true,
|
|
showColumnChooser: true,
|
|
gridLines: "Vertical",
|
|
filterSettings: { type: "Menu" },
|
|
sortSettings: { columns: [{ field: "countryIso", direction: <any>"Ascending" }] },
|
|
selectionSettings: { checkboxMode: "ResetOnRowClick", checkboxOnly: false },
|
|
columns: <any>[
|
|
{ field: "select", type: "checkbox", width: 50, allowFiltering: false, allowSorting: false, showInColumnChooser: false, allowReordering: false },
|
|
{ field: "id", type: "number", visible: false, showInColumnChooser: false },
|
|
{ field: "countryIso", headerText: self._localizationMananger.get("Common_Country"), type: "string", template: "#flagTemplate" },
|
|
{ field: "price", headerText: self._localizationMananger.get("Product_Price"), type: "number", format: "n4", textAlign: "right" },
|
|
{ field: "oldPrice", headerText: self._localizationMananger.get("Product_OldPrice"), type: "number", format: "n4", textAlign: "right" },
|
|
{ field: "price2", headerText: self._localizationMananger.get("Product_Price2"), type: "number", format: "n4", textAlign: "right" },
|
|
{ field: "oldPrice2", headerText: self._localizationMananger.get("Product_OldPrice2"), type: "number", format: "n4", textAlign: "right" },
|
|
{ field: "notAvailable", headerText: self._localizationMananger.get("Product_NotAvailable"), type: "boolean", displayAsCheckBox: true },
|
|
],
|
|
pageSettings: { pageSizes: [5, 10, 25, 50, 100], pageSize: 50 },
|
|
rowSelected: function (args: RowSelectEventArgs) {
|
|
self.handleSelection();
|
|
},
|
|
rowDeselected: function (args: any) {
|
|
self.handleSelection();
|
|
},
|
|
recordDoubleClick: function (args: any) {
|
|
self._grid.clearSelection();
|
|
if (args.rowIndex !== undefined) {
|
|
self._grid.selectRow(args.rowIndex);
|
|
self.edit();
|
|
}
|
|
},
|
|
headerCellInfo: function (args) {
|
|
if (args.cell.column.field !== "select") {
|
|
const toolcontent = args.cell.column.headerText;
|
|
args.node.setAttribute("title", toolcontent);
|
|
args.node.setAttribute("data-placement", "top");
|
|
args.node.setAttribute("data-toggle", "tooltip");
|
|
}
|
|
},
|
|
dataBound: function () {
|
|
const cloned = getValue("addOnPersist", self._grid);
|
|
setValue("addOnPersist", function (key) {
|
|
key = key.filter(item => item !== "selectedRowIndex");
|
|
return cloned.call(this, key);
|
|
}, self._grid);
|
|
setTimeout(() => { $(".tooltip").remove(); $('[data-toggle="tooltip"]').tooltip(); }, 500);
|
|
},
|
|
actionComplete: function (args) {
|
|
if (args.requestType === "filterafteropen") {
|
|
if (args.filterModel.dlgDiv.querySelector(".e-autocomplete")) {
|
|
var autoObject = args.filterModel.dlgDiv.querySelector(".e-autocomplete").ej2_instances[0];
|
|
autoObject.autofill = false;
|
|
autoObject.minLength = 20;
|
|
autoObject.open = args => { args.popup.element.classList.add("d-none"); };
|
|
}
|
|
}
|
|
}
|
|
});
|
|
self._grid.appendTo(self.prefix("#gridProductCountries"));
|
|
self._uiManager.unblockUi(self.prefix("#listCountriesContainer"));
|
|
}
|
|
|
|
|
|
/**
|
|
* Bei Auswahl oder abwahl einer Row...
|
|
*/
|
|
private handleSelection(): void {
|
|
var self = this;
|
|
let rows = self._grid.getSelectedRecords() as Array<ProductCountryItem>;
|
|
if (rows.length === 0) {
|
|
$(self.prefix("#btnEdit")).prop("disabled", true);
|
|
$(self.prefix("#btnDelete")).prop("disabled", true);
|
|
}
|
|
else {
|
|
if (rows.length === 1) {
|
|
$(self.prefix("#btnEdit")).prop("disabled", false);
|
|
} else {
|
|
$(self.prefix("#btnEdit")).prop("disabled", true);
|
|
}
|
|
$(self.prefix("#btnDelete")).prop("disabled", false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Laden der Einträge
|
|
*/
|
|
private loadItems(): void {
|
|
var self = this;
|
|
self._grid.clearSelection();
|
|
self._grid.refresh();
|
|
self.handleSelection();
|
|
}
|
|
|
|
/**
|
|
* Behandeln der Suche via Feld
|
|
*/
|
|
private _oldSearch = "";
|
|
private handleSearch(): void {
|
|
var self = this;
|
|
if ($(self.prefix("#search")).doSearch(2)) {
|
|
var search = $(self.prefix("#search")).valForSearch(2);
|
|
if (self._oldSearch !== search) {
|
|
self._oldSearch = search;
|
|
self._grid.clearSelection();
|
|
self._grid.query = new Query().addParams("searchValue", $(self.prefix("#search")).valForSearch(2));
|
|
self.handleSelection();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* anlegen
|
|
*/
|
|
private create(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsCreateUrl")).val(),
|
|
data: <any>{},
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
$(self.prefix("#detailCountries")).html(data);
|
|
$(self.prefix("#listCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#detailCountries")).fadeIn("slow");
|
|
});
|
|
},
|
|
error() {
|
|
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* bearbeiten
|
|
*/
|
|
private edit(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsEditUrl")).val(),
|
|
data: <any>{ id: (<ProductCountryItem>self._grid.getSelectedRecords()[0]).id },
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
$(self.prefix("#detailCountries")).html(data);
|
|
$(self.prefix("#listCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#detailCountries")).fadeIn("slow");
|
|
});
|
|
},
|
|
error() {
|
|
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Löschen
|
|
*/
|
|
private delete(): void {
|
|
var self = productCountriesModule; //Hier so weil Callback!
|
|
self._uiManager.blockMainUi();
|
|
let rows = self._grid.getSelectedRecords() as Array<ProductCountryItem>;
|
|
if (rows.length > 0) {
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsDeleteUrl")).val(),
|
|
data: <any>{ ids: rows.map(({ id }) => id) },
|
|
dataType: "json",
|
|
type: "POST",
|
|
success(response) {
|
|
if (response.success)
|
|
self._uiManager.showSuccessMessage(self._localizationMananger.get("Common_Delete_Success"));
|
|
else
|
|
self._uiManager.showWarningMessage(response.errorMessage);
|
|
self.loadItems();
|
|
},
|
|
error(e) {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Delete_NoSuccess"));
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bindungen erstellen
|
|
*/
|
|
private setupBindings(): void {
|
|
var self = this;
|
|
|
|
$(self.prefix("#btnBack")).off("click").on("click", function () {
|
|
|
|
var persistData = self._grid.getPersistData();
|
|
localStorage.setItem("grid" + "gridProductCountries", persistData);
|
|
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(Events.Product.countriesBack);
|
|
});
|
|
|
|
$(self.prefix("#btnColumns")).off("click").on("click", function () {
|
|
self._grid.columnChooserModule.openColumnChooser();
|
|
});
|
|
|
|
$(self.prefix("#btnAdd")).off("click").on("click", function () {
|
|
self.create();
|
|
});
|
|
|
|
$(self.prefix("#btnEdit")).off("click").on("click", function () {
|
|
self.edit();
|
|
});
|
|
|
|
$(self.prefix("#btnDelete")).off("click").on("click", function () {
|
|
if (self._grid.getSelectedRows().length === 1) {
|
|
self._uiManager.showModal(self._localizationMananger.get("Common_Delete_Question"), true, self.delete);
|
|
}
|
|
else if (self._grid.getSelectedRows().length > 1) {
|
|
self._uiManager.showModal(self._localizationMananger.get("Common_Delete_Question_Batch"), true, self.delete);
|
|
}
|
|
});
|
|
|
|
|
|
$(self.prefix("#search")).on("keyup change", Utility.debounce(() => {
|
|
self.handleSearch();
|
|
}, 500));
|
|
|
|
self._eventManager.subscribe(Events.ProductCountry.createCancel, self._moduleName, function () {
|
|
$(self.prefix("#detailCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#listCountries")).fadeIn();
|
|
$(self.prefix("#detailCountries")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.ProductCountry.createSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detailCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#listCountries")).fadeIn();
|
|
$(self.prefix("#detailCountries")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.ProductCountry.editCancel, self._moduleName, function () {
|
|
$(self.prefix("#detailCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#listCountries")).fadeIn();
|
|
$(self.prefix("#detailCountries")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.ProductCountry.editSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detailCountries")).fadeOut("slow", () => {
|
|
$(self.prefix("#listCountries")).fadeIn();
|
|
$(self.prefix("#detailCountries")).html("");
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Aktivieren des Moduls
|
|
*/
|
|
public activate(): void {
|
|
|
|
var self = this;
|
|
$.setupValidator();
|
|
$.reinitializeValidator();
|
|
this.setupBindings();
|
|
self.setupList();
|
|
self._uiManager.pageTitleAdd(self._component, self.prefix("#pageTitleAdd"));
|
|
$.randomAutocompleteValue();
|
|
}
|
|
|
|
/**
|
|
* Initialisieren des Moduls
|
|
*/
|
|
public init(): void {
|
|
if (this._global.appInitialized) {
|
|
productCountriesModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let productCountriesModule = new ProductCountriesModule();
|
|
productCountriesModule.init(); |