diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.component.js similarity index 50% rename from src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js rename to src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.component.js index f2a2fc0cc2..03a7207720 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.component.js @@ -1,224 +1,67 @@ -angular.module("umbraco").controller("Umbraco.PropertyEditors.NestedContent.DocTypePickerController", [ +(function () { + 'use strict'; - "$scope", - "Umbraco.PropertyEditors.NestedContent.Resources", - "overlayService", - "localizationService", - "iconHelper", - - function ($scope, ncResources, overlayService, localizationService, iconHelper) { - var selectElementTypeModalTitle = ""; - - $scope.elemTypeTabs = []; - - - init(); - - - function init() { - localizationService.localize("content_nestedContentSelectElementTypeModalTitle").then(function (value) { - selectElementTypeModalTitle = value; - }); - - ncResources.getContentTypes().then(function (elemTypes) { - $scope.model.elemTypes = elemTypes; - - // convert legacy icons - iconHelper.formatContentTypeIcons($scope.model.elemTypes); - - // Count doctype name occurrences - var elTypeNameOccurrences= _.countBy(elemTypes, 'name'); - - // Populate document type tab dictionary - // And append alias to name if multiple doctypes have the same name - elemTypes.forEach(function (value) { - $scope.elemTypeTabs[value.alias] = value.tabs; - - if (elTypeNameOccurrences[value.name] > 1) { - value.name += " (" + value.alias + ")"; - } - }); - }); - - } - - - $scope.add = function () { - $scope.model.value.push({ - // As per PR #4, all stored content type aliases must be prefixed "nc" for easier recognition. - // For good measure we'll also prefix the tab alias "nc" - ncAlias: "", - ncTabAlias: "", - nameTemplate: "" - }); - } - - $scope.canAdd = function () { - return !$scope.model.docTypes || !$scope.model.value || $scope.model.value.length < $scope.model.docTypes.length; - } - - $scope.remove = function (index) { - $scope.model.value.splice(index, 1); - } - - $scope.sortableOptions = { - axis: "y", - cursor: "move", - handle: ".handle", - placeholder: 'sortable-placeholder', - forcePlaceholderSize: true, - helper: function (e, ui) { - // When sorting table rows, the cells collapse. This helper fixes that: https://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/ - ui.children().each(function () { - $(this).width($(this).width()); - }); - return ui; - }, - start: function (e, ui) { - - var cellHeight = ui.item.height(); - - // Build a placeholder cell that spans all the cells in the row: https://stackoverflow.com/questions/25845310/jquery-ui-sortable-and-table-cell-size - var cellCount = 0; - $('td, th', ui.helper).each(function () { - // For each td or th try and get it's colspan attribute, and add that or 1 to the total - var colspan = 1; - var colspanAttr = $(this).attr('colspan'); - if (colspanAttr > 1) { - colspan = colspanAttr; - } - cellCount += colspan; - }); - - // Add the placeholder UI - note that this is the item's content, so td rather than tr - and set height of tr - ui.placeholder.html('