<commit_before>/* Backlog Stats */

var StatsModel = Backbone.Model.extend({
    url: function() {
        return this.get('view').$el.attr('url');
    }
});

var StatsView = Backbone.View.extend({
    el: $(".user-story-stats"),

    initialize: function() {
        _.bindAll(this, 'render');
        this.model = new StatsModel({view:this});
    },

    render: function() {
        var self = this,
            deff = this.model.fetch();

        deff.done(function() {
            self.$el.html(self.model.get('stats_html'));
        });
    }
});

/* Unassigned user storyes (left block) */

var LeftBlockModel = Backbone.Model.extend({
    url: function() {
        return this.get('view').fetch_url();
    }
});

var LeftBlockView = Backbone.View.extend({
    el: $(".left-block"),

    events: {
        "dragstart .unassigned-us .un-us-item": "unassigned_us_dragstart",
        "dragover .left-block .unassigned-us": "left_block_dragover",
        "dragleave .left-block .unassigned-us": "left_block_dragleave",
        "drop .left-block .unassigned-us": "left_block_drop",

        /* Iniline edit */
        "click .unassigned-us .config-us-inline": "on_us_edit_inline",
        "click .unassigned-us .user-story-inline-submit": "on_us_edit_inline_submit",
        "click .unassigned-us .user-story-inline-cancel": "on_us_edit_form_cancel",

        "click .un-us-item .delete": "unassign_us",

        /* Ordering */
        "click .unassigned-us .head-title .row a": "on_order_link_clicked",
    },

    initialize: function() {
        _.bindAll(this, 'render', 'rehash', 'fetch_url');

        this.options.order_by = "-priority";

        this.model = new LeftBlockModel({view:this});
        this.model.on('change', this.render);
        this.model.fetch();
    },

    render: function() {
        this.$('.unassigned-us').html(this.model.get('html'))
    },

    fetch_url: function() {
        var base_url = this.$el.attr('url');
        return base_url + "?order_by=" + this.options.order_by;
    },

    /*
     * Reload state fetching new content from server. 
    */

    rehash: function() {    
        this.model.fetch({success:this.render});
    },

    on_order_link_clicked: function(event) {
        event.preventDefault();
        var self = $(event.currentTarget);
        var opt = self.attr('order_opt') || undefined;
        if (opt === undefined || opt == "") {
            this.options.order_by = self.attr('order_by');
        } else {
            this.options.order_by = "-" + self.attr('order_by');
        }
        this.model.fetch({success:this.render});
    },


    /* 
     * On click to delete button on unassigned user story list. 
    */

    unassign_us: function(event) {
        event.preventDefault();
        var self = $(event.currentTarget);
        var buttons = {};
        buttons[gettext('Delete')] = function() {
            $(this).dialog('close');
            $.post(self.attr('href'), {}, function(data) {
                console.log(data);
                self.parents('.un-us-item').remove();
            });
        };

        buttons[gettext('Cancel')] = function() {
            $(this).dialog('close');
        };

        $(".delete-us-dialog").dialog({
            modal: true,
            width: '220px',<commit_msg>Improved ordering on backlog. (now required localStorage)<commit_after>/* Backlog Stats */

var StatsModel = Backbone.Model.extend({
    url: function() {
        return this.get('view').$el.attr('url');
    }
});

var StatsView = Backbone.View.extend({
    el: $(".user-story-stats"),

    initialize: function() {
        _.bindAll(this, 'render');
        this.model = new StatsModel({view:this});
    },

    render: function() {
        var self = this,
            deff = this.model.fetch();

        deff.done(function() {
            self.$el.html(self.model.get('stats_html'));
        });
    }
});

/* Unassigned user storyes (left block) */

var LeftBlockModel = Backbone.Model.extend({
    url: function() {
        return this.get('view').fetch_url();
    }
});

var LeftBlockView = Backbone.View.extend({
    el: $(".left-block"),

    events: {
        "dragstart .unassigned-us .un-us-item": "unassigned_us_dragstart",
        "dragover .left-block .unassigned-us": "left_block_dragover",
        "dragleave .left-block .unassigned-us": "left_block_dragleave",
        "drop .left-block .unassigned-us": "left_block_drop",

        /* Iniline edit */
        "click .unassigned-us .config-us-inline": "on_us_edit_inline",
        "click .unassigned-us .user-story-inline-submit": "on_us_edit_inline_submit",
        "click .unassigned-us .user-story-inline-cancel": "on_us_edit_form_cancel",

        "click .un-us-item .delete": "unassign_us",

        /* Ordering */
        "click .unassigned-us .head-title .row a": "on_order_link_clicked",
    },

    initialize: function() {
        _.bindAll(this, 'render', 'rehash', 'fetch_url');

        this.options.order_by = "-priority";

        this.model = new LeftBlockModel({view:this});
        this.model.on('change', this.render);
        this.model.fetch();
    },

    render: function() {
        this.$('.unassigned-us').html(this.model.get('html'))
    },

    fetch_url: function() {
        var base_url = this.$el.attr('url');
        return base_url + "?order_by=" + this.options.order_by;
    },

    /*
     * Reload state fetching new content from server. 
    */

    rehash: function() {    
        this.model.fetch({success:this.render});
    },

    on_order_link_clicked: function(event) {
        event.preventDefault();
        var self = $(event.currentTarget);
        
        var order_by = self.attr('order_by');
        var opt_key = "backlog_order_by_" + order_by + "_opt";
        var opt = localStorage.getItem(opt_key)

        if (opt == "" || opt === null) {
            this.options.order_by = order_by;
            localStorage.setItem(opt_key, "-")
        } else {
            this.options.order_by = "-" + order_by;
            localStorage.setItem(opt_key, "");
        }

        this.model.fetch({success:this.render});
    },


    /* 
     * On click to delete button on unassigned user story list. 
    */

    unassign_us: function(event) {
        event.preventDefault();
        var self = $(event.currentTarget);
        var buttons = {};
        buttons[gettext('Delete')] = function() {
            $(this).dialog('close');
            $.post(self.attr('href'), {}, function(data) {
                console.log(data);
                self.parents('.un-us-item').remove();
            });
        };

        buttons[gettext('Cancel')] = function() {
            $(this).dialog('close');
        };

        $(".delete-us-dialog").dialog({
            modal: true,
            width: '220px',
{'fraction_non_alphanumeric': 0.1670584778136938, 'fraction_numerical': 0.000881575080811049, 'mean_word_length': 2.1882903981264636, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, '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': '5689764', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2101, 'n_words': 372}