4 changed files with 72 additions and 166 deletions
			
			
		| @ -1,146 +1,55 @@ | |||||
| odoo.define('one2many_mass_select_delete.form_widgets', function (require) { | /** @odoo-module */ | ||||
| 	"use strict"; |  | ||||
| 
 | 
 | ||||
| 	var core = require('web.core'); | import { X2ManyField } from "@web/views/fields/x2many/x2many_field"; | ||||
| 	var utils = require('web.utils'); | import { registry } from "@web/core/registry"; | ||||
| 	var fieldRegistry = require('web.field_registry'); | import { standardFieldProps } from "@web/views/fields/standard_field_props"; | ||||
| 	var ListRenderer = require('web.ListRenderer'); | import { ListRenderer } from "@web/views/list/list_renderer"; | ||||
| 	var rpc = require('web.rpc'); | import {listView} from '@web/views/list/list_view'; | ||||
| 	var FieldOne2Many = require('web.relational_fields').FieldOne2Many; | import { patch } from "@web/core/utils/patch"; | ||||
| 	var _t = core._t; |  | ||||
| 
 | 
 | ||||
| 	ListRenderer.include({ | export class TestListRenderer extends ListRenderer { | ||||
| 		_updateSelection: function () { |   get hasSelectors() { | ||||
| 	        this.selection = []; |         this.props.allowSelectors = true | ||||
| 	        var self = this; |         this.props.list.selection = true | ||||
| 	        var $inputs = this.$('tbody .o_list_record_selector input:visible:not(:disabled)'); |         return this.props.allowSelectors && !this.env.isSmall; | ||||
| 	        var allChecked = $inputs.length > 0; |  | ||||
| 	        $inputs.each(function (index, input) { |  | ||||
| 	            if (input.checked) { |  | ||||
| 	                self.selection.push($(input).closest('tr').data('id')); |  | ||||
| 	            } else { |  | ||||
| 	                allChecked = false; |  | ||||
|     } |     } | ||||
| 	        }); |     toggleRecordSelection(record) { | ||||
| 	        if(this.selection.length > 0){ |         record.toggleSelection(); | ||||
| 	        	$('.button_delete_order_lines').show() |  | ||||
| 	            $('.button_select_order_lines').show() |  | ||||
| 
 |  | ||||
| 	        }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._updateFooter(); |  | ||||
| 	    }, |  | ||||
| 	}) |  | ||||
| 
 | 
 | ||||
|     var One2manyDelete = FieldOne2Many.extend({ | } | ||||
| 		template: 'One2manyDelete', | export class TestX2ManyField extends X2ManyField { | ||||
| 		events: { |     get hasSelected(){ | ||||
| 			"click .button_delete_order_lines": "delete_selected_lines", |         return this.list.records.filter((rec) => rec.selected).length | ||||
| 			"click .button_select_order_lines": "selected_lines", |  | ||||
| 		}, |  | ||||
| 		init: function() { |  | ||||
| 	        this._super.apply(this, arguments); |  | ||||
| 	    }, |  | ||||
| 		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' }); |  | ||||
|     } |     } | ||||
| 
 |     deleteSelected(){ | ||||
|         var w_response = confirm("Dou You Want to Delete ?"); |         var w_response = confirm("Dou You Want to Delete ?"); | ||||
| 			if (w_response) { |         if (w_response){ | ||||
|                 rpc.query({ |             console.log(this.list.records) | ||||
|                     'model': current_model, |             let selected = this.list.records.filter((rec) => rec.selected) | ||||
|                     'method': 'unlink', |             if (this.activeActions.onDelete) { | ||||
|                     'args': [selected_lines], |                 selected.forEach((rec) => { | ||||
|                 }).then(function(result){ |                         this.activeActions.onDelete(rec); | ||||
|                     self.trigger_up('reload'); |                 }) | ||||
|                 }); |  | ||||
|             } |             } | ||||
| 		}, |  | ||||
| 		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' }); |  | ||||
|         } |         } | ||||
| 			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){ |  | ||||
|                 self.trigger_up('reload'); |  | ||||
|             }); |  | ||||
|     } |     } | ||||
| 		}, |     deleteUnselected(){ | ||||
| 		_getRenderer: function () { |          var w_response = confirm("Dou You Want to Select?"); | ||||
|             if (this.view.arch.tag === 'kanban') { |          if (w_response){ | ||||
|                 return One2ManyKanbanRenderer; |              let unselected = this.list.records.filter((rec) => !rec.selected) | ||||
|             } |             if (this.activeActions.onDelete) { | ||||
|             if (this.view.arch.tag === 'tree') { |                 unselected.forEach((rec) => { | ||||
|                 return ListRenderer.extend({ |                         this.activeActions.onDelete(rec); | ||||
|                     init: function (parent, state, params) { |                 }) | ||||
|                         this._super.apply(this, arguments); |  | ||||
|                         this.hasSelectors = true; |  | ||||
|                     }, |  | ||||
|                 }); |  | ||||
|             } |             } | ||||
|             return this._super.apply(this, arguments); |  | ||||
|         }, |  | ||||
| 		find_deleted_lines: function () { |  | ||||
|             var self=this; |  | ||||
|             var selected_list =[]; |  | ||||
|             this.$el.find('td.o_list_record_selector input:checked') |  | ||||
|                     .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 =[]; |  | ||||
| 	       this.$el.find('td.o_list_record_selector input:checked') |  | ||||
| 	               .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 () { |  | ||||
| 				   selected_list1.push(parseInt(self._getResId($(this).data('id')))); |  | ||||
| 			   }); |  | ||||
| 			   selected_list2 = selected_list1.filter(function (x) { |  | ||||
| 				   return selected_list.indexOf(x) < 0 |  | ||||
| 			   }); |  | ||||
|         } |         } | ||||
| 		   return selected_list2; |  | ||||
| 	   }, |  | ||||
|     _getResId: function (recordId) { |  | ||||
|        var record; |  | ||||
|        utils.traverse_records(this.recordData[this.name], function (r) { |  | ||||
|        if (r.id === recordId) { |  | ||||
|             record = r; |  | ||||
|     } |     } | ||||
|         }); | } | ||||
|             return record.res_id; | TestX2ManyField.components = { | ||||
|         }, |     ...X2ManyField.components, ListRenderer: TestListRenderer | ||||
|  | }; | ||||
|  | TestX2ManyField.template = "one2many_mass_select_delete.One2manyDelete"; | ||||
|  | 
 | ||||
