443 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 AppUserReportStatus = Models.AppUserReportStatus;
import AppUserReportSection = Models.AppUserReportSection;
import AppUserReportType = Models.AppUserReportType;
import AppUserReportListItem = Models.AppUserReportListItem;
import AppUserReportBlockType = Models.AppUserReportBlockType;
class AppUserReportsModule {
private _moduleName = "AppUserReportsModule";
private _component = "#appReportsContainer";
private _global: Global;
private _eventManager: EventManager;
private _uiManager: Ui;
private _localizationMananger: LocalizationManager;
private _data: any;
private _grid: Grid;
private _dataManager: DataManager;
private _statusList;
private _filterStatus: DropDownList;
private _sectionList;
private _filterSection: DropDownList;
private _typeList;
private _filterType: DropDownList;
private _blockTypeList;
private _filterBlockType: 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._statusList = [
{ value: AppUserReportStatus.Open, text: self._localizationMananger.get("AppUserReportStatus_Open")},
{ value: AppUserReportStatus.Processing, text: self._localizationMananger.get("AppUserReportStatus_Processing") },
{ value: AppUserReportStatus.Rejected, text: self._localizationMananger.get("AppUserReportStatus_Rejected") },
{ value: AppUserReportStatus.ClosedNoAction, text: self._localizationMananger.get("AppUserReportStatus_ClosedNoAction") },
{ value: AppUserReportStatus.ClosedLockedForTime, text: self._localizationMananger.get("AppUserReportStatus_ClosedLockedForTime") },
{ value: AppUserReportStatus.ClosedLockedForever, text: self._localizationMananger.get("AppUserReportStatus_ClosedLockedForever") },
{ value: AppUserReportStatus.ClosedContentEdited, text: self._localizationMananger.get("AppUserReportStatus_ClosedContentEdited") },
{ value: AppUserReportStatus.ClosedContentDeleted, text: self._localizationMananger.get("AppUserReportStatus_ClosedContentDeleted")},
{ value: AppUserReportStatus.Reopened, text: self._localizationMananger.get("AppUserReportStatus_Reopened") }];
self._sectionList = [
{ value: AppUserReportSection.ProfileDog, text: self._localizationMananger.get("AppUserReportSection_ProfileDog")},
{ value: AppUserReportSection.Conversations, text: self._localizationMananger.get("AppUserReportSection_Conversations")},
{ value: AppUserReportSection.Messages, text: self._localizationMananger.get("AppUserReportSection_Messages")},
{ value: AppUserReportSection.ConversationCreate, text: self._localizationMananger.get("AppUserReportSection_ConversationCreate") },
{ value: AppUserReportSection.ProfileDogOwner, text: self._localizationMananger.get("AppUserReportSection_ProfileDogOwner") },
{ value: AppUserReportSection.RatingsDog, text: self._localizationMananger.get("AppUserReportSection_RatingsDog") },
{ value: AppUserReportSection.RatingsDogOwner, text: self._localizationMananger.get("AppUserReportSection_RatingsDogOwner") },
{ value: AppUserReportSection.RatingsMy, text: self._localizationMananger.get("AppUserReportSection_RatingsMy") },
{ value: AppUserReportSection.RatingsWalker, text: self._localizationMananger.get("AppUserReportSection_RatingsWalker") },
{ value: AppUserReportSection.WalkersSearch, text: self._localizationMananger.get("AppUserReportSection_WalkersSearch") },
{ value: AppUserReportSection.ProfileWalker, text: self._localizationMananger.get("AppUserReportSection_ProfileWalker") },
{ value: AppUserReportSection.OpenRequestDogOwner, text: self._localizationMananger.get("AppUserReportSection_OpenRequestDogOwner") },
{ value: AppUserReportSection.OpenRequestWalker, text: self._localizationMananger.get("AppUserReportSection_OpenRequestWalker") },
{ value: AppUserReportSection.OpenRequestResponse, text: self._localizationMananger.get("AppUserReportSection_OpenRequestResponse") },
{ value: AppUserReportSection.WalksDogOwner, text: self._localizationMananger.get("AppUserReportSection_WalksDogOwner") },
{ value: AppUserReportSection.OpenRequestDogOwnerDetails, text: self._localizationMananger.get("AppUserReportSection_OpenRequestDogOwnerDetails") },
{ value: AppUserReportSection.OpenRequestWalkerDetails, text: self._localizationMananger.get("AppUserReportSection_OpenRequestWalkerDetails") },
{ value: AppUserReportSection.OpenRequestResponses, text: self._localizationMananger.get("AppUserReportSection_OpenRequestResponses") },
{ value: AppUserReportSection.WalksWalker, text: self._localizationMananger.get("AppUserReportSection_WalksWalker") },
{ value: AppUserReportSection.WalkDetailDogOwner, text: self._localizationMananger.get("AppUserReportSection_WalkDetailDogOwner") },
{ value: AppUserReportSection.WalkDetailsWalker, text: self._localizationMananger.get("AppUserReportSection_WalkDetailsWalker") },
{ value: AppUserReportSection.FavouritesDogOwner, text: self._localizationMananger.get("AppUserReportSection_FavouritesDogOwner") },
{ value: AppUserReportSection.FavouritesWalker, text: self._localizationMananger.get("AppUserReportSection_FavouritesWalker") },
{ value: AppUserReportSection.HomeDogOwner, text: self._localizationMananger.get("AppUserReportSection_HomeDogOwner") },
{ value: AppUserReportSection.HomeWalker, text: self._localizationMananger.get("AppUserReportSection_HomeWalker") }];
self._typeList = [
{ value: AppUserReportType.Objectionable, text: self._localizationMananger.get("AppUserReportType_Objectionable") },
{ value: AppUserReportType.PoliticallyIncorrect, text: self._localizationMananger.get("AppUserReportType_PoliticallyIncorrect") },
{ value: AppUserReportType.Obscene, text: self._localizationMananger.get("AppUserReportType_Obscene") },
{ value: AppUserReportType.IncorrectData, text: self._localizationMananger.get("AppUserReportType_IncorrectData")},
{ value: AppUserReportType.Intrusive, text: self._localizationMananger.get("AppUserReportType_Intrusive") }];
self._blockTypeList = [
{ value: AppUserReportBlockType.NoBlock, text: self._localizationMananger.get("AppUserReportBlockType_NoBlock") },
{ value: AppUserReportBlockType.BlockForTime, text: self._localizationMananger.get("AppUserReportBlockType_BlockForTime") },
{ value: AppUserReportBlockType.BlockForever, text: self._localizationMananger.get("AppUserReportBlockType_BlockForever") }];
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: "created", 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: "created", headerText: self._localizationMananger.get("Common_Created"), type: "datetime", format: { type: "dateTime", skeleton: "medium" } },
{
field: "status", headerText: self._localizationMananger.get("AppUserReport_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._filterStatus = new DropDownList({
dataSource: new DataManager(self._statusList),
fields: { text: "text", value: "value" },
placeholder: self._localizationMananger.get("Common_Select"),
popupHeight: "200px", popupWidth: "300px"
});
self._filterStatus.appendTo(flValInput);
},
write: (args: {
column: Object, target: Element, parent: any, filteredValue: number | string
}) => {
self._filterStatus.value = args.filteredValue;
},
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterStatus.value);
}
}
}
},
{
field: "section", headerText: self._localizationMananger.get("AppUserReport_Section"), type: "number", template: "${sectionText}",
filter: {
ui: {
create: (args: { target: Element, column: Object }) => {
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
args.target.appendChild(flValInput);
self._filterSection = new DropDownList({
dataSource: new DataManager(self._sectionList),
fields: { text: "text", value: "value" },
placeholder: self._localizationMananger.get("Common_Select"),
popupHeight: "200px", popupWidth: "300px"
});
self._filterSection.appendTo(flValInput);
},
write: (args: {
column: Object, target: Element, parent: any, filteredValue: number | string
}) => {
self._filterSection.value = args.filteredValue;
},
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterSection.value);
}
}
}
},
{
field: "type", headerText: self._localizationMananger.get("AppUserReport_Type"), type: "number", template: "${typeText}",
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: "updated", headerText: self._localizationMananger.get("AppUserReport_Updated"), type: "datetime", format: { type: "dateTime", skeleton: "medium" } },
{ field: "updatedBy", headerText: self._localizationMananger.get("AppUserReport_UpdatedBy"), type: "string" },
{ field: "reportingAppUserName", headerText: self._localizationMananger.get("AppUserReport_ReportingAppUserId"), type: "string" },
{ field: "reportingAppUserTypeText", headerText: self._localizationMananger.get("AppUser_Type") + " " + self._localizationMananger.get("AppUserReport_ReportingAppUserId"), type: "string", allowFiltering: false, allowSorting: false },
{ field: "reportedAppUserName", headerText: self._localizationMananger.get("AppUserReport_ReportedAppUserId"), type: "string" },
{ field: "reportedAppUserTypeText", headerText: self._localizationMananger.get("AppUser_Type") + " " + self._localizationMananger.get("AppUserReport_ReportedAppUserId"), type: "string", allowFiltering: false, allowSorting: false },
{
field: "blockType", headerText: self._localizationMananger.get("AppUserReport_Block"), type: "number", template: "${blockTypeText}",
filter: {
ui: {
create: (args: { target: Element, column: Object }) => {
let flValInput: HTMLElement = createElement("input", { className: "flm-input" });
args.target.appendChild(flValInput);
self._filterBlockType = new DropDownList({
dataSource: new DataManager(self._blockTypeList),
fields: { text: "text", value: "value" },
placeholder: self._localizationMananger.get("Common_Select"),
popupHeight: "200px"
});
self._filterBlockType.appendTo(flValInput);
},
write: (args: {
column: Object, target: Element, parent: any, filteredValue: number | string
}) => {
self._filterBlockType.value = args.filteredValue;
},
read: (args: { target: Element, column: any, operator: string, fltrObj: Filter }) => {
args.fltrObj.filterByColumn(args.column.field, args.operator, self._filterBlockType.value);
}
}
}
},
],
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("#gridAppReports"));
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<AppUserReportListItem>;
$(self.prefix("#btnDetails")).prop("disabled", true);
//$(self.prefix("#btnDelete")).prop("disabled", true);
if (rows.length === 0) {
$(self.prefix("#btnDetails")).prop("disabled", true);
//$(self.prefix("#btnDelete")).prop("disabled", true);
}
else {
if (rows.length === 1)
$(self.prefix("#btnDetails")).prop("disabled", false);
else
$(self.prefix("#btnDetails")).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();
}
}
}
/**
* Details
*/
private details(): void {
var self = this;
self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsDetailsUrl")).val(),
data: <any>{ id: (<AppUserReportListItem>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();
}
});
}
/**
* Bindungen erstellen
*/
private setupBindings(): void {
var self = this;
$(self.prefix("#btnColumns")).off("click").on("click", function () {
self._grid.columnChooserModule.openColumnChooser();
});
$(self.prefix("#btnDetails")).off("click").on("click", function () {
self.details();
});
$(self.prefix("#search")).on("keyup change", Utility.debounce(() => {
self.handleSearch();
}, 500));
self._eventManager.subscribe(Events.AppUserReport.detailsCancel, self._moduleName, function () {
$(self.prefix("#detail")).fadeOut("slow", () => {
$(self.prefix("#list")).fadeIn();
$(self.prefix("#detail")).html("");
});
});
self._eventManager.subscribe(Events.AppUserReport.detailsSuccess, 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) {
appUserReportsModule.activate();
} else {
setTimeout(() => { this.init(); }, 10);
}
}
}
let appUserReportsModule = new AppUserReportsModule();
appUserReportsModule.init();