[10.0][ADD] Module web_listview_invert_selection (#538)

* [10.0][ADD] Module web_listview_invert_selection

* [FIX] Multiple code reviews

* [FIX] Changed single-quotes to double-quotes for improving codacy tests;
This commit is contained in:
Antonio Esposito
2017-07-25 18:03:35 +02:00
committed by Dave Lasley
parent 21f50a61f1
commit 2b33af50de
9 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
/* Copyright 2017 Onestein
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_listview_invert_selection", function (require) {
"use strict";
var ListView = require("web.ListView");
ListView.include(/** @lends instance.web.ListView# */{
load_list: function (data, grouped) {
var self = this;
var result = this._super.apply(this, arguments);
this.$("span.o_invert_selection").click(function () {
var checked = self.$("tbody .o_list_record_selector input:checked");
var unchecked = self.$("tbody .o_list_record_selector input:not(:checked)");
checked.prop("checked", false);
unchecked.prop("checked", true);
var selected = [];
checked.each(function () {
selected.push($(this).attr("name"));
});
if (selected.length === 0) {
self.$("thead .o_list_record_selector input").prop("checked", true);
} else {
self.$("thead .o_list_record_selector input").prop("checked", false);
}
});
return result;
}
});
});

View File

@@ -0,0 +1,5 @@
.o_list_view {
.o_invert_selection {
padding-left: 2px;
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="ListView">
<t t-jquery="th.o_list_record_selector" t-operation="prepend">
<div>
<span class="o_invert_selection" title="Invert Selection"><i class="fa fa-refresh" aria-hidden="true"></i></span>
</div>
</t>
</t>
</templates>