Skip to content

Commit

Permalink
Move forwarding-js-code from inline to external script-file
Browse files Browse the repository at this point in the history
  • Loading branch information
Udera committed Apr 15, 2017
1 parent 92a9e7a commit 94a4580
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
23 changes: 3 additions & 20 deletions vexim/adminuserchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,8 @@
<title><?php echo _('Virtual Exim') . ': ' . _('Manage Users'); ?></title>
<link rel="stylesheet" href="style.css" type="text/css">
<script src="scripts.js" type="text/javascript"></script>
<script type='text/javascript'>
function fwac() {
document.getElementById('forward').disabled = !document.getElementById('on_forward').checked;
document.getElementById('forwardmenu').disabled = !document.getElementById('on_forward').checked;
}
function boxadd() {
var exstring = document.getElementById('forward').value;
var box = document.getElementById('forwardmenu');
var selectitem = box.options[box.selectedIndex].value;
if (!exstring.match(/\S/)) {
document.getElementById('forward').value=selectitem;
} else {
document.getElementById('forward').value += "," + selectitem;
}
}

</script>
</head>
<body onLoad="fwac()">
<body>
<?php include dirname(__FILE__) . '/config/header.php'; ?>
<div id="Menu">
<a href="adminuser.php"><?php echo _('Manage Accounts'); ?></a><br>
Expand Down Expand Up @@ -279,7 +262,7 @@ function boxadd() {
<td><input name="on_forward" id="on_forward" type="checkbox" <?php
if ($row['on_forward'] == "1") {
print " checked";
} ?> onchange="fwac()" onclick="fwac()">
} ?>>
</td>
</tr>
<tr>
Expand All @@ -289,7 +272,7 @@ function boxadd() {
value="<?php print $row['forward']; ?>" class="textfield"><br>
<?php echo _('Enter full e-mail addresses, use commas to separate them'); ?>!<br>
<?php echo _('or select from this list') .":<br>\n"; ?>
<select name="forwardmenu" id="forwardmenu" onchange="boxadd()">
<select name="forwardmenu" id="forwardmenu">
<option selected value=""></option>
<?php
$queryuserlist = "SELECT realname, username, user_id, unseen
Expand Down
49 changes: 46 additions & 3 deletions vexim/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,52 @@ function copyPassword(sourceFieldName, target1FieldName, target2FieldName) {


/**
* Add event listener for buttons on the password generator form
* Enables forward-destination field and selection box only if forwarding is enabled
*/
function fwform() {
document.getElementById('forward').disabled = !document.getElementById('on_forward').checked;
if (document.getElementById('forwardmenu') != null) { //userchange.php has no box
document.getElementById('forwardmenu').disabled = !document.getElementById('on_forward').checked;
}
return true;
}


/**
* If item on forwarding destination is selected from a list of destinations
* the forwarding text box is updated
*/
function boxadd() {
var exstring = document.getElementById('forward').value;
var box = document.getElementById('forwardmenu');
var selectitem = box.options[box.selectedIndex].value;
if (!exstring.match(/\S/)) {
document.getElementById('forward').value=selectitem;
} else {
document.getElementById('forward').value += "," + selectitem;
}
}


/**
* Add event listener
*/
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('pwcopy').addEventListener('click', function() { copyPassword('suggest', 'clear', 'vclear')});
document.getElementById('pwgenerate').addEventListener('click', function() { suggestPassword('suggest')});
if (document.getElementById('pwcopy') != null) {
document.getElementById('pwcopy').addEventListener('click', function() { copyPassword('suggest', 'clear', 'vclear')});
}
if (document.getElementById('pwgenerate') != null) {
document.getElementById('pwgenerate').addEventListener('click', function() { suggestPassword('suggest') });
}
if (document.getElementById('on_forward') != null) {
document.getElementById('on_forward').addEventListener('change', function() { fwform() });
}
if (document.getElementById('forwardmenu') != null) {
document.getElementById('forwardmenu').addEventListener('change', function() { boxadd() });
}

// settings at page load
if (document.getElementById('forward') != null) {
fwform();
}
});
10 changes: 3 additions & 7 deletions vexim/userchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
<head>
<title><?php echo _("Virtual Exim") . ": " . _("Manage Users"); ?></title>
<link rel="stylesheet" href="style.css" type="text/css">
<script type='text/javascript'>
function fwac() {
document.getElementById('forward').disabled = !document.getElementById('on_forward').checked;
}
</script>
<script src="scripts.js" type="text/javascript"></script>
</head>
<body onLoad="fwac()">
<body>
<?php include dirname(__FILE__) . "/config/header.php"; ?>
<div id="Menu">
<a href="logout.php"><?php echo _("Logout"); ?></a><br>
Expand Down Expand Up @@ -131,7 +127,7 @@ function fwac() {
</tr>
<tr><td><?php echo _("Forwarding enabled"); ?>:</td>
<td><input name="on_forward" type="checkbox" id="on_forward"
<?php if($row['on_forward'] == "1") { print " checked "; } ?> onchange="fwac()" onclick="fwac()">
<?php if($row['on_forward'] == "1") { print " checked "; } ?>>
</td></tr>
<tr><td><?php echo _("Forward mail to");?>:</td>
<td><input type="text" name="forward" id="forward" value="<?php print $row['forward']; ?>" class="textfield"><br>
Expand Down

0 comments on commit 94a4580

Please sign in to comment.