|
|
@ -1,4 +1,4 @@ |
|
|
|
odoo.define('one2many_mass_select_delete.form_widgets', function (require) { |
|
|
|
odoo.define('one2many_mass_select_delete.form_widgets', function(require) { |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
@ -8,34 +8,71 @@ odoo.define('one2many_mass_select_delete.form_widgets', function (require) { |
|
|
|
var rpc = require('web.rpc'); |
|
|
|
var FieldOne2Many = require('web.relational_fields').FieldOne2Many; |
|
|
|
var _t = core._t; |
|
|
|
var FormController = require('web.FormController'); |
|
|
|
var core = require('web.core'); |
|
|
|
|
|
|
|
ListRenderer.include({ |
|
|
|
_updateSelection: function () { |
|
|
|
_updateSelection: function() { |
|
|
|
this.selection = []; |
|
|
|
var self = this; |
|
|
|
var $inputs = this.$('tbody .o_list_record_selector input:visible:not(:disabled)'); |
|
|
|
var allChecked = $inputs.length > 0; |
|
|
|
$inputs.each(function (index, input) { |
|
|
|
$inputs.each(function(index, input) { |
|
|
|
if (input.checked) { |
|
|
|
self.selection.push($(input).closest('tr').data('id')); |
|
|
|
} else { |
|
|
|
allChecked = false; |
|
|
|
} |
|
|
|
}); |
|
|
|
if(this.selection.length > 0){ |
|
|
|
if (this.selection.length > 0) { |
|
|
|
$('.button_delete_order_lines').show() |
|
|
|
$('.button_select_order_lines').show() |
|
|
|
|
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
$('.button_delete_order_lines').hide() |
|
|
|
$('.button_select_order_lines').hide() |
|
|
|
} |
|
|
|
this.$('thead .o_list_record_selector input').prop('checked', allChecked); |
|
|
|
this.trigger_up('selection_changed', { selection: this.selection }); |
|
|
|
this.trigger_up('selection_changed', { |
|
|
|
selection: this.selection |
|
|
|
}); |
|
|
|
this._updateFooter(); |
|
|
|
}, |
|
|
|
}) |
|
|
|
|
|
|
|
FormController.include({ |
|
|
|
_onQuickEdit: function(ev) { |
|
|
|
ev.stopPropagation(); |
|
|
|
}, |
|
|
|
_setEditMode: function() { |
|
|
|
this._disableButtons(); |
|
|
|
this.selection = []; |
|
|
|
var self = this; |
|
|
|
var $inputs = this.$('tbody .o_list_record_selector input:visible:not(:disabled)'); |
|
|
|
var allChecked = $inputs.length > 0; |
|
|
|
$inputs.each(function(index, input) { |
|
|
|
console.log(input.checked) |
|
|
|
if (input.checked) { |
|
|
|
self.selection.push($(input).closest('tr').data('id')); |
|
|
|
} else { |
|
|
|
allChecked = false; |
|
|
|
} |
|
|
|
}); |
|
|
|
return this.mutex.getUnlockedDef() |
|
|
|
.then(this._setMode.bind(this, 'edit')) |
|
|
|
.then(this._enableButtons.bind(this)) |
|
|
|
.guardedCatch(this._enableButtons.bind(this)); |
|
|
|
}, |
|
|
|
saveRecord: async function() { |
|
|
|
var $inputs = this.$('tbody .o_list_record_selector input:visible:not(:disabled)'); |
|
|
|
var allChecked = $inputs.length > 0; |
|
|
|
$inputs.each(function(index, input) { |
|
|
|
console.log(input.checked) |
|
|
|
}); |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
var One2manyDelete = FieldOne2Many.extend({ |
|
|
|
template: 'One2manyDelete', |
|
|
|
events: { |
|
|
@ -43,16 +80,18 @@ odoo.define('one2many_mass_select_delete.form_widgets', function (require) { |
|
|
|
"click .button_select_order_lines": "selected_lines", |
|
|
|
}, |
|
|
|
init: function() { |
|
|
|
var self = this; |
|
|
|
this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
delete_selected_lines: function() |
|
|
|
{ |
|
|
|
var self=this; |
|
|
|
delete_selected_lines: function() { |
|
|
|
var self = this; |
|
|
|
var current_model = this.recordData[this.name].model; |
|
|
|
var selected_lines = self.find_deleted_lines(); |
|
|
|
if (selected_lines.length === 0) |
|
|
|
{ |
|
|
|
return this.displayNotification({ message: _t('Please Select at least One Record.'), type: 'danger' }); |
|
|
|
if (selected_lines.length === 0) { |
|
|
|
return this.displayNotification({ |
|
|
|
message: _t('Please Select at least One Record.'), |
|
|
|
type: 'danger' |
|
|
|
}); |
|
|
|
} |
|
|
|
var w_response = confirm("Dou You Want to Delete ?"); |
|
|
|
if (w_response) { |
|
|
@ -61,39 +100,39 @@ odoo.define('one2many_mass_select_delete.form_widgets', function (require) { |
|
|
|
'model': current_model, |
|
|
|
'method': 'unlink', |
|
|
|
'args': [selected_lines], |
|
|
|
}).then(function(result){ |
|
|
|
}).then(function(result) { |
|
|
|
self.trigger_up('reload'); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
selected_lines: function() |
|
|
|
{ |
|
|
|
var self=this; |
|
|
|
selected_lines: function() { |
|
|
|
var self = this; |
|
|
|
var current_model = this.recordData[this.name].model; |
|
|
|
var selected_lines = self.find_selected_lines(); |
|
|
|
if (selected_lines.length === 0) |
|
|
|
{ |
|
|
|
return this.displayNotification({ message: _t('Please Select at least One Record.'), type: 'danger' }); |
|
|
|
if (selected_lines.length === 0) { |
|
|
|
return this.displayNotification({ |
|
|
|
message: _t('Please Select at least One Record.'), |
|
|
|
type: 'danger' |
|
|
|
}); |
|
|
|
} |
|
|
|
var w_response = confirm("Dou You Want to Select ?"); |
|
|
|
if (w_response) { |
|
|
|
|
|
|
|
rpc.query({ |
|
|
|
'model': current_model, |
|
|
|
'method': 'unlink', |
|
|
|
'args': [selected_lines], |
|
|
|
}).then(function(result){ |
|
|
|
}).then(function(result) { |
|
|
|
self.trigger_up('reload'); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
_getRenderer: function () { |
|
|
|
_getRenderer: function() { |
|
|
|
if (this.view.arch.tag === 'kanban') { |
|
|
|
return One2ManyKanbanRenderer; |
|
|
|
} |
|
|
|
if (this.view.arch.tag === 'tree') { |
|
|
|
return ListRenderer.extend({ |
|
|
|
init: function (parent, state, params) { |
|
|
|
init: function(parent, state, params) { |
|
|
|
this._super.apply(this, arguments); |
|
|
|
this.hasSelectors = true; |
|
|
|
}, |
|
|
@ -101,39 +140,39 @@ odoo.define('one2many_mass_select_delete.form_widgets', function (require) { |
|
|
|
} |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
find_deleted_lines: function () { |
|
|
|
var self=this; |
|
|
|
var selected_list =[]; |
|
|
|
find_deleted_lines: function() { |
|
|
|
var self = this; |
|
|
|
var selected_list = []; |
|
|
|
this.$el.find('td.o_list_record_selector input:checked') |
|
|
|
.closest('tr').each(function () { |
|
|
|
.closest('tr').each(function() { |
|
|
|
selected_list.push(parseInt(self._getResId($(this).data('id')))); |
|
|
|
}); |
|
|
|
return selected_list; |
|
|
|
}, |
|
|
|
|
|
|
|
find_selected_lines: function () |
|
|
|
{ var self = this; |
|
|
|
var selected_list =[]; |
|
|
|
var selected_list1 =[]; |
|
|
|
var selected_list2 =[]; |
|
|
|
find_selected_lines: function() { |
|
|
|
var self = this; |
|
|
|
var selected_list = []; |
|
|
|
var selected_list1 = []; |
|
|
|
var selected_list2 = []; |
|
|
|
this.$el.find('td.o_list_record_selector input:checked') |
|
|
|
.closest('tr').each(function () { |
|
|
|
.closest('tr').each(function() { |
|
|
|
selected_list.push(parseInt(self._getResId($(this).data('id')))); |
|
|
|
}); |
|
|
|
if (selected_list.length != 0) { |
|
|
|
this.$el.find('td.o_list_record_selector') |
|
|
|
.closest('tr').each(function () { |
|
|
|
.closest('tr').each(function() { |
|
|
|
selected_list1.push(parseInt(self._getResId($(this).data('id')))); |
|
|
|
}); |
|
|
|
selected_list2 = selected_list1.filter(function (x) { |
|
|
|
selected_list2 = selected_list1.filter(function(x) { |
|
|
|
return selected_list.indexOf(x) < 0 |
|
|
|
}); |
|
|
|
} |
|
|
|
return selected_list2; |
|
|
|
}, |
|
|
|
_getResId: function (recordId) { |
|
|
|
_getResId: function(recordId) { |
|
|
|
var record; |
|
|
|
utils.traverse_records(this.recordData[this.name], function (r) { |
|
|
|
utils.traverse_records(this.recordData[this.name], function(r) { |
|
|
|
if (r.id === recordId) { |
|
|
|
record = r; |
|
|
|
} |
|
|
|