noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 aName[x].checked = check;
65 }
66 } else {
67 aName[x].checked = check;
68 }
69 }
70}
71
72
73/**
74 * For each checkbox , add an event on click
75 * @param {string} p_range_name name of the checkbox object
76 * @returns {undefined}
77 */
78function activate_checkbox_range(p_range_name) {
79 let node_lstCheckBox = document.getElementsByClassName(p_range_name);
80 var aCheckBox=Array.from(node_lstCheckBox)
81 if (aCheckBox == undefined) {
82 console.error("activate_checkbox_range_failed")
83 }
84
85 aCheckBox.forEach(elt => elt.addEventListener ('click',function (event) {
86 checkbox_set_range(event, elt, p_range_name);
87 },false));
88}
89
90/**
91 * Checkbox for Debit - Credit , from Misc Operation
92 */
93function activate_checkbox_side()
94{
95 var aCheckBox=$$('.debit-credit')
96 aCheckBox.forEach((item)=>item.addEventListener('click',function (event) {
97 display_range_dcside(event,item);
98 display_dcside(item);
99 }
100 ));
101 aCheckBox.forEach((item)=>display_dcside(item))
102}
103
104/**
105 * Update the range of checkbox in Misc Operation
106 * @see Acc_Ledger::input
107 * @param item checkbox to change
108 * @param event event
109 */
110function display_range_dcside(evt,item)
111{
112 if (!evt.shiftKey) {
113 lastcheck = item;
114 return;
115 }
116 var p_name='debit-credit'
117 var aName = document.getElementsByClassName(p_name);
118
119 var from = 0;
120 var end = 0;
121 for (var i = 0; i < aName.length; i++) {
122 if (aName[i] == item) {
123 endcheck = aName[i];
124 from = i;
125 }
126 if (aName[i] == lastcheck) {
127 end = i;
128 }
129 }
130 if (from > end) {
131 let a = from;
132 from = end;
133 end = a;
134 }
135 var check = (aName[from].checked) ? true : false;
136 for (x = from; x <= end; x++) {
137 aName[x].checked = check;
138 display_dcside(aName[x]);
139 }
140 checkTotalDirect()
141}
142
143/**
144 * Update the SPAN for the range , id based on checkbox id (txtck0), if checked , display Debit otherwise Credit
145 * @param item
146 */
147function display_dcside(item)
148{
149 if (item.checked == true) {
150 $('txt'+item.id).update("Débit")
151 } else {
152 $('txt'+item.id).update("Crédit")
153 }
154}