jsf.js_next_gen 4.0.1-beta.1 → 4.0.1-beta.3
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.
- package/README.md +6 -0
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/functions/myfaces.ab.html +1 -1
- package/dist/docs/functions/{myfaces.onOnDomReady.html → myfaces.onDomReady.html} +5 -5
- package/dist/docs/index.html +9 -0
- package/dist/docs/modules/myfaces.html +2 -2
- package/dist/docs/variables/myfaces.oam.html +1 -1
- package/dist/window/faces-development.js +1285 -1295
- package/dist/window/faces-development.js.br +0 -0
- package/dist/window/faces-development.js.gz +0 -0
- package/dist/window/faces-development.js.map +1 -1
- package/dist/window/faces.js +1 -1
- package/dist/window/faces.js.br +0 -0
- package/dist/window/faces.js.gz +0 -0
- package/dist/window/faces.js.map +1 -1
- package/dist/window/jsf-development.js +1285 -1295
- package/dist/window/jsf-development.js.br +0 -0
- package/dist/window/jsf-development.js.gz +0 -0
- package/dist/window/jsf-development.js.map +1 -1
- package/dist/window/jsf.js +1 -1
- package/dist/window/jsf.js.br +0 -0
- package/dist/window/jsf.js.gz +0 -0
- package/dist/window/jsf.js.map +1 -1
- package/package.json +5 -5
- package/plans for 4.0.1.txt +8 -0
- package/src/main/typescript/api/_api.ts +1 -1
- package/src/main/typescript/impl/AjaxImpl.ts +60 -44
- package/src/main/typescript/impl/core/Const.ts +5 -2
- package/src/main/typescript/impl/util/AsyncRunnable.ts +81 -6
- package/src/main/typescript/impl/util/ExtDomQuery.ts +7 -9
- package/src/main/typescript/impl/util/FileUtils.ts +26 -22
- package/src/main/typescript/impl/util/HiddenInputBuilder.ts +7 -3
- package/src/main/typescript/impl/util/Lang.ts +61 -4
- package/src/main/typescript/impl/util/XhrQueueController.ts +112 -0
- package/src/main/typescript/impl/xhrCore/EventData.ts +3 -3
- package/src/main/typescript/impl/xhrCore/ResponseProcessor.ts +12 -10
- package/src/main/typescript/impl/xhrCore/XhrFormData.ts +32 -19
- package/src/main/typescript/impl/xhrCore/XhrRequest.ts +51 -72
- package/src/main/typescript/myfaces/OamSubmit.ts +6 -6
- package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +179 -40
- package/src/main/typescript/test/frameworkBase/_ext/monadish/MonadTest.spec.ts +4 -4
- package/src/main/typescript/test/frameworkBase/_ext/monadish/fixtures/blank.css +0 -0
- package/src/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-with-header.ts +921 -0
- package/src/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-without-header.ts +108 -0
- package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +3 -2
- package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/jakarta.faces.resource/faces.js.jsf +0 -0
- package/src/main/typescript/test/myfaces/OnLoadSpec.ts +52 -0
- package/src/main/typescript/test/queue/AsynchronousProbe.ts +5 -5
- package/src/main/typescript/test/queue/AsynchronousQueueTest.spec.ts +4 -3
- package/src/main/typescript/test/xhrCore/EventTests.spec.ts +28 -22
- package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +4 -4
- package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +2 -2
- package/src/main/typescript/test/xhrCore/RequestTest.spec.ts +80 -6
- package/src/main/typescript/test/xhrCore/RequestTest_23.spec.ts +6 -1
- package/src/main/typescript/test/xhrCore/ResponseTest.spec.ts +23 -22
- package/target/api/_api.js +2 -2
- package/target/api/_api.js.map +1 -1
- package/target/impl/AjaxImpl.js +48 -38
- package/target/impl/AjaxImpl.js.map +1 -1
- package/target/impl/core/Const.js +7 -5
- package/target/impl/core/Const.js.map +1 -1
- package/target/impl/util/AsyncRunnable.js +60 -0
- package/target/impl/util/AsyncRunnable.js.map +1 -1
- package/target/impl/util/ExtDomQuery.js +8 -8
- package/target/impl/util/ExtDomQuery.js.map +1 -1
- package/target/impl/util/FileUtils.js +21 -20
- package/target/impl/util/FileUtils.js.map +1 -1
- package/target/impl/util/HiddenInputBuilder.js +7 -3
- package/target/impl/util/HiddenInputBuilder.js.map +1 -1
- package/target/impl/util/Lang.js +52 -1
- package/target/impl/util/Lang.js.map +1 -1
- package/target/impl/xhrCore/EventData.js +2 -2
- package/target/impl/xhrCore/EventData.js.map +1 -1
- package/target/impl/xhrCore/ResponseProcessor.js +9 -7
- package/target/impl/xhrCore/ResponseProcessor.js.map +1 -1
- package/target/impl/xhrCore/XhrFormData.js +29 -15
- package/target/impl/xhrCore/XhrFormData.js.map +1 -1
- package/target/impl/xhrCore/XhrRequest.js +43 -64
- package/target/impl/xhrCore/XhrRequest.js.map +1 -1
- package/target/myfaces/OamSubmit.js +5 -3
- package/target/myfaces/OamSubmit.js.map +1 -1
- package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +138 -37
- package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js.map +1 -1
- package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js +4 -4
- package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js.map +1 -1
- package/target/test/frameworkBase/_ext/shared/StandardInits.js +3 -2
- package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
- package/target/test/queue/AsynchronousQueueTest.spec.js +3 -3
- package/target/test/queue/AsynchronousQueueTest.spec.js.map +1 -1
- package/target/test/xhrCore/EventTests.spec.js +26 -19
- package/target/test/xhrCore/EventTests.spec.js.map +1 -1
- package/target/test/xhrCore/NamespacesRequestTest.spec.js +3 -3
- package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -1
- package/target/test/xhrCore/RequestParamsTest.spec.js +1 -1
- package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
- package/target/test/xhrCore/RequestTest.spec.js +73 -4
- package/target/test/xhrCore/RequestTest.spec.js.map +1 -1
- package/target/test/xhrCore/RequestTest_23.spec.js +6 -0
- package/target/test/xhrCore/RequestTest_23.spec.js.map +1 -1
- package/target/test/xhrCore/ResponseTest.spec.js +22 -15
- package/target/test/xhrCore/ResponseTest.spec.js.map +1 -1
- package/src/main/typescript/impl/util/AsyncQueue.ts +0 -133
- package/src/main/typescript/test/frameworkBase/_ext/monadish/StreamTest.spec.ts +0 -231
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {Lang as LangBase, Config, Optional, DomQuery, DQ
|
|
18
|
+
import {Lang as LangBase, Config, Optional, DomQuery, DQ} from "mona-dish";
|
|
19
19
|
import {Messages} from "../i18n/Messages";
|
|
20
20
|
import {EMPTY_STR, HTML_TAG_FORM} from "../core/Const";
|
|
21
21
|
import {getEventTarget} from "../xhrCore/RequestDataResolver";
|
|
@@ -85,10 +85,10 @@ export module ExtLang {
|
|
|
85
85
|
installedLocale = installedLocale ?? new Messages();
|
|
86
86
|
|
|
87
87
|
let msg = installedLocale[key] ?? defaultMessage ?? key;
|
|
88
|
-
|
|
89
|
-
Stream.of(...templateParams).each((param, cnt) => {
|
|
88
|
+
templateParams.forEach((param, cnt) => {
|
|
90
89
|
msg = msg.replace(new RegExp(["\\{", cnt, "\\}"].join(EMPTY_STR), "g"), param);
|
|
91
|
-
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
92
|
|
|
93
93
|
return msg;
|
|
94
94
|
}
|
|
@@ -202,6 +202,61 @@ export module ExtLang {
|
|
|
202
202
|
defaultValue;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* expands an associative array into an array of key value tuples
|
|
207
|
+
* @param value
|
|
208
|
+
*/
|
|
209
|
+
export function ofAssoc(value: {[key: string]: any}) {
|
|
210
|
+
return Object.keys(value)
|
|
211
|
+
.map(key => [key, value[key]]);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function collectAssoc(target: any, item: any) {
|
|
215
|
+
target[item[0]] = item[1];
|
|
216
|
+
return target;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The active timeout for the "debounce".
|
|
221
|
+
* Since we only use it in the XhrController
|
|
222
|
+
* we can use a local module variable here
|
|
223
|
+
*/
|
|
224
|
+
let activeTimeouts = {};
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* a simple debounce function
|
|
231
|
+
* which waits until a timeout is reached and
|
|
232
|
+
* if something comes in in between debounces
|
|
233
|
+
*
|
|
234
|
+
* @param runnable a runnable which should go under debounce control
|
|
235
|
+
* @param timeout a timeout for the debounce window
|
|
236
|
+
*/
|
|
237
|
+
export function debounce(key, runnable, timeout) {
|
|
238
|
+
function clearActiveTimeout() {
|
|
239
|
+
clearTimeout(activeTimeouts[key]);
|
|
240
|
+
delete activeTimeouts[key];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!!(activeTimeouts?.[key])) {
|
|
244
|
+
clearActiveTimeout();
|
|
245
|
+
}
|
|
246
|
+
if (timeout > 0) {
|
|
247
|
+
activeTimeouts[key] = setTimeout(() => {
|
|
248
|
+
try {
|
|
249
|
+
runnable();
|
|
250
|
+
} finally {
|
|
251
|
+
clearActiveTimeout();
|
|
252
|
+
}
|
|
253
|
+
}, timeout);
|
|
254
|
+
} else {
|
|
255
|
+
runnable();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
205
260
|
/**
|
|
206
261
|
* assert that the form exists and throw an exception in the case it does not
|
|
207
262
|
*
|
|
@@ -212,4 +267,6 @@ export module ExtLang {
|
|
|
212
267
|
throw makeException(new Error(), null, null, "Impl", "getForm", getMessage("ERR_FORM"));
|
|
213
268
|
}
|
|
214
269
|
}
|
|
270
|
+
|
|
271
|
+
|
|
215
272
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {IAsyncRunnable} from "./AsyncRunnable";
|
|
2
|
+
import {ExtLang} from "./Lang";
|
|
3
|
+
import debounce = ExtLang.debounce;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A simple XHR queue controller
|
|
7
|
+
* following the async op -> next pattern
|
|
8
|
+
* Faces enforces for the XHR handling
|
|
9
|
+
*/
|
|
10
|
+
export class XhrQueueController<T extends IAsyncRunnable<any>> {
|
|
11
|
+
queue = [];
|
|
12
|
+
taskRunning = false;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* executes or enqueues an element
|
|
19
|
+
* @param runnable the runnable (request) to be enqueued
|
|
20
|
+
* @param timeOut timeout if > 0 which defers the execution
|
|
21
|
+
* until the debounce window for the timeout is closed.
|
|
22
|
+
*/
|
|
23
|
+
enqueue(runnable: T, timeOut: number = 0) {
|
|
24
|
+
debounce("xhrQueue", () => {
|
|
25
|
+
const requestHandler = this.enrichRunnable(runnable);
|
|
26
|
+
if (!this.taskRunning) {
|
|
27
|
+
this.signalTaskRunning();
|
|
28
|
+
requestHandler.start();
|
|
29
|
+
} else {
|
|
30
|
+
this.queue.push(requestHandler);
|
|
31
|
+
}
|
|
32
|
+
}, timeOut);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* trigger the next element in the queue
|
|
37
|
+
* to be started!
|
|
38
|
+
*/
|
|
39
|
+
next() {
|
|
40
|
+
this.updateTaskRunning();
|
|
41
|
+
const next = this.queue.shift();
|
|
42
|
+
next?.start();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* clears and resets the queue
|
|
47
|
+
*/
|
|
48
|
+
clear() {
|
|
49
|
+
this.queue.length = 0;
|
|
50
|
+
this.updateTaskRunning();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* true if queue is empty
|
|
55
|
+
*/
|
|
56
|
+
get isEmpty(): boolean {
|
|
57
|
+
return !this.queue.length;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Enriches the incoming async asyncRunnable
|
|
62
|
+
* with the error and next handling
|
|
63
|
+
* (aka: asyncRunnable is done -> next
|
|
64
|
+
* error -> clear queue
|
|
65
|
+
* @param asyncRunnable the async runnable which needs enrichment
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
private enrichRunnable(asyncRunnable: T) {
|
|
69
|
+
/**
|
|
70
|
+
* we can use the Promise pattern asyncrunnable uses
|
|
71
|
+
* to trigger queue control callbacks of next element
|
|
72
|
+
* and clear the queue (theoretically this
|
|
73
|
+
* would work with any promise)
|
|
74
|
+
*/
|
|
75
|
+
try {
|
|
76
|
+
return asyncRunnable
|
|
77
|
+
.then(() => this.next())
|
|
78
|
+
.catch((e) => this.handleError(e));
|
|
79
|
+
} catch (e) {
|
|
80
|
+
this.handleError(e);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* alerts the queue that a task is running
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
private signalTaskRunning() {
|
|
91
|
+
this.taskRunning = true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* updates the task running status according to the current queue
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
private updateTaskRunning() {
|
|
99
|
+
this.taskRunning = !this.isEmpty;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* standard error handling
|
|
104
|
+
* we clear the queue and then bomb out
|
|
105
|
+
* @param e
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
private handleError(e) {
|
|
109
|
+
this.clear();
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import {Config, DQ} from "mona-dish";
|
|
17
|
-
import {BEGIN, CTX_PARAM_REQ_PASS_THR, EVENT,
|
|
17
|
+
import {BEGIN, CTX_PARAM_REQ_PASS_THR, EVENT, P_AJAX_SOURCE, SOURCE} from "../core/Const";
|
|
18
18
|
|
|
19
19
|
export class EventData implements IEventData{
|
|
20
20
|
type: string;
|
|
@@ -32,8 +32,8 @@ export class EventData implements IEventData{
|
|
|
32
32
|
eventData.status = name;
|
|
33
33
|
|
|
34
34
|
let sourceId: string = context.getIf(SOURCE)
|
|
35
|
-
.orElseLazy(() => context.getIf(
|
|
36
|
-
.orElseLazy(() => context.getIf(CTX_PARAM_REQ_PASS_THR,
|
|
35
|
+
.orElseLazy(() => context.getIf(P_AJAX_SOURCE).value)
|
|
36
|
+
.orElseLazy(() => context.getIf(CTX_PARAM_REQ_PASS_THR, P_AJAX_SOURCE).value)
|
|
37
37
|
.value;
|
|
38
38
|
if (sourceId) {
|
|
39
39
|
eventData.source = DQ.byId(sourceId, true).first().value.value;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {Config, DomQuery, DomQueryCollector, DQ, DQ$, Lang,
|
|
17
|
+
import {Config, DomQuery, DomQueryCollector, DQ, DQ$, Lang, XMLQuery} from "mona-dish";
|
|
18
18
|
import {Implementation} from "../AjaxImpl";
|
|
19
19
|
import {Assertions} from "../util/Assertions";
|
|
20
20
|
import {IResponseProcessor} from "./IResponseProcessor";
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
ON_EVENT,
|
|
47
47
|
P_CLIENT_WINDOW,
|
|
48
48
|
P_EXECUTE,
|
|
49
|
-
|
|
49
|
+
P_AJAX_SOURCE,
|
|
50
50
|
P_RENDER,
|
|
51
51
|
P_RENDER_OVERRIDE,
|
|
52
52
|
P_VIEWSTATE,
|
|
@@ -65,6 +65,8 @@ import {
|
|
|
65
65
|
import {ExtConfig, ExtDomQuery} from "../util/ExtDomQuery";
|
|
66
66
|
import {HiddenInputBuilder} from "../util/HiddenInputBuilder";
|
|
67
67
|
import trim = Lang.trim;
|
|
68
|
+
import {ExtLang} from "../util/Lang";
|
|
69
|
+
import ofAssoc = ExtLang.ofAssoc;
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -174,7 +176,7 @@ export class ResponseProcessor implements IResponseProcessor {
|
|
|
174
176
|
*/
|
|
175
177
|
|
|
176
178
|
const mergedErrorData = new ExtConfig({});
|
|
177
|
-
mergedErrorData.assign(SOURCE).value = this.externalContext.getIf(
|
|
179
|
+
mergedErrorData.assign(SOURCE).value = this.externalContext.getIf(P_AJAX_SOURCE).get(0).value;
|
|
178
180
|
mergedErrorData.assign(ERROR_NAME).value = node.querySelectorAll(ERROR_NAME).textContent(EMPTY_STR);
|
|
179
181
|
mergedErrorData.assign(ERROR_MESSAGE).value = node.querySelectorAll(ERROR_MESSAGE).cDATAAsString;
|
|
180
182
|
|
|
@@ -346,15 +348,15 @@ export class ResponseProcessor implements IResponseProcessor {
|
|
|
346
348
|
* as last lifecycle step, before going into the next request.
|
|
347
349
|
*/
|
|
348
350
|
fixViewStates() {
|
|
349
|
-
|
|
350
|
-
.
|
|
351
|
+
ofAssoc(this.internalContext.getIf(APPLIED_VST).orElse({}).value)
|
|
352
|
+
.forEach(([, value]) => {
|
|
351
353
|
const namingContainerId = this.internalContext.getIf(NAMING_CONTAINER_ID);
|
|
352
354
|
const namedViewRoot = !!this.internalContext.getIf(NAMED_VIEWROOT).value
|
|
353
355
|
const affectedForms = this.getContainerForms(namingContainerId)
|
|
354
356
|
.filter(affectedForm => this.isInExecuteOrRender(affectedForm));
|
|
355
357
|
|
|
356
358
|
this.appendViewStateToForms(affectedForms, namedViewRoot, value.value, namingContainerId.orElse("").value);
|
|
357
|
-
})
|
|
359
|
+
})
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
|
|
@@ -364,8 +366,8 @@ export class ResponseProcessor implements IResponseProcessor {
|
|
|
364
366
|
* is done.
|
|
365
367
|
*/
|
|
366
368
|
fixClientWindow() {
|
|
367
|
-
|
|
368
|
-
.
|
|
369
|
+
ofAssoc(this.internalContext.getIf(APPLIED_CLIENT_WINDOW).orElse({}).value)
|
|
370
|
+
.forEach(([, value]) => {
|
|
369
371
|
const namingContainerId = this.internalContext.getIf(NAMING_CONTAINER_ID);
|
|
370
372
|
const namedViewRoot = !!this.internalContext.getIf(NAMED_VIEWROOT).value;
|
|
371
373
|
const affectedForms = this.getContainerForms(namingContainerId)
|
|
@@ -522,7 +524,7 @@ export class ResponseProcessor implements IResponseProcessor {
|
|
|
522
524
|
.orElseLazy(() => this.externalContext.getIf($nsp(P_RENDER)).value)
|
|
523
525
|
.orElse(IDENT_NONE).value.split(/\s+/gi);
|
|
524
526
|
const executeAndRenders = executes.concat(...renders);
|
|
525
|
-
return
|
|
527
|
+
return [...executeAndRenders].filter(nameOrId => {
|
|
526
528
|
if ([IDENT_ALL, IDENT_NONE].indexOf(nameOrId) != -1) {
|
|
527
529
|
return true;
|
|
528
530
|
}
|
|
@@ -532,7 +534,7 @@ export class ResponseProcessor implements IResponseProcessor {
|
|
|
532
534
|
return affectedForm.matchesSelector(NAME_OR_ID) ||
|
|
533
535
|
affectedForm.querySelectorAll(NAME_OR_ID).isPresent() ||
|
|
534
536
|
affectedForm.firstParent(NAME_OR_ID).isPresent();
|
|
535
|
-
}).
|
|
537
|
+
}).length > 0;
|
|
536
538
|
}
|
|
537
539
|
|
|
538
540
|
/**
|
|
@@ -13,19 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {Config, DQ
|
|
16
|
+
import {Config, DQ} from "mona-dish";
|
|
17
17
|
import {$nsp, EMPTY_STR, IDENT_NONE, P_VIEWSTATE} from "../core/Const";
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
encodeFormData,
|
|
21
|
-
|
|
21
|
+
fixEmptyParameters, getFormInputsAsArr
|
|
22
22
|
} from "../util/FileUtils";
|
|
23
|
+
import {ExtLang} from "../util/Lang";
|
|
24
|
+
import ofAssoc = ExtLang.ofAssoc;
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
type ParamsMapper<V, K> = (key: V, item: K) => [V, K];
|
|
26
28
|
const defaultParamsMapper: ParamsMapper<string, any> = (key, item) => [key, item];
|
|
27
29
|
|
|
28
|
-
|
|
29
30
|
/**
|
|
30
31
|
* A unified form data class
|
|
31
32
|
* which builds upon our configuration.
|
|
@@ -76,13 +77,17 @@ export class XhrFormData extends Config {
|
|
|
76
77
|
*/
|
|
77
78
|
toFormData(): FormData {
|
|
78
79
|
/*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
|
|
80
|
+
* expands key: [item1, item2]
|
|
81
|
+
* to: [{key: key, value: item1}, {key: key, value: item2}]
|
|
82
|
+
*/
|
|
83
|
+
let expandValueArrays = ([key, item]) => {
|
|
84
|
+
if (Array.isArray(item)) {
|
|
85
|
+
return item.map(value => {
|
|
86
|
+
return {key, value}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
return [{key, value: item}]
|
|
90
|
+
}
|
|
86
91
|
|
|
87
92
|
/*
|
|
88
93
|
* remaps the incoming {key, value} tuples
|
|
@@ -96,10 +101,13 @@ export class XhrFormData extends Config {
|
|
|
96
101
|
/*
|
|
97
102
|
* collects everything into a FormData object
|
|
98
103
|
*/
|
|
99
|
-
return
|
|
100
|
-
.flatMap(
|
|
104
|
+
return ofAssoc(this.value)
|
|
105
|
+
.flatMap(expandValueArrays)
|
|
101
106
|
.map(remapForNamingContainer)
|
|
102
|
-
.
|
|
107
|
+
.reduce((formData: FormData, {key, value}: any) => {
|
|
108
|
+
formData.append(key, value);
|
|
109
|
+
return formData;
|
|
110
|
+
}, new FormData()) as FormData;
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
/**
|
|
@@ -113,6 +121,7 @@ export class XhrFormData extends Config {
|
|
|
113
121
|
|
|
114
122
|
/**
|
|
115
123
|
* generic post init code, for now, this performs some post assign data post-processing
|
|
124
|
+
* @param rootElement the root element which knows the request type (usually a form)
|
|
116
125
|
* @param executes the executable dom nodes which need to be processed into the form data, which we can send
|
|
117
126
|
* in our ajax request
|
|
118
127
|
*/
|
|
@@ -139,20 +148,24 @@ export class XhrFormData extends Config {
|
|
|
139
148
|
|
|
140
149
|
/**
|
|
141
150
|
* determines fields to submit
|
|
142
|
-
* @param {Object} targetBuf - the target form buffer receiving the data
|
|
143
151
|
* @param {Node} parentItem - form element item is nested in
|
|
144
152
|
* @param {Array} partialIds - ids fo PPS
|
|
145
153
|
*/
|
|
146
|
-
private encodeSubmittableFields(parentItem: DQ, partialIds
|
|
154
|
+
private encodeSubmittableFields(parentItem: DQ, partialIds: string[] = []) {
|
|
147
155
|
|
|
148
|
-
const formInputs = getFormInputsAsStream(parentItem);
|
|
149
156
|
const mergeIntoThis = ([key, value]) => this.append(key).value = value;
|
|
150
157
|
const namingContainerRemap = ([key, value]) => this.paramsMapper(key as string, value);
|
|
151
158
|
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
const remappedPartialIds = partialIds.map(partialId => this.remapKeyForNamingContainer(partialId));
|
|
160
|
+
const partialIdsFilter = ([key, value]) => (!remappedPartialIds.length || key.indexOf("@") == 0) ? true :
|
|
161
|
+
remappedPartialIds.indexOf(key) != -1;
|
|
162
|
+
|
|
163
|
+
let inputs = getFormInputsAsArr(parentItem);
|
|
164
|
+
inputs
|
|
165
|
+
.map(fixEmptyParameters)
|
|
154
166
|
.map(namingContainerRemap)
|
|
155
|
-
.
|
|
167
|
+
.filter(partialIdsFilter)
|
|
168
|
+
.forEach(mergeIntoThis);
|
|
156
169
|
}
|
|
157
170
|
|
|
158
171
|
private remapKeyForNamingContainer(key: string): string {
|