﻿/**
 * @ngdoc controller
 * @name Umbraco.Editors.Dictionary.CreateController
 * @function
 * 
 * @description
 * The controller for creating dictionary items
 */
function DictionaryCreateController($scope, $location, dictionaryResource, navigationService, notificationsService, formHelper, appState) {

    var vm = this;

    vm.itemKey = "";

    vm.createItem = createItem;

    function createItem() {

        if (formHelper.submitForm({ scope: $scope, formCtrl: this.createDictionaryForm })) {

            var node = $scope.currentNode;

            dictionaryResource.create(node.id, vm.itemKey).then(function (data) {
                navigationService.hideMenu();

                // set new item as active in tree
                var currPath = node.path ? node.path : "-1";
                navigationService.syncTree({ tree: "dictionary", path: currPath + "," + data, forceReload: true, activate: true });

                // reset form state
                formHelper.resetForm({ scope: $scope, formCtrl: this.createDictionaryForm });

                // navigate to edit view
                var currentSection = appState.getSectionState("currentSection");
                $location.path("/" + currentSection + "/dictionary/edit/" + data);

            }, function (err) {
                formHelper.resetForm({ scope: $scope, formCtrl: this.createDictionaryForm, hasErrors: true });
                if (err.data && err.data.message) {
                    notificationsService.error(err.data.message);
                    navigationService.hideMenu();
                }
            });
        }
    }
}

angular.module("umbraco").controller("Umbraco.Editors.Dictionary.CreateController", DictionaryCreateController);

﻿/**
 * @ngdoc controller
 * @name Umbraco.Editors.Dictionary.CreateController
 * @function
 * 
 * @description
 * The controller for creating dictionary items
 */
function DictionaryCreateController($scope, $location, dictionaryResource, navigationService, notificationsService, formHelper, appState) {

    var vm = this;

    vm.itemKey = "";

    vm.createItem = createItem;

    function createItem() {

        if (formHelper.submitForm({ scope: $scope, formCtrl: $scope.createDictionaryForm })) {

            var node = $scope.currentNode;

            dictionaryResource.create(node.id, vm.itemKey).then(function (data) {
                navigationService.hideMenu();

                // set new item as active in tree
                var currPath = node.path ? node.path : "-1";
                navigationService.syncTree({ tree: "dictionary", path: currPath + "," + data, forceReload: true, activate: true });

                // reset form state
                formHelper.resetForm({ scope: $scope, formCtrl: $scope.createDictionaryForm });

                // navigate to edit view
                var currentSection = appState.getSectionState("currentSection");
                $location.path("/" + currentSection + "/dictionary/edit/" + data);

            }, function (err) {
                formHelper.resetForm({ scope: $scope, formCtrl: $scope.createDictionaryForm, hasErrors: true });
                if (err.data && err.data.message) {
                    notificationsService.error(err.data.message);
                    navigationService.hideMenu();
                }
            });
        }
    }
}

angular.module("umbraco").controller("Umbraco.Editors.Dictionary.CreateController", DictionaryCreateController);

Fix JS error preventing newly created dictionary items from opening automatically
Fix JS error preventing newly created dictionary items from opening automatically

(cherry picked from commit 59f90bd08be677817133584fc877f4a53a349359)
