559 lines
25 KiB
TypeScript
559 lines
25 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 { createElement } from "@syncfusion/ej2-base";
|
|
import { DropDownList } from "@syncfusion/ej2-dropdowns";
|
|
import ListingListItem = Models.ListingListItem;
|
|
import ListingType = Models.ListingType;
|
|
import ListingStatus = Models.ListingStatus;
|
|
import PaymentType = Models.PaymentType;
|
|
import PaymentStatus = Models.PaymentStatus;
|
|
import GeoMode = Models.GeoMode;
|
|
|
|
|
|
class ListingsCustomerModule {
|
|
private _moduleName = "ListingsCustomerModule";
|
|
private _component = "#listingsCustomerContainer";
|
|
private _global: Global;
|
|
private _eventManager: EventManager;
|
|
private _uiManager: Ui;
|
|
private _localizationMananger: LocalizationManager;
|
|
private _data: any;
|
|
private _grid: Grid;
|
|
private _dataManager: DataManager;
|
|
|
|
private _listingTypeList;
|
|
private _filterListingType: DropDownList;
|
|
private _listingStatusList;
|
|
private _filterListingStatus: DropDownList;
|
|
private _paymentTypeList;
|
|
private _filterPaymentType: DropDownList;
|
|
private _paymentStatusList;
|
|
private _filterPaymentStatus: DropDownList;
|
|
|
|
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._listingTypeList = [
|
|
{ value: ListingType.Base, text: self._localizationMananger.get("ListingType_Base")},
|
|
{ value: ListingType.Silver, text: self._localizationMananger.get("ListingType_Silver")},
|
|
{ value: ListingType.Gold, text: self._localizationMananger.get("ListingType_Gold")},
|
|
{ value: ListingType.Platin, text: self._localizationMananger.get("ListingType_Platin") }];
|
|
|
|
self._listingStatusList = [
|
|
//{ value: ListingStatus.Draft, text: self._localizationMananger.get("ListingStatus_Draft")},
|
|
{ value: ListingStatus.Reserverd, text: self._localizationMananger.get("ListingStatus_Reserverd")},
|
|
{ value: ListingStatus.ToPay, text: self._localizationMananger.get("ListingStatus_ToPay")},
|
|
{ value: ListingStatus.Booked, text: self._localizationMananger.get("ListingStatus_Booked") },
|
|
{ value: ListingStatus.Running, text: self._localizationMananger.get("ListingStatus_Running") },
|
|
{ value: ListingStatus.Ended, text: self._localizationMananger.get("ListingStatus_Ended") },
|
|
{ value: ListingStatus.Canceled, text: self._localizationMananger.get("ListingStatus_Canceled") }];
|
|
|
|
self._paymentTypeList = [
|
|
{ value: PaymentType.None, text: self._localizationMananger.get("PaymentType_None")},
|
|
{ value: PaymentType.Invoice, text: self._localizationMananger.get("PaymentType_Invoice")},
|
|
{ value: PaymentType.Klarna, text: self._localizationMananger.get("PaymentType_Klarna")},
|
|
{ value: PaymentType.PayPal, text: self._localizationMananger.get("PaymentType_PayPal") }];
|
|
|
|
self._paymentStatusList = [
|
|
{ value: PaymentStatus.None, text: self._localizationMananger.get("PaymentStatus_None")},
|
|
{ value: PaymentStatus.Pending, text: self._localizationMananger.get("PaymentStatus_Pending")},
|
|
{ value: PaymentStatus.Authorized, text: self._localizationMananger.get("PaymentStatus_Authorized")},
|
|
{ value: PaymentStatus.Paid, text: self._localizationMananger.get("PaymentStatus_Paid") },
|
|
//{ value: PaymentStatus.PartiallyRefunded, text: self._localizationMananger.get("PaymentStatus_PartiallyRefunded") },
|
|
{ value: PaymentStatus.Refunded, text: self._localizationMananger.get("PaymentStatus_Refunded") },
|
|
{ value: PaymentStatus.Voided, text: self._localizationMananger.get("PaymentStatus_Voided") }];
|
|
|
|
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("#listContainer"));
|
|
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: "startDate", direction: <any>"Descending" }] },
|
|
selectionSettings: { checkboxMode: "ResetOnRowClick", checkboxOnly: false },
|
|
columns: <any>[
|
|
{ field: "select", type: "checkbox", width: 50, allowFiltering: false, allowSorting: false, showInColumnChooser: false, allowReordering: false },
|
|
{ field: "id", type: "string", visible: false, showInColumnChooser: false },
|
|
{
|
|
field: "listingType", headerText: self._localizationMananger.get("Common_ListingType"), type: "number", template: "${listingTypeText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterListingType = new DropDownList({
|
|
dataSource: new DataManager(self._listingTypeList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterListingType.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterListingType.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterListingType.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ field: "branchName", headerText: self._localizationMananger.get("Listing_BranchId"), type: "string" },
|
|
{ field: "name", headerText: self._localizationMananger.get("Listing_Name"), type: "string" },
|
|
{
|
|
field: "status", headerText: self._localizationMananger.get("Listing_Status"), type: "number", template: "${statusText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterListingStatus = new DropDownList({
|
|
dataSource: new DataManager(self._listingStatusList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterListingStatus.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterListingStatus.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterListingStatus.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ field: "startDate", headerText: self._localizationMananger.get("Listing_StartDate"), type: "datetime", format: { type: "date", skeleton: "medium" } },
|
|
{ field: "endDate", headerText: self._localizationMananger.get("Listing_EndDate"), type: "datetime", format: { type: "date", skeleton: "medium" } },
|
|
{ field: "reservedUntil", headerText: self._localizationMananger.get("Listing_ReservedUntil"), type: "datetime", format: { type: "date", skeleton: "medium" } },
|
|
{
|
|
field: "paymentStatus", headerText: self._localizationMananger.get("Common_PaymentStatus"), type: "number", template: "${paymentStatusText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterPaymentStatus = new DropDownList({
|
|
dataSource: new DataManager(self._paymentStatusList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterPaymentStatus.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterPaymentStatus.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterPaymentStatus.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: "paymentType", headerText: self._localizationMananger.get("Common_PaymentType"), type: "number", template: "${paymentTypeText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterPaymentType = new DropDownList({
|
|
dataSource: new DataManager(self._paymentTypeList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterPaymentType.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterPaymentType.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterPaymentType.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ field: "created", headerText: self._localizationMananger.get("Common_Created"), type: "datetime", format: { type: "date", skeleton: "medium" } }
|
|
|
|
],
|
|
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.details();
|
|
}
|
|
},
|
|
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("#gridListingsCustomer"));
|
|
self._uiManager.unblockUi(self.prefix("#listContainer"));
|
|
}
|
|
|
|
|
|
/**
|
|
* Bei Auswahl oder abwahl einer Row...
|
|
*/
|
|
private handleSelection(): void {
|
|
var self = this;
|
|
let rows = self._grid.getSelectedRecords() as Array<ListingListItem>;
|
|
if (rows.length === 0) {
|
|
$(self.prefix("#btnEdit")).prop("disabled", true);
|
|
$(self.prefix("#btnDetails")).prop("disabled", true);
|
|
$(self.prefix("#btnCancel")).prop("disabled", true);
|
|
}
|
|
else {
|
|
var countEnded = rows.filter(c => c.status === ListingStatus.Ended);
|
|
var countCancelled = rows.filter(c => c.status === ListingStatus.Canceled);
|
|
|
|
if (rows.length === 1) {
|
|
$(self.prefix("#btnDetails")).prop("disabled", false);
|
|
if (countEnded.length === 0 && countCancelled.length === 0) {
|
|
$(self.prefix("#btnEdit")).prop("disabled", false);
|
|
} else {
|
|
$(self.prefix("#btnEdit")).prop("disabled", true);
|
|
}
|
|
} else {
|
|
$(self.prefix("#btnEdit")).prop("disabled", true);
|
|
$(self.prefix("#btnDetails")).prop("disabled", true);
|
|
}
|
|
|
|
if (countEnded.length === 0 && countCancelled.length === 0) {
|
|
$(self.prefix("#btnCancel")).prop("disabled", false);
|
|
} else {
|
|
$(self.prefix("#btnCancel")).prop("disabled", true);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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()) {
|
|
var search = $(self.prefix("#search")).valForSearch();
|
|
if (self._oldSearch !== search) {
|
|
self._oldSearch = search;
|
|
self._grid.clearSelection();
|
|
self._grid.query = new Query().addParams("searchValue", $(self.prefix("#search")).valForSearch());
|
|
self.handleSelection();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Shop
|
|
*/
|
|
private shop(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsShopUrl")).val(),
|
|
data: <any>{},
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
$(self.prefix("#shop")).html(data);
|
|
$(self.prefix("#list")).fadeOut("slow", () => {
|
|
$(self.prefix("#shop")).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: (<ListingListItem>self._grid.getSelectedRecords()[0]).id },
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
$(self.prefix("#detail")).html(data);
|
|
$(self.prefix("#list")).fadeOut("slow", () => {
|
|
$(self.prefix("#detail")).fadeIn("slow");
|
|
});
|
|
},
|
|
error() {
|
|
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Details
|
|
*/
|
|
private details(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsDetailsUrl")).val(),
|
|
data: <any>{ id: (<ListingListItem>self._grid.getSelectedRecords()[0]).id },
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
$(self.prefix("#detail")).html(data);
|
|
$(self.prefix("#list")).fadeOut("slow", () => {
|
|
$(self.prefix("#detail")).fadeIn("slow");
|
|
});
|
|
},
|
|
error() {
|
|
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Stornieren
|
|
*/
|
|
private cancel(): void {
|
|
var self = listingsCustomerModule; //Hier so weil Callback!
|
|
self._uiManager.blockMainUi();
|
|
let rows = self._grid.getSelectedRecords() as Array<ListingListItem>;
|
|
if (rows.length > 0) {
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsCancelUrl")).val(),
|
|
data: <any>{ ids: rows.map(({ id }) => id) },
|
|
dataType: "json",
|
|
type: "POST",
|
|
success(response) {
|
|
if (response.success)
|
|
self._uiManager.showSuccessMessage(self._localizationMananger.get("Common_Cancel_Success"));
|
|
else
|
|
self._uiManager.showWarningMessage(response.errorMessage);
|
|
self.loadItems();
|
|
},
|
|
error(e) {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Cancel_NoSuccess"));
|
|
},
|
|
complete() {
|
|
self._uiManager.unblockMainUi();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bindungen erstellen
|
|
*/
|
|
private setupBindings(): void {
|
|
var self = this;
|
|
|
|
$(self.prefix("#btnColumns")).off("click").on("click", function () {
|
|
self._grid.columnChooserModule.openColumnChooser();
|
|
});
|
|
|
|
$(self.prefix("#btnShop")).off("click").on("click", function () {
|
|
self.shop();
|
|
});
|
|
|
|
$(self.prefix("#btnEdit")).off("click").on("click", function () {
|
|
self.edit();
|
|
});
|
|
|
|
$(self.prefix("#btnDetails")).off("click").on("click", function () {
|
|
self.details();
|
|
});
|
|
|
|
$(self.prefix("#btnCancel")).off("click").on("click", function () {
|
|
if (self._grid.getSelectedRows().length === 1) {
|
|
self._uiManager.showModal(self._localizationMananger.get("Common_Cancel_Question"), true, self.cancel);
|
|
}
|
|
else if (self._grid.getSelectedRows().length > 1) {
|
|
self._uiManager.showModal(self._localizationMananger.get("Common_Cancel_Question_Batch"), true, self.cancel);
|
|
}
|
|
});
|
|
|
|
$(self.prefix("#search")).on("keyup change", Utility.debounce(() => {
|
|
self.handleSearch();
|
|
}, 500));
|
|
|
|
self._eventManager.subscribe(Events.Listing.bookCancel, self._moduleName, function () {
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Listing.bookSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Listing.editCancel, self._moduleName, function () {
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Listing.editSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Listing.detailsBack, self._moduleName, function () {
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Shop.back, self._moduleName, function () {
|
|
$(self.prefix("#shop")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#shop")).html("");
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Aktivieren des Moduls
|
|
*/
|
|
public activate(): void {
|
|
|
|
var self = this;
|
|
$.setupValidator();
|
|
$.reinitializeValidator();
|
|
|
|
this.setupBindings();
|
|
|
|
self.setupList();
|
|
$.randomAutocompleteValue();
|
|
}
|
|
|
|
/**
|
|
* Initialisieren des Moduls
|
|
*/
|
|
public init(): void {
|
|
if (this._global.appInitialized) {
|
|
listingsCustomerModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let listingsCustomerModule = new ListingsCustomerModule();
|
|
listingsCustomerModule.init(); |