@saltcorn/server 0.6.4-beta.2 → 0.6.4-beta.6

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.
@@ -177,6 +177,14 @@ function rep_down(e) {
177
177
  apply_form_subset_record(theform, vals1);
178
178
  }
179
179
  }
180
+
181
+ function reload_on_init() {
182
+ localStorage.setItem("reload_on_init", true);
183
+ }
184
+ if (localStorage.getItem("reload_on_init")) {
185
+ localStorage.removeItem("reload_on_init");
186
+ location.reload();
187
+ }
180
188
  function initialize_page() {
181
189
  $("form").change(apply_showif);
182
190
  apply_showif();
@@ -247,6 +255,7 @@ function initialize_page() {
247
255
  navigator.browserLanguage ||
248
256
  navigator.systemLanguage ||
249
257
  "en";
258
+ window.detected_locale = locale;
250
259
  const parse = (s) => JSON.parse(decodeURIComponent(s));
251
260
  $("time[locale-time-options]").each(function () {
252
261
  var el = $(this);
@@ -266,6 +275,7 @@ function initialize_page() {
266
275
  const options = parse(el.attr("locale-date-options"));
267
276
  el.text(date.toLocaleDateString(locale, options));
268
277
  });
278
+ $('a[data-toggle="tab"]').historyTabs();
269
279
  }
270
280
 
271
281
  $(initialize_page);
@@ -610,7 +620,15 @@ function ajax_post_btn(e, reload_on_done, reload_delay) {
610
620
 
611
621
  return false;
612
622
  }
613
- function make_unique_field(id, table_id, field_name, value) {
623
+ function make_unique_field(
624
+ id,
625
+ table_id,
626
+ field_name,
627
+ value,
628
+ space,
629
+ start,
630
+ always_append
631
+ ) {
614
632
  if (!value) return;
615
633
  $.ajax(
616
634
  `/api/${table_id}?approximate=true&${encodeURIComponent(
@@ -623,9 +641,9 @@ function make_unique_field(id, table_id, field_name, value) {
623
641
  const vals = res.success
624
642
  .map((o) => o[field_name])
625
643
  .filter((s) => s.startsWith(value));
626
- if (vals.includes(value)) {
627
- for (let i = 1; i < vals.length + 1; i++) {
628
- const newname = `${value} ${i}`;
644
+ if (vals.includes(value) || always_append) {
645
+ for (let i = start || 0; i < vals.length + (start || 0) + 2; i++) {
646
+ const newname = `${value}${space ? " " : ""}${i}`;
629
647
  if (!vals.includes(newname)) {
630
648
  $("#" + id).val(newname);
631
649
  return;
@@ -702,6 +720,51 @@ function room_older(viewname, room_id, btn) {
702
720
  }
703
721
  );
704
722
  }
705
- function showHideCol(nm, e) {
706
- $("#jsGrid").jsGrid("fieldOption", nm, "visible", e.checked);
707
- }
723
+
724
+ /*
725
+ https://github.com/jeffdavidgreen/bootstrap-html5-history-tabs/blob/master/bootstrap-history-tabs.js
726
+ Copyright (c) 2015 Jeff Green
727
+ */
728
+
729
+ +(function ($) {
730
+ "use strict";
731
+ $.fn.historyTabs = function () {
732
+ var that = this;
733
+ window.addEventListener("popstate", function (event) {
734
+ if (event.state) {
735
+ $(that)
736
+ .filter('[href="' + event.state.url + '"]')
737
+ .tab("show");
738
+ }
739
+ });
740
+ return this.each(function (index, element) {
741
+ $(element).on("show.bs.tab", function () {
742
+ var stateObject = { url: $(this).attr("href") };
743
+
744
+ if (window.location.hash && stateObject.url !== window.location.hash) {
745
+ window.history.pushState(
746
+ stateObject,
747
+ document.title,
748
+ window.location.pathname +
749
+ window.location.search +
750
+ $(this).attr("href")
751
+ );
752
+ } else {
753
+ window.history.replaceState(
754
+ stateObject,
755
+ document.title,
756
+ window.location.pathname +
757
+ window.location.search +
758
+ $(this).attr("href")
759
+ );
760
+ }
761
+ });
762
+ if (!window.location.hash && $(element).is(".active")) {
763
+ // Shows the first element if there are no query parameters.
764
+ $(element).tab("show");
765
+ } else if ($(this).attr("href") === window.location.hash) {
766
+ $(element).tab("show");
767
+ }
768
+ });
769
+ };
770
+ })(jQuery);