From 394572a8fc8a049e2ad5f52f1e51c8488388438e Mon Sep 17 00:00:00 2001 From: kjac Date: Sat, 23 Apr 2016 10:14:56 +0200 Subject: [PATCH] Yet another stab at fixing it By tracking the fieldsets that have been expanded (loaded), we can make sure the submit watchers fire appropriately, even when the fieldsets are collapsed down again. Apart from hopefully fixing the publishing issues for collapsed fieldsets, this also adds a performance gain if the users expand and collapse the same fieldsets more than once, since the fieldsets now only load the first time they're expanded (instead of every time). This also - at least partially - fixes the validation issue #325 introduced by #301 --- app/controllers/controller.js | 17 +++++++++++++++-- app/directives/archetypesubmitwatcher.js | 5 ++--- app/views/archetype.default.html | 11 +++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/controller.js b/app/controllers/controller.js index 61092a0..f690129 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -364,6 +364,12 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc return fieldset.collapse; } + // added to track loaded fieldsets + $scope.loadedFieldsets = []; + $scope.isLoaded = function (fieldset) { + return $scope.loadedFieldsets.indexOf(fieldset) >= 0; + } + //helper for expanding/collapsing fieldsets $scope.focusFieldset = function(fieldset){ fixDisableSelection(); @@ -386,12 +392,14 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc if(!fieldset && $scope.model.value.fieldsets.length == 1) { $scope.model.value.fieldsets[0].collapse = false; + $scope.loadedFieldsets.push($scope.model.value.fieldsets[0]); return; } if(iniState && fieldset) { fieldset.collapse = !iniState; + $scope.loadedFieldsets.push(fieldset); } } @@ -448,6 +456,9 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc // reset submit watcher counter on save $scope.activeSubmitWatcher = 0; + // init loaded fieldsets tracking + $scope.loadedFieldsets = _.where($scope.model.value.fieldsets, { collapse: false }); + // create properties needed for the backoffice to work (data that is not serialized to DB) addCustomProperties($scope.model.value.fieldsets); }); @@ -563,13 +574,15 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc $scope.$broadcast("archetypeFormSubmitting", args); } - $scope.saveCustomFieldsetProperties = function () { + // we'll use our own "archetypeFormSubmitting" event to save custom properties, as at least some + // of the editors store their values back to the model on the core "formSubmitting" event + $scope.$on("archetypeFormSubmitting", function (ev, args) { _.each($scope.model.value.fieldsets, function (fieldset) { // extract the publish configuration from the fieldsets (and convert local datetimes to UTC) fieldset.releaseDate = toUtc(fieldset.releaseDateModel.value); fieldset.expireDate = toUtc(fieldset.expireDateModel.value); }); - } + }); function toUtc(date) { if (!date) { diff --git a/app/directives/archetypesubmitwatcher.js b/app/directives/archetypesubmitwatcher.js index dab7c84..3311e6c 100644 --- a/app/directives/archetypesubmitwatcher.js +++ b/app/directives/archetypesubmitwatcher.js @@ -5,7 +5,7 @@ angular.module("umbraco.directives").directive('archetypeSubmitWatcher', functio scope.$on("formSubmitting", function (ev, args) { // on the "formSubmitting" event, call the submit callback on scope to notify the Archetype controller to do it's magic - if (id == scope.activeSubmitWatcher || scope.forceSubmitCallback) { + if (id == scope.activeSubmitWatcher) { scope.submitCallback(args); } }); @@ -19,8 +19,7 @@ angular.module("umbraco.directives").directive('archetypeSubmitWatcher', functio scope: { loadCallback: '=', submitCallback: '=', - activeSubmitWatcher: '=', - forceSubmitCallback: '=' + activeSubmitWatcher: '=' } } }); \ No newline at end of file diff --git a/app/views/archetype.default.html b/app/views/archetype.default.html index 70bb84f..8a661db 100644 --- a/app/views/archetype.default.html +++ b/app/views/archetype.default.html @@ -6,8 +6,7 @@
- - +
-
+
-
+
@@ -76,8 +77,6 @@
- -