<commit_before>/**
 * Text history window builder in text editor.
 *
 * @author <NAME> from Ubrainians for imCode
 * 29.01.18
 */
Imcms.define("imcms-text-history-window-builder",
    [
        "imcms-window-builder", "imcms-bem-builder", "imcms-components-builder", "jquery",
        "imcms-texts-history-rest-api", "tinyMCE"
    ],
    function (WindowBuilder, BEM, components, $, textsHistoryRestAPI, tinyMCE) {

        var $historyListContainer, $textHistoryView;

        function onWriteToTextField() {
            var textButton = textHistoryWindowBuilder.$editor.find(".view-text-button")[0];
            viewText.call(textButton);

            tinyMCE.activeEditor.setContent($textHistoryView.html());
            textHistoryWindowBuilder.closeWindow();
        }

        function onCancel() {
            textHistoryWindowBuilder.closeWindow();
        }

        function buildFooter() {
            return textHistoryWindowBuilder.buildFooter([
                components.buttons.negativeButton({
                    text: "Cancel",
                    click: onCancel
                }),
                components.buttons.saveButton({
                    text: "Write to text field",
                    click: onWriteToTextField
                })
            ]);
        }

        function isClickAllowed(element) {
            var $element = $(element);

            if ($element.hasClass("imcms-button--disabled")) {
                return false;
            }

            textHistoryWindowBuilder.$editor.find(".imcms-button--disabled")
                .removeClass("imcms-button--disabled");

            $element.addClass("imcms-button--disabled");

            return true;
        }

        function viewSource() {
            isClickAllowed(this) && $textHistoryView.text($textHistoryView.html());
        }

        function viewText() {
            isClickAllowed(this) && $textHistoryView.html($textHistoryView.text());
        }

        function buildTextHistoryControlButtons() {
            return components.buttons.buttonsContainer("<div>", [
                components.buttons.negativeButton({
                    "class": "view-source-button",
                    text: "View Source",
                    click: viewSource
                }),
                components.buttons.negativeButton({
                    "class": "view-text-button",
                    text: "View Text",
                    click: viewText
                })
            ]);
        }

        function buildHistoryView() {
            return new BEM({
                block: "imcms-right-side",
                elements: {<commit_msg>IMCMS-255 - Upgrade server side to work with new client: - Setting editor as able to save after inserting history; - View history text/html buttons hidden until history unit is selected.<commit_after>/**
 * Text history window builder in text editor.
 *
 * @author <NAME> from Ubrainians for imCode
 * 29.01.18
 */
Imcms.define("imcms-text-history-window-builder",
    [
        "imcms-window-builder", "imcms-bem-builder", "imcms-components-builder", "jquery",
        "imcms-texts-history-rest-api", "tinyMCE"
    ],
    function (WindowBuilder, BEM, components, $, textsHistoryRestAPI, tinyMCE) {

        var $historyListContainer, $textHistoryView;

        function onWriteToTextField() {
            var textButton = textHistoryWindowBuilder.$editor.find(".view-text-button")[0];
            viewText.call(textButton);

            tinyMCE.activeEditor.setContent($textHistoryView.html());
            tinyMCE.activeEditor.setDirty(true);
            textHistoryWindowBuilder.closeWindow();
        }

        function onCancel() {
            textHistoryWindowBuilder.closeWindow();
        }

        function buildFooter() {
            return textHistoryWindowBuilder.buildFooter([
                components.buttons.negativeButton({
                    text: "Cancel",
                    click: onCancel
                }),
                components.buttons.saveButton({
                    text: "Write to text field",
                    click: onWriteToTextField
                })
            ]);
        }

        function isClickAllowed(element) {
            var $element = $(element);

            if ($element.hasClass("imcms-button--disabled")) {
                return false;
            }

            textHistoryWindowBuilder.$editor.find(".imcms-button--disabled")
                .removeClass("imcms-button--disabled");

            $element.addClass("imcms-button--disabled");

            return true;
        }

        function viewSource() {
            isClickAllowed(this) && $textHistoryView.text($textHistoryView.html());
        }

        function viewText() {
            isClickAllowed(this) && $textHistoryView.html($textHistoryView.text());
        }

        function buildTextHistoryControlButtons() {
            return components.buttons.buttonsContainer("<div>", [
                components.buttons.negativeButton({
                    "class": "view-source-button",
                    "style": "display: none;",
                    text: "View Source",
                    click: viewSource
                }),
                components.buttons.negativeButton({
                    "class": "view-text-button",
                    "style": "display: none;",
                    text: "View Text",
                    click: viewText
                })
            ]);
        }

        function buildHistoryView() {
            return new BEM({
                block: "imcms-right-side",
                elements: {
{'fraction_non_alphanumeric': 0.11290896159317212, 'fraction_numerical': 0.00302275960170697, 'mean_word_length': 1.6836832061068703, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, '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': '7395376', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1335, 'n_words': 252}