From d4d7425c24f2e15fd78d220e75504da5ac6f4a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 23 Jan 2020 19:09:48 +0100 Subject: [PATCH] Refactoring part 2 of umb-editor, splitview, variants. --- .../content/umbtabbedcontent.directive.js | 33 +++++++++---------- .../components/editor/umbeditorsubview.js | 2 +- .../content/umb-tabbed-content.html | 8 ++--- .../content/umb-variant-content.html | 2 +- .../apps/content/content.controller.js | 28 ++++++++-------- .../views/content/apps/content/content.html | 4 +-- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbtabbedcontent.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbtabbedcontent.directive.js index 1d17b044f9..3131fbc6d3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbtabbedcontent.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbtabbedcontent.directive.js @@ -19,8 +19,8 @@ var viewFocusY = scrollableNode.scrollTop + scrollableNode.clientHeight * .5; - for(var i in $scope.variant.tabs) { - var group = $scope.variant.tabs[i]; + for(var i in $scope.content.tabs) { + var group = $scope.content.tabs[i]; var node = propertyGroupNodesDictionary[group.id]; if (viewFocusY >= node.offsetTop && viewFocusY <= node.offsetTop + node.clientHeight) { setActiveAnchor(group); @@ -32,18 +32,18 @@ function setActiveAnchor(tab) { if (tab.active !== true) { - var i = $scope.variant.tabs.length; + var i = $scope.content.tabs.length; while(i--) { - $scope.variant.tabs[i].active = false; + $scope.content.tabs[i].active = false; } tab.active = true; } } function getActiveAnchor() { - var i = $scope.variant.tabs.length; + var i = $scope.content.tabs.length; while(i--) { - if ($scope.variant.tabs[i].active === true) - return $scope.variant.tabs[i]; + if ($scope.content.tabs[i].active === true) + return $scope.content.tabs[i]; } return false; } @@ -115,18 +115,17 @@ } - function controller($scope, $element, $attrs) { + function controller($scope) { //expose the property/methods for other directives to use this.content = $scope.content; - console.log($scope) - console.log(this.content); - - $scope.defaultVariant = _.find(this.content.variants, variant => { - return variant.language && variant.language.isDefault; - }); - + if($scope.variantNodeModel) { + $scope.defaultVariant = _.find($scope.variantNodeModel.variants, variant => { + return variant.language && variant.language.isDefault; + }); + } + $scope.unlockInvariantValue = function(property) { property.unlockInvariantValue = !property.unlockInvariantValue; }; @@ -134,7 +133,7 @@ $scope.$watch("tabbedContentForm.$dirty", function (newValue, oldValue) { if (newValue === true) { - $scope.variant.isDirty = true; + $scope.content.isDirty = true; } } ); @@ -148,7 +147,7 @@ link: link, scope: { content: "=", - variant: "=" + variantNodeModel: "=?" } }; diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubview.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubview.js index ebb53415c3..614f421699 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubview.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubview.js @@ -20,7 +20,7 @@ templateUrl: 'views/components/editor/umb-editor-sub-view.html', scope: { model: "=", - variant: "=?", + variantContent: "=?", content: "=" }, link: link diff --git a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-tabbed-content.html b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-tabbed-content.html index 85ba05ee16..56f2835d3f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-tabbed-content.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-tabbed-content.html @@ -1,6 +1,6 @@ 
-
+
{{ group.label }}
@@ -11,13 +11,13 @@ data-element="property-{{property.alias}}" ng-repeat="property in group.properties track by property.alias" property="property" - show-inherit="content.variants.length > 1 && ((!variant.language.isDefault && !property.culture) || (variant.segment && !property.segment)) && !property.unlockInvariantValue" + show-inherit="variantNodeModel.variants.length > 1 && ((!content.language.isDefault && !property.culture) || (content.segment && !property.segment)) && !property.unlockInvariantValue" inherits-from="defaultVariant.language.name"> -
+
+ preview="variantNodeModel.variants.length > 1 && ((!content.language.isDefault && !property.culture) || (content.segment && !property.segment)) && !property.unlockInvariantValue">
diff --git a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html index bf1fe34d07..ba3cf9fc92 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html @@ -35,7 +35,7 @@
- +
diff --git a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js index 00eca43059..bbe09e1e14 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js @@ -23,25 +23,27 @@ //if this variant has a culture/language assigned, then we need to watch it since it will change //if the language drop down changes and we need to re-init - if ($scope.variant.language) { - unbindLanguageWatcher = $scope.$watch(function () { - return $scope.variant.language.culture; + if ($scope.variantContent) { + if ($scope.variantContent.language) { + unbindLanguageWatcher = $scope.$watch(function () { + return $scope.variantContent.language.culture; + }, function (newVal, oldVal) { + if (newVal !== oldVal) { + requestUpdate(); + } + }); + } else { + unbindLanguageWatcher = function() {} + } + + unbindSegmentWatcher = $scope.$watch(function () { + return $scope.variantContent.segment; }, function (newVal, oldVal) { if (newVal !== oldVal) { requestUpdate(); } }); - } else { - unbindLanguageWatcher = function() {} } - - unbindSegmentWatcher = $scope.$watch(function () { - return $scope.variant.segment; - }, function (newVal, oldVal) { - if (newVal !== oldVal) { - requestUpdate(); - } - }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.html b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.html index d49b78b8a4..eebed6bae9 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.html @@ -2,8 +2,8 @@ + variant-node-model="content" + content="variantContent">