249 lines
8.7 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 { Tab } from "@syncfusion/ej2-navigations";
import { NumericTextBox } from "@syncfusion/ej2-inputs";
import { Query, DataManager, UrlAdaptor } from "@syncfusion/ej2-data";
import { AutoComplete } from '@syncfusion/ej2-dropdowns';
import { Switch } from '@syncfusion/ej2-buttons';
import * as Models from "../../Common/Models";
class EditShipmentCostModule {
private _moduleName = "EditShipmentCostModule";
private _component = "#shipmentCostEditContainer";
private _global: Global;
private _eventManager: EventManager;
private _uiManager: Ui;
private _localizationMananger: LocalizationManager;
private _tabText: Tab;
private _countryAutoComplete: AutoComplete;
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("#frmEditShipmentCost")).attr("action");
var data = $(self.prefix("#frmEditShipmentCost")).serialize();
$.post(action, data)
.done(result => {
if (result.success) {
self._uiManager.pageTitleClear(self._component);
self._eventManager.unSubscribeAll(self._moduleName);
self._eventManager.publish(Events.ShipmentCost.editSuccess, result.data);
}
else {
$(self._component).replaceWith(result.html);
$.highlightErrors();
Utility.showErrorTab();
self.activate();
}
})
.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("#frmEditShipmentCost"), () => {
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(Events.ShipmentCost.editCancel);
});
self._tabText = new Tab({
animation: { previous: { effect: "FadeIn", duration: 100 }, next: { effect: "FadeIn", duration: 100 } },
selecting: (arsg: any) => {
if (arsg.isSwiped) {
arsg.cancel = true;
}
}
});
self._tabText.appendTo(self.prefix("#tabContainerText"));
let weightFrom = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#WeightFrom")).val()),
decimals: 2,
step: 1,
min: 0,
max: 100000,
format: "n2",
change: (e: any) => {
$(self.prefix("#WeightFrom")).val(Globalize.formatNumber(e.value));
}
});
weightFrom.appendTo(self.prefix("#WeightFromHelper"));
let weightTo = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#WeightTo")).val()),
decimals: 2,
step: 1,
min: 0,
max: 100000,
format: "n2",
change: (e: any) => {
$(self.prefix("#WeightTo")).val(Globalize.formatNumber(e.value));
}
});
weightTo.appendTo(self.prefix("#WeightToHelper"));
let subtotalFrom = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#SubtotalFrom")).val()),
decimals: 2,
step: 1,
min: 0,
max: 100000000,
format: "n2",
change: (e: any) => {
$(self.prefix("#SubtotalFrom")).val(Globalize.formatNumber(e.value));
}
});
subtotalFrom.appendTo(self.prefix("#SubtotalFromHelper"));
let subtotalTo = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#SubtotalTo")).val()),
decimals: 2,
step: 1,
min: 0,
max: 100000000,
format: "n2",
change: (e: any) => {
$(self.prefix("#SubtotalTo")).val(Globalize.formatNumber(e.value));
}
});
subtotalTo.appendTo(self.prefix("#SubtotalToHelper"));
let fixedPrice = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#FixedPrice")).val()),
decimals: 4,
step: 1,
min: 0,
max: 100000000,
format: "n4",
change: (e: any) => {
$(self.prefix("#FixedPrice")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 4 }));
}
});
fixedPrice.appendTo(self.prefix("#FixedPriceHelper"));
let subtotalPercent = new NumericTextBox({
value: Globalize.parseNumber($(self.prefix("#SubtotalPercent")).val()),
decimals: 2,
step: 1,
min: 0,
max: 100.0,
format: "n2",
change: (e: any) => {
$(self.prefix("#SubtotalPercent")).val(Globalize.formatNumber(e.value));
}
});
subtotalPercent.appendTo(self.prefix("#SubtotalPercentHelper"));
self._countryAutoComplete = new AutoComplete({
dataSource: new DataManager({
url: <string>$(self.prefix("#jsLookupCountriesUrl")).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("#TargetCountryName")).val(),
change: (e: any) => {
if (e.itemData === null) {
$(self.prefix("#TargetCountryIso")).val("");
} else if (e.itemData.id === e.itemData.name) {
//nichts tun
} else {
$(self.prefix("#TargetCountryIso")).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._countryAutoComplete.appendTo(self.prefix("#TargetCountryName"));
$('[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) {
editShipmentCostModule.activate();
} else {
setTimeout(() => { this.init() }, 10);
}
}
}
let editShipmentCostModule = new EditShipmentCostModule();
editShipmentCostModule.init();