inviton-powerduck 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +1 -0
  2. package/app/powerduck-initializer.ts +18 -0
  3. package/app/powerduck-state.ts +145 -0
  4. package/app/powerduck-system-resources.ts +61 -0
  5. package/app/vuestsx-extended.ts +5 -0
  6. package/app/vuetsx.ts +90 -0
  7. package/common/IWebClient.ts +11 -0
  8. package/common/ajax-xhr.ts +121 -0
  9. package/common/api-http.ts +747 -0
  10. package/common/base-component.tsx +350 -0
  11. package/common/cdn-webpack-shim.ts +5 -0
  12. package/common/country-iso-mapping.ts +249 -0
  13. package/common/date-wrapper.ts +249 -0
  14. package/common/declarations.d.ts +24 -0
  15. package/common/dialog-utils.ts +525 -0
  16. package/common/enums.ts +55 -0
  17. package/common/excel/excel-js-provider.ts +113 -0
  18. package/common/excel/excel-reader.ts +66 -0
  19. package/common/external-barcode-scanner.ts +334 -0
  20. package/common/history-handler.ts +155 -0
  21. package/common/json-column-utils.ts +14 -0
  22. package/common/ladda-lite.ts +396 -0
  23. package/common/local-storage-shim.ts +132 -0
  24. package/common/localized-text.ts +11 -0
  25. package/common/query-string-utils.ts +60 -0
  26. package/common/slot-name-identifier.ts +3 -0
  27. package/common/static-wrappers/history-handler-ext.ts +27 -0
  28. package/common/static-wrappers/interfaces/validation-interface.ts +28 -0
  29. package/common/timezone-helper.ts +75 -0
  30. package/common/utils/array-extend.ts +169 -0
  31. package/common/utils/array-remove.ts +12 -0
  32. package/common/utils/array-sort.ts +54 -0
  33. package/common/utils/broswer-image-compression.ts +27 -0
  34. package/common/utils/capitalize-string.ts +11 -0
  35. package/common/utils/checkbox-utils.ts +56 -0
  36. package/common/utils/clipboard-provider.ts +106 -0
  37. package/common/utils/cookie.ts +54 -0
  38. package/common/utils/currency-utils.ts +18 -0
  39. package/common/utils/domain-helper.ts +63 -0
  40. package/common/utils/dropdown-utils.ts +62 -0
  41. package/common/utils/esmodule-import-helper.ts +9 -0
  42. package/common/utils/flags-enum.ts +54 -0
  43. package/common/utils/form-utils.ts +45 -0
  44. package/common/utils/format-string.ts +12 -0
  45. package/common/utils/is-null-or-empty.ts +7 -0
  46. package/common/utils/language-utils.ts +228 -0
  47. package/common/utils/latinize-string.ts +8 -0
  48. package/common/utils/localized-string.ts +95 -0
  49. package/common/utils/string-utils.ts +20 -0
  50. package/common/utils/upload-image-helper.ts +40 -0
  51. package/common/utils/utils.ts +426 -0
  52. package/common/validation.ts +267 -0
  53. package/components/accordion/accordion-page.tsx +28 -0
  54. package/components/accordion/accordion.tsx +132 -0
  55. package/components/app/breadcrumb.ts +5 -0
  56. package/components/app/dynamic-component-container.tsx +88 -0
  57. package/components/app/dynamic-component-contracts.ts +13 -0
  58. package/components/app/menu.ts +13 -0
  59. package/components/app/navigation-guard.ts +64 -0
  60. package/components/app/root-dynamic-component-container.tsx +33 -0
  61. package/components/app/vue-plugin-jsxtransform.ts +32 -0
  62. package/components/app/vue-plugin-toplevelpage.ts +33 -0
  63. package/components/bootstrap-toggle/index.tsx +174 -0
  64. package/components/button/button-layout.ts +38 -0
  65. package/components/button/button-message-container.tsx +28 -0
  66. package/components/button/button.tsx +100 -0
  67. package/components/button/excel-upload-button.tsx +58 -0
  68. package/components/button/ladda-button.tsx +64 -0
  69. package/components/button/text-button.tsx +62 -0
  70. package/components/button/upload-button.tsx +179 -0
  71. package/components/card/card-body.tsx +12 -0
  72. package/components/card/card-header-with-options.tsx +57 -0
  73. package/components/card/card-header.tsx +33 -0
  74. package/components/card/card.tsx +62 -0
  75. package/components/card/image-card.tsx +79 -0
  76. package/components/chart-js/bar-chart.tsx +208 -0
  77. package/components/chart-js/line-chart-flot.tsx +308 -0
  78. package/components/chart-js/line-chart.tsx +220 -0
  79. package/components/chart-js/pie-chart.tsx +201 -0
  80. package/components/chart-js/plot.tsx +206 -0
  81. package/components/chart-js/ts/color-helper.ts +104 -0
  82. package/components/chart-js/ts/line-chart-contracts.ts +35 -0
  83. package/components/chart-js/ts/utils.ts +11 -0
  84. package/components/chart-js/utils.ts +11 -0
  85. package/components/contenteditable/index.tsx +53 -0
  86. package/components/context-menu/context-menu-binder.ts +47 -0
  87. package/components/context-menu/context-menu.tsx +22 -0
  88. package/components/counter/fetchdata.tsx +94 -0
  89. package/components/counter/index.tsx +100 -0
  90. package/components/counter/testall.tsx +438 -0
  91. package/components/datatable/col-vis-modal.tsx +67 -0
  92. package/components/datatable/datatable-static.tsx +114 -0
  93. package/components/datatable/datatable.tsx +2153 -0
  94. package/components/datatable/export-excel-modal.tsx +211 -0
  95. package/components/datatable/filter-modal.tsx +183 -0
  96. package/components/datatable/ts/reorder.ts +178 -0
  97. package/components/datatable/upper-buttons-wrapper.tsx +46 -0
  98. package/components/dropdown/country-dropdown.tsx +367 -0
  99. package/components/dropdown/image-dropdown.tsx +240 -0
  100. package/components/dropdown/index.tsx +997 -0
  101. package/components/dropdown/language-dropdown.tsx +93 -0
  102. package/components/dropdown/mobile/legacy_fdd.ts +462 -0
  103. package/components/dropdown/mobile/legacy_lvb.ts +363 -0
  104. package/components/dropdown/ts/select2-multi-checkboxes.ts +152 -0
  105. package/components/dropdown-button/dropdown-button-heading.tsx +16 -0
  106. package/components/dropdown-button/dropdown-button-item.tsx +95 -0
  107. package/components/dropdown-button/dropdown-button-separator.tsx +12 -0
  108. package/components/dropdown-button/dropdown-button.tsx +77 -0
  109. package/components/dropdown-button/language-dropdown-button.tsx +53 -0
  110. package/components/dropzone/gallery-dropzone.tsx +336 -0
  111. package/components/file-downloader/index.tsx +265 -0
  112. package/components/form/fieldset.tsx +81 -0
  113. package/components/form/flex-container.tsx +28 -0
  114. package/components/form/footer-buttons.tsx +16 -0
  115. package/components/form/form-item-flex.tsx +38 -0
  116. package/components/form/form-item-wrapper.tsx +198 -0
  117. package/components/form/form.tsx +12 -0
  118. package/components/form/separator.tsx +18 -0
  119. package/components/form/validation-result-displayer.tsx +35 -0
  120. package/components/fullcalendar/fullcalendar-draggable-event.tsx +85 -0
  121. package/components/fullcalendar/timegrid-calendar.tsx +499 -0
  122. package/components/google/maps.tsx +156 -0
  123. package/components/google/places-autocomplete.tsx +331 -0
  124. package/components/google/ts/google-maps-api.ts +47 -0
  125. package/components/highlight-js/index.tsx +62 -0
  126. package/components/home/index.tsx +48 -0
  127. package/components/html-literal/html-literal.tsx +40 -0
  128. package/components/image-crop/image-cropping-modal.tsx +311 -0
  129. package/components/image-crop/upload-and-crop.tsx +171 -0
  130. package/components/input/checkbox-without-label.tsx +65 -0
  131. package/components/input/checkbox.tsx +121 -0
  132. package/components/input/color-picker.tsx +91 -0
  133. package/components/input/daterange-picker.tsx +409 -0
  134. package/components/input/datetime-picker.tsx +330 -0
  135. package/components/input/image-upload.tsx +128 -0
  136. package/components/input/localized-string-input.tsx +269 -0
  137. package/components/input/localized-string-textarea.tsx +128 -0
  138. package/components/input/localized-string-wysiwyg.tsx +125 -0
  139. package/components/input/localized-url-input.tsx +363 -0
  140. package/components/input/numeric-input.tsx +204 -0
  141. package/components/input/plugins/daterangepicker/jquery.daterangepicker.ts +2465 -0
  142. package/components/input/plugins/trumbowyg/custom-cleanpaste.ts +105 -0
  143. package/components/input/plugins/trumbowyg/custom-colors.ts +278 -0
  144. package/components/input/plugins/trumbowyg/lang/cs.ts +56 -0
  145. package/components/input/plugins/trumbowyg/lang/de.ts +59 -0
  146. package/components/input/plugins/trumbowyg/lang/sk.ts +58 -0
  147. package/components/input/plugins/trumbowyg/open-modal-fix.ts +127 -0
  148. package/components/input/radio-button-group.tsx +208 -0
  149. package/components/input/textarea.tsx +85 -0
  150. package/components/input/textbox-without-label.tsx +108 -0
  151. package/components/input/textbox.tsx +135 -0
  152. package/components/input/ts/dateInputHelper.ts +123 -0
  153. package/components/input/wysiwig.tsx +523 -0
  154. package/components/loading-indicator/index.tsx +39 -0
  155. package/components/modal/animation-error.tsx +28 -0
  156. package/components/modal/animation-success.tsx +30 -0
  157. package/components/modal/icon-question.tsx +25 -0
  158. package/components/modal/icon-warning.tsx +25 -0
  159. package/components/modal/modal-body.tsx +16 -0
  160. package/components/modal/modal-footer.tsx +12 -0
  161. package/components/modal/modal-utils.ts +94 -0
  162. package/components/modal/modal.tsx +178 -0
  163. package/components/modal/ts/file-manager-dialog.ts +95 -0
  164. package/components/open-street-map/open-street-map.tsx +248 -0
  165. package/components/progress-bar/index.tsx +54 -0
  166. package/components/share/share-modal.tsx +268 -0
  167. package/components/share/share.tsx +240 -0
  168. package/components/sortable/sortable-container.tsx +62 -0
  169. package/components/sortable/sortable-item.tsx +18 -0
  170. package/components/spreadsheet/spreadsheet.tsx +135 -0
  171. package/components/summary-stats/summary-stats-item.tsx +61 -0
  172. package/components/summary-stats/summary-stats.tsx +18 -0
  173. package/components/tabs/tab-page.tsx +30 -0
  174. package/components/tabs/tabs.tsx +275 -0
  175. package/components/tilebox/tilebox.tsx +80 -0
  176. package/components/tooltip/index.tsx +97 -0
  177. package/components/transition/index.tsx +17 -0
  178. package/components/ui/bootstrap-modal.ts +52 -0
  179. package/components/ui/notification.ts +210 -0
  180. package/components/wizard/wizard-subtitle.tsx +12 -0
  181. package/components/wizard/wizard-tab.tsx +28 -0
  182. package/components/wizard/wizard.tsx +173 -0
  183. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # inviton-powerduck
