@saltcorn/mobile-app 1.1.0-beta.13 → 1.1.0-beta.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saltcorn/mobile-app",
3
3
  "displayName": "Saltcorn mobile app",
4
- "version": "1.1.0-beta.13",
4
+ "version": "1.1.0-beta.15",
5
5
  "description": "Apache Cordova application with @saltcorn/markup",
6
6
  "main": "index.js",
7
7
  "scripts": {
@@ -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
@@ -5,8 +5,6 @@
5
5
  name="viewport"
6
6
  content="width=device-width, initial-scale=1, maximum-scale=1"
7
7
  />
8
- <script src="cordova.js"></script>
9
-
10
8
  <script src="data/tables.js"></script>
11
9
  <script src="data/tables_created_at.js"></script>
12
10
  <script src="data/config.js"></script>
@@ -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${path}`,
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, href) {
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
- let currentQuery = parent.saltcorn.mobileApp.navigation.currentQuery();
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
- await parent.saltcorn.mobileApp.navigation.handleRoute(
322
- href,
323
- queryParams.join("&")
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
- parent.saltcorn.mobileApp.navigation.currentLocation()
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
- parent.saltcorn.mobileApp.navigation.currentLocation()
423
+ false,
424
+ e
379
425
  );
380
426
  }
381
427