<commit_before>/**
 * Tab in Page Info window for File Document type.
 *
 * @author <NAME> from Ubrainians for imCode
 * 15.01.18
 */
Imcms.define("imcms-file-tab-builder",
    [
        "imcms-bem-builder", "imcms-components-builder", "imcms-document-types", "imcms-page-info-tab-form-builder",
        "imcms-controls-builder", "jquery"
    ],
    function (BEM, components, docTypes, tabContentBuilder, controls, $) {

        var $filesContainerBody;

        function buildFilesContainerBody() {
            return $filesContainerBody = $("<div>", {"class": "files-container-body"});
        }

        function buildFilesContainerHead() {
            var filesContainerHeadBEM = new BEM({
                block: "files-container-head",
                elements: {
                    "title": "imcms-title"
                }
            });

            var $idTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "ID"});
            var $nameTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "Name"});
            var $isDefaultFileTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "Default"});

            return filesContainerHeadBEM.buildBlock("<div>", [
                {"title": $idTitle},
                {"title": $nameTitle},
                {"title": $isDefaultFileTitle}
            ]);
        }

        function buildFileRow(file) {
            var $isDefaultFileRadioBtn = components.radios.imcmsRadio("<div>", {
                name: "isDefaultFile",
                value: file.name
            });

            var $row;

            return ($row = new BEM({
                block: "file-row",
                elements: {
                    "id": components.texts.textInput({value: file.fileId}),
                    "name": $("<div>", {text: file.filename}),
                    "default": $isDefaultFileRadioBtn,
                    "delete": controls.remove(function () {
                        $row.detach();

                        if (!tabData.formData) {

                        }

                        // tabData.formData.
                    })
                }
            }).buildBlockStructure("<div>", {"class": "files-container-body__file-row"}));
        }

        function buildFilesRow(files) {
            return (files || []).map(buildFileRow);
        }

        function appendFiles(files) {
            $filesContainerBody.append(buildFilesRow(files));
        }

        function transformFileToDTO(file) {
            return {
                fileId: "",
                filename: file.name,
                mimeType: file.type,
                defaultFile: false
            }
        }

        function transformFilesToDTO(files) {
            return Array.prototype.slice.call(files || []).map(transformFileToDTO);
        }

        var tabData = {};

        return {
            name: "files",
            tabIndex: null,
            isDocumentTypeSupported: function (docType) {
                return docType === docTypes.FILE;
            },
            showTab: function () {
                tabContentBuilder.showTab(this.tabIndex);
            },
            hideTab: function () {
                tabContentBuilder.hideTab(this.tabIndex);
            },
            buildTab: function (index) {
                this.tabIndex = index;

                var $fileInput = $("<input>", {
                    type: "file",
                    style: "display: none;",
                    multiple: "",
                    change: function () {
                        tabData.formData = tabData.formData || new FormData();

                        for (var i = 0; i < this.files.length; i++) {
                            tabData.formData.append('files', this.files[i]);
                        }

                        console.log(this.files);
                        console.log(tabData.formData.getAll("files"));
                        appendFiles(transformFilesToDTO(this.files));
                    }
                });

                var $uploadButtonContainer = $("<div>", {"class": "imcms-field"});

                var $uploadNewFilesButton = components.buttons.positiveButton({
                    text: "Upload",
                    click: function () {
                        $fileInput.click();
                    }
                });

                $uploadButtonContainer.append($fileInput, $uploadNewFilesButton);

                var $filesContainer = new BEM({
                    block: "files-container",
                    elements: {
                        "head": buildFilesContainerHead(),
                        "body": buildFilesContainerBody()
                    }
                }).buildBlockStructure("<div>");

                var blockElements = [
                    $uploadButtonContainer,
                    $filesContainer
                ];
                return tabContentBuilder.buildFormBlock(blockElements, index);
            },
            fillTabDataFromDocument: function (document) {
                appendFiles(document.files);
                // append to this.data.$filesContainerBody
            },
            saveData: function (documentDTO) {
                return documentDTO;
            },
            clearTabData: function () {
            }
        };
    }
);<commit_msg>IMCMS-255 - Upgrade server side to work with new client: - Cleaning files on Page Info window closing.<commit_after>/**
 * Tab in Page Info window for File Document type.
 *
 * @author <NAME> from Ubrainians for imCode
 * 15.01.18
 */
