~txerpa-openerp/openobject-client-web/txerpa

« back to all changes in this revision

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

  • Committer: Biel - txerpa.com
  • Date: 2013-08-09 12:30:58 UTC
  • mfrom: (4670.2.245 openobject-client-web)
  • Revision ID: biel.massot@txerpa.com-20130809123058-892zu673ti1j8yjd
Actualizo a la ultima revision de trunk. Hay muchos bugs correjidos desde 2012. Elimino la revision 4873 por problemas de rendimiento en el dashboard de Contabilidad

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        this.view_id = jQuery('[id="'+prefix + '_terp_view_id'+'"]').get() ? jQuery('[id="'+prefix + '_terp_view_id'+'"]').val() : null;
50
50
        this.view_mode = jQuery('[id*="'+prefix + '_terp_view_mode'+'"]').get() ? jQuery('[id*="'+prefix + '_terp_view_mode'+'"]').val() : null;
51
51
        this.view_type = jQuery('[id*="'+prefix + '_terp_view_type'+'"]').get() ? jQuery('[id*="'+prefix + '_terp_view_type'+'"]').val() : null;
 
52
        this.context = jQuery('[id*="'+prefix + '_terp_context'+'"]').get() ? jQuery('[id*="'+prefix + '_terp_context'+'"]').val() : {};
52
53
 
53
54
        // if o2m
54
55
 
62
63
    },
63
64
 
64
65
    checkAll: function(clear) {
65
 
        jQuery('[id="' + this.name + '"]:first :checkbox').each(function() {
66
 
            jQuery(this).attr('checked', !clear)
67
 
        });
68
 
 
 
66
        jQuery('[id="' + this.name + '"] input.grid-record-selector').attr('checked', !clear);
69
67
        this.onBooleanClicked();
70
68
    },
71
69
 
247
245
                sort_key = check_order[i];
248
246
            }
249
247
        }
