Project

General

Profile

« Previous | Next » 

Revision 65a0e193

Added by Stephen Beaver almost 10 years ago

Completed #5356
Refactor row toggle javascript

View differences:

src/usr/local/www/firewall_nat.php
352 352
							<?=htmlspecialchars($natent['descr'])?>
353 353
						</td>
354 354
						<td>
355
							<a class="btn btn-xs btn-info"	title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"><?=gettext("Edit"); ?></a>
356
							<a class="btn btn-xs btn-danger"  title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>"><?=gettext("Del")?></a>
357
							<a class="btn btn-xs btn-success"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"><?=gettext("Clone")?></a>
355
							<a class="fa fa-pencil" title="<?=gettext("Edit rule"); ?>" href="firewall_nat_edit.php?id=<?=$i?>"></a>
356
							<a class="fa fa-clone"	  title="<?=gettext("Add a new NAT based on this one")?>" href="firewall_nat_edit.php?dup=<?=$i?>"></a>
357
							<a class="fa fa-trash"	title="<?=gettext("Delete rule")?>" href="firewall_nat.php?act=del&amp;id=<?=$i?>" onclick="return confirm('<?=gettext("Are you sure you want to delete this rule?")?>')"></a>
358 358
						</td>
359 359
					</tr>
360 360
<?php
......
375 375
</form>
376 376

  
377 377
<script>
378
function fr_toggle(id, prefix) {
379
	if (!prefix)
380
		prefix = 'fr';
381

  
382
	var checkbox = document.getElementById(prefix + 'c' + id);
383
	checkbox.checked = !checkbox.checked;
384
	fr_bgcolor(id, prefix);
385
}
386

  
387
function fr_bgcolor(id, prefix) {
388
	if (!prefix)
389
		prefix = 'fr';
390

  
391
	var row = document.getElementById(prefix + id);
392
	var checkbox = document.getElementById(prefix + 'c' + id);
393
	var cells = row.getElementsByTagName('td');
394
	var cellcnt = cells.length;
378
events.push(function() {
395 379

  
396
	for (i = 0; i < cellcnt-1; i++) {
397
		cells[i].style.backgroundColor = checkbox.checked ? "#DDF4FF" : "#FFFFFF";
398
	}
399
}
400
</script>
380
	stripe_table();
401 381

  
402
<script>
403
events.push(function() {
404
	// Make rules draggable/sortable
382
	// Make rules sortable
405 383
	$('table tbody.user-entries').sortable({
406 384
		cursor: 'grabbing',
407 385
		update: function(event, ui) {
408 386
			$('#order-store').removeAttr('disabled');
387
			stripe_table();
409 388
		}
410 389
	});
411 390

  
src/usr/local/www/firewall_nat_1to1.php
245 245
						</td>
246 246

  
247 247
						<td>
248
							<a class="btn btn-xs btn-info"		  title="<?=gettext("Edit rule")?>" href="firewall_nat_1to1.php?id=<?=$i?>"><?=gettext("Edit")?></a>
249
							<a class="btn btn-xs btn-danger"  title="<?=gettext("Delete rule")?>" href="firewall_nat_1to1.php?act=del&amp;id=<?=$i?>"><?=gettext("Del")?></a>
250
							<a class="btn btn-xs btn-success"	  title="<?=gettext("Add a new rule based on this one")?>" href="firewall_nat_1to1_edit.php?dup=<?=$i?>"><?=gettext("Clone")?></a>
248
							<a class="fa fa-pencil" title="<?=gettext("Edit rule")?>" href="firewall_nat_1to1.php?id=<?=$i?>"></a>
249
							<a class="fa fa-clone" title="<?=gettext("Add a new rule based on this one")?>" href="firewall_nat_1to1_edit.php?dup=<?=$i?>"></a>
250
							<a class="fa fa-trash" title="<?=gettext("Delete rule")?>" href="firewall_nat_1to1.php?act=del&amp;id=<?=$i?>" onclick="return confirm('<?=gettext("Are you sure you want to delete this rule?")?>')"></a>
251 251
						</td>
252 252

  
253 253
					</tr>
......
280 280
</div>
281 281

  
282 282
<script>
283
function fr_toggle(id, prefix) {
284
	if (!prefix)
285
		prefix = 'fr';
286

  
287
	var checkbox = document.getElementById(prefix + 'c' + id);
288
	checkbox.checked = !checkbox.checked;
289
	fr_bgcolor(id, prefix);
290
}
291

  
292
function fr_bgcolor(id, prefix) {
293
	if (!prefix)
294
		prefix = 'fr';
295

  
296
	var row = document.getElementById(prefix + id);
297
	var checkbox = document.getElementById(prefix + 'c' + id);
298
	var cells = row.getElementsByTagName('td');
299
	var cellcnt = cells.length;
283
events.push(function() {
300 284

  
301
	for (i = 0; i < cellcnt-1; i++) {
302
		cells[i].style.backgroundColor = checkbox.checked ? "#DDF4FF" : "#FFFFFF";
303
	}
304
}
305
</script>
285
	stripe_table();
306 286

  
307
<script>
308
events.push(function() {
309
	// Make rules draggable/sortable
287
	// Make rules sortable
310 288
	$('table tbody.user-entries').sortable({
311 289
		cursor: 'grabbing',
312 290
		update: function(event, ui) {
313 291
			$('#order-store').removeAttr('disabled');
292
			stripe_table();
314 293
		}
315 294
	});
316 295

  
src/usr/local/www/firewall_nat_out.php
304 304
	<div class="panel panel-default">
305 305
		<div class="panel-heading"><?=gettext('Mappings')?></div>
306 306
		<div class="panel-body table-responsive">
307
			<table class="table table-striped table-hover table-condensed">
307
			<table class="table table-hover table-condensed">
308 308
				<thead>
309 309
					<tr>
310 310
						<th><!-- checkbox	  --></th>
......
499 499

  
500 500
						<!-- Action	 icons -->
501 501
						<td>
502
							<a class="icon icon-pencil"	 title="<?=gettext("Edit mapping")?>" href="firewall_nat_out_edit.php?id=<?=$i?>"></a>
503
							<a class="icon icon-ban-circle"	 title="<?=gettext("Delete mapping")?>" href="firewall_nat_out.php?act=del&amp;id=<?=$i?>"
502
							<a class="fa fa-pencil"	 title="<?=gettext("Edit mapping")?>" href="firewall_nat_out_edit.php?id=<?=$i?>"></a>
503
							<a class="fa fa-clone" title="<?=gettext("Add a new mapping based on this one")?>" href="firewall_nat_out_edit.php?dup=<?=$i?>"></a>
504
							<a class="fa fa-trash"	 title="<?=gettext("Delete mapping")?>" href="firewall_nat_out.php?act=del&amp;id=<?=$i?>"
504 505
							onclick="return confirm('<?=gettext("Are you sure you want to delete this mapping?")?>')"></a>
505
							<a class="icon icon-plus" title="<?=gettext("Add a new mapping based on this one")?>" href="firewall_nat_out_edit.php?dup=<?=$i?>"></a>
506 506
						</td>
507 507
<?php
508 508
				$i++;
......
534 534
	<div class="panel panel-default">
535 535
		<div class="panel-heading"><?=gettext("Automatic rules:")?></div>
536 536
		<div class="panel-body table-responsive">
537
			<table class="table table-striped table-hover table-condensed">
537
			<table class="table table-hover table-condensed">
538 538
				<thead>
539 539
					<tr>
540 540
						<th><!-- status	  --></th>
......
651 651
?>
652 652
</div>
653 653

  
654
<script>
655
function fr_toggle(id, prefix) {
656
	if (!prefix)
657
		prefix = 'fr';
658

  
659
	var checkbox = document.getElementById(prefix + 'c' + id);
660
	checkbox.checked = !checkbox.checked;
661
	fr_bgcolor(id, prefix);
662
}
663

  
664
function fr_bgcolor(id, prefix) {
665
	if (!prefix)
666
		prefix = 'fr';
667

  
668
	var row = document.getElementById(prefix + id);
669
	var checkbox = document.getElementById(prefix + 'c' + id);
670
	var cells = row.getElementsByTagName('td');
671
	var cellcnt = cells.length;
672

  
673
	for (i = 0; i < cellcnt; i++) {
674
		cells[i].style.backgroundColor = checkbox.checked ? "#DDF4FF" : "#FFFFFF";
675
	}
676
}
677
</script>
678

  
679 654
<script>
680 655
events.push(function() {
681
	// Make rules draggable/sortable
656
	stripe_table();
657

  
658
	// Make rules sortable
682 659
	$('table tbody.user-entries').sortable({
683 660
		cursor: 'grabbing',
684 661
		update: function(event, ui) {
685 662
			$('#order-store').removeAttr('disabled');
663
			stripe_table();
686 664
		}
687 665
	});
688 666

  
src/usr/local/www/firewall_rules.php
688 688

  
689 689
?>
690 690

  
691
<script>
692
function stripe_table() {
693
	$("tr:odd").addClass('active');
694
	$("tr:even").removeClass('active');
695
}
696

  
697
function fr_toggle(id, prefix) {
698
	if (!prefix)
699
		prefix = 'fr';
700

  
701
	var checkbox = document.getElementById(prefix + 'c' + id);
702
	checkbox.checked = !checkbox.checked;
703
	fr_bgcolor(id, prefix);
704
}
705

  
706
// Change background color based on state of checkbox
707
// On resetting background, reapply table striping
708
function fr_bgcolor(id, prefix) {
709
	if (!prefix)
710
		prefix = 'fr';
711

  
712
	var row = $('#' + prefix + id);
713

  
714
	if ($('#' + prefix + 'c' + id).prop('checked') ) {
715
		row.css("background-color", "#DDF4FF");
716
		row.removeClass('active');
717
	} else {
718
		row.css("background-color", "#FFFFFF");
719
		stripe_table();
720
	}
721
}
722

  
723
</script>
724

  
725 691
<script>
726 692

  
727 693
events.push(function() {
......
741 707
	$('#order-store').click(function () {
742 708
	   $('[id^=frc]').prop('checked', true);
743 709
	});
744

  
745
	// Replace direct delete with quicker front-end action
746
/*FIXME: event ordering
747
	$('.btn-danger').on('click', function(e){
748
		$(this).parents('tr').remove();
749

  
750
		$('#order-store').removeAttr('disabled');
751
	});
752
*/});
710
});
753 711
</script>
754 712
<?php include("foot.inc");?>
src/usr/local/www/guiconfig.inc
609 609
	return;
610 610
}
611 611

  
612
// This version of dump_clog() does not output <td></td> or any other table elements. It can be renamed
613
// and the dump_clog() removed once all of the diag_log*.php files have been converted to Bootstrap
612
// This version of dump_clog() does not output <td></td> or any other table elements.
614 613
function dump_clog_no_table($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
615 614
	global $g, $config;
616 615
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
src/usr/local/www/jquery/pfSenseHelpers.js
138 138
		element.parent('div').removeClass('hidden');
139 139
}
140 140

  
141
// Toggle table row chackboxes and background colors on the pages that use sortable tables:
142
//	/usr/local/www/firewall_nat.php
143
//	/usr/local/www/firewall_nat_1to1.php
144
//	/usr/local/www/firewall_nat_out.php
145
//	/usr/local/www/firewall_rules.php
146
//	/usr/local/www/vpn_ipsec.php
147
// Striping of the tables is handled here, NOT with hte Bootstrap table-striped class because it would
148
// get confused when rows are sorted or deleted.
149

  
150
function stripe_table() {
151
	$("tr:odd").addClass('active');
152
	$("tr:even").removeClass('active');
153
}
154

  
155
function fr_toggle(id, prefix) {
156
	if (!prefix)
157
		prefix = 'fr';
158

  
159
	var checkbox = document.getElementById(prefix + 'c' + id);
160
	checkbox.checked = !checkbox.checked;
161
	fr_bgcolor(id, prefix);
162
}
163

  
164
// Change background color based on state of checkbox
165
// On resetting background, reapply table striping
166
function fr_bgcolor(id, prefix) {
167
	if (!prefix)
168
		prefix = 'fr';
169

  
170
	var row = $('#' + prefix + id);
171

  
172
	if ($('#' + prefix + 'c' + id).prop('checked') ) {
173
		row.css("background-color", "#DDF4FF");
174
		row.removeClass('active');
175
	} else {
176
		row.css("background-color", "#FFFFFF");
177
		stripe_table();
178
	}
179
}
180

  
141 181
// The following functions are used by Form_Groups assigned a class of "repeatable" and provide the ability
142 182
// to add/delete rows of sequentially numbered elements, their labels and their help text
143 183
// See firewall_aliases_edit.php for an example

Also available in: Unified diff