From 01332db0a6ae5402b8a545e55cd1d4602df6d165 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 11 Apr 2018 15:44:43 +0200 Subject: [PATCH] "split not a function" error fix --- .../treepicker/treepicker.controller.js | 4 +- .../prevalueeditors/treepicker.controller.js | 194 +++++++++--------- 2 files changed, 102 insertions(+), 96 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js index d61550d3ae..3eb34d63cc 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js @@ -74,7 +74,7 @@ angular.module("umbraco").controller("Umbraco.Overlays.TreePickerController", }); }); - $scope.selectLanguage = function (language, languages) { + $scope.selectLanguage = function (language) { $scope.selectedLanguage = language; // close the language selector $scope.page.languageSelectorIsOpen = false; @@ -254,7 +254,7 @@ angular.module("umbraco").controller("Umbraco.Overlays.TreePickerController", //This is a tree node, so we don't have an entity to pass in, it will need to be looked up //from the server in this method. if ($scope.model.select) { - $scope.model.select(args.node) + $scope.model.select(args.node); } else { select(args.node.name, args.node.id); //toggle checked state 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 c5746ec149..757429ef46 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 @@ -1,20 +1,20 @@ //this controller simply tells the dialogs service to open a mediaPicker window //with a specified callback, this callback will receive an object with a selection on it angular.module('umbraco') -.controller("Umbraco.PrevalueEditors.TreePickerController", - - function($scope, dialogService, entityResource, $log, iconHelper){ - $scope.renderModel = []; - $scope.ids = []; + .controller("Umbraco.PrevalueEditors.TreePickerController", - $scope.allowRemove = true; - $scope.allowEdit = true; - $scope.sortable = false; + function ($scope, dialogService, entityResource, $log, iconHelper) { + $scope.renderModel = []; + $scope.ids = []; - var config = { - multiPicker: false, - entityType: "Document", - type: "content", + $scope.allowRemove = true; + $scope.allowEdit = true; + $scope.sortable = false; + + var config = { + multiPicker: false, + entityType: "Document", + type: "content", treeAlias: "content", idType: "int" }; @@ -23,107 +23,113 @@ angular.module('umbraco') if ($scope.model.config) { angular.extend(config, $scope.model.config); } - - if($scope.model.value){ - $scope.ids = $scope.model.value.split(','); - entityResource.getByIds($scope.ids, config.entityType).then(function (data) { - _.each(data, function (item, i) { - 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; - }); + if ($scope.model.value) { - }); - }); - } + if (Array.isArray($scope.model.value)) { + $scope.ids = $scope.model.value.split(","); + } else { + $scope.ids.push($scope.model.value); + } - $scope.openContentPicker = function() { - $scope.treePickerOverlay = config; + entityResource.getByIds($scope.ids, config.entityType).then(function (data) { + _.each(data, function (item, i) { + + 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; + }); + + }); + }); + } + + $scope.openContentPicker = function () { + $scope.treePickerOverlay = config; $scope.treePickerOverlay.section = config.type; - $scope.treePickerOverlay.view = "treePicker"; + $scope.treePickerOverlay.view = "treePicker"; $scope.treePickerOverlay.show = true; - $scope.treePickerOverlay.submit = function(model) { + $scope.treePickerOverlay.submit = function (model) { - if(config.multiPicker) { - populate(model.selection); - } else { - populate(model.selection[0]); - } + if (config.multiPicker) { + populate(model.selection); + } else { + populate(model.selection[0]); + } - $scope.treePickerOverlay.show = false; - $scope.treePickerOverlay = null; - }; + $scope.treePickerOverlay.show = false; + $scope.treePickerOverlay = null; + }; - $scope.treePickerOverlay.close = function(oldModel) { - $scope.treePickerOverlay.show = false; - $scope.treePickerOverlay = null; - }; + $scope.treePickerOverlay.close = function (oldModel) { + $scope.treePickerOverlay.show = false; + $scope.treePickerOverlay = null; + }; - } - - $scope.remove =function(index){ - $scope.renderModel.splice(index, 1); - $scope.ids.splice(index, 1); - $scope.model.value = trim($scope.ids.join(), ","); - }; + } + + $scope.remove = function (index) { + $scope.renderModel.splice(index, 1); + $scope.ids.splice(index, 1); + $scope.model.value = trim($scope.ids.join(), ","); + }; + + $scope.clear = function () { + $scope.model.value = ""; + $scope.renderModel = []; + $scope.ids = []; + }; - $scope.clear = function() { - $scope.model.value = ""; - $scope.renderModel = []; - $scope.ids = []; - }; - $scope.add = function (item) { var itemId = config.idType === "udi" ? item.udi : item.id; - if ($scope.ids.indexOf(itemId) < 0){ - - item.icon = iconHelper.convertFromLegacyIcon(item.icon); - $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(), ","); + if ($scope.ids.indexOf(itemId) < 0) { - // 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; - }); + item.icon = iconHelper.convertFromLegacyIcon(item.icon); + $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; + }); + + } + }; - var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { - $scope.model.value = trim($scope.ids.join(), ","); - }); + var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { + $scope.model.value = trim($scope.ids.join(), ","); + }); - //when the scope is destroyed we need to unsubscribe - $scope.$on('$destroy', function () { - unsubscribe(); - }); + //when the scope is destroyed we need to unsubscribe + $scope.$on('$destroy', function () { + unsubscribe(); + }); - function trim(str, chr) { - var rgxtrim = (!chr) ? new RegExp('^\\s+|\\s+$', 'g') : new RegExp('^'+chr+'+|'+chr+'+$', 'g'); - return str.replace(rgxtrim, ''); - } + function trim(str, chr) { + var rgxtrim = (!chr) ? new RegExp('^\\s+|\\s+$', 'g') : new RegExp('^' + chr + '+|' + chr + '+$', 'g'); + return str.replace(rgxtrim, ''); + } - function populate(data){ - if(angular.isArray(data)){ - _.each(data, function (item, i) { - $scope.add(item); - }); - }else{ - $scope.clear(); - $scope.add(data); - } - } -}); + function populate(data) { + if (angular.isArray(data)) { + _.each(data, function (item, i) { + $scope.add(item); + }); + } else { + $scope.clear(); + $scope.add(data); + } + } + });