<commit_before>/**
 * Created by <NAME> from Ubrainians for imCode
 * 29.08.17
 */
Imcms.define("imcms-loop-editor-builder",
    [
        "imcms-bem-builder", "imcms-components-builder", "imcms-loop-rest-api", "imcms-window-builder",
        "imcms-controls-builder", "jquery"
    ],
    function (BEM, components, loopREST, WindowBuilder, controls, $) {
        var $title, $body, $listItems;

        var modifiers = {
            ID: ["col-1", "id"],
            CONTENT: ["col-10"],
            CONTROLS: ["col-1"]
        };

        var docId, loopId;

        var LOOP_ITEM_CLASS = "imcms-loop-item";

        var itemsBEM = new BEM({
            block: "imcms-loop-items",
            elements: {
                "item": LOOP_ITEM_CLASS
            }
        });

        var bodyBEM = new BEM({
            block: "imcms-loop-editor-body",
            elements: {
                "list": "imcms-loop-list"
            }
        });

        function buildEditor() {
            function getMaxLoopItemID() {
                return $listItems.children()
                    .toArray()
                    .map(function (listItem) {
                        var loopItemIdClass = BEM.buildClass(LOOP_ITEM_CLASS, "info", modifiers.ID[1]);
                        return +($(listItem).find("." + loopItemIdClass).text());
                    })
                    .sort(function (a, b) {
                        return (a - b);
                    })
                    .pop();
            }

            function onCreateNewClicked() {
                var newLoopEntry = {
                    no: getMaxLoopItemID() + 1,
                    content: "",
                    enabled: true
                };

                $listItems.append(itemsBEM.makeBlockElement("item", buildItem(newLoopEntry)));
            }

            function onSaveAndCloseClicked() {
                // todo: implement saving, for now it's just closing!!1
                loopWindowBuilder.closeWindow();
            }

            var $head = loopWindowBuilder.buildHead("Loop Editor");
            $title = $head.find(".imcms-title");

            var $footer = loopWindowBuilder.buildFooter([
                components.buttons.positiveButton({
                    text: "Create new",
                    click: onCreateNewClicked
                }),
                components.buttons.saveButton({
                    text: "Save and close",
                    click: onSaveAndCloseClicked
                })
            ]);

            return new BEM({
                block: "imcms-loop-editor",
                elements: {
                    "head": $head,
                    "body": $body = bodyBEM.buildBlock("<div>"),
                    "footer": $footer
                }<commit_msg>IMCMS-233 - Apply new UI to the admin panel and editors: - Calling mock loop rest api update on Loop Editor "save and close".<commit_after>/**
 * Created by <NAME> from Ubrainians for imCode
 * 29.08.17
 */
Imcms.define("imcms-loop-editor-builder",
    [
        "imcms-bem-builder", "imcms-components-builder", "imcms-loop-rest-api", "imcms-window-builder",
        "imcms-controls-builder", "jquery"
    ],
    function (BEM, components, loopREST, WindowBuilder, controls, $) {
        var $title, $body, $listItems;

        var modifiers = {
            ID: ["col-1", "id"],
            CONTENT: ["col-10"],
            CONTROLS: ["col-1"]
        };

        var docId, loopId;

        var LOOP_ITEM_CLASS = "imcms-loop-item";

        var itemsBEM = new BEM({
            block: "imcms-loop-items",
            elements: {
                "item": LOOP_ITEM_CLASS
            }
        });

        var bodyBEM = new BEM({
            block: "imcms-loop-editor-body",
            elements: {
                "list": "imcms-loop-list"
            }
        });

        function buildEditor() {
            function getMaxLoopItemID() {
                return $listItems.children()
                    .toArray()
                    .map(function (listItem) {
                        var loopItemIdClass = BEM.buildClass(LOOP_ITEM_CLASS, "info", modifiers.ID[1]);
                        return +($(listItem).find("." + loopItemIdClass).text());
                    })
                    .sort(function (a, b) {
                        return (a - b);
                    })
                    .pop();
            }

            function onCreateNewClicked() {
                var newLoopEntry = {
                    no: getMaxLoopItemID() + 1,
                    content: "",
                    enabled: true
                };

                $listItems.append(itemsBEM.makeBlockElement("item", buildItem(newLoopEntry)));
            }

            function onSaveAndCloseClicked() {
                loopREST.update().done(loopWindowBuilder.closeWindow.bind(loopWindowBuilder));
            }

            var $head = loopWindowBuilder.buildHead("Loop Editor");
            $title = $head.find(".imcms-title");

            var $footer = loopWindowBuilder.buildFooter([
                components.buttons.positiveButton({
                    text: "Create new",
                    click: onCreateNewClicked
                }),
                components.buttons.saveButton({
                    text: "Save and close",
                    click: onSaveAndCloseClicked
                })
            ]);

            return new BEM({
                block: "imcms-loop-editor",
                elements: {
                    "head": $head,
                    "body": $body = bodyBEM.buildBlock("<div>"),
                    "footer": $footer
                }
{'fraction_non_alphanumeric': 0.12098198516425292, 'fraction_numerical': 0.004945249028611798, 'mean_word_length': 1.2761254019292605, 'pattern_counts': {'":': 10, '<': 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': '683184', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1434, 'n_words': 295}