~unifield-team/unifield-web/UF_1719

« back to all changes in this revision

Viewing changes to addons/openerp/static/javascript/listgrid.js

  • Committer: jf
  • Date: 2013-09-10 08:03:59 UTC
  • mfrom: (4712.1.8 web-jfb-utp-732-727)
  • Revision ID: jfb@tempo-consulting.fr-20130910080359-qkk1bz9nnxwnsm90
UTP-732 [IMP] Entering cash register closing balance (cash count) is extremely slow
UTP-727 [IMP]Error message appears when trying to display 500 entries on the same page (change limit)
lp:~unifield-team/unifield-web/jfb-utp-732-727

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        this.sort_key = null;
62
62
    },
63
63
 
 
64
    get_previously_selected: function() {
 
65
        var prefix = this.name == '_terp_list' ? '' : this.name + '/';
 
66
        var previous_field = jQuery('[id*="'+prefix + '_terp_previously_selected'+'"]')
 
67
        if (previous_field) {
 
68
            sel = previous_field.val() || "";
 
69
            if (!sel) {return []};
 
70
            return sel.split(',').map(function(b) {return parseInt(b, 10)});
 
71
        }
 
72
        return [];
 
73
    },
 
74
 
 
75
    update_previously_selected: function(value_arr) {
 
76
        var prefix = this.name == '_terp_list' ? '' : this.name + '/';
 
77
        field_previously_selected = jQuery('[id*="'+prefix + '_terp_previously_selected'+'"]');
 
78
        if (field_previously_selected) {
 
79
            field_previously_selected.val(value_arr.join(','));
 
80
            $('#num_selected').html(value_arr.length);
 
81
        }
 
82
    },
 
83
 
 
84
    set_previously_selected: function(value) {
 
85
        var previous = this.get_previously_selected()
 
86
        for (var v in value) {
 
87
            if (previous.indexOf(value[v]) == -1) {
 
88
                previous.push(value[v])
 
89
            }
 
90
        }
 
91
        this.update_previously_selected(previous);
 
92
    },
 
93
 
 
94
    add_previously_selected: function(value) {
 
95
        if (value) {
 
96
            this.set_previously_selected([parseInt(value, 10)]);
 
97
        }
 
98
    },
 
99
 
 
100
    remove_previously_selected: function(value) {
 
101
        if (value) {
 
102
            value = parseInt(value, 10);
 
103
            var previous = this.get_previously_selected()
 
104
            var pos = previous.indexOf(value)
 
105
            if (pos != -1) {
 
106
                previous.splice(pos, 1);
 
107
                this.update_previously_selected(previous);
 
108
            }
 
109
        }
 
110
    },
 
111
 
64
112
    checkAll: function(clear) {
65
 
        jQuery('[id="' + this.name + '"] input.grid-record-selector').attr('checked', !clear);
 
113
        var self = this
 
114
        jQuery('[id="' + this.name + '"] input.grid-record-selector').each(function(){
 
115
            jthis = jQuery(this)
 
116
            if (clear && jthis.attr('checked')) {
 
117
                self.remove_previously_selected(jthis.val());
 
118
            } else if (!clear && !jthis.attr('checked')) {
 
119
                self.add_previously_selected(jthis.val());
 
120
            }
 
121
            jthis.attr('checked', !clear);
 
122
        });
66
123
        this.onBooleanClicked();
67
124
    },
68
125
 
116
173
    },
117
174
 
