From 39bdc1bc781a98cea088773d7f704ec8f4ff8e8a Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 30 Mar 2016 09:04:26 +0200 Subject: [PATCH] handle 1sites with 1 language --- .../editor/umbeditorheader.directive.js | 41 ++++++++++++++++++- .../components/umbvariations.directive.js | 1 + .../components/editor/umb-editor-header.html | 20 +++++---- .../src/views/components/umb-variations.html | 10 ++++- .../views/content/content.edit.controller.js | 1 + 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js index 124b834169..2551d30204 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js @@ -5,8 +5,21 @@ function link(scope, el, attr, ctrl) { + scope.showVariationsQuickSwitchToggle = false; scope.showVariationsQuickSwitch = false; + function activate() { + showVariationsQuickSwitch(scope.variations); + } + + function showVariationsQuickSwitch(variations) { + if(variations && variations.length > 1 || variations && variations.length === 1 && variations[0].variations && variations[0].variations.length > 0) { + scope.showVariationsQuickSwitchToggle = true; + } else { + scope.showVariationsQuickSwitchToggle = false; + } + } + scope.openIconPicker = function() { scope.dialogModel = { view: "iconpicker", @@ -42,13 +55,37 @@ }; - scope.selectItem = function(variation) { + scope.selectItem = function(item) { if(scope.onSelectItem) { - scope.onSelectItem(variation); + + for(var i = 0; i < scope.variations.length; i++) { + var language = scope.variations[i]; + language.active = false; + + if(language.variations && language.variations.length > 0) { + for(var variationIndex = 0; variationIndex < language.variations.length; variationIndex++) { + var variation = language.variations[variationIndex]; + variation.active = false; + } + + } + } + + // set selected item to active + item.active = true; + + scope.onSelectItem(item); scope.showVariationsQuickSwitch = false; + } }; + scope.$watch('variations', function(newValue, oldValue){ + showVariationsQuickSwitch(newValue); + }, true); + + activate(); + } var directive = { diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbvariations.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbvariations.directive.js index 86cb52eba6..0ea1cfd552 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbvariations.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbvariations.directive.js @@ -37,6 +37,7 @@ variation.variationName = newVariation.name; variation.variationDescription = newVariation.description; variation.segments = newVariation.segments; + variation.active = false; language.variations.unshift(variation); diff --git a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html index bde9cef69d..4604b4cfc8 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html @@ -34,7 +34,7 @@
-
+
{{ language }}
@@ -48,29 +48,35 @@ - - +
    +
  • - + + + {{variation.name}} + (Original) + + + {{variation.language}} variations ▾ -
      + diff --git a/src/Umbraco.Web.UI.Client/src/views/components/umb-variations.html b/src/Umbraco.Web.UI.Client/src/views/components/umb-variations.html index 8108ae3527..ac1ced2c66 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/umb-variations.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/umb-variations.html @@ -21,8 +21,14 @@
      - - {{ language.language }} +
      + {{ language.name }} + (Original) +
      +
      + + {{ language.language }} +
      diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index 38da27d1ce..06a039a2ed 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -83,6 +83,7 @@ function ContentEditController($scope, $rootScope, $routeParams, $q, $timeout, $ // set up English locale as master var english = angular.copy(content); english.language = "English (United States)"; + english.active = true; english.variations = []; variationsHelper.setMaster(english);