<commit_before>openerp.web_kanban = function (openerp) {

var QWeb = openerp.web.qweb;
QWeb.add_template('/web_kanban/static/src/xml/web_kanban.xml');
openerp.web.views.add('kanban', 'openerp.web_kanban.KanbanView');
openerp.web_kanban.KanbanView = openerp.web.View.extend({
    init: function (parent, dataset, view_id, options) {
        this._super(parent);
        this.set_default_options(options);
        this.dataset = dataset;
        this.model = dataset.model;
        this.domain = dataset.domain;
        this.context = dataset.context;
        this.view_id = view_id;
        this.fields_view = {};
        this.group_by = [];
        this.source_index = {};
        this.all_display_data = false;
        this.groups = [];
        this.qweb = new QWeb2.Engine();
        this.aggregates = {};
        this.NO_OF_COLUMNS = 3;
        if (this.options.action_views_ids.form) {
            this.form_dialog = new openerp.web.FormDialog(this, {}, this.options.action_views_ids.form, dataset).start();
            this.form_dialog.on_form_dialog_saved.add_last(this.on_record_saved);
        }
    },
    start: function() {
        this._super();
        return this.rpc("/web/view/load", {"model": this.model, "view_id": this.view_id, "view_type": "kanban"}, this.on_loaded);
    },
    on_loaded: function(data) {
        var self = this;
        this.fields_view = data;
        this.add_qweb_template();
        if (this.qweb.has_template('kanban-box')) {
            this.do_actual_search();
        }
    },
    add_qweb_template: function() {
        var group_operator = ["avg", "max", "min", "sum", "count"]
        for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
            var child = this.fields_view.arch.children[i];
            if (child.tag === "field") {
                for(j=0, jj=group_operator.length; j < jj;  j++) {
                    if (child.attrs[group_operator[j]]) {
                        this.aggregates[child.attrs.name] = child.attrs[group_operator[j]];
                        break;
                    }
                }
            }
            if (child.tag === "templates") {
                this.transform_qweb_template(child);
                this.qweb.add_template(openerp.web.json_node_to_xml(child));
                break;
            }
        }
    },
    kanban_color: function(variable) {
        var number_of_color_schemes = 8,
            index = 0;
        switch (typeof(variable)) {
            case 'string':
                for (var i=0, ii=variable.length; i<ii; i++) {
                    index += variable.charCodeAt(i);
                }
                break;
            case 'number':
                index = Math.round(variable);
                break;
            default:
                return '';
        }
        return 'oe_kanban_color_' + ((index % number_of_color_schemes) || number_of_color_schemes);
    },
    kanban_gravatar: function(email, size) {
        size = size || 22;
        var email_md5 = '2eb60ad22dadcf4dc456b28390a80268';
        return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size;
    },
    transform_qweb_template: function(node) {
        var qweb_prefix = QWeb.prefix;
        switch (node.tag) {
            case 'field':
                node.tag = 't';
                node.attrs['t-esc'] = 'record.' + node.attrs['name'] + '.value';
                break
            case 'button':
            case 'a':
                var type = node.attrs.type || '';
                if (_.indexOf('action,object,edit,delete,color'.split(','), type) !== -1) {
                    _.each(node.attrs, function(v, k) {
                        if (_.indexOf('icon,type,name,string,context,states'.split(','), k) != -1) {
                            node.attrs['data-' + k] = v;
                            delete(node.attrs[k]);
                        }
                    });
                    if (node.attrs['data-states']) {
                        var states = _.map(node.attrs['data-states'].split(','), function(state) {
                            return "record.state.value == '" + _.trim(state) + "'";
                        });
                        node.attrs['t-if'] = states.join(' or ');
                    }
                    if (node.attrs['data-string']) {
                        node.attrs.title = node.attrs['data-string'];
                    }
                    if (node.attrs['data-icon']) {
                        node.children = [{
                            tag: 'img',
                            attrs: {
                                src: '/web/static/src/img/icons/' + node.attrs['data-icon'] + '.png',
                                width: '16',
                                height: '16'
                            }
                        }];
                    }
                    if (node.tag == 'a') {
                        node.attrs.href = '#';
                    } else {
                        node.attrs.type = 'button';
                    }
                    node.attrs['class'] = (node.attrs['class'] || '') + ' oe_kanban_action oe_kanban_action_' + node.tag;
                }
                break;
        }
        if (node.children) {
            for (var i = 0, ii = node.children.length; i < ii; i++) {
                this.transform_qweb_template(node.children[i]);
            }
        }
    },
    sort_group: function (first, second) {
        if (first.header && second.header)
        {
            first = first.header.toLowerCase();
            second = second.header.toLowerCase();
            if (first > second) return 1;
            else if (first < second) return -1;
            else return 0;
        }
        else return 0;
    },
    on_show_data: function() {
        var self = this;
        if (!this.group_by.length) {
            this.do_record_group();
        }
        self.all_display_data.sort(this.sort_group);
        this.$element.html(QWeb.render("KanbanView", {"data": self.all_display_data}));
        this.on_reload_kanban();
        this.$element.find(".oe_vertical_text").hide();
        var drag_handel = false;
        if (this.$element.find(".oe_kanban_draghandle").length > 0) {
            drag_handel = ".oe_kanban_draghandle";
        }
        if (!this.group_by.length) {
            drag_handel = true;
        }
        this.$element.find(".oe_column").sortable({
            connectWith: ".oe_column",
            handle : drag_handel,
            start: function(event, ui) {
                self.source_index['index'] = ui.item.index();
                self.source_index['column'] = ui.item.parent().attr('id');
            },
            stop: self.on_receive_record,
        });
        this.$element.find(".oe_column").disableSelection()
        this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
        this.$element.find(".fold-columns-icon").click(function(event) {
            self.do_fold_unfold_columns(event, this.id);
        });<commit_msg>[IMP] kanban :- donot scroll when draging record out side of page.<commit_after>openerp.web_kanban = function (openerp) {

var QWeb = openerp.web.qweb;
QWeb.add_template('/web_kanban/static/src/xml/web_kanban.xml');
openerp.web.views.add('kanban', 'openerp.web_kanban.KanbanView');
openerp.web_kanban.KanbanView = openerp.web.View.extend({
    init: function (parent, dataset, view_id, options) {
        this._super(parent);
        this.set_default_options(options);
        this.dataset = dataset;
        this.model = dataset.model;
        this.domain = dataset.domain;
        this.context = dataset.context;
        this.view_id = view_id;
        this.fields_view = {};
        this.group_by = [];
        this.source_index = {};
        this.all_display_data = false;
        this.groups = [];
        this.qweb = new QWeb2.Engine();
        this.aggregates = {};
        this.NO_OF_COLUMNS = 3;
        if (this.options.action_views_ids.form) {
            this.form_dialog = new openerp.web.FormDialog(this, {}, this.options.action_views_ids.form, dataset).start();
            this.form_dialog.on_form_dialog_saved.add_last(this.on_record_saved);
        }
    },
    start: function() {
        this._super();
        return this.rpc("/web/view/load", {"model": this.model, "view_id": this.view_id, "view_type": "kanban"}, this.on_loaded);
    },
    on_loaded: function(data) {
        var self = this;
        this.fields_view = data;
        this.add_qweb_template();
        if (this.qweb.has_template('kanban-box')) {
            this.do_actual_search();
        }
    },
    add_qweb_template: function() {
        var group_operator = ["avg", "max", "min", "sum", "count"]
        for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
            var child = this.fields_view.arch.children[i];
            if (child.tag === "field") {
                for(j=0, jj=group_operator.length; j < jj;  j++) {
                    if (child.attrs[group_operator[j]]) {
                        this.aggregates[child.attrs.name] = child.attrs[group_operator[j]];
                        break;
                    }
                }
            }
            if (child.tag === "templates") {
                this.transform_qweb_template(child);
                this.qweb.add_template(openerp.web.json_node_to_xml(child));
                break;
            }
        }
    },
    kanban_color: function(variable) {
        var number_of_color_schemes = 8,
            index = 0;
        switch (typeof(variable)) {
            case 'string':
                for (var i=0, ii=variable.length; i<ii; i++) {
                    index += variable.charCodeAt(i);
                }
                break;
            case 'number':
                index = Math.round(variable);
                break;
            default:
                return '';
        }
        return 'oe_kanban_color_' + ((index % number_of_color_schemes) || number_of_color_schemes);
    },
    kanban_gravatar: function(email, size) {
        size = size || 22;
        var email_md5 = '2eb60ad22dadcf4dc456b28390a80268';
        return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size;
    },
    transform_qweb_template: function(node) {
        var qweb_prefix = QWeb.prefix;
        switch (node.tag) {
            case 'field':
                node.tag = 't';
                node.attrs['t-esc'] = 'record.' + node.attrs['name'] + '.value';
                break
            case 'button':
            case 'a':
                var type = node.attrs.type || '';
                if (_.indexOf('action,object,edit,delete,color'.split(','), type) !== -1) {
                    _.each(node.attrs, function(v, k) {
                        if (_.indexOf('icon,type,name,string,context,states'.split(','), k) != -1) {
                            node.attrs['data-' + k] = v;
                            delete(node.attrs[k]);
                        }
                    });
                    if (node.attrs['data-states']) {
                        var states = _.map(node.attrs['data-states'].split(','), function(state) {
                            return "record.state.value == '" + _.trim(state) + "'";
                        });
                        node.attrs['t-if'] = states.join(' or ');
                    }
                    if (node.attrs['data-string']) {
                        node.attrs.title = node.attrs['data-string'];
                    }
                    if (node.attrs['data-icon']) {
                        node.children = [{
                            tag: 'img',
                            attrs: {
                                src: '/web/static/src/img/icons/' + node.attrs['data-icon'] + '.png',
                                width: '16',
                                height: '16'
                            }
                        }];
                    }
                    if (node.tag == 'a') {
                        node.attrs.href = '#';
                    } else {
                        node.attrs.type = 'button';
                    }
                    node.attrs['class'] = (node.attrs['class'] || '') + ' oe_kanban_action oe_kanban_action_' + node.tag;
                }
                break;
        }
        if (node.children) {
            for (var i = 0, ii = node.children.length; i < ii; i++) {
                this.transform_qweb_template(node.children[i]);
            }
        }
    },
    sort_group: function (first, second) {
        if (first.header && second.header)
        {
            first = first.header.toLowerCase();
            second = second.header.toLowerCase();
            if (first > second) return 1;
            else if (first < second) return -1;
            else return 0;
        }
        else return 0;
    },
    on_show_data: function() {
        var self = this;
        if (!this.group_by.length) {
            this.do_record_group();
        }
        self.all_display_data.sort(this.sort_group);
        this.$element.html(QWeb.render("KanbanView", {"data": self.all_display_data}));
        this.on_reload_kanban();
        this.$element.find(".oe_vertical_text").hide();
        var drag_handel = false;
        if (this.$element.find(".oe_kanban_draghandle").length > 0) {
            drag_handel = ".oe_kanban_draghandle";
        }
        if (!this.group_by.length) {
            drag_handel = true;
        }
        this.$element.find(".oe_column").sortable({
            connectWith: ".oe_column",
            handle : drag_handel,
            start: function(event, ui) {
                self.source_index['index'] = ui.item.index();
                self.source_index['column'] = ui.item.parent().attr('id');
            },
            stop: self.on_receive_record,
            scroll: false
        });
        this.$element.find(".oe_column").disableSelection()
        this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
        this.$element.find(".fold-columns-icon").click(function(event) {
            self.do_fold_unfold_columns(event, this.id);
        });
{'fraction_non_alphanumeric': 0.14109521460286137, 'fraction_numerical': 0.0059200789343857915, 'mean_word_length': 1.4929725931131412, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '3618041', 'n_tokens_mistral': 4233, 'n_tokens_neox': 4070, 'n_words': 656}