@saltcorn/mobile-app 1.1.0-beta.12 → 1.1.0-beta.14
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/package.json +1 -1
- package/src/helpers/api.js +2 -0
- package/src/helpers/navigation.js +6 -0
- package/www/index.html +0 -2
- package/www/js/iframe_view_utils.js +58 -12
package/package.json
CHANGED
package/src/helpers/api.js
CHANGED
|
@@ -9,6 +9,7 @@ export async function apiCall({
|
|
|
9
9
|
body,
|
|
10
10
|
responseType,
|
|
11
11
|
timeout,
|
|
12
|
+
additionalHeaders,
|
|
12
13
|
}) {
|
|
13
14
|
const config =
|
|
14
15
|
typeof saltcorn !== "undefined"
|
|
@@ -19,6 +20,7 @@ export async function apiCall({
|
|
|
19
20
|
const headers = {
|
|
20
21
|
"X-Requested-With": "XMLHttpRequest",
|
|
21
22
|
"X-Saltcorn-Client": "mobile-app",
|
|
23
|
+
...(additionalHeaders || {}),
|
|
22
24
|
};
|
|
23
25
|
if (config.tenantAppName) headers["X-Saltcorn-App"] = config.tenantAppName;
|
|
24
26
|
const token = config.jwt;
|
|
@@ -16,6 +16,12 @@ export function currentLocation() {
|
|
|
16
16
|
return routingHistory[index].route;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function currentUrl() {
|
|
20
|
+
const query = currentQuery();
|
|
21
|
+
const safeQuery = query ? (query.startsWith("?") ? query : `?${query}`) : "";
|
|
22
|
+
return `${currentLocation()}${safeQuery}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
export function currentQuery(skipPosts = false) {
|
|
20
26
|
if (routingHistory.length == 0) return undefined;
|
|
21
27
|
let index = routingHistory.length - 1;
|
package/www/index.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*eslint-env browser*/
|
|
2
|
-
/*global $, KTDrawer, submitWithEmptyAction, is_paging_param, bootstrap, common_done, unique_field_from_rows, inline_submit_success*/
|
|
2
|
+
/*global $, KTDrawer, submitWithEmptyAction, is_paging_param, bootstrap, common_done, unique_field_from_rows, inline_submit_success, get_current_state_url, initialize_page */
|
|
3
3
|
|
|
4
4
|
function combineFormAndQuery(form, query) {
|
|
5
5
|
let paramsList = [];
|
|
@@ -32,8 +32,11 @@ async function execLink(url, linkSrc) {
|
|
|
32
32
|
else {
|
|
33
33
|
const { path, query } =
|
|
34
34
|
parent.saltcorn.mobileApp.navigation.splitPathQuery(url);
|
|
35
|
+
const safePath = path.startsWith("http")
|
|
36
|
+
? new URL(path).pathname
|
|
37
|
+
: path;
|
|
35
38
|
await parent.saltcorn.mobileApp.navigation.handleRoute(
|
|
36
|
-
`get${
|
|
39
|
+
`get${safePath}`,
|
|
37
40
|
query
|
|
38
41
|
);
|
|
39
42
|
}
|
|
@@ -300,11 +303,14 @@ function invalidate_pagings(currentQuery) {
|
|
|
300
303
|
return newQuery;
|
|
301
304
|
}
|
|
302
305
|
|
|
303
|
-
async function set_state_fields(kvs,
|
|
306
|
+
async function set_state_fields(kvs, disablePjax, e) {
|
|
304
307
|
try {
|
|
305
308
|
showLoadSpinner();
|
|
309
|
+
let newhref = get_current_state_url(e);
|
|
306
310
|
let queryParams = [];
|
|
307
|
-
|
|
311
|
+
const { path, query } =
|
|
312
|
+
parent.saltcorn.mobileApp.navigation.splitPathQuery(newhref);
|
|
313
|
+
let currentQuery = query || {};
|
|
308
314
|
if (Object.keys(kvs).some((k) => !is_paging_param(k))) {
|
|
309
315
|
currentQuery = invalidate_pagings(currentQuery);
|
|
310
316
|
}
|
|
@@ -318,15 +324,53 @@ async function set_state_fields(kvs, href) {
|
|
|
318
324
|
for (const [k, v] of new URLSearchParams(currentQuery).entries()) {
|
|
319
325
|
queryParams.push(`${k}=${v}`);
|
|
320
326
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
);
|
|
327
|
+
const queryStr = queryParams.join("&");
|
|
328
|
+
if (disablePjax)
|
|
329
|
+
await parent.saltcorn.mobileApp.navigation.handleRoute(path, queryStr);
|
|
330
|
+
else await pjax_to(path, queryStr, e);
|
|
325
331
|
} finally {
|
|
326
332
|
removeLoadSpinner();
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
335
|
|
|
336
|
+
async function pjax_to(href, query, e) {
|
|
337
|
+
const safeHref = href.startsWith("get") ? href.substring(3) : href;
|
|
338
|
+
const path = `${safeHref}?${query}`;
|
|
339
|
+
let $modal = $("#scmodal");
|
|
340
|
+
const inModal = $modal.length && $modal.hasClass("show");
|
|
341
|
+
const localizer = e ? $(e).closest("[data-sc-local-state]") : [];
|
|
342
|
+
let $dest = localizer.length
|
|
343
|
+
? localizer
|
|
344
|
+
: inModal
|
|
345
|
+
? $("#scmodal .modal-body")
|
|
346
|
+
: $("#page-inner-content");
|
|
347
|
+
if (!$dest.length)
|
|
348
|
+
await parent.saltcorn.mobileApp.navigation.handleRoute(safeHref, query);
|
|
349
|
+
else
|
|
350
|
+
try {
|
|
351
|
+
const headers = {
|
|
352
|
+
pjaxpageload: "true",
|
|
353
|
+
};
|
|
354
|
+
if (localizer.length) headers.localizedstate = "true";
|
|
355
|
+
const result = await parent.saltcorn.mobileApp.api.apiCall({
|
|
356
|
+
path: path,
|
|
357
|
+
method: "GET",
|
|
358
|
+
additionalHeaders: headers,
|
|
359
|
+
});
|
|
360
|
+
if (!inModal && !localizer.length) {
|
|
361
|
+
// not sure for mobile
|
|
362
|
+
// window.history.pushState({ url: href }, "", href);
|
|
363
|
+
}
|
|
364
|
+
if (inModal && !localizer.length)
|
|
365
|
+
$(".sc-modal-linkout").attr("href", path);
|
|
366
|
+
$dest.html(result.data);
|
|
367
|
+
if (localizer.length) localizer.attr("data-sc-local-state", path);
|
|
368
|
+
initialize_page();
|
|
369
|
+
} catch (error) {
|
|
370
|
+
parent.saltcorn.mobileApp.common.errorAlert(error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
330
374
|
async function set_state_field(key, value) {
|
|
331
375
|
try {
|
|
332
376
|
showLoadSpinner();
|
|
@@ -358,24 +402,26 @@ async function unset_state_field(key) {
|
|
|
358
402
|
}
|
|
359
403
|
}
|
|
360
404
|
|
|
361
|
-
async function sortby(k, desc, viewIdentifier) {
|
|
405
|
+
async function sortby(k, desc, viewIdentifier, e) {
|
|
362
406
|
await set_state_fields(
|
|
363
407
|
{
|
|
364
408
|
[`_${viewIdentifier}_sortby`]: k,
|
|
365
409
|
[`_${viewIdentifier}_sortdesc`]: desc ? "on" : { unset: true },
|
|
366
410
|
},
|
|
367
|
-
|
|
411
|
+
false,
|
|
412
|
+
e
|
|
368
413
|
);
|
|
369
414
|
}
|
|
370
415
|
|
|
371
|
-
async function gopage(n, pagesize, viewIdentifier, extra) {
|
|
416
|
+
async function gopage(n, pagesize, viewIdentifier, extra, e) {
|
|
372
417
|
await set_state_fields(
|
|
373
418
|
{
|
|
374
419
|
...extra,
|
|
375
420
|
[`_${viewIdentifier}_page`]: n,
|
|
376
421
|
[`_${viewIdentifier}_pagesize`]: pagesize,
|
|
377
422
|
},
|
|
378
|
-
|
|
423
|
+
false,
|
|
424
|
+
e
|
|
379
425
|
);
|
|
380
426
|
}
|
|
381
427
|
|