@@ -0,0 +1,18 @@
1
+ import PowerduckState, { PowerduckStateInitArgs } from './powerduck-state';
2
+ import { IPowerduckSystemResources } from './powerduck-system-resources';
3
+ import jquery from "jquery";
4
+ import moment from "moment";
5
+ import select2 from "select2";
6
+
7
+ export default class PowerduckInitializer {
8
+ static initPlugins() {
9
+ window["jQuery"] = jquery;
10
+ window["$"] = window["jQuery"];
11
+ window["moment"] = moment;
12
+ window["select2"] = select2();
13
+ }
14
+
15
+ static initState<TResoures extends IPowerduckSystemResources>(resources: TResoures, args?: PowerduckStateInitArgs) {
16
+ PowerduckState.initialize(resources, args);
17
+ }
18
+ }
@@ -0,0 +1,145 @@
1
+ import { Language } from "../common/enums";
2
+ import { isNullOrEmpty } from "../common/utils/is-null-or-empty";
3
+ import { LanguageUtils } from "../common/utils/language-utils";
4
+ import { IDynamicComponentContainer } from "../components/app/dynamic-component-contracts";
5
+ import { IPowerduckSystemResources } from "./powerduck-system-resources";
6
+
7
+
8
+ type PublicStaticMethods<T> = {
9
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never;
10
+ };
11
+
12
+ // Extract the public static methods from PowerduckState
13
+ export type PowerduckStateInitArgs = Partial<PublicStaticMethods<typeof PowerduckState>>;
14
+
15
+ export default class PowerduckState {
16
+ private static _resources: IPowerduckSystemResources;
17
+ private static _language: Language;
18
+ private static _fullBlockerHtml = document.querySelector(".loading-full-overlay")?.outerHTML || `<div class="loading-full-overlay"><div class="loading-inner"><div class="loading-indicator-wrap"><div class="holdon-white holdon-overlay holdon-element"><div class="holdon-content"><div class="sk-rect"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div></div></div></div></div></div>`;
19
+ private static _blockerHtml = '<div class="holdon-white holdon-overlay holdon-element"><div class="holdon-content"><div class="sk-rect"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div></div></div>';
20
+ private static _blockerSelector = ".holdon-overlay";
21
+ private static _stickyMap: { [index: string]: IStickyDeclaration } = {}
22
+
23
+ static initialize(resources: IPowerduckSystemResources, args?: PowerduckStateInitArgs) {
24
+ PowerduckState._resources = resources;
25
+
26
+ if (args != null) {
27
+ for (const key in args) {
28
+ PowerduckState[key] = args[key];
29
+ }
30
+ }
31
+ }
32
+
33
+ static getCurrentLanguage(): Language {
34
+ return this._language ?? Language.Slovak;
35
+ }
36
+
37
+ static getCurrentLanguageCode(): string {
38
+ return LanguageUtils.getLanguageCode(PowerduckState.getCurrentLanguage())
39
+ }
40
+
41
+ static getIntransparentBlockerHtml(): string {
42
+ return PowerduckState._fullBlockerHtml;
43
+ }
44
+
45
+ static getBlockerHtml(): string {
46
+ return PowerduckState._blockerHtml;
47
+ }
48
+
49
+ static getBlockerSelector(): string {
50
+ return PowerduckState._blockerSelector;
51
+ }
52
+
53
+ static getResourceValue(key: keyof IPowerduckSystemResources) {
54
+ if (this._resources != null) {
55
+ return this._resources[key] || `{{${key}}}`;
56
+ }
57
+
58
+ return `{{${key}}}`;
59
+ }
60
+
61
+ static getCdnPath() {
62
+ return '';
63
+ }
64
+
65
+ static getCurrentRouteQuery(): any {
66
+ return null;
67
+ }
68
+
69
+ static getBootstrapOnStyle(): 'primary' | 'info' {
70
+ return 'primary';
71
+ }
72
+
73
+ static getGeonamesUsername(): string {
74
+ return null;
75
+ }
76
+
77
+ static getGoogleMapsApiKey(): string {
78
+ return null;
79
+ }
80
+
81
+ static parseErrorMessage(respText: string): string {
82
+ let parsedErr: any;
83
+ if (respText == null || respText.indexOf("{") != 0) {
84
+ return respText;
85
+ }
86
+
87
+ try {
88
+ parsedErr = JSON.parse(respText);
89
+ } catch (error) {
90
+ parsedErr = respText as any;
91
+ }
92
+
93
+ if (!isNullOrEmpty(parsedErr?.messages)) {
94
+ let msgBuilder = "";
95
+ parsedErr.messages.forEach((msgData) => {
96
+ if (!isNullOrEmpty(msgData.message)) {
97
+ if (msgBuilder.length > 0) {
98
+ msgBuilder += "\n\n";
99
+ }
100
+
101
+ msgBuilder += msgData.message;
102
+ }
103
+ });
104
+
105
+ return msgBuilder;
106
+ }
107
+
108
+ return null;
109
+ }
110
+
111
+ static get rootDynamicComponentContainer(): IDynamicComponentContainer {
112
+ return window["RootDynamicContainerInstance"];
113
+ }
114
+
115
+
116
+ static registerStickyTabs(id: string, state: IStickyDeclaration): void {
117
+ PowerduckState._stickyMap[id] = state
118
+ }
119
+
120
+ static unregisterStickyTabs(id: string): void {
121
+ if (PowerduckState._stickyMap[id] != null) {
122
+ try {
123
+ delete PowerduckState._stickyMap[id]
124
+ } catch (e) { }
125
+ }
126
+ }
127
+
128
+ static get stickyTabs(): IStickyDeclaration {
129
+ for (let id in PowerduckState._stickyMap) {
130
+ if (PowerduckState._stickyMap[id].HasSticky) {
131
+ return PowerduckState._stickyMap[id]
132
+ }
133
+ }
134
+
135
+ return {
136
+ AllowTabChange: true,
137
+ HasSticky: false,
138
+ }
139
+ }
140
+ }
141
+
142
+ interface IStickyDeclaration {
143
+ HasSticky: boolean
144
+ AllowTabChange: boolean
145
+ }
@@ -0,0 +1,61 @@
1
+ export interface IPowerduckSystemResources {
2
+ requestTimeout: string
3
+ yes: string
4
+ no: string;
5
+ all: string
6
+ add: string
7
+ error: string
8
+ errorFetchingData: string
9
+ allTogether: string;
10
+ edit: string
11
+ remove: string
12
+ warning: string
13
+ cancel: string
14
+ negationBase: string
15
+ continue: string
16
+ back: string
17
+ submit: string
18
+ close: string
19
+ search: string
20
+ searchedValue: string
21
+ image: string
22
+ noResultsFound: string
23
+ colVisLabel: string
24
+ deletePromptSingular: string
25
+ dtMassOperationWarningText: string
26
+ dtLayoutMobile: string
27
+ dtLayoutTable: string
28
+ dtLayoutCompact: string
29
+ recordsDtLabel: string
30
+ dtCountText: string
31
+ dtCountFilteredOutOf: string
32
+ dtNoMobileFilter: string
33
+ dtOnlyExclusive: string
34
+ itemsOutOfArray: string
35
+ fileDownloadTitle: string
36
+ imageCrop: string
37
+ copyToClipboard: string
38
+ copyToClipboardSuccess: string
39
+ loginExpired: string
40
+
41
+ language0: string;
42
+ language1: string;
43
+ language2: string;
44
+ language3: string;
45
+ language4: string;
46
+ language5: string;
47
+ language6: string;
48
+ language7: string;
49
+
50
+ errorsOnForm: string;
51
+ validationErrorRequired: string;
52
+ validationErrorMinValue: string;
53
+ validationErrorMaxValue: string;
54
+ validationErrorMinLength: string;
55
+ validationErrorMaxLength: string;
56
+ validationErrorBetween: string;
57
+ validationErrorEmail: string;
58
+ validationErrorAlpha: string;
59
+ validationErrorAlphaNum: string;
60
+ validationErrorGeneric: string;
61
+ }
@@ -0,0 +1,5 @@
1
+ import { PowerduckViewModelBase } from "../common/base-component";
2
+
3
+ export abstract class TsxComponentExtendedBase<P> extends PowerduckViewModelBase {
4
+ private vueTsxProps: Readonly<{ ref?: string; key?: string | number }> & Readonly<P>;
5
+ }
package/app/vuetsx.ts ADDED
@@ -0,0 +1,90 @@
1
+ import { ComponentCustomOptions, MethodOptions } from "vue";
2
+ import { Prop, Vue, Component as OriginalComponent } from "vue-facing-decorator";
3
+ import { ComponentSetupFunction, Cons } from "vue-facing-decorator/dist/component";
4
+ import { ValidationRuleset, ValidationState } from "../common/static-wrappers/interfaces/validation-interface";
5
+
6
+ @Component
7
+ export default class TsxComponent<P> extends Vue {
8
+ private vueTsxProps: Readonly<{ ref?: string; key?: string | number }> & Readonly<P>;
9
+ model: never;
10
+
11
+ @Prop() validationState!: ValidationState;
12
+
13
+ protected get hasValidationError(): boolean {
14
+ return this.validationState != null && this.validationState.valid == false;
15
+ }
16
+
17
+ protected get validationCssClass(): string {
18
+ return this.hasValidationError ? "has-danger" : "";
19
+ }
20
+
21
+ protected get validationErrorMessage(): string {
22
+ return this.hasValidationError ? this.validationState.errorMessage : null;
23
+ }
24
+
25
+ protected populateValidationDeclaration(): void {
26
+ if (this.validationState != null) {
27
+ // @ts-expect-error it is readonly
28
+ this.validationState.validationDeclaration["_changed"] = true;
29
+ // @ts-expect-error it is readonly
30
+ this.validationState.validationDeclaration["_label"] = this["label"];
31
+ }
32
+ }
33
+
34
+ protected getSlotProperties<T>(type: string): Array<T> {
35
+ var retVal: Array<T> = [];
36
+ for (const node of (this.$slots.default?.() || [])) {
37
+ const fwId = (node as any).type?.__vfdConstructor?.$fwName;
38
+ if (fwId == type) {
39
+ retVal.push(node.props as any)
40
+ }
41
+ }
42
+
43
+ return retVal;
44
+ }
45
+ }
46
+
47
+ @Component
48
+ export class TsxComponentLite<P> extends Vue {
49
+ model: never;
50
+ private vueTsxProps: Readonly<{ ref?: string }> & Readonly<P>;
51
+ }
52
+
53
+ type ComponentOption = {
54
+ name?: string;
55
+ emits?: string[];
56
+ provide?: Record<string, any> | Function;
57
+ components?: Record<string, any>;
58
+ directives?: Record<string, any>;
59
+ inheritAttrs?: boolean;
60
+ expose?: string[];
61
+ render?: Function;
62
+ modifier?: (raw: any) => any;
63
+ options?: ComponentCustomOptions & Record<string, any>;
64
+ template?: string;
65
+ mixins?: any[];
66
+ setup?: ComponentSetupFunction;
67
+ methods?: MethodOptions;
68
+ };
69
+
70
+ type ComponentConsOption = Cons | ComponentOption;
71
+
72
+ type ComponentOptions = {
73
+ validations?: ValidationRuleset<any>;
74
+ } & ComponentConsOption;
75
+
76
+ export function Component(options: ComponentOptions, ctx?: any) {
77
+ return OriginalComponent(options as any, ctx);
78
+ }
79
+
80
+ declare global {
81
+ namespace JSX {
82
+ interface ElementAttributesProperty {
83
+ vueTsxProps: {};
84
+ }
85
+ }
86
+
87
+ interface PublicMethodSet<T> {
88
+ methods: T;
89
+ }
90
+ }
@@ -0,0 +1,11 @@
1
+ export interface IWebApiClient {
2
+ webClient: boolean;
3
+ }
4
+
5
+ export enum WebClientApiMethod {
6
+ Get = "get",
7
+ GetAll = "getAll",
8
+ Post = "post",
9
+ Put = "put",
10
+ Delete = "delete",
11
+ }
@@ -0,0 +1,121 @@
1
+ import { AjaxRequestProvider, AjaxRequestProviderRequestArgs, AjaxRequestProviderRequestResponse } from "./api-http";
2
+
3
+ export class AjaxProviderXhr implements AjaxRequestProvider {
4
+ sendRequest<T>(args: AjaxRequestProviderRequestArgs): Promise<AjaxRequestProviderRequestResponse> {
5
+ return new Promise((resolve) => {
6
+ var x = new XMLHttpRequest()
7
+
8
+ x.open(args.method, args.url, true)
9
+ x.onreadystatechange = function () {
10
+ if (x.readyState == 4) {
11
+ let status = x.status
12
+ if (status == 0) {
13
+ status = -4
14
+ }
15
+
16
+ resolve({
17
+ httpCode: status,
18
+ responseText: x.responseText,
19
+ })
20
+ }
21
+ }
22
+ ;(args.headers || []).forEach(function (ajaxHeader) {
23
+ x.setRequestHeader(
24
+ ajaxHeader.name,
25
+ typeof ajaxHeader.value === "string" || ajaxHeader.value instanceof String
26
+ ? (ajaxHeader.value as string)
27
+ : ajaxHeader.value(),
28
+ )
29
+ })
30
+
31
+ if (args.timeout != null) {
32
+ x.timeout = args.timeout
33
+ }
34
+
35
+ x.send(args.data)
36
+ })
37
+ }
38
+ }
39
+
40
+ export class AjaxProviderCordova implements AjaxRequestProvider {
41
+ sendRequest<T>(args: AjaxRequestProviderRequestArgs): Promise<AjaxRequestProviderRequestResponse> {
42
+ return new Promise((resolve) => {
43
+ let cordova = (window as any).cordova
44
+ let timeout: number = 45
45
+
46
+ if (args.timeout > 0) {
47
+ timeout = args.timeout / 1000
48
+ }
49
+
50
+ let headerMap = {} as any
51
+ ;(args.headers || []).forEach((header) => {
52
+ headerMap[header.name] = header.value
53
+ })
54
+
55
+ let requestArgs = {
56
+ timeout: timeout,
57
+ method: args.method.toLowerCase(),
58
+ serializer: "json",
59
+ responseType: "text",
60
+ headers: headerMap,
61
+ }
62
+
63
+ if (args.data != null) {
64
+ let data = args.data
65
+ if (typeof data === "string" || data instanceof String) {
66
+ data = JSON.parse(data as any)
67
+ }
68
+
69
+ ;(requestArgs as any).data = data
70
+ }
71
+
72
+ let timeoutEnsure = timeout * 1000 + 3500
73
+ let cbRaised = false
74
+ let timeoutEnsureHandle = setTimeout(function () {
75
+ if (!cbRaised) {
76
+ cbRaised = true
77
+ resolve({
78
+ httpCode: 0,
79
+ responseText: "timeout",
80
+ })
81
+ }
82
+ }, timeoutEnsure)
83
+
84
+ let tryClearTimeoutEnsure = function () {
85
+ cbRaised = true
86
+
87
+ try {
88
+ clearTimeout(timeoutEnsureHandle)
89
+ } catch (e) {}
90
+ }
91
+
92
+ cordova.plugin.http.sendRequest(
93
+ args.url,
94
+ requestArgs,
95
+ function (response) {
96
+ if (cbRaised) {
97
+ return
98
+ }
99
+
100
+ tryClearTimeoutEnsure()
101
+ resolve({
102
+ httpCode: response.status,
103
+ responseText: response.data,
104
+ })
105
+ },
106
+ function (response) {
107
+ if (cbRaised) {
108
+ return
109
+ }
110
+
111
+ tryClearTimeoutEnsure()
112
+ resolve({
113
+ httpCode: response.status,
114
+ responseText: response.error,
115
+ })
116
+ },
117
+ )
118
+ })
119
+ }
120
+ }
121
+