204 lines
7.5 KiB
TypeScript
204 lines
7.5 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 * as Utility from "../../Core/Utility";
|
|
import { FormValidation } from "../../Core/Forms"
|
|
import { Query, DataManager, UrlAdaptor } from "@syncfusion/ej2-data";
|
|
import { DatePicker, ChangedEventArgs } from "@syncfusion/ej2-calendars";
|
|
import SubscriptionBooking = Events.SubscriptionBooking;
|
|
import { AutoComplete } from "@syncfusion/ej2-dropdowns";
|
|
|
|
class EditBookingModule {
|
|
private _moduleName = "EditBookingModule";
|
|
private _component = "#bookingEditContainer";
|
|
private _global: Global;
|
|
private _eventManager: EventManager;
|
|
private _uiManager: Ui;
|
|
private _localizationMananger: LocalizationManager;
|
|
private _appUserAutoComplete: AutoComplete;
|
|
private _subscriptionAutoComplete: AutoComplete;
|
|
private _expirationDatePicker: DatePicker;
|
|
|
|
constructor() {
|
|
this._global = Global.getInstance();
|
|
this._eventManager = EventManager.getInstance();
|
|
this._uiManager = Ui.getInstance();
|
|
this._localizationMananger = LocalizationManager.getInstance();
|
|
}
|
|
|
|
/**
|
|
* 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}`;
|
|
}
|
|
|
|
/**
|
|
* Speichern
|
|
*/
|
|
private save(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
|
|
var action = $(self.prefix("#frmEditBooking")).attr("action");
|
|
var data = $(self.prefix("#frmEditBooking")).serialize();
|
|
$.post(action, data)
|
|
.done(result => {
|
|
if (result.success) {
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(SubscriptionBooking.editSuccess, result.data);
|
|
}
|
|
else {
|
|
$(self._component).replaceWith(result.html);
|
|
$.highlightErrors();
|
|
Utility.showErrorTab();
|
|
self.activate();
|
|
if (result.errorMessage && result.errorMessage.length > 0)
|
|
self._uiManager.showErrorMessage(result.errorMessage);
|
|
}
|
|
})
|
|
.fail(result => {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Save_NoSuccess"));
|
|
})
|
|
.always(result => {
|
|
self._uiManager.unblockMainUi();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Bindungen erstellen
|
|
*/
|
|
private setupBindings(): void {
|
|
var self = this;
|
|
|
|
$(self.prefix("#btnSave")).off("click").on("click", function () {
|
|
FormValidation.getInstance().validateForm(self.prefix("#frmEditBooking"), () => {
|
|
self.save();
|
|
}, () => {
|
|
$.highlightErrors();
|
|
Utility.showErrorTab();
|
|
});
|
|
});
|
|
|
|
$(self.prefix("#btnCancel")).off("click").on("click", function () {
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(SubscriptionBooking.editCancel);
|
|
});
|
|
|
|
self._appUserAutoComplete = new AutoComplete({
|
|
dataSource: new DataManager({
|
|
url: <string>$(self.prefix("#jsLookupAppUsersUrl")).val(),
|
|
adaptor: new UrlAdaptor(),
|
|
crossDomain: true,
|
|
headers: [{ "X-Requested-With": "XmlHttpRequest" }]
|
|
}),
|
|
showPopupButton: true,
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
fields: { value: "id", text: "name" },
|
|
value: <string>$(self.prefix("#AppUserName")).val(),
|
|
change: (e: any) => {
|
|
if (e.itemData === null) {
|
|
$(self.prefix("#AppUserId")).val("");
|
|
}
|
|
else if (e.itemData.id === e.itemData.name) {
|
|
//nichts tun
|
|
} else {
|
|
$(self.prefix("#AppUserId")).val(e.itemData.id);
|
|
}
|
|
},
|
|
htmlAttributes: { openhelper: "off" },
|
|
open: function () {
|
|
if (this.value !== null && this.text === this.queryString) {
|
|
this.value = null;
|
|
this.htmlAttributes["openhelper"] = "on";
|
|
}
|
|
},
|
|
close: function () {
|
|
if (this.value === null && this.htmlAttributes["openhelper"] === "on") {
|
|
this.showPopup();
|
|
this.htmlAttributes["openhelper"] = "off";
|
|
}
|
|
}
|
|
});
|
|
self._appUserAutoComplete.appendTo(self.prefix("#AppUserName"));
|
|
self._appUserAutoComplete.enabled = false;
|
|
|
|
self._subscriptionAutoComplete = new AutoComplete({
|
|
dataSource: new DataManager({
|
|
url: <string>$(self.prefix("#jsLookupSubscriptionsUrl")).val(),
|
|
adaptor: new UrlAdaptor(),
|
|
crossDomain: true,
|
|
headers: [{ "X-Requested-With": "XmlHttpRequest" }]
|
|
}),
|
|
showPopupButton: true,
|
|
placeholder: self._localizationMananger.get("Common_Select"),
|
|
fields: { value: "id", text: "name" },
|
|
value: <string>$(self.prefix("#SubscriptionName")).val(),
|
|
change: (e: any) => {
|
|
if (e.itemData === null) {
|
|
$(self.prefix("#SubscriptionId")).val("");
|
|
}
|
|
else if (e.itemData.id === e.itemData.name) {
|
|
//nichts tun
|
|
} else {
|
|
$(self.prefix("#SubscriptionId")).val(e.itemData.id);
|
|
}
|
|
},
|
|
htmlAttributes: { openhelper: "off" },
|
|
open: function () {
|
|
if (this.value !== null && this.text === this.queryString) {
|
|
this.value = null;
|
|
this.htmlAttributes["openhelper"] = "on";
|
|
}
|
|
},
|
|
close: function () {
|
|
if (this.value === null && this.htmlAttributes["openhelper"] === "on") {
|
|
this.showPopup();
|
|
this.htmlAttributes["openhelper"] = "off";
|
|
}
|
|
}
|
|
});
|
|
self._subscriptionAutoComplete.appendTo(self.prefix("#SubscriptionName"));
|
|
|
|
self._expirationDatePicker = new DatePicker({
|
|
value: new Date(Date.parse(<string>$(self.prefix("#ExpirationDate")).val()))
|
|
});
|
|
self._expirationDatePicker.appendTo(self.prefix("#ExpirationDate"));
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
}
|
|
|
|
/**
|
|
* Aktivieren des Moduls
|
|
*/
|
|
public activate(): void {
|
|
var self = this;
|
|
$.setupValidator();
|
|
$.reinitializeValidator();
|
|
this.setupBindings();
|
|
self._uiManager.pageTitleAdd(self._component, self.prefix("#pageTitleAdd"));
|
|
$.randomAutocompleteValue();
|
|
}
|
|
|
|
/**
|
|
* Initialisieren des Moduls
|
|
*/
|
|
public init(): void {
|
|
if (this._global.appInitialized) {
|
|
editBookingModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init() }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let editBookingModule = new EditBookingModule();
|
|
editBookingModule.init(); |