~jfb-tempo-consulting/unifield-web/us-736

« back to all changes in this revision

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

  • Committer: jf
  • Date: 2015-09-30 07:44:15 UTC
  • mfrom: (4754.4.4 unifield-web)
  • Revision ID: jfb@tempo-consulting.fr-20150930074415-is7xaaxvq6teqymc
OEB-146 [FIX] Group by: use all records and add pager on grouped items
lp:~jfb-tempo-consulting/unifield-web/oeb-146

Show diffs side-by-side

added added

removed removed

Lines of Context:
310
310
        this.expand_all = 0;
311
311
        $('#expand_all').hide();
312
312
    },
313
 
    group_by: function(id, record, no_leaf, group) {
 
313
    group_by: function(id, record, no_leaf, group, offset, remove) {
314
314
        var $group_record = jQuery('[records="' + record + '"]');
315
315
        var group_by_context = $group_record.attr('grp_context');
316
316
        var domain = $group_record.attr('grp_domain');
319
319
        var check_order = eval(total_groups);
320
320
        var sort_order;
321
321
        var sort_key;
 
322
        offset = offset || 0;
322
323
        for(var i in check_order) {
323
324
            var $img = $header.find('th[id="'+'grid-data-column/'+check_order[i]+'"] img');
324
325
            if($img.length) {
328
329
        }
329
330
        var expand_all = this.expand_all;
330
331
        var self = this;
331
 
        if (group_by_context == '[]') {
332
 
            jQuery('#' + record + '[parent_grp_id="' + id + '"]').toggle();
 
332
        if (group_by_context == '[]' && this.sort_order) {
 
333
            sort_order = this.sort_order;
 
334
            sort_key = this.sort_key;
 
335
        }
 
336
        if (jQuery(group).hasClass('group-expand')) {
 
337
            // get listview selectable value, so we know if we are in
 
338
            // simple or multiple selection mode
 
339
            var selectable = openobject.dom.get('_terp_selectable');
 
340
            if (selectable) {
 
341
                selectable = selectable.value
 
342
            }
 
343
            jQuery.ajax({
 
344
                url: '/openerp/listgrid/multiple_groupby',
 
345
                type: 'POST',
 
346
                data: { 'model': this.model, 'name': this.name,
 
347
                        'grp_domain': domain, 'group_by': group_by_context,
 
348
                        'view_id': this.view_id,
 
349
                        'view_type': this.view_type,
 
350
                        'parent_group': record,
 
351
                        'group_level': jQuery(group).index() + 1,
 
352
                        'groups': total_groups,
 
353
                        'no_leaf': no_leaf,
 
354
                        'sort_order': sort_order,
 
355
                        'sort_key': sort_key,
 
356
                        '_terp_editable': openobject.dom.get('_terp_editable').value,
 
357
                        '_terp_selectable': selectable,
 
358
                        '_terp_context': openobject.dom.get('_terp_context').value,
 
359
                        '_terp_offset': offset,
 
360
                    //'_terp_offset': openobject.dom.get('_terp_offset').value, // we force offset to 0 for multiple_groupby calls
 
361
                    '_terp_limit': openobject.dom.get('_terp_limit').value,
 
362
            },
 
363
                dataType: 'html',
 
364
                success: function(xmlHttp) {
 
365
                    $group_record.after(xmlHttp);
 
366
                    if (remove) {
 
367
                        remove.remove();
 
368
                    }
 
369
                }
 
370
            });
333
371
        } else {
334
 
            if (jQuery(group).hasClass('group-expand')) {
335
 
                jQuery.ajax({
336
 
                    url: '/openerp/listgrid/multiple_groupby',
337
 
                    type: 'POST',
338
 
                    data: { 'model': this.model, 'name': this.name,
339
 
                            'grp_domain': domain, 'group_by': group_by_context,
340
 
                            'view_id': this.view_id,
341
 
                            'view_type': this.view_type,
342
 
                            'parent_group': record,
343
 
                            'group_level': jQuery(group).index() + 1,
344
 
                            'groups': total_groups,
345
 
                            'no_leaf': no_leaf,
346
 
                            'sort_order': sort_order,
347
 
                            'sort_key': sort_key},
348
 
                    dataType: 'html',
349
 
                    success: function(xmlHttp) {
350
 
                        $group_record.after(xmlHttp);
351
 
                        if (expand_all) {
352
 
                            self.expand_all_group(record);
353
 
                        }
354
 
                    }
355
 
                });
356
 
            } else {
357
 
                jQuery('[parent="' + record + '"]').each(function() {
358
 
                    var parent_id = jQuery('[parent="' + record + '"]').attr('records');
359
 
                    if (jQuery('[parent="' + parent_id + '"]').length > 0) {
360
 
                        jQuery('[parent="' + parent_id + '"]').remove();
361
 
                    }
362
 
                    jQuery(this).remove();
363
 
                })
364
 
            }
 
372
            jQuery('[parent="' + record + '"]').each(function() {
 
373
                var parent_id = jQuery('[parent="' + record + '"]').attr('records');
 
374
                if (jQuery('[parent="' + parent_id + '"]').length > 0) {
 
375
                    jQuery('[parent="' + parent_id + '"]').remove();
 
376
                }
 
377
                jQuery(this).remove();
 
378
            })
 
379
 
365
380
        }
366
381
 
367
382
        jQuery(group).toggleClass('group-collapse group-expand');
371
386
        var _list_view = new ListView(view);
372
387
        var domain;
373
388
        var children;
 
389
        var level = "0";
374
390
 
375
391
        var drop_record = drop.attr('record');
376
392
        var drag_record = drag.attr('record');
377
 
        if(drop_record) {
378
 
            var dropGroup = drop.attr('id').split('grid-row ')[1];
379
 
            domain = jQuery('tr.grid-row-group[records="'+dropGroup+'"]').attr('grp_domain');
380
 
        }
381
 
        else {
 
393
        if (drop_record) {
 
394
            domain = jQuery('tr.grid-row-group[records="'+drop.attr('parent')+'"]').attr('grp_domain');
 
395
            level = jQuery('tr.grid-row-group[records="'+drop.attr('parent')+'"]').attr('grp_level');
 
396
        } else {
382
397
            domain = drop.attr('grp_domain');
 
398
            level = drop.attr('grp_level');
383
399
        }
384
400
 
385
401
        var ch_records = drag.attr('ch_records');
386
 
        if(ch_records) {
387
 
            children = ch_records;
 
402
        if (ch_records) {
 
403
            children = drag.attr('grp_domain');
 
404
        } else if (drag.attr('id') == drop.attr('id')) {
 
405
            children = jQuery('tr.grid-row-group[records="'+drag.attr('parent')+'"]').attr('ch_records');
388
406
        }
389
407
        else {
390
 
            if(drag.attr('id') == drop.attr('id')) {
391
 
                var dragGroup = drag.attr('id').split('grid-row ')[1];
392
 
                children = jQuery('tr.grid-row-group[records="'+dragGroup+'"]').attr('ch_records');
393
 
            }
394
 
            else {
395
 
                children = drag_record;
396
 
            }
 
408
            children = "[('id','=',"+drag_record+")]";
397
409
        }
398
410
 
399
 
        if((drag_record && drop_record) && (drag.attr('id')) == drop.attr('id')) {
 
411
        if ((drag_record && drop_record) && (drag.attr('id') == drop.attr('id'))) {
 
412
            // drag'n'drop within the same group
 
413
            // - get group ids and new position
 
414
            var drop_ids = [];
 
415
            jQuery('[parent='+drop.attr('parent')+']').each(function() {
 
416
                drop_ids.push(jQuery(this).attr('record'));
 
417
            });
 
418
            // target position is always drop_position + 1,
 
419
            // exception when dropping on the 1st line where we force exclusive position of 0
 
420
            var drop_position = drop_ids.indexOf(drop_record) > 0 ? drop_ids.indexOf(drop_record) + 1 : 0;
400
421
            this.dragRow(
401
422
                drag.attr('record'),
402
 
                drag.prevAll().length);
 
423
                drop_position,
 
424
                '['+drop_ids.join(',')+']');
403
425
        }
404
426
        else {
405
427
            jQuery.ajax({
406
428
                url: '/openerp/listgrid/groupbyDrag',
407
429
                type: 'POST',
408
 
                data: {'model': _list_view.model, 'children': children, 'domain': domain},
 
430
                data: {'model': _list_view.model, 'children': children, 'domain': domain, 'level': level},
409
431
                dataType: 'json',
410
432
                success: function () {
411
433
                    _list_view.reload();
414
436
        }
415
437
    },
416
438
 
417
 
    dragRow: function(id, to_index) {
 
439
    dragRow: function(id, to_index, to_ids) {
 
440
        var ids = to_ids ? to_ids : this.ids;
418
441
        jQuery.ajax({
419
442
            url: '/openerp/listgrid/dragRow',
420
443
            type: 'POST',
421
444
            context: this,
422
445
            data: {'_terp_model': this.model,
423
 
                   '_terp_ids': this.ids,
 
446
                   '_terp_ids': ids,
424
447
                   '_terp_id': id,
425
448
                   '_terp_destination_index': to_index
426
449
                  },
1100
1123
        }
1101
1124
    }
1102
1125
}
 
1126
 
 
1127
function next_p(el, name, no_leaf, limit, way) {
 
1128
    pr = jQuery(el).parent().parent().parent().prev('.grid-row-group');
 
1129
    offset = pr.attr('offset') || 0
 
1130
    offset = parseInt(offset)
 
1131
    offset = offset + way * limit
 
1132
    pr.attr('offset', offset)
 
1133
    grp_by = pr.attr('grp_by_id');
 
1134
    pr.toggleClass('group-expand', true);
 
1135
    records = pr.attr('records');
 
1136
    to_remove = pr.siblings('[parent="'+records+'"]');
 
1137
    new ListView(name).group_by(grp_by, records, no_leaf, pr, offset, to_remove);
 
1138
}
 
1139