118
175
    getSelectedRecords: function() {
119
 
        return this.$getSelectedItems().map(function() {
 
176
        return this.get_previously_selected();
 
177
 
 
178
        /*return this.$getSelectedItems().map(function() {
120
179
            if(this.value) {
121
180
                return this.value
122
181
            } else {
123
182
                var box_id = this.id.split('/');
124
183
                return box_id[box_id.length - 1]
125
184
            }
126
 
        }).get();
 
185
        }).get();*/
127
186
    },
128
187
 
129
188
    $getSelectedItems: function () {
139
198
    },
140
199
 
141
200
    onBooleanClicked: function() {
 
201
        if (arguments.length == 2) {
 
202
            var clicked = !arguments[0];
 
203
            var id = arguments[1];
 
204
            if (clicked) {
 
205
                this.add_previously_selected(id);
 
206
            } else {
 
207
                this.remove_previously_selected(id);
 
208
            }
 
209
        }
142
210
        var $sidebar = jQuery('.toggle-sidebar');
143
211
        if ($sidebar.is('.closed')) {
144
212
            $sidebar.click()
392
460
            self.reload();
393
461
        });
394
462
    },
 
463
    
 
464
    show_selected_records: function() {
 
465
        group_by = new Array();
 
466
        filter_context = [];
 
467
        this.reload(null, null, this.default_get_ctx, false, this.getSelectedRecords())
 
468
    },
395
469
 
396
470
    clear: function() {
397
471
        group_by = new Array();
644
718
        var self = this;
645
719
        var args = getFormParams('_terp_concurrency_info');
646
720
 
 
721
        var todel = [];
 
722
 
647
723
        if(ids==0) {
648
724
            var $o2m = jQuery(idSelector('_terp_default_o2m/' + this.name));
649
725
            var $tr = jQuery(arguments[1]).parents('tr.grid-row:first');
658
734
            return;
659
735
        }
660
736
        else if (!ids) {
661
 
            ids = this.getSelectedRecords();
 
737
            ids = this.$getSelectedItems().map(function() {
 
738
                if(this.value) {
 
739
                    return this.value
 
740
                } else {
 
741
                    var box_id = this.id.split('/');
 
742
                    return box_id[box_id.length - 1]
 
743
                }
 
744
            }).get();
 
745
            //ids = this.getSelectedRecords();
662
746
            if (ids.length > 0) {
 
747
                todel = ids.slice(0)
663
748
                ids = '[' + ids.join(', ') + ']';
664
749
            }
 
750
        } else {
 
751
            todel = [ids]
665
752
        }
666
753
 
667
754
        if(ids.length == 0 || !confirm(_('Do you really want to delete selected record(s) ?'))) {
668
755
            return false;
669
756
        }
670
757
 
 
758
        $.each(todel, function() {
 
759
            self.remove_previously_selected(this);
 
760
        });
 
761
 
671
762
        var $terp_ids;
672
763
        var $terp_count;
673
764
 
736
827
        this.reload();
737
828
    },
738
829
 
739
 
    reload: function(edit_inline, concurrency_info, default_get_ctx, clear) {
 
830
    reload: function(edit_inline, concurrency_info, default_get_ctx, clear, ids_to_show) {
740
831
        if (openobject.http.AJAX_COUNT > 0) {
741
832
            return callLater(1, bind(this.reload, this), edit_inline, concurrency_info);
742
833
        }
773
864
            args['_terp_clear'] = true;
774
865
        }
775
866
 
 
867
        if (ids_to_show) {
 
868
            args['_terp_ids_to_show'] = '['+ids_to_show.join(',')+']';
 
869
            args['_terp_offset'] = 0;
 
870
        }
776
871
        jQuery(idSelector(self.name) + ' .loading-list').show();
777
872
        jQuery.ajax({
778
873
            url: '/openerp/listgrid/get',
829
924
                    $list.parent().replaceWith(obj.view);
830
925
                }
831
926
 
 
927
                var selfname = self.name
 
928
                var has_selected = false;
 
929
                var all_selected = self.getSelectedRecords()
 
930
                $.each(all_selected, function() {
 
931
                    var el = jQuery(idSelector(selfname+'/'+this));
 
932
                    if (el.length) {
 
933
                        has_selected = true;
 
934
                        el.attr('checked', true);
 
935
                    }
 
936
                });
 
937
                if (has_selected) {
 
938
                    jQuery(idSelector(self.name + '_delete_record')).parent().show();
 
939
                }
 
940
                if (all_selected.length) {
 
941
                    self.selectedRow_sum();
 
942
                }
832
943
                var $editors = self.$adjustEditors(
833
944
                        document.getElementById(self.name));
834
945
                if ($editors.length > 0) {