@saltcorn/mobile-app 0.9.0-beta.6 → 0.9.0-beta.7

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": "0.9.0-beta.6",
4
+ "version": "0.9.0-beta.7",
5
5
  "description": "Apache Cordova application with @saltcorn/markup",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/www/index.html CHANGED
@@ -22,6 +22,7 @@
22
22
  <script src="js/routes/error.js"></script>
23
23
  <script src="js/routes/page.js"></script>
24
24
  <script src="js/routes/view.js"></script>
25
+ <script src="js/routes/fields.js"></script>
25
26
  <script src="js/routes/sync.js"></script>
26
27
  <script src="js/routes/init.js"></script>
27
28
 
@@ -4,6 +4,7 @@ function MobileRequest({
4
4
  xhr = false,
5
5
  files = undefined,
6
6
  query = undefined,
7
+ body = undefined,
7
8
  refererRoute = undefined,
8
9
  } = {}) {
9
10
  const cfg = saltcorn.data.state.getState().mobileConfig;
@@ -54,6 +55,7 @@ function MobileRequest({
54
55
  xhr,
55
56
  files,
56
57
  query,
58
+ body,
57
59
  headers: {
58
60
  referer: referer,
59
61
  },
@@ -40,6 +40,7 @@ function MobileResponse() {
40
40
 
41
41
  function status(value) {
42
42
  resStatus = value;
43
+ return this;
43
44
  }
44
45
 
45
46
  function getStatus() {
@@ -0,0 +1,31 @@
1
+ /*global saltcorn, apiCall, MobileRequest, MobileResponse, offlineHelper, parseQuery */
2
+
3
+ const postShowCalculated = async (context) => {
4
+ const { tableName, fieldName, fieldview } = context.params;
5
+ const mobileConfig = saltcorn.data.state.getState().mobileConfig;
6
+ const table = saltcorn.data.models.Table.findOne({ name: tableName });
7
+ if (!table) throw new Error(`The table '${tableName}' does not exist.`);
8
+ if (
9
+ mobileConfig.isOfflineMode ||
10
+ mobileConfig.localTableIds.indexOf(table.id) >= 0
11
+ ) {
12
+ const req = new MobileRequest({
13
+ query: context.query ? parseQuery(context.query) : {},
14
+ body: context.data || {},
15
+ });
16
+ const res = new MobileResponse();
17
+ await saltcorn.data.web_mobile_commons.show_calculated_fieldview(req, res, {
18
+ tableName,
19
+ fieldName,
20
+ fieldview,
21
+ });
22
+ return res.getSendData();
23
+ } else {
24
+ const response = await apiCall({
25
+ method: "POST",
26
+ path: `/field/show-calculated/${tableName}/${fieldName}/${fieldview}`,
27
+ body: context.data || {},
28
+ });
29
+ return response.data;
30
+ }
31
+ };
@@ -1,4 +1,4 @@
1
- /*global postView, postViewRoute, getView, postToggleField, deleteRows, postPageAction, getPage, getLoginView, logoutAction, getSignupView, getErrorView, window, getSyncSettingsView, getAskDeleteOfflineData, getAskUploadNotEnded, updateTableRow, insertTableRow */
1
+ /*global postView, postViewRoute, getView, postToggleField, deleteRows, postPageAction, getPage, getLoginView, logoutAction, getSignupView, getErrorView, window, getSyncSettingsView, getAskDeleteOfflineData, getAskUploadNotEnded, updateTableRow, insertTableRow, postShowCalculated */
2
2
  // TODO module namespacese
3
3
 
4
4
  const initRoutes = async () => {
@@ -67,6 +67,10 @@ const initRoutes = async () => {
67
67
  path: "get/sync/ask_delete_offline_data",
68
68
  action: getAskDeleteOfflineData,
69
69
  },
70
+ {
71
+ path: "post/field/show-calculated/:tableName/:fieldName/:fieldview",
72
+ action: postShowCalculated,
73
+ },
70
74
  ];
71
75
  window.router = new window.UniversalRouter(routes);
72
76
  };
@@ -4,7 +4,11 @@ let routingHistory = [];
4
4
 
5
5
  function currentLocation() {
6
6
  if (routingHistory.length == 0) return undefined;
7
- return routingHistory[routingHistory.length - 1].route;
7
+ let index = routingHistory.length - 1;
8
+ while (index > 0 && routingHistory[index].route.startsWith("post/")) {
9
+ index--;
10
+ }
11
+ return routingHistory[index].route;
8
12
  }
9
13
 
10
14
  function currentQuery() {
@@ -210,12 +214,15 @@ async function gotoEntryView() {
210
214
  }
211
215
 
212
216
  function handleOpenModal() {
217
+ const result = { moddalWasOpen: false, noSubmitReload: false };
213
218
  const iframe = document.getElementById("content-iframe");
214
- if (!iframe) return false;
219
+ if (!iframe) return result;
215
220
  const openModal = iframe.contentWindow.$("#scmodal.modal.show");
216
- if (openModal.length === 0) return;
221
+ if (openModal.length === 0) return result;
222
+ result.moddalWasOpen = true;
217
223
  iframe.contentWindow.bootstrap.Modal.getInstance(openModal[0]).hide();
218
- return true;
224
+ result.noSubmitReload = openModal[0].classList.contains("no-submit-reload");
225
+ return result;
219
226
  }
220
227
 
221
228
  async function handleRoute(route, query, files, data) {
@@ -242,7 +249,11 @@ async function handleRoute(route, query, files, data) {
242
249
  alerts: [],
243
250
  });
244
251
  if (page.redirect) {
245
- if (handleOpenModal()) return;
252
+ const { moddalWasOpen, noSubmitReload } = handleOpenModal();
253
+ if (moddalWasOpen) {
254
+ if (noSubmitReload) return;
255
+ else return await reload();
256
+ }
246
257
  if (
247
258
  page.redirect.startsWith("http://localhost") ||
248
259
  page.redirect === "undefined"
@@ -479,9 +479,10 @@ async function mobile_modal(url, opts = {}) {
479
479
  var modal = bootstrap.Modal.getInstance(myModalEl);
480
480
  modal.dispose();
481
481
  }
482
+ if (opts.submitReload === false) $("#scmodal").addClass("no-submit-reload");
483
+ else $("#scmodal").removeClass("no-submit-reload");
482
484
  try {
483
485
  const { path, query } = parent.splitPathQuery(url);
484
- // submitReload ?
485
486
  const mobileConfig = parent.saltcorn.data.state.getState().mobileConfig;
486
487
  if (
487
488
  mobileConfig.networkState === "none" &&
@@ -534,17 +535,21 @@ async function local_post(url, args) {
534
535
  }
535
536
  }
536
537
 
537
- async function local_post_json(url) {
538
+ async function local_post_json(url, data, cb) {
538
539
  try {
539
540
  showLoadSpinner();
540
541
  const result = await parent.router.resolve({
541
542
  pathname: `post${url}`,
543
+ data: data,
544
+ query: parent.currentQuery(),
542
545
  });
543
546
  if (result.server_eval) await evalServerCode(url);
544
547
  if (result.redirect) await parent.handleRoute(result.redirect);
545
548
  else common_done(result, "", false);
549
+ if (cb?.success) cb.success(result);
546
550
  } catch (error) {
547
551
  parent.errorAlert(error);
552
+ if (cb?.error) cb.error(error);
548
553
  } finally {
549
554
  removeLoadSpinner();
550
555
  }