noalyss Version-9
noalyss_checkbox.js
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Dany De Bontridder <dany@alchimerys.be>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18/**
19 *
20 * @param {event} evt event
21 * @param {object} elt checkbox elt
22 * @param {string} p_name name of the checkbox object
23
24 * @returns {undefined}
25 */
26
27var lastcheck = null;
28var endcheck = null;
29
30/**
31 * Check or uncheck checkbox if shift key is pressed and between the last checked elemet and the current one
32 * @param {type} evt event
33 * @param {type} elt Dom element
34 * @param {type} p_name name of range
35 */
36function checkbox_set_range(evt, elt, p_name) {
37 if (!evt.shiftKey) {
38 lastcheck = elt;
39 return;
40 }
41 var aName = document.getElementsByClassName(p_name);
42
43 var from = 0;
44 var end = 0;
45 for (var i = 0; i < aName.length; i++) {
46 if (aName[i] == elt) {
47 endcheck = aName[i];
48 from = i;
49 }
50 if (aName[i] == lastcheck) {
51 end = i;
52 }
53 }
54 if (from > end) {
55 let a = from;
56 from = end;
57 end = a;
58 }
59 var check = (aName[from].checked) ? true : false;
60 for (x = from; x <= end; x++) {
61 if (aName[x].parentNode.parentNode )
62 {
63 if ( window.getComputedStyle(aName[x].parentNode.parentNode).display != "none" ) {
64 /* console.debug(window.getComputedStyle(aName[x].parentNode.parentNode).display);*/
65 aName[x].checked = check;
66 }
67 } else {
68 aName[x].checked = check;
69 }
70 }
71}
72
73
74/**
75 * For each checkbox , add an event on click
76 * @param {string} p_range_name name of the checkbox object
77 * @returns {undefined}
78 */
79function activate_checkbox_range(p_range_name) {
80 let node_lstCheckBox = document.getElementsByClassName(p_range_name);
81 var aCheckBox=Array.from(node_lstCheckBox)
82 if (aCheckBox == undefined) {
83 console.error("activate_checkbox_range_failed")
84 }
85
86 aCheckBox.forEach(elt => elt.addEventListener ('click',function (event) {
87 checkbox_set_range(event, elt, p_range_name);
88 },false));
89}
90
91/**
92 * Checkbox for Debit - Credit , from Misc Operation
93 */
94function activate_checkbox_side()
95{
96 var aCheckBox=$$('.debit-credit')
97 aCheckBox.forEach((item)=>item.addEventListener('click',function (event) {
98 display_range_dcside(event,item);
99 display_dcside(item);
100 }
101 ));
102 aCheckBox.forEach((item)=>display_dcside(item))
103}
104
105/**
106 * Update the range of checkbox in Misc Operation
107 * @see Acc_Ledger::input
108 * @param item checkbox to change
109 * @param event event
110 */
111function display_range_dcside(evt,item)
112{
113 if (!evt.shiftKey) {
114 lastcheck = item;
115 return;
116 }
117 var p_name='debit-credit'
118 var aName = document.getElementsByClassName(p_name);
119
120 var from = 0;
121 var end = 0;
122 for (var i = 0; i < aName.length; i++) {
123 if (aName[i] == item) {
124 endcheck = aName[i];
125 from = i;
126 }
127 if (aName[i] == lastcheck) {
128 end = i;
129 }
130 }
131 if (from > end) {
132 let a = from;
133 from = end;
134 end = a;
135 }
136 var check = (aName[from].checked) ? true : false;
137 for (x = from; x <= end; x++) {
138 aName[x].checked = check;
139 display_dcside(aName[x]);
140 }
141 checkTotalDirect()
142}
143
144/**
145 * Update the SPAN for the range , id based on checkbox id (txtck0), if checked , display Debit otherwise Credit
146 * @param item
147 */
148function display_dcside(item)
149{
150 if (item.checked == true) {
151 $('txt'+item.id).update("Débit")
152 } else {
153 $('txt'+item.id).update("Crédit")
154 }
155}