250
 
        if (group_by_context == '[]') {
251
 
            jQuery('#' + record + '[parent_grp_id="' + id + '"]').toggle();
 
248
        if (group_by_context == '[]' && this.sort_order) {
 
249
            sort_order = this.sort_order;
 
250
            sort_key = this.sort_key;
 
251
        }
 
252
 
 
253
        if (jQuery(group).hasClass('group-expand')) {
 
254
            // get listview selectable value, so we know if we are in
 
255
            // simple or multiple selection mode
 
256
            var selectable = openobject.dom.get('_terp_selectable');
 
257
            selectable = selectable ? selectable.value : undefined;
 
258
            jQuery.ajax({
 
259
                url: '/openerp/listgrid/multiple_groupby',
 
260
                type: 'POST',
 
261
                data: { 'model': this.model, 'name': this.name,
 
262
                        'grp_domain': domain, 'group_by': group_by_context,
 
263
                        'view_id': this.view_id,
 
264
                        'view_type': this.view_type,
 
265
                        'parent_group': record,
 
266
                        'group_level': jQuery(group).index() + 1,
 
267
                        'groups': total_groups,
 
268
                        'no_leaf': no_leaf,
 
269
                        'sort_order': sort_order,
 
270
                        'sort_key': sort_key,
 
271
                        '_terp_editable': openobject.dom.get('_terp_editable').value,
 
272
                        '_terp_selectable': selectable,
 
273
                        '_terp_context': openobject.dom.get('_terp_context').value,
 
274
                    //'_terp_offset': openobject.dom.get('_terp_offset').value, // we force offset to 0 for multiple_groupby calls
 
275
                    '_terp_limit': openobject.dom.get('_terp_limit').value,
 
276
            },
 
277
                dataType: 'html',
 
278
                success: function(xmlHttp) {
 
279
                    $group_record.after(xmlHttp);
 
280
                }
 
281
            });
252
282
        } else {
253
 
            if (jQuery(group).hasClass('group-expand')) {
254
 
                jQuery.ajax({
255
 
                    url: '/openerp/listgrid/multiple_groupby',
256
 
                    type: 'POST',
257
 
                    data: { 'model': this.model, 'name': this.name,
258
 
                            'grp_domain': domain, 'group_by': group_by_context,
259
 
                            'view_id': this.view_id,
260
 
                            'view_type': this.view_type,
261
 
                            'parent_group': record,
262
 
                            'group_level': jQuery(group).index() + 1,
263
 
                            'groups': total_groups,
264
 
                            'no_leaf': no_leaf,
265
 
                            'sort_order': sort_order,
266
 
                            'sort_key': sort_key},
267
 
                    dataType: 'html',
268
 
                    success: function(xmlHttp) {
269
 
                        $group_record.after(xmlHttp);
270
 
                    }
271
 
                });
272
 
            } else {
273
 
                jQuery('[parent="' + record + '"]').each(function() {
274
 
                    var parent_id = jQuery('[parent="' + record + '"]').attr('records');
275
 
                    if (jQuery('[parent="' + parent_id + '"]').length > 0) {
276
 
                        jQuery('[parent="' + parent_id + '"]').remove();
277
 
                    }
278
 
                    jQuery(this).remove();
279
 
                })
280
 
            }
 
283
            jQuery('[parent="' + record + '"]').each(function() {
 
284
                var parent_id = jQuery('[parent="' + record + '"]').attr('records');
 
285
                if (jQuery('[parent="' + parent_id + '"]').length > 0) {
 
286
                    jQuery('[parent="' + parent_id + '"]').remove();
 
287
                }
 
288
                jQuery(this).remove();
 
289
            })
281
290
        }
282
291
 
283
292
        jQuery(group).toggleClass('group-collapse group-expand');
287
296
        var _list_view = new ListView(view);
288
297
        var domain;
289
298
        var children;
 
299
        var level = "0";
290
300
 
291
301
        var drop_record = drop.attr('record');
292
302
        var drag_record = drag.attr('record');
293
 
        if(drop_record) {
294
 
            var dropGroup = drop.attr('id').split('grid-row ')[1];
295
 
            domain = jQuery('tr.grid-row-group[records="'+dropGroup+'"]').attr('grp_domain');
296
 
        }
297
 
        else {
 
303
        if (drop_record) {
 
304
            domain = jQuery('tr.grid-row-group[records="'+drop.attr('parent')+'"]').attr('grp_domain');
 
305
            level = jQuery('tr.grid-row-group[records="'+drop.attr('parent')+'"]').attr('grp_level');
 
306
        } else {
298
307
            domain = drop.attr('grp_domain');
 
308
            level = drop.attr('grp_level');
299
309
        }
300
310
 
301
311
        var ch_records = drag.attr('ch_records');
302
 
        if(ch_records) {
303
 
            children = ch_records;
 
312
        if (ch_records) {
 
313
            children = drag.attr('grp_domain');
 
314
        } else if (drag.attr('id') == drop.attr('id')) {
 
315
            children = jQuery('tr.grid-row-group[records="'+drag.attr('parent')+'"]').attr('ch_records');
304
316
        }
305
317
        else {
306
 
            if(drag.attr('id') == drop.attr('id')) {
307
 
                var dragGroup = drag.attr('id').split('grid-row ')[1];
308
 
                children = jQuery('tr.grid-row-group[records="'+dragGroup+'"]').attr('ch_records');
309
 
            }
310
 
            else {
311
 
                children = drag_record;
312
 
            }
 
318
            children = "[('id','=',"+drag_record+")]";
313
319
        }
314
320
 
315
 
        if((drag_record && drop_record) && (drag.attr('id')) == drop.attr('id')) {
 
321
        if ((drag_record && drop_record) && (drag.attr('id') == drop.attr('id'))) {
 
322
            // drag'n'drop within the same group
 
323
            // - get group ids and new position
 
324
            var drop_ids = [];
 
325
            jQuery('[parent='+drop.attr('parent')+']').each(function() {
 
326
                drop_ids.push(jQuery(this).attr('record'));
 
327
            });
 
328
            // target position is always drop_position + 1,
 
329
            // exception when dropping on the 1st line where we force exclusive position of 0
 
330
            var drop_position = drop_ids.indexOf(drop_record) > 0 ? drop_ids.indexOf(drop_record) + 1 : 0;
316
331
            this.dragRow(
317
332
                drag.attr('record'),
318
 
                drag.prevAll().length);
 
333
                drop_position,
 
334
                '['+drop_ids.join(',')+']');
319
335
        }
320
336
        else {
321
337
            jQuery.ajax({
322
338
                url: '/openerp/listgrid/groupbyDrag',
323
339
                type: 'POST',
324
 
                data: {'model': _list_view.model, 'children': children, 'domain': domain},
 
340
                data: {'model': _list_view.model, 'children': children, 'domain': domain, 'level': level},
325
341
                dataType: 'json',
326
342
                success: function () {
327
343
                    _list_view.reload();
330
346
        }
331
347
    },
332
348
 
333
 
    dragRow: function(id, to_index) {
 
349
    dragRow: function(id, to_index, to_ids) {
 
350
        var ids = to_ids ? to_ids : this.ids;
334
351
        jQuery.ajax({
335
352
            url: '/openerp/listgrid/dragRow',
336
353
            type: 'POST',
337
354
            context: this,
338
355
            data: {'_terp_model': this.model,
339
 
                   '_terp_ids': this.ids,
 
356
                   '_terp_ids': ids,
340
357
                   '_terp_id': id,
341
358
                   '_terp_destination_index': to_index
342
359
                  },
468
485
    },
469
486
 
470
487
    onButtonClick: function(name, btype, id, sure, context) {
 
488
        if (!validate_action()) {
 
489
            return;
 
490
        }
471
491
        if (sure && !confirm(sure)) {
472
492
            return;
473
493
        }
667
687
        args['_terp_ids'] = $terp_ids.val()
668
688
        args['_terp_model'] = this.model;
669
689
        args['_terp_id'] = ids;
 
690
        args['_terp_context'] = this.context
670
691
        var req = openobject.http.postJSON('/openerp/listgrid/remove', args);
671
692
 
672
693
        req.addCallback(function(obj) {
728
749
        var self = this;
729
750
 
730
751
        var current_id = edit_inline ? (parseInt(edit_inline) || 0) : edit_inline;
 
752
        var prefix = this.name == '_terp_list' ? '' : this.name + '/';
 
753
        var names = this.name.split('/');
 
754
        var parent_prefix = names.length < 2 ? '' : names.slice(0, names.length - 1).join('/') + '/';
731
755
 
732
756
        var args = jQuery.extend(this.makeArgs(), {
733
757
            _terp_source: this.name,
734
758
            _terp_edit_inline: edit_inline,
735
759
            _terp_source_default_get: default_get_ctx,
736
760
            _terp_concurrency_info: concurrency_info,
737
 
            _terp_editable: openobject.dom.get('_terp_editable').value,
738
 
            _terp_group_by_ctx: openobject.dom.get('_terp_group_by_ctx').value
 
761
            _terp_editable: openobject.dom.get(prefix + '_terp_editable').value,
 
762
            _terp_group_by_ctx: openobject.dom.get(prefix + '_terp_group_by_ctx').value
739
763
        });
740
764
 
741
765
        if (this.name == '_terp_list') {
742
766
            jQuery.extend(args, {
743
767
                _terp_search_domain: openobject.dom.get('_terp_search_domain').value,
744
768
                _terp_search_data: openobject.dom.get('_terp_search_data').value,
745
 
                _terp_filter_domain: openobject.dom.get('_terp_filter_domain').value
 
769
                _terp_filter_domain: openobject.dom.get('_terp_filter_domain').value,
 
770
                _terp_context: openobject.dom.get(prefix + '_terp_context').value,
 
771
                _terp_domain: openobject.dom.get(prefix + '_terp_domain').value
 
772
            });
 
773
        } else {
 
774
            jQuery.extend(args, {
 
775
                _terp_search_domain: "[]",
 
776
                _terp_search_data: "{}",
 
777
                _terp_filter_domain: "[]",
 
778
                _terp_context: openobject.dom.get(parent_prefix + "_terp_context").value,
 
779
                _terp_domain: openobject.dom.get(parent_prefix + "_terp_domain").value
746
780
            });
747
781
        }
748
782
 
819
853
                    $editors.each(function () {
820
854
                        var $this = jQuery(this);
821
855
                        if ($this.val() && $this.attr('callback')) {
822
 
                            MochiKit.Signal.signal(this, 'onchange');
 
856
                            if (($this.attr('kind') == 'many2one' && $this.attr('id').slice($this.attr('id').length - 5) == '_text')
 
857
                                || ($this.attr('kind') == 'many2many' && $this.attr('id').slice($this.attr('id').length - 4) == '_set')) {
 
858
                                // skip many2x 'text' element, onchange will be triggered from real many2x field
 
859
                                return;
 
860
                            }
 
861
                            $this.trigger('change');
823
862
                        }
824
863
                    });
825
864
                }