~therp-nl/openerp-web/7.0-lp1013636-x2m_honour_required_attribute

« back to all changes in this revision

Viewing changes to addons/web/static/src/js/data.js

[MERGE] from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
741
741
                             : (v1 > v2) ? 1
742
742
                             : 0;
743
743
                    };
744
 
            records.sort(function (a, b) {
745
 
                return _.reduce(sort_fields, function (acc, field) {
746
 
                    if (acc) { return acc; }
747
 
 
748
 
                    var sign = 1;
749
 
                    if (field[0] === '-') {
750
 
                        sign = -1;
751
 
                        field = field.slice(1);
752
 
                    }
753
 
                    return sign * compare(a[field], b[field]);
754
 
                }, 0);
755
 
            });
 
744
            // Array.sort is not necessarily stable. We must be careful with this because
 
745
            // sorting an array where all items are considered equal is a worst-case that
 
746
            // will randomize the array with an unstable sort! Therefore we must avoid
 
747
            // sorting if there are no sort_fields (i.e. all items are considered equal)
 
748
            // See also: http://ecma262-5.com/ELS5_Section_15.htm#Section_15.4.4.11 
 
749
            //           http://code.google.com/p/v8/issues/detail?id=90
 
750
            if (sort_fields.length) {
 
751
                records.sort(function (a, b) {
 
752
                    return _.reduce(sort_fields, function (acc, field) {
 
753
                        if (acc) { return acc; }
 
754
                        var sign = 1;
 
755
                        if (field[0] === '-') {
 
756
                            sign = -1;
 
757
                            field = field.slice(1);
 
758
                        }
 
759
                        return sign * compare(a[field], b[field]);
 
760
                    }, 0);
 
761
                });
 
762
            }
756
763
            completion.resolve(records);
757
764
        };
758
765
        if(to_get.length > 0) {