Imcms.define("imcms-file-tab-builder",
    [
        "imcms-bem-builder", "imcms-components-builder", "imcms-document-types", "imcms-page-info-tab-form-builder",
        "imcms-controls-builder", "jquery"
    ],
    function (BEM, components, docTypes, tabContentBuilder, controls, $) {

        var $filesListContainerBody, $fileInput;

        function buildFilesContainerBody() {
            return $filesListContainerBody = $("<div>", {"class": "files-container-body"});
        }

        function buildFilesContainerHead() {
            var filesContainerHeadBEM = new BEM({
                block: "files-container-head",
                elements: {
                    "title": "imcms-title"
                }
            });

            var $idTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "ID"});
            var $nameTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "Name"});
            var $isDefaultFileTitle = filesContainerHeadBEM.buildElement("title", "<div>", {text: "Default"});

            return filesContainerHeadBEM.buildBlock("<div>", [
                {"title": $idTitle},
                {"title": $nameTitle},
                {"title": $isDefaultFileTitle}
            ]);
        }

        function buildFileRow(file) {
            var $isDefaultFileRadioBtn = components.radios.imcmsRadio("<div>", {
                name: "isDefaultFile",
                value: file.name
            });

            var $row;

            return ($row = new BEM({
                block: "file-row",
                elements: {
                    "id": components.texts.textInput({value: file.fileId}),
                    "name": $("<div>", {text: file.filename}),
                    "default": $isDefaultFileRadioBtn,
                    "delete": controls.remove(function () {
                        $row.detach();

                        if (!tabData.formData) {

                        }

                        // tabData.formData.
                    })
                }
            }).buildBlockStructure("<div>", {"class": "files-container-body__file-row"}));
        }

        function buildFilesRow(files) {
            return (files || []).map(buildFileRow);
        }

        function appendFiles(files) {
            $filesListContainerBody.append(buildFilesRow(files));
        }

        function transformFileToDTO(file) {
            return {
                fileId: "",
                filename: file.name,
                mimeType: file.type,
                defaultFile: false
            }
        }

        function transformFilesToDTO(files) {
            return Array.prototype.slice.call(files || []).map(transformFileToDTO);
        }

        var tabData = {};

        return {
            name: "files",
            tabIndex: null,
            isDocumentTypeSupported: function (docType) {
                return docType === docTypes.FILE;
            },
            showTab: function () {
                tabContentBuilder.showTab(this.tabIndex);
            },
            hideTab: function () {
                tabContentBuilder.hideTab(this.tabIndex);
            },
            buildTab: function (index) {
                this.tabIndex = index;

                $fileInput = $("<input>", {
                    type: "file",
                    style: "display: none;",
                    multiple: "",
                    change: function () {
                        tabData.formData = tabData.formData || new FormData();

                        for (var i = 0; i < this.files.length; i++) {
                            tabData.formData.append('files', this.files[i]);
                        }

                        console.log(this.files);
                        console.log(tabData.formData.getAll("files"));
                        appendFiles(transformFilesToDTO(this.files));
                    }
                });

                var $uploadButtonContainer = $("<div>", {"class": "imcms-field"});

                var $uploadNewFilesButton = components.buttons.positiveButton({
                    text: "Upload",
                    click: function () {
                        $fileInput.click();
                    }
                });

                $uploadButtonContainer.append($fileInput, $uploadNewFilesButton);

                var $filesListContainer = new BEM({
                    block: "files-container",
                    elements: {
                        "head": buildFilesContainerHead(),
                        "body": buildFilesContainerBody()
                    }
                }).buildBlockStructure("<div>");

                var blockElements = [
                    $uploadButtonContainer,
                    $filesListContainer
                ];
                return tabContentBuilder.buildFormBlock(blockElements, index);
            },
            fillTabDataFromDocument: function (document) {
                appendFiles(document.files);
            },
            saveData: function (documentDTO) {
                // todo: implement saving
                return documentDTO;
            },
            clearTabData: function () {
                $filesListContainerBody.empty();
                $fileInput.val('');
                tabData = {};
            }
        };
    }
);
{'fraction_non_alphanumeric': 0.12048963186261076, 'fraction_numerical': 0.0015529368776833836, 'mean_word_length': 1.3559285560576717, 'pattern_counts': {'":': 26, '<': 29, '<?xml version=': 0, '>': 27, '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': '3114161', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2553, 'n_words': 486}