| 
 | 
 | ||||
| 	}); | registry.category("fields").add("one2many_delete", TestX2ManyField); | ||||
| 	fieldRegistry.add('one2many_delete', One2manyDelete); |  | ||||
| }); |  | ||||
|  | |||||
| @ -1,20 +1,19 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> |  | ||||
| <templates id="template" xml:space="preserve"> | <templates id="template" xml:space="preserve"> | ||||
| 	<t t-name="One2manyDelete"> | <t t-name="one2many_mass_select_delete.One2manyDelete" t-inherit="web.X2ManyField" t-inherit-mode="primary" owl="1"> | ||||
|  |     <xpath expr="//div[hasclass('o_x2m_control_panel')]" position="before"> | ||||
|         <div> |         <div> | ||||
| 			<button t-if="!widget.get('effective_readonly')" style="margin-bottom: 1%;display:none;" |         <button t-if="hasSelected" class="btn btn-danger" t-on-click="deleteSelected"> | ||||
|                     class="button_delete_order_lines" |  | ||||
|                     href="javascript:void(0)"> |  | ||||
|             <span class="fa fa-trash"/> |             <span class="fa fa-trash"/> | ||||
|         </button> |         </button> | ||||
|             <button t-if="!widget.get('effective_readonly')" style="margin-bottom: 1%;display:none;" |         <button t-if="hasSelected" class="btn btn-success" t-on-click="deleteUnselected"> | ||||
|                     class="button_select_order_lines" |  | ||||
|                     href="javascript:void(0)"> |  | ||||
|              <span class="fa fa-check"/> |              <span class="fa fa-check"/> | ||||
|         </button> |         </button> | ||||
|             <t t-if="widget.get('effective_readonly')"> |             <t t-if="props.readonly"> | ||||
| 				<span class="oe_form_char_content"></span> |          <span class="oe_form_char_content"/> | ||||
|         </t> |         </t> | ||||
|     </div> |     </div> | ||||
|     </t> |     </xpath> | ||||
|  | </t> | ||||
| </templates> | </templates> | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | |||||
					Loading…
					
					
				
		Reference in new issue