<commit_before>﻿angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor", [
    
    "$scope",
    "$rootScope",
    "$timeout",
    "$routeParams",
    "editorState",
    'assetsService',
    "Our.Umbraco.DocTypeGridEditor.Services.DocTypeDialogService",
    "Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",

    function ($scope, $rootScope, $timeout, $routeParams, editorState, assetsService, dtgeDialogService, dtgeResources) {

        $scope.title = "Click to insert item";
        $scope.icon = "icon-item-arrangement"; 

        $scope.setValue = function (data, callback) {
            $scope.control.value = data;
            if (!("id" in $scope.control.value) || $scope.control.value.id == "") {
                $scope.control.value.id = guid();
            }
            if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
                $scope.title = $scope.control.value.value.name;
            }
            if ("dtgeContentTypeAlias" in $scope.control.value && $scope.control.value.dtgeContentTypeAlias) {
                dtgeResources.getContentTypeIcon($scope.control.value.dtgeContentTypeAlias).then(function (data2) {
                    if (data2.icon) {
                        $scope.icon = data2.icon;
                    }
                });
            }
            if (callback)
                callback();
        };

        $scope.setDocType = function () {
            dtgeDialogService.open({
                editorName: $scope.control.editor.name,
                allowedDocTypes: $scope.control.editor.config.allowedDocTypes || [],
                nameTemplate: $scope.control.editor.config.nameTemplate,
                dialogData: {
                    docTypeAlias: $scope.control.value.dtgeContentTypeAlias,
                    value: $scope.control.value.value
                },
                callback: function (data) {
                    $scope.setValue({
                        dtgeContentTypeAlias: data.docTypeAlias,
                        value: data.value
                    });
                    $scope.setPreview($scope.control.value);
                }
            });
        };

        $scope.setPreview = function (model) {
            if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview) {
                var nodeId = $routeParams.id;
                dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, $scope.control.editor.alias, model.dtgeContentTypeAlias, model.value, $scope.control.editor.config.viewPath, $scope.control.editor.config.previewViewPath)
                    .success(function(htmlResult) {
                        if (htmlResult.trim().length > 0) {
                            $scope.preview = htmlResult;
                        }
                    });
            }
        };

        function init() {
            $timeout(function () {
                if ($scope.control.$initializing) {
                    $scope.setDocType();
                } else if ($scope.control.value) {
                    $scope.setPreview($scope.control.value);
                }
            }, 200);
        }

        if ($scope.control.value) {
            if (!$scope.control.value.dtgeContentTypeAlias && $scope.control.value.docType) {
                $scope.control.value.dtgeContentTypeAlias = $scope.control.value.docType;
            }
            if ($scope.control.value.docType) {
                delete $scope.control.value.docType;
            }
            if (isGuid($scope.control.value.dtgeContentTypeAlias)) {
                dtgeResources.getContentTypeAliasByGuid($scope.control.value.dtgeContentTypeAlias).then(function(data1) {
                    $scope.control.value.dtgeContentTypeAlias = data1.alias;
                    $scope.setValue($scope.control.value, init);
                });
            } else {
                $scope.setValue($scope.control.value, init);
            }
        } else {
            $scope.setValue({
                id: guid(),
                dtgeContentTypeAlias: "",
                value: {}
            }, init);
        }

        // Load preview css / js files
        if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview)
        {
            if ("previewCssFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewCssFilePath) {
                assetsService.loadCss($scope.control.editor.config.previewCssFilePath, $scope);
            };

            if ("previewJsFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewJsFilePath) {
                assetsService.loadJs($scope.control.editor.config.previewJsFilePath, $scope);
            }
        }

        function guid() {
            function s4() {
                return Math.floor((1 + Math.random()) * 0x10000)
                  .toString(16)
                  .substring(1);
            }
            return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
              s4() + '-' + s4() + s4() + s4();
        }

        function isGuid(input) {
            return new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i").test(input.toString());
        }

    }
]);

angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog",
    [
        "$scope",
        "$interpolate",
        "contentResource",
        "Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",

        function ($scope, $interpolate, contentResource, dtgeResources) {

            $scope.dialogOptions = $scope.$parent.dialogOptions;

            $scope.docTypes = [];
            $scope.dialogMode = "selectDocType";
            $scope.selectedDocType = null;
            $scope.node = null;

            var nameExp = !!$scope.dialogOptions.nameTemplate
                ? $interpolate($scope.dialogOptions.nameTemplate)
                : undefined;

            $scope.selectDocType = function () {
                $scope.dialogMode = "edit";
                $scope.dialogData.docTypeAlias = $scope.selectedDocType.alias;
                loadNode();
            };

            $scope.save = function () {

                // Make sure form is valid
                if (!$scope.dtgeForm.$valid)
                    return;

                // Copy property values to scope model value
                if ($scope.node) {
                    var value = {
                        name: $scope.dialogOptions.editorName
                    };

                    for (var t = 0; t < $scope.node.tabs.length; t++) {<commit_msg>Added formSubmitting call when saving dialog to ensure property editors that rely on this update before closing<commit_after>﻿angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor", [
    
    "$scope",
    "$rootScope",
    "$timeout",
    "$routeParams",
    "editorState",
    'assetsService',
    "Our.Umbraco.DocTypeGridEditor.Services.DocTypeDialogService",
    "Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",

    function ($scope, $rootScope, $timeout, $routeParams, editorState, assetsService, dtgeDialogService, dtgeResources) {

        $scope.title = "Click to insert item";
        $scope.icon = "icon-item-arrangement"; 

        $scope.setValue = function (data, callback) {
            $scope.control.value = data;
            if (!("id" in $scope.control.value) || $scope.control.value.id == "") {
                $scope.control.value.id = guid();
            }
            if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
                $scope.title = $scope.control.value.value.name;
            }
            if ("dtgeContentTypeAlias" in $scope.control.value && $scope.control.value.dtgeContentTypeAlias) {
                dtgeResources.getContentTypeIcon($scope.control.value.dtgeContentTypeAlias).then(function (data2) {
                    if (data2.icon) {
                        $scope.icon = data2.icon;
                    }
                });
            }
            if (callback)
                callback();
        };

        $scope.setDocType = function () {
            dtgeDialogService.open({
                editorName: $scope.control.editor.name,
                allowedDocTypes: $scope.control.editor.config.allowedDocTypes || [],
                nameTemplate: $scope.control.editor.config.nameTemplate,
                dialogData: {
                    docTypeAlias: $scope.control.value.dtgeContentTypeAlias,
                    value: $scope.control.value.value
                },
                callback: function (data) {
                    $scope.setValue({
                        dtgeContentTypeAlias: data.docTypeAlias,
                        value: data.value
                    });
                    $scope.setPreview($scope.control.value);
                }
            });
        };

        $scope.setPreview = function (model) {
            if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview) {
                var nodeId = $routeParams.id;
                dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, $scope.control.editor.alias, model.dtgeContentTypeAlias, model.value, $scope.control.editor.config.viewPath, $scope.control.editor.config.previewViewPath)
                    .success(function(htmlResult) {
                        if (htmlResult.trim().length > 0) {
                            $scope.preview = htmlResult;
                        }
                    });
            }
        };

        function init() {
            $timeout(function () {
                if ($scope.control.$initializing) {
                    $scope.setDocType();
                } else if ($scope.control.value) {
                    $scope.setPreview($scope.control.value);
                }
            }, 200);
        }

        if ($scope.control.value) {
            if (!$scope.control.value.dtgeContentTypeAlias && $scope.control.value.docType) {
                $scope.control.value.dtgeContentTypeAlias = $scope.control.value.docType;
            }
            if ($scope.control.value.docType) {
                delete $scope.control.value.docType;
            }
            if (isGuid($scope.control.value.dtgeContentTypeAlias)) {
                dtgeResources.getContentTypeAliasByGuid($scope.control.value.dtgeContentTypeAlias).then(function(data1) {
                    $scope.control.value.dtgeContentTypeAlias = data1.alias;
                    $scope.setValue($scope.control.value, init);
                });
            } else {
                $scope.setValue($scope.control.value, init);
            }
        } else {
            $scope.setValue({
                id: guid(),
                dtgeContentTypeAlias: "",
                value: {}
            }, init);
        }

        // Load preview css / js files
        if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview)
        {
            if ("previewCssFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewCssFilePath) {
                assetsService.loadCss($scope.control.editor.config.previewCssFilePath, $scope);
            };

            if ("previewJsFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewJsFilePath) {
                assetsService.loadJs($scope.control.editor.config.previewJsFilePath, $scope);
            }
        }

        function guid() {
            function s4() {
                return Math.floor((1 + Math.random()) * 0x10000)
                  .toString(16)
                  .substring(1);
            }
            return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
              s4() + '-' + s4() + s4() + s4();
        }

        function isGuid(input) {
            return new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i").test(input.toString());
        }

    }
]);

angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog",
    [
        "$scope",
        "$interpolate",
        "contentResource",
        "Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",

        function ($scope, $interpolate, contentResource, dtgeResources) {

            $scope.dialogOptions = $scope.$parent.dialogOptions;

            $scope.docTypes = [];
            $scope.dialogMode = "selectDocType";
            $scope.selectedDocType = null;
            $scope.node = null;

            var nameExp = !!$scope.dialogOptions.nameTemplate
                ? $interpolate($scope.dialogOptions.nameTemplate)
                : undefined;

            $scope.selectDocType = function () {
                $scope.dialogMode = "edit";
                $scope.dialogData.docTypeAlias = $scope.selectedDocType.alias;
                loadNode();
            };

            $scope.save = function () {

                // Make sure form is valid
                if (!$scope.dtgeForm.$valid)
                    return;

                // Cause formSubmitting to fire
                $scope.$broadcast("formSubmitting", { scope: $scope });

                // Copy property values to scope model value
                if ($scope.node) {
                    var value = {
                        name: $scope.dialogOptions.editorName
                    };

                    for (var t = 0; t < $scope.node.tabs.length; t++) {
{'fraction_non_alphanumeric': 0.127421595145844, 'fraction_numerical': 0.006579428320783683, 'mean_word_length': 1.634315424610052, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4236066', 'n_tokens_mistral': 3774, 'n_tokens_neox': 3587, 'n_words': 533}