Overview
Comment:Improve/fix checking of all checkboxes in a table
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 75e626819a6fc98019479097bbeb49a9375622bc
User & Date: bohwaz on 2020-11-18 13:51:47
Other Links: branch diff | manifest | tags
Context
2020-11-18
19:56
Try to magically match columns with the same header label in CSV import check-in: 7ee830853d user: bohwaz tags: dev
13:51
Improve/fix checking of all checkboxes in a table check-in: 75e626819a user: bohwaz tags: dev
13:08
Fix checkbox sending back to top of the page check-in: 33290306f7 user: bohwaz tags: dev
Changes

Modified src/www/admin/static/scripts/global.js from [30f1b3874f] to [2ad4a5110b].

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162



163
164
165
166
167
168
169
	}

	// From KD2fw/js/xhr.js
	g.load = function(b,d,f,e){var a=new XMLHttpRequest();if(!a||!b)return false;if(a.overrideMimeType)a.overrideMimeType('text/xml');b+=(b.indexOf('?')+1?'&':'?')+(+(new Date));a.onreadystatechange=function(){if(a.readyState!=4)return;if((s=a.status)==200){if(!d)return true;var c=a.responseText;if(f=='json'){return((j=window.JSON)&&j.parse)?j.parse(c):eval('('+c.replace(/[\n\r]/g,'')+')')}d(c)}else if(e){e(s)}};a.open('GET',b,true);a.send(null)};

	g.checkUncheck = function()
	{
		var elements = this.form.querySelectorAll('tbody input[type=checkbox]');
		var el_length = elements.length;
		var checked = this.checked;

		for (var i = 0; i < el_length; i++)
		{
			var elm = elements[i];
			elm.checked = checked;
			elm.dispatchEvent(new Event("change"));

		}




		return true;
	};

	g.togglePasswordVisibility = (field, repeat, show) => {
		if (typeof show == 'undefined') {
			show = field.type.toLowerCase() == 'password';







<
<

|
<
<
<


>
|
>
>
>







146
147
148
149
150
151
152


153
154



155
156
157
158
159
160
161
162
163
164
165
166
167
168
	}

	// From KD2fw/js/xhr.js
	g.load = function(b,d,f,e){var a=new XMLHttpRequest();if(!a||!b)return false;if(a.overrideMimeType)a.overrideMimeType('text/xml');b+=(b.indexOf('?')+1?'&':'?')+(+(new Date));a.onreadystatechange=function(){if(a.readyState!=4)return;if((s=a.status)==200){if(!d)return true;var c=a.responseText;if(f=='json'){return((j=window.JSON)&&j.parse)?j.parse(c):eval('('+c.replace(/[\n\r]/g,'')+')')}d(c)}else if(e){e(s)}};a.open('GET',b,true);a.send(null)};

	g.checkUncheck = function()
	{


		var checked = this.checked;
		this.form.querySelectorAll('tbody input[type=checkbox]').forEach((elm) => {



			elm.checked = checked;
			elm.dispatchEvent(new Event("change"));
		});

		this.form.querySelectorAll('thead input[type=checkbox], tfoot input[type=checkbox]').forEach((elm) => {
			elm.checked = checked;
		});

		return true;
	};

	g.togglePasswordVisibility = (field, repeat, show) => {
		if (typeof show == 'undefined') {
			show = field.type.toLowerCase() == 'password';
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
				}

				this.form.submit();
			};
		}

		// Ajouter action check/uncheck sur les checkbox de raccourci dans les tableaux
		var checkTables = document.querySelectorAll('table thead input[type=checkbox], table tfoot input[type=checkbox]');
		var l = checkTables.length;

		for (var i = 0; i < l; i++)
		{
			var masterCheck = checkTables[i];
			masterCheck.onchange = g.checkUncheck;

			var parent = masterCheck.parentNode;

			while (parent.nodeType != Node.ELEMENT_NODE || parent.tagName != 'TABLE')
			{
				parent = parent.parentNode;
			}

			var checkBoxes = parent.querySelectorAll('tbody tr input[type=checkbox]');
			var ll = checkBoxes.length;

			for (var j = 0; j < ll; j++)
			{
				checkBoxes[j].onchange = function (e) {
					let elm = e.target;
					var checked = elm.checked ? true : false;

					var parent = elm.parentNode;

					while (parent.nodeType != Node.ELEMENT_NODE || parent.tagName != 'TR')
					{
						parent = parent.parentNode;
					}

					if (checked)
						parent.className = parent.className.replace(/ checked$|$/, ' checked');
					else
						parent.className = parent.className.replace(/ checked/, '');
				};

				if (checkBoxes[j].checked)
				{
					checkBoxes[j].checkUncheck(checkBoxes[j]);
					elm.dispatchEvent(new Event("change"));
				}
			}
		}
	});
})();







|
<
<
<
<
<
|
<
<
<
<
<
<
|

<
<
|
<
<
<
<
<
|
<
|
<
<
<
|
<
<
<
<
<
|
<
<
<
<
<
|
|
<
<

325
326
327
328
329
330
331
332





333






334
335


336





337

338



339





340





341
342


343
				}

				this.form.submit();
			};
		}

		// Ajouter action check/uncheck sur les checkbox de raccourci dans les tableaux
		document.querySelectorAll('table thead input[type=checkbox], table tfoot input[type=checkbox]').forEach((elm) => {





			elm.addEventListener('change', g.checkUncheck);






		});



		document.querySelectorAll('table tbody input[type=checkbox]').forEach((elm) => {





			elm.addEventListener('change', () => {

				elm.parentNode.parentNode.classList.toggle('checked', elm.checked);



			});





		});





	});



})();