forms-angular 0.12.0-beta.367 → 0.12.0-beta.369

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.
@@ -801,7 +801,7 @@ var fng;
801
801
  (function (fng) {
802
802
  var directives;
803
803
  (function (directives) {
804
- formInput.$inject = ["$compile", "$rootScope", "$filter", "$timeout", "CssFrameworkService", "FormGeneratorService", "FormMarkupHelperService", "SecurityService"];
804
+ formInput.$inject = ["$compile", "$rootScope", "$filter", "$timeout", "$$rAF", "CssFrameworkService", "FormGeneratorService", "FormMarkupHelperService", "SecurityService"];
805
805
  var tabsSetupState;
806
806
  (function (tabsSetupState) {
807
807
  tabsSetupState[tabsSetupState["Y"] = 0] = "Y";
@@ -809,7 +809,7 @@ var fng;
809
809
  tabsSetupState[tabsSetupState["Forced"] = 2] = "Forced";
810
810
  })(tabsSetupState || (tabsSetupState = {}));
811
811
  /*@ngInject*/
812
- function formInput($compile, $rootScope, $filter, $timeout, CssFrameworkService, FormGeneratorService, FormMarkupHelperService, SecurityService) {
812
+ function formInput($compile, $rootScope, $filter, $timeout, $$rAF, CssFrameworkService, FormGeneratorService, FormMarkupHelperService, SecurityService) {
813
813
  return {
814
814
  restrict: 'EA',
815
815
  link: function (scope, element, attrs) {
@@ -1149,8 +1149,10 @@ var fng;
1149
1149
  // with being linked after the record has loaded (see fngSelectTab), and anything that changes the
1150
1150
  // record when it is saved must not rely on being compiled.
1151
1151
  scope.fngTabRendered = scope.fngTabRendered || {};
1152
+ scope.fngTabPending = scope.fngTabPending || {};
1152
1153
  result.before += "<uib-tab ".concat(attrs_1, " deselect=\"tabDeselect($event, $selectedIndex)\" select=\"fngSelectTab('").concat(cleanTitle, "')\"");
1153
- result.before += "><div fng-lazy-tab=\"fngTabRendered['".concat(cleanTitle, "']\">");
1154
+ result.before += "><div class=\"spinner fng-tab-spinner\" ng-show=\"fngTabPending['".concat(cleanTitle, "']\">Just a second&#8230;</div>");
1155
+ result.before += "<div fng-lazy-tab=\"fngTabRendered['".concat(cleanTitle, "']\">");
1154
1156
  result.after = '</div></uib-tab>';
1155
1157
  }
1156
1158
  else {
@@ -1733,25 +1735,52 @@ var fng;
1733
1735
  // registered (such as fng-ui-select's, which turn ids into text), apply showIf, broadcast fngTabRendered
1734
1736
  // (for anything that needs to adjust the tab's DOM) and call updateQueryForTab (which a model controller may
1735
1737
  // override to fetch data for the tab and tell the directives on it).
1738
+ //
1739
+ // Compiling a big tab can take a few seconds, so when a tab is selected after another has been shown a spinner is
1740
+ // put up and the browser is given the chance to paint it (a requestAnimationFrame runs just before a paint, and a
1741
+ // timeout set from it runs after) before the tab is compiled. The spinner only becomes visible after 250ms (in CSS,
1742
+ // as the compilation blocks JavaScript), so fast tabs don't flash it. The first tab shown is compiled straight away, as
1743
+ // the form's own Loading spinner covers it.
1736
1744
  scope.fngSelectTab = function (tabTitle) {
1737
1745
  var _a;
1746
+ if (scope.fngTabPending[tabTitle]) {
1747
+ return;
1748
+ }
1738
1749
  if (scope.fngTabRendered[tabTitle]) {
1739
1750
  (_a = scope.updateQueryForTab) === null || _a === void 0 ? void 0 : _a.call(scope, tabTitle);
1740
1751
  }
1741
- else {
1742
- scope.fngTabRendered[tabTitle] = true;
1743
- $timeout(function () {
1744
- var _a, _b;
1745
- (_a = scope.applyLateConversions) === null || _a === void 0 ? void 0 : _a.call(scope);
1746
- var theRecord = scope[attrs.model || 'record'];
1747
- if (FormGeneratorService.updateDataDependentDisplay && theRecord && Object.keys(theRecord).length > 0) {
1748
- FormGeneratorService.updateDataDependentDisplay(theRecord, null, true, scope);
1749
- }
1750
- $rootScope.$broadcast('fngTabRendered', tabTitle);
1751
- (_b = scope.updateQueryForTab) === null || _b === void 0 ? void 0 : _b.call(scope, tabTitle);
1752
+ else if (Object.keys(scope.fngTabRendered).some(function (t) { return scope.fngTabRendered[t]; })) {
1753
+ scope.fngTabPending[tabTitle] = true;
1754
+ $$rAF(function () {
1755
+ $timeout(function () { return compileTab(tabTitle); });
1752
1756
  });
1753
1757
  }
1758
+ else {
1759
+ compileTab(tabTitle);
1760
+ }
1754
1761
  };
1762
+ function compileTab(tabTitle) {
1763
+ // Some directives set their control's view value when they are linked (angular-ui-date, which date fields use,
1764
+ // for one), which makes the form dirty. When every tab is compiled up front that happens before the record has
1765
+ // loaded and the form is made pristine, so here the form is put back the way it was once the tab is compiled.
1766
+ var form = scope[scope.topLevelFormName];
1767
+ var wasPristine = form === null || form === void 0 ? void 0 : form.$pristine;
1768
+ scope.fngTabRendered[tabTitle] = true;
1769
+ $timeout(function () {
1770
+ var _a, _b;
1771
+ (_a = scope.applyLateConversions) === null || _a === void 0 ? void 0 : _a.call(scope);
1772
+ var theRecord = scope[attrs.model || 'record'];
1773
+ if (FormGeneratorService.updateDataDependentDisplay && theRecord && Object.keys(theRecord).length > 0) {
1774
+ FormGeneratorService.updateDataDependentDisplay(theRecord, null, true, scope);
1775
+ }
1776
+ if (wasPristine && !form.$pristine) {
1777
+ form.$setPristine();
1778
+ }
1779
+ $rootScope.$broadcast('fngTabRendered', tabTitle);
1780
+ (_b = scope.updateQueryForTab) === null || _b === void 0 ? void 0 : _b.call(scope, tabTitle);
1781
+ delete scope.fngTabPending[tabTitle];
1782
+ });
1783
+ }
1755
1784
  var unwatch = scope.$watch(attrs.schema, function (newValue) {
1756
1785
  if (newValue) {
1757
1786
  var newArrayValue = angular.isArray(newValue) ? newValue : [newValue]; // otherwise some old tests stop working for no real reason