Improve Javascript (allow toggling of deletion and highlight "Save and Update" button on deletion) and :codacy:

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2017-10-21 12:08:00 +02:00
parent b70e43f8ba
commit a1d96e4e63
2 changed files with 13 additions and 13 deletions

View File

@@ -152,21 +152,21 @@ $(document).ready(function(){
// Handle list deletion // Handle list deletion
$("button[id^='adlist-btn-']").on("click", function (e) { $("button[id^='adlist-btn-']").on("click", function (e) {
var idstring = $(this).context.id; var id = parseInt($(this).context.id.replace(/[^0-9\.]/g, ""), 10);
var id = parseInt(idstring.replace(/[^0-9\.]/g, ''), 10);
e.preventDefault(); e.preventDefault();
var status = $("input[id='adlist-del-"+id+"']").is(":checked"); var status = $("input[name=\"adlist-del-"+id+"\"]").is(":checked");
var textType = status ? "none" : "line-through"; var textType = status ? "none" : "line-through";
console.log("idstring: "+idstring);
console.log("id: "+id);
console.log("status: "+status);
console.log("textType: "+textType);
$("input[name='adlist-del-"+id+"']").prop("checked", !status); // Check hidden delete box (or reset)
$("input[name='adlist-enable-"+id+"']").prop("disabled", !status); $("input[name=\"adlist-del-"+id+"\"]").prop("checked", !status);
$("button[id='adlist-btn-"+id+"']").prop("disabled", true); // Untick and disable check box (or reset)
$("a[id='adlist-text-"+id+"']").css("text-decoration", textType); $("input[name=\"adlist-enable-"+id+"\"]").prop("checked", status).prop("disabled", !status);
// Strink through text (or reset)
$("a[id=\"adlist-text-"+id+"\"]").css("text-decoration", textType);
// Highlight that the button has to be clicked in order to make the change live
$("button[id=\"blockinglistsaveupdate\"]").addClass("btn-danger").css("font-weight", "bold");
}); });
// Javascript to go to specified tab on save or hyperlink // Javascript to go to specified tab on save or hyperlink

View File

@@ -296,9 +296,9 @@ if (isset($setupVars["API_PRIVACY_MODE"])) {
</div> </div>
<input type="hidden" name="field" value="adlists"> <input type="hidden" name="field" value="adlists">
<input type="hidden" name="token" value="<?php echo $token ?>"> <input type="hidden" name="token" value="<?php echo $token ?>">
<button type="submit" class="btn btn-primary" name="submit" value="save">Save <button type="submit" class="btn btn-primary" name="submit" value="save" id="blockinglistsave">Save
</button> </button>
<button type="submit" class="btn btn-primary pull-right" name="submit" <button type="submit" class="btn btn-primary pull-right" name="submit" id="blockinglistsaveupdate"
value="saveupdate"> value="saveupdate">
Save and Update Save and Update
</button> </button>