<commit_before>openerp.website = function(instance) {
var _lt = instance.web._lt;
instance.website.EditorBar = instance.web.Widget.extend({
    template: 'Website.EditorBar',
    events: {
        'click button[data-action=edit]': 'edit',
        'click button[data-action=save]': 'save',
        'click button[data-action=cancel]': 'cancel',
        'click button[data-action=snippet]': 'snippet',
    },
    container: 'body',
    init: function () {
        this._super.apply(this, arguments);
        this.saving_mutex = new $.Mutex();
    },
    start: function() {
        var self = this;

        this.$('button[data-action]').prop('disabled', true);
        this.$buttons = {
            edit: this.$('button[data-action=edit]'),
            save: this.$('button[data-action=save]'),
            cancel: this.$('button[data-action=cancel]'),
            snippet: this.$('button[data-action=snippet]'),
        };
        this.$buttons.edit.add(this.$buttons.snippet).prop('disabled', false);

        self.snippet_start();

        this.rte = new instance.website.RTE(this);
        this.rte.on('change', this, this.proxy('rte_changed'));

        return $.when(
            this._super.apply(this, arguments),
            this.rte.appendTo(this.$el)
        );
    },
    edit: function () {
        this.$buttons.edit.prop('disabled', true);
        this.$buttons.cancel.prop('disabled', false);
        // TODO: span edition changing edition state (save button)
        this.rte.start_edition(
                $('[data-oe-model]')
                    .not('link, script')
                    .prop('contentEditable', true)
                    .addClass('oe_editable'));
    },
    rte_changed: function () {
        this.$buttons.save.prop('disabled', false);
    },
    save: function () {
        var self = this;
        var defs = [];
        $('.oe_dirty').each(function (i, v) {
            var $el = $(this);
            // TODO: Add a queue with concurrency limit in webclient
            // https://github.com/medikoo/deferred/blob/master/lib/ext/function/gate.js
            var def = self.saving_mutex.exec(function () {
                return self.saveElement($el).then(function () {
                    $el.removeClass('oe_dirty');
                }).fail(function () {
                    var data = $el.data();
                    console.error(_.str.sprintf('Could not save %s#%d#%s', data.oeModel, data.oeId, data.oeField));
                });
            });
            defs.push(def);
        });
        return $.when.apply(null, defs).then(function () {
            window.location.reload();
        });
    },
    saveElement: function ($el) {
        var data = $el.data();
        var html = $el.html();
        var xpath = data.oeXpath;
        if (xpath) {
            var $w = $el.clone();
            $w.removeClass('oe_dirty');
            _.each(['model', 'id', 'field', 'xpath'], function(d) {$w.removeAttr('data-oe-' + d);});
            $w
                .removeClass('oe_editable')
                .prop('contentEditable', false);
            html = $w.wrap('<div>').parent().html();
        }
        return (new instance.web.DataSet(this, 'ir.ui.view')).call('save', [data.oeModel, data.oeId, data.oeField, html, xpath]);
    },
    cancel: function () {
        window.location.reload();
    },
    snippet_start: function () {
        var self = this;
        $('.oe_snippet').click(function(ev) {
            $('.oe_selected').removeClass('oe_selected');
            var $snippet = $(ev.currentTarget);
            $snippet.addClass('oe_selected');
            $snippet.draggable();
            var selector = $snippet.data("selector");
            var $zone = $(".oe_website_body " + selector);
            var droppable = '<div class="oe_snippet_drop" style="border:1px solid red;">.<br/>.<br/>.<br/>.<br/>.<br/></div>';
            $zone.before(droppable);
            $zone.after(droppable);
            $(".oe_snippet_drop").droppable({
                drop: function( event, ui ) {
                    console.log(event, ui, "DROP");
                    var $target = $(event.target);
                    $target.before($snippet.html());
                    $('.oe_selected').remove();
                    $('.oe_snippet_drop').remove();
                }
            });
        });

    },
    snippet: function (ev) {
        $('.oe_snippet_editor').toggle();
    },
});

instance.website.RTE = instance.web.Widget.extend({
    tagName: 'li',
    className: 'oe_right',
    commands: [
        {name: _lt('Bold'), command: 'bold'},
        {name: _lt('Italic'), command: 'italic'},
        {name: _lt('Underline'), command: 'underline'},
        {name: _lt('Strikethrough'), command: 'strike'},
        {name: _lt('H1'), style: { element: 'h1' }},
        {name: _lt('H2'), style: { element: 'h2', }},
        {name: _lt('H3'), style: { element: 'h3', }},
        {name: _lt('H4'), style: { element: 'h4', }},
        {name: _lt("Red"), style: { element: 'span', styles: { color: 'red' } }}
    ],
    // editor.ui.items -> possible commands &al
    // editor.applyStyle(new CKEDITOR.style({element: "span",styles: {color: "#(color)"},overrides: [{element: "font",attributes: {color: null}}]}, {color: '#ff0000'}));
    start: function () {
        var self = this;
        this.$el.hide();

        _(this.commands).foldl(function (jq, command) {
            return jq.add(self.button_for(command));
        }, $()).appendTo(this.$el);
    },
    start_edition: function ($elements) {
        var self = this;
        $elements
            .not('span')
            .each(function () {
                var $this = $(this);
                CKEDITOR.inline(this, self._config()).on('change', function () {
                    $this.addClass('oe_dirty');
                    self.trigger('change', this, null);
                });
            });
        this.$el.show();
    },

    button_for: function (command) {
        var self = this;
        return $('<button type="button">').click(function () {
            var editor = self._current_editor();
            editor.fire('saveSnapshot');

            if (command.style) {
                editor.applyStyle(new CKEDITOR.style(command.style));
            } else if (typeof command.command === 'string') {
                editor.execCommand(command.command);
            } else {
                command.command(editor);
            }
        }).text(command.name);
    },

    _current_editor: function () {
        return CKEDITOR.currentInstance;
    },
    _config: function () {
        return {
            // Don't load ckeditor's style rules
            stylesSet: [],
            // Remove toolbar entirely
            removePlugins: 'toolbar,elementspath,resize',
            uiColor: '',
            // Ensure no config file is loaded
            customConfig: '',
            // Disable ACF
            allowedContent: true,
        };
    },
});

$(function(){

    function make_static(){
        $('.oe_snippet_demo').removeClass('oe_new');
        $('.oe_page *').off('mouseover mouseleave');
        $('.oe_page .oe_selected').removeClass('oe_selected');
    }

    var selected_snippet = null;
    function snippet_click(event){
        if(selected_snippet){
            selected_snippet.removeClass('oe_selected');
            if(selected_snippet[0] === $(this)[0]){<commit_msg>[IMP] disable RTE on t-record results (data-oe-type)<commit_after>openerp.website = function(instance) {
var _lt = instance.web._lt;
instance.website.EditorBar = instance.web.Widget.extend({
    template: 'Website.EditorBar',
    events: {
        'click button[data-action=edit]': 'edit',
        'click button[data-action=save]': 'save',
        'click button[data-action=cancel]': 'cancel',
        'click button[data-action=snippet]': 'snippet',
    },
    container: 'body',
    init: function () {
        this._super.apply(this, arguments);
        this.saving_mutex = new $.Mutex();
    },
    start: function() {
        var self = this;

        this.$('button[data-action]').prop('disabled', true);
        this.$buttons = {
            edit: this.$('button[data-action=edit]'),
            save: this.$('button[data-action=save]'),
            cancel: this.$('button[data-action=cancel]'),
            snippet: this.$('button[data-action=snippet]'),
        };
        this.$buttons.edit.add(this.$buttons.snippet).prop('disabled', false);

        self.snippet_start();

        this.rte = new instance.website.RTE(this);
        this.rte.on('change', this, this.proxy('rte_changed'));

        return $.when(
            this._super.apply(this, arguments),
            this.rte.appendTo(this.$el)
        );
    },
    edit: function () {
        this.$buttons.edit.prop('disabled', true);
        this.$buttons.cancel.prop('disabled', false);
        // TODO: span edition changing edition state (save button)
        this.rte.start_edition(
                $('[data-oe-model]')
                    .not('link, script')
                    .prop('contentEditable', true)
                    .addClass('oe_editable'));
    },
    rte_changed: function () {
        this.$buttons.save.prop('disabled', false);
    },
    save: function () {
        var self = this;
        var defs = [];
        $('.oe_dirty').each(function (i, v) {
            var $el = $(this);
            // TODO: Add a queue with concurrency limit in webclient
            // https://github.com/medikoo/deferred/blob/master/lib/ext/function/gate.js
            var def = self.saving_mutex.exec(function () {
                return self.saveElement($el).then(function () {
                    $el.removeClass('oe_dirty');
                }).fail(function () {
                    var data = $el.data();
                    console.error(_.str.sprintf('Could not save %s#%d#%s', data.oeModel, data.oeId, data.oeField));
                });
            });
            defs.push(def);
        });
        return $.when.apply(null, defs).then(function () {
            window.location.reload();
        });
    },
    saveElement: function ($el) {
        var data = $el.data();
        var html = $el.html();
        var xpath = data.oeXpath;
        if (xpath) {
            var $w = $el.clone();
            $w.removeClass('oe_dirty');
            _.each(['model', 'id', 'field', 'xpath'], function(d) {$w.removeAttr('data-oe-' + d);});
            $w
                .removeClass('oe_editable')
                .prop('contentEditable', false);
            html = $w.wrap('<div>').parent().html();
        }
        return (new instance.web.DataSet(this, 'ir.ui.view')).call('save', [data.oeModel, data.oeId, data.oeField, html, xpath]);
    },
    cancel: function () {
        window.location.reload();
    },
    snippet_start: function () {
        var self = this;
        $('.oe_snippet').click(function(ev) {
            $('.oe_selected').removeClass('oe_selected');
            var $snippet = $(ev.currentTarget);
            $snippet.addClass('oe_selected');
            $snippet.draggable();
            var selector = $snippet.data("selector");
            var $zone = $(".oe_website_body " + selector);
            var droppable = '<div class="oe_snippet_drop" style="border:1px solid red;">.<br/>.<br/>.<br/>.<br/>.<br/></div>';
            $zone.before(droppable);
            $zone.after(droppable);
            $(".oe_snippet_drop").droppable({
                drop: function( event, ui ) {
                    console.log(event, ui, "DROP");
                    var $target = $(event.target);
                    $target.before($snippet.html());
                    $('.oe_selected').remove();
                    $('.oe_snippet_drop').remove();
                }
            });
        });

    },
    snippet: function (ev) {
        $('.oe_snippet_editor').toggle();
    },
});

instance.website.RTE = instance.web.Widget.extend({
    tagName: 'li',
    className: 'oe_right',
    commands: [
        {name: _lt('Bold'), command: 'bold'},
        {name: _lt('Italic'), command: 'italic'},
        {name: _lt('Underline'), command: 'underline'},
        {name: _lt('Strikethrough'), command: 'strike'},
        {name: _lt('H1'), style: { element: 'h1' }},
        {name: _lt('H2'), style: { element: 'h2', }},
        {name: _lt('H3'), style: { element: 'h3', }},
        {name: _lt('H4'), style: { element: 'h4', }},
        {name: _lt("Red"), style: { element: 'span', styles: { color: 'red' } }}
    ],
    // editor.ui.items -> possible commands &al
    // editor.applyStyle(new CKEDITOR.style({element: "span",styles: {color: "#(color)"},overrides: [{element: "font",attributes: {color: null}}]}, {color: '#ff0000'}));
    start: function () {
        var self = this;
        this.$el.hide();

        _(this.commands).foldl(function (jq, command) {
            return jq.add(self.button_for(command));
        }, $()).appendTo(this.$el);
    },
    start_edition: function ($elements) {
        var self = this;
        CKEDITOR.on('currentInstance', this.proxy('_change_focused_editor'));
        $elements
            .not('span, [data-oe-type]')
            .each(function () {
                var $this = $(this);
                CKEDITOR.inline(this, self._config()).on('change', function () {
                    $this.addClass('oe_dirty');
                    self.trigger('change', this, null);
                });
            });
    },

    button_for: function (command) {
        var self = this;
        return $('<button type="button">').click(function () {
            var editor = self._current_editor();
            editor.fire('saveSnapshot');

            if (command.style) {
                editor.applyStyle(new CKEDITOR.style(command.style));
            } else if (typeof command.command === 'string') {
                editor.execCommand(command.command);
            } else {
                command.command(editor);
            }
        }).text(command.name);
    },

    _current_editor: function () {
        return CKEDITOR.currentInstance;
    },
    _change_focused_editor: function () {
        this.$el.toggle(!!CKEDITOR.currentInstance);
    },
    _config: function () {
        return {
            // Don't load ckeditor's style rules
            stylesSet: [],
            // Remove toolbar entirely
            removePlugins: 'toolbar,elementspath,resize',
            uiColor: '',
            // Ensure no config file is loaded
            customConfig: '',
            // Disable ACF
            allowedContent: true,
        };
    },
});

$(function(){

    function make_static(){
        $('.oe_snippet_demo').removeClass('oe_new');
        $('.oe_page *').off('mouseover mouseleave');
        $('.oe_page .oe_selected').removeClass('oe_selected');
    }

    var selected_snippet = null;
    function snippet_click(event){
        if(selected_snippet){
            selected_snippet.removeClass('oe_selected');
            if(selected_snippet[0] === $(this)[0]){
{'fraction_non_alphanumeric': 0.17433816682187042, 'fraction_numerical': 0.001995476918983637, 'mean_word_length': 1.9393939393939394, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '236196', 'n_tokens_mistral': 4460, 'n_tokens_neox': 4360, 'n_words': 794}