Skip to content

Commit

Permalink
Added logic to pre-select the user's selected culture when creating a…
Browse files Browse the repository at this point in the history
… new redirect
  • Loading branch information
abjerner committed Apr 26, 2023
1 parent af08a8c commit 6f2d463
Showing 1 changed file with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module("umbraco").controller("SkybrudUmbracoRedirects.RedirectDialog.Controller", function ($scope, $http, editorService, notificationsService, skybrudRedirectsService, localizationService, formHelper, eventsService) {
angular.module("umbraco").controller("SkybrudUmbracoRedirects.RedirectDialog.Controller", function ($scope, $routeParams, $http, editorService, notificationsService, skybrudRedirectsService, localizationService, formHelper, eventsService) {

// Get the cache buster value
const cacheBuster = Umbraco.Sys.ServerVariables.skybrud.redirects.cacheBuster;
Expand Down Expand Up @@ -320,20 +320,47 @@
properties.culture.config = { cultures: r.data };
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;
properties.culture.culture = r.data[0];
properties.culture.value = r.data[0].alias;


let culture = null;

if ($routeParams.mculture) {
culture = r.data.find(x => x.alias == $routeParams.mculture.toLowerCase()) ?? r.data[0];
} else {
culture = r.data[0];
}


properties.culture.culture = culture;
properties.culture.value = culture.alias;
});

});

if ($scope.model.redirect && $scope.model.redirect.destination && $scope.model.redirect.destination.type === "content") {
if ($scope.model.destination) {

if ($scope.model.destination.type == "content") {

skybrudRedirectsService.getCulturesByNodeId($scope.model.destination.id).then(function(r) {
properties.culture.config = { cultures: r.data };
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;
properties.culture.culture = r.data.find(x => x.alias == $routeParams.mculture.toLowerCase()) ?? r.data[0];
properties.culture.value = properties.culture.culture?.alias;
});

}

} else if ($scope.model.redirect && $scope.model.redirect.destination && $scope.model.redirect.destination.type === "content") {

skybrudRedirectsService.getCulturesByNodeId($scope.model.redirect.destination.id).then(function(r) {
properties.culture.config = { cultures: r.data };
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;
properties.culture.culture = r.data.find(x => x.alias == $scope.model.redirect.destination.culture);
properties.culture.value = properties.culture.culture?.alias;
});

}

vm.save = function () {
Expand Down

0 comments on commit 6f2d463

Please sign in to comment.