<commit_before>/**
 * @ngdoc controller
 * @name Umbraco.Editors.DocumentType.EditController
 * @function
 *
 * @description
 * The controller for the content type editor
 */
(function() {
	"use strict";

	function DocumentTypeEditController($scope, $routeParams, contentTypeResource, dataTypeResource, editorState, contentEditingHelper, formHelper, navigationService, iconHelper, contentTypeHelper, notificationsService, $filter) {

		var vm = this;

		vm.save = save;

		vm.currentNode = null;
		vm.contentType = {};
		vm.page = {};
		vm.page.navigation = [
			{
				"name": "Design",
				"icon": "icon-document-dashed-line",
				"view": "views/documentType/views/design/design.html",
				"active": true
			},
			{
				"name": "List view",
				"icon": "icon-list",
				"view": "views/documentType/views/listview/listview.html"
			},
			{
				"name": "Permissions",
				"icon": "icon-keychain",
				"view": "views/documentType/views/permissions/permissions.html"
			},
			{
				"name": "Templates",
				"icon": "icon-layout",
				"view": "views/documentType/views/templates/templates.html"
			}
		];

		vm.page.keyboardShortcutsOverview = [
			{
				"name": "Sections",
				"shortcuts": [
					{
						"description": "Navigate sections",
						"keys": [{"key": "1"}, {"key": "4"}],
						"keyRange": true
					}
				]
			},
			{
				"name": "Design",
				"shortcuts": [
				{
					"description": "Add tab",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "t"}]
				},
				{
					"description": "Add property",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "p"}]
				},
				{
					"description": "Add editor",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "e"}]
				},
				{
					"description": "Edit data type",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "d"}]
				}
			]
		},
		{
			"name": "List view",
			"shortcuts": [
				{
					"description": "Toggle list view",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "l"}]
				}
			]
		},
		{
			"name": "Permissions",
			"shortcuts": [
				{
					"description": "Toggle allow as root",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "r"}]
				},
				{
					"description": "Add child node",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "c"}]
				}
			]
		},
		{
			"name": "Templates",
			"shortcuts": [
				{
					"description": "Add template",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "t"}]
				}
			]
		}
	];

		if ($routeParams.create) {
			//we are creating so get an empty data type item
			contentTypeResource.getScaffold($routeParams.id)
				.then(function(dt) {
					init(dt);
				});
		}
		else {
			contentTypeResource.getById($routeParams.id).then(function(dt){
				init(dt);

				syncTreeNode(vm.contentType, dt.path, true);
			});
		}


		/* ---------- SAVE ---------- */

		function save() {

			// reformat allowed content types to array if id's
			vm.contentType.allowedContentTypes = contentTypeHelper.createIdArray(vm.contentType.allowedContentTypes);

			// update placeholder template information on new doc types
			if (!$routeParams.notemplate && vm.contentType.id === 0) {
				vm.contentType = contentTypeHelper.updateTemplatePlaceholder(vm.contentType);
			}

			contentTypeResource.save(vm.contentType).then(function(dt){

				formHelper.resetForm({ scope: $scope, notifications: dt.notifications });
				contentEditingHelper.handleSuccessfulSave({
					scope: $scope,
					savedContent: dt,
					rebindCallback: function() {

					}
				});

				notificationsService.success("Document type save");
				//post save logic here -the saved doctype returns as a new object
				init(dt);

				syncTreeNode(vm.contentType, dt.path);
			});
		}


		function init(contentType){

			// set all tab to inactive
			if( contentType.groups.length !== 0 ) {
				angular.forEach(contentType.groups, function(group){<commit_msg>Validate form before submit - still need to show messages<commit_after>/**
 * @ngdoc controller
 * @name Umbraco.Editors.DocumentType.EditController
 * @function
 *
 * @description
 * The controller for the content type editor
 */
(function() {
	"use strict";

	function DocumentTypeEditController($scope, $routeParams, contentTypeResource, dataTypeResource, editorState, contentEditingHelper, formHelper, navigationService, iconHelper, contentTypeHelper, notificationsService, $filter) {

		var vm = this;

		vm.save = save;

		vm.currentNode = null;
		vm.contentType = {};
		vm.page = {};
		vm.page.navigation = [
			{
				"name": "Design",
				"icon": "icon-document-dashed-line",
				"view": "views/documentType/views/design/design.html",
				"active": true
			},
			{
				"name": "List view",
				"icon": "icon-list",
				"view": "views/documentType/views/listview/listview.html"
			},
			{
				"name": "Permissions",
				"icon": "icon-keychain",
				"view": "views/documentType/views/permissions/permissions.html"
			},
			{
				"name": "Templates",
				"icon": "icon-layout",
				"view": "views/documentType/views/templates/templates.html"
			}
		];

		vm.page.keyboardShortcutsOverview = [
			{
				"name": "Sections",
				"shortcuts": [
					{
						"description": "Navigate sections",
						"keys": [{"key": "1"}, {"key": "4"}],
						"keyRange": true
					}
				]
			},
			{
				"name": "Design",
				"shortcuts": [
				{
					"description": "Add tab",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "t"}]
				},
				{
					"description": "Add property",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "p"}]
				},
				{
					"description": "Add editor",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "e"}]
				},
				{
					"description": "Edit data type",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "d"}]
				}
			]
		},
		{
			"name": "List view",
			"shortcuts": [
				{
					"description": "Toggle list view",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "l"}]
				}
			]
		},
		{
			"name": "Permissions",
			"shortcuts": [
				{
					"description": "Toggle allow as root",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "r"}]
				},
				{
					"description": "Add child node",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "c"}]
				}
			]
		},
		{
			"name": "Templates",
			"shortcuts": [
				{
					"description": "Add template",
					"keys": [{"key": "alt"},{"key": "shift"},{"key": "t"}]
				}
			]
		}
	];

		if ($routeParams.create) {
			//we are creating so get an empty data type item
			contentTypeResource.getScaffold($routeParams.id)
				.then(function(dt) {
					init(dt);
				});
		}
		else {
			contentTypeResource.getById($routeParams.id).then(function(dt){
				init(dt);

				syncTreeNode(vm.contentType, dt.path, true);
			});
		}


		/* ---------- SAVE ---------- */

		function save() {

			// validate form
			if (formHelper.submitForm({ scope: $scope })) {

				formHelper.resetForm({ scope: $scope });

				// if form validates - perform save
				performSave();

			}

		}

		function performSave() {

			// reformat allowed content types to array if id's
			vm.contentType.allowedContentTypes = contentTypeHelper.createIdArray(vm.contentType.allowedContentTypes);

			// update placeholder template information on new doc types
			if (!$routeParams.notemplate && vm.contentType.id === 0) {
				vm.contentType = contentTypeHelper.updateTemplatePlaceholder(vm.contentType);
			}

			contentTypeResource.save(vm.contentType).then(function(dt){

				formHelper.resetForm({ scope: $scope, notifications: dt.notifications });
				contentEditingHelper.handleSuccessfulSave({
					scope: $scope,
					savedContent: dt,
					rebindCallback: function() {

					}
				});

				notificationsService.success("Document type save");
				//post save logic here -the saved doctype returns as a new object
				init(dt);

				syncTreeNode(vm.contentType, dt.path);
			});

		}


		function init(contentType){

			// set all tab to inactive
			if( contentType.groups.length !== 0 ) {
				angular.forEach(contentType.groups, function(group){
{'fraction_non_alphanumeric': 0.19608826479438315, 'fraction_numerical': 0.0010030090270812437, 'mean_word_length': 3.016616314199396, 'pattern_counts': {'":': 136, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2370501', 'n_tokens_mistral': 3373, 'n_tokens_neox': 2613, 'n_words': 532}