diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js index a4dda97fe1..95b2c64a6f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/mediapicker.controller.js @@ -69,11 +69,17 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon return dialogOptions.idType === "udi" ? i.udi : i.id; }); if (currIds.indexOf(itemId) < 0) { + item.icon = iconHelper.convertFromLegacyIcon(item.icon); - entityResource.getUrl(item.id, "Media").then(function(data){ - item.path = data; - $scope.renderModel.push({ name: item.name, id: item.id, path: item.path, icon: item.icon, udi: item.udi }); + $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi }); + + // store the index of the new item in the renderModel collection so we can find it again + var itemRenderIndex = $scope.renderModel.length - 1; + // get and update the path for the picked node + entityResource.getUrl(item.id, dialogOptions.entityType).then(function(data){ + $scope.renderModel[itemRenderIndex].path = data; }); + } }; @@ -95,11 +101,16 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon entityResource.getByIds(modelIds, dialogOptions.entityType).then(function (data) { _.each(data, function (item, i) { - entityResource.getUrl(item.id, "Media").then(function(data){ - item.path = data; - item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.renderModel.push({ name: item.name, id: item.id, path: item.path, icon: item.icon, udi: item.udi }); - }); + item.icon = iconHelper.convertFromLegacyIcon(item.icon); + $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi }); + + // store the index of the new item in the renderModel collection so we can find it again + var itemRenderIndex = $scope.renderModel.length - 1; + // get and update the path for the picked node + entityResource.getUrl(item.id, dialogOptions.entityType).then(function(data){ + $scope.renderModel[itemRenderIndex].path = data; + }); + }); }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js index 8e0c68f1c1..c5746ec149 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/treepicker.controller.js @@ -3,7 +3,7 @@ angular.module('umbraco') .controller("Umbraco.PrevalueEditors.TreePickerController", - function($scope, dialogService, entityResource, $log, iconHelper, miniEditorHelper){ + function($scope, dialogService, entityResource, $log, iconHelper){ $scope.renderModel = []; $scope.ids = []; @@ -28,11 +28,17 @@ angular.module('umbraco') $scope.ids = $scope.model.value.split(','); entityResource.getByIds($scope.ids, config.entityType).then(function (data) { _.each(data, function (item, i) { - entityResource.getUrl(item.id, "Document").then(function(data){ - item.path = data; - item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $scope.renderModel.push({name: item.name, path: item.path, id: item.id, icon: item.icon, udi: item.udi}); - }); + + item.icon = iconHelper.convertFromLegacyIcon(item.icon); + $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon, udi: item.udi}); + + // store the index of the new item in the renderModel collection so we can find it again + var itemRenderIndex = $scope.renderModel.length - 1; + // get and update the path for the picked node + entityResource.getUrl(item.id, config.entityType).then(function(data){ + $scope.renderModel[itemRenderIndex].path = data; + }); + }); }); } @@ -62,9 +68,6 @@ angular.module('umbraco') } - - - $scope.remove =function(index){ $scope.renderModel.splice(index, 1); $scope.ids.splice(index, 1); @@ -82,14 +85,20 @@ angular.module('umbraco') var itemId = config.idType === "udi" ? item.udi : item.id; if ($scope.ids.indexOf(itemId) < 0){ + item.icon = iconHelper.convertFromLegacyIcon(item.icon); - entityResource.getUrl(item.id, "Document").then(function(data){ - item.path = data; - $scope.ids.push(itemId); - $scope.renderModel.push({name: item.name, path: item.path, id: item.id, icon: item.icon, udi: item.udi}); - $scope.model.value = trim($scope.ids.join(), ","); - }); - } + $scope.ids.push(itemId); + $scope.renderModel.push({name: item.name, id: item.id, icon: item.icon, udi: item.udi}); + $scope.model.value = trim($scope.ids.join(), ","); + + // store the index of the new item in the renderModel collection so we can find it again + var itemRenderIndex = $scope.renderModel.length - 1; + // get and update the path for the picked node + entityResource.getUrl(item.id, config.entityType).then(function(data){ + $scope.renderModel[itemRenderIndex].path = data; + }); + + } };