502 lines
23 KiB
TypeScript
502 lines
23 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 { Dialog } from "@syncfusion/ej2-popups";
|
|
import AppMode = Models.AppMode;
|
|
import SubscriptionLength = Models.SubscriptionLength;
|
|
import SubscriptionBookingListItem = Models.SubscriptionBookingListItem;
|
|
import AppUserType = Models.AppUserType;
|
|
import Platform = Models.Platform;
|
|
|
|
class SubscriptionBookingsModule {
|
|
private _moduleName = "SubscriptionBookingsModule";
|
|
private _component = "#subscriptionBookingsContainer";
|
|
private _global: Global;
|
|
private _eventManager: EventManager;
|
|
private _uiManager: Ui;
|
|
private _localizationMananger: LocalizationManager;
|
|
private _data: any;
|
|
private _grid: Grid;
|
|
private _dataManager: DataManager;
|
|
private _downloadDialog: Dialog;
|
|
|
|
private _subscriptionLengthList;
|
|
private _filterSubscriptionLength: DropDownList;
|
|
private _appModeList;
|
|
private _filterAppMode: DropDownList;
|
|
private _typeList;
|
|
private _filterType: DropDownList;
|
|
private _platformList;
|
|
private _filterPlatform: 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._typeList = [
|
|
{ value: AppUserType.DogOwner, text: self._localizationMananger.get("AppUserType_DogOwner") },
|
|
{ value: AppUserType.DogWalker, text: self._localizationMananger.get("AppUserType_DogWalker") },
|
|
{ value: AppUserType.Both, text: self._localizationMananger.get("AppUserType_Both") }];
|
|
|
|
self._subscriptionLengthList = [
|
|
{ value: SubscriptionLength.OneWeek, text: self._localizationMananger.get("SubscriptionLength_OneWeek")},
|
|
{ value: SubscriptionLength.OneMonth, text: self._localizationMananger.get("SubscriptionLength_OneMonth") },
|
|
{ value: SubscriptionLength.TwoMonths, text: self._localizationMananger.get("SubscriptionLength_TwoMonths") },
|
|
{ value: SubscriptionLength.ThreeMonths, text: self._localizationMananger.get("SubscriptionLength_ThreeMonths") },
|
|
{ value: SubscriptionLength.SixMonths, text: self._localizationMananger.get("SubscriptionLength_SixMonths") },
|
|
{ value: SubscriptionLength.OneYear, text: self._localizationMananger.get("SubscriptionLength_OneYear")}];
|
|
|
|
self._appModeList = [
|
|
{ value: AppMode.DogOwner, text: self._localizationMananger.get("AppMode_DogOwner")},
|
|
{ value: AppMode.DogWalker, text: self._localizationMananger.get("AppMode_DogWalker") }];
|
|
|
|
self._platformList = [
|
|
{ value: Platform.Windows, text: self._localizationMananger.get("Platform_Windows") },
|
|
{ value: Platform.Mac, text: self._localizationMananger.get("Platform_Mac") },
|
|
{ value: Platform.Ios, text: self._localizationMananger.get("Platform_Ios") },
|
|
{ value: Platform.Android, text: self._localizationMananger.get("Platform_Android") }];
|
|
|
|
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: "subscriptionCode", headerText: self._localizationMananger.get("Subscription_Code"), type: "string" },
|
|
{ field: "subscriptionName", headerText: self._localizationMananger.get("Subscription_Name"), type: "string" },
|
|
{
|
|
field: "subscriptionLength", headerText: self._localizationMananger.get("Subscription_Length"), type: "number", template: "${subscriptionLengthText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterSubscriptionLength = new DropDownList({
|
|
dataSource: new DataManager(self._subscriptionLengthList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterSubscriptionLength.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterSubscriptionLength.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterSubscriptionLength.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ field: "subscriptionPrice", headerText: self._localizationMananger.get("Subscription_Price"), type: "number", format: "n4", textAlign: "right" },
|
|
|
|
{
|
|
field: "subscriptionAppMode", headerText: self._localizationMananger.get("Subscription_AppMode"), type: "number", template: "${subscriptionAppModeText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterAppMode = new DropDownList({
|
|
dataSource: new DataManager(self._appModeList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterAppMode.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterAppMode.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterAppMode.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: "platform", headerText: self._localizationMananger.get("AppVersion_Platform"), type: "number", template: "${platformText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterPlatform = new DropDownList({
|
|
dataSource: new DataManager(self._platformList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterPlatform.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterPlatform.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterPlatform.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: "appUserType", headerText: self._localizationMananger.get("SubscriptionBooking_AppUserType"), type: "number", template: "${appUserTypeText}",
|
|
filter: {
|
|
ui: {
|
|
create: (args: { target: Element, column: Object }) => {
|
|
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
|
|
args.target.appendChild(flValInput);
|
|
self._filterType = new DropDownList({
|
|
dataSource: new DataManager(self._typeList),
|
|
fields: { text: "text", value: "value" },
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
popupHeight: "200px"
|
|
});
|
|
self._filterType.appendTo(flValInput);
|
|
},
|
|
write: (args: {
|
|
column: Object, target: Element, parent: any, filteredValue: number | string
|
|
}) => {
|
|
self._filterType.value = args.filteredValue;
|
|
},
|
|
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
|
|
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterType.value);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{ field: "appUserName", headerText: self._localizationMananger.get("SubscriptionBooking_AppUserName"), type: "string" },
|
|
{ field: "manual", headerText: self._localizationMananger.get("SubscriptionBooking_Manual"), type: "boolean", textAlign: "Center", displayAsCheckBox: true },
|
|
{ field: "isValid", headerText: self._localizationMananger.get("SubscriptionBooking_IsValid"), type: "boolean", textAlign: "Center", displayAsCheckBox: true },
|
|
{ field: "expirationDate", headerText: self._localizationMananger.get("SubscriptionBooking_ExpirationDate"), format: { type: "dateTime", skeleton: "medium" } },
|
|
{ field: "subscriptionGracePeriodInDays", headerText: self._localizationMananger.get("Subscription_SubscriptionGracePeriodInDays"), type: "number", format: "n0", textAlign: "right" },
|
|
{ field: "expirationDateWithGrace", headerText: self._localizationMananger.get("SubscriptionBooking_ExpirationDateWithGrace"), format: { type: "dateTime", skeleton: "medium" } },
|
|
|
|
{ field: "lastRenewalDate", headerText: self._localizationMananger.get("SubscriptionBooking_LastRenewalDate"), format: { type: "dateTime", skeleton: "medium" } },
|
|
{ field: "lastUpdate", headerText: self._localizationMananger.get("Common_LastUpdate"), format: { type: "dateTime", skeleton: "medium" } },
|
|
{ field: "created", headerText: self._localizationMananger.get("Common_Created"), format: { type: "dateTime", 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.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("#gridSubscriptionBookings"));
|
|
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<SubscriptionBookingListItem>;
|
|
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()) {
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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("#detail")).html(data);
|
|
$(self.prefix("#list")).fadeOut("slow", () => {
|
|
$(self.prefix("#detail")).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: (<SubscriptionBookingListItem>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();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Löschen
|
|
*/
|
|
private delete(): void {
|
|
var self = subscriptionBookingsModule; //Hier so weil Callback!
|
|
self._uiManager.blockMainUi();
|
|
let rows = self._grid.getSelectedRecords() as Array<SubscriptionBookingListItem>;
|
|
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("#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.SubscriptionBooking.createCancel, self._moduleName, function () {
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.SubscriptionBooking.createSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.SubscriptionBooking.editCancel, self._moduleName, function () {
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).html("");
|
|
});
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.SubscriptionBooking.editSuccess, self._moduleName, function () {
|
|
self.loadItems();
|
|
$(self.prefix("#detail")).fadeOut("slow", () => {
|
|
$(self.prefix("#list")).fadeIn();
|
|
$(self.prefix("#detail")).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) {
|
|
subscriptionBookingsModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let subscriptionBookingsModule = new SubscriptionBookingsModule();
|
|
subscriptionBookingsModule.init(); |