Skip to content

Commit

Permalink
Avoid inline scripting for onclick handler (sympa-community#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed Apr 21, 2023
1 parent 163294e commit d8c48af
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
8 changes: 6 additions & 2 deletions default/web_tt2/compose_mail.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<input type="hidden" name="html_news_letter" value="[% subaction %]" />
[% END %]
<input type="hidden" name="action" value="send_mail"/>
<input class="MainMenuLinks" type="submit" name="sub_action_sendmailtolist" value="[%|loc%]Send to list[%END%]" [%- IF topic_required -%] onclick="return checkbox_check_topic(compose_mail)" [% END %]/>
<input class="MainMenuLinks" type="submit" name="sub_action_sendmailtome" value="[%|loc%]Send to me[%END%]" [%- IF topic_required -%] onclick="return checkbox_check_topic(compose_mail)" [% END %]/>
<input class="MainMenuLinks[%IF topic_required%] topicChecked[%END%]"
type="submit"
name="sub_action_sendmailtolist" value="[%|loc%]Send to list[%END%]" />
<input class="MainMenuLinks[%IF topic_required%] topicChecked[%END%]"
type="submit"
name="sub_action_sendmailtome" value="[%|loc%]Send to me[%END%]" />
<br />

<input type="hidden" name="in_reply_to" value="[% in_reply_to %]" />
Expand Down
5 changes: 3 additions & 2 deletions default/web_tt2/request_topic.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
[% END %]
<br />
[%- IF topic_required -%]
<input class="MainMenuLinks" type="submit" name="action_tag_topic_by_sender" value="[%|loc%]Tag this mail[%END%]"
onclick="return checkbox_check_topic(select_topic_msg)" />
<input class="MainMenuLinks topicChecked" type="submit"
name="action_tag_topic_by_sender"
value="[%|loc%]Tag this mail[%END%]" />
[%- ELSE -%]
<input class="MainMenuLinks" type="submit" name="action_tag_topic_by_sender" value="[%|loc%]Tag this mail[%END%]" />
[%- END -%]
Expand Down
14 changes: 8 additions & 6 deletions default/web_tt2/viewmod.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
</button>&nbsp;
</p>
<p>
<button class="action" type="submit" name="action_reject"
value="[%|loc%]Reject[%END%]" data-tooltip
[% IF msg.value.spam_status == 'spam' ~%]
onclick="return check_reject_spam(reject_mail,'warningSpam')" aria-haspopup="true"
[%~ END %]
title="[%|loc%]Reject[%END%]">
<button class="action"
[%~IF msg.value.spam_status == 'spam'%] checkRejectSpam[%END%]"
type="submit" name="action_reject"
value="[%|loc%]Reject[%END%]" data-tooltip
[% IF msg.value.spam_status == 'spam' ~%]
aria-haspopup="true"
[% END ~%]
title="[%|loc%]Reject[%END%]">
<i class="fas fa-trash-alt fa-lg"></i> [%|loc%]Reject[%END%]
</button>
<select name="message_template">
Expand Down
50 changes: 33 additions & 17 deletions www/js/sympa.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2023 The Sympa Community. See the
# Copyright 2017, 2018, 2019, 2023 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -72,11 +72,13 @@ $(function() {
});

/*
* No longer used as of 6.2.17, however, can be included in older archives.
* No longer used, however, can be included in older archives.
*/
function isNotEmpty(i) { return true; }
function request_confirm(m) { return true; }
function toggle_selection(myfield) { return false; }
function checkbox_check_topic(f) { return true; }
function check_reject_spam(f, w) { return true; }

/* Toggle selection. */
/* Fields included in .toggleContainer and specified by data-selector
Expand All @@ -102,23 +104,37 @@ $(function() {
});
});

// check if rejecting quietly spams TODO
function check_reject_spam(form,warningId) {
if(form.elements['iConfirm'].checked) return true;

if(form.elements['message_template'].options[form.elements['message_template'].selectedIndex].value == 'reject_quiet') return true;

$('#' + warningId).show();
return false;
}
// check if rejecting quietly spams
$(function() {
$('.checkRejectSpam').on('click', function() {
var form = $(this).parents('form');

if (form.elements['iConfirm'].checked)
return true;
if (form.elements['message_template']
.options[form.elements['message_template'].selectedIndex]
.value == 'reject_quiet')
return true;

$('#warningSpam').show();
return false;
});
});

// To check at least one checkbox checked
function checkbox_check_topic(form, warningId) {
if($(form).find('input[name^="topic_"]:checked').length) return true;

$('#' + warningId).show();
return false;
}
$(function() {
$('.topicChecked').each(
function () {
var form = $(this).parents('form');
$(this).on('click', function() {
if (form.find('input[name^="topic_"]:checked').length)
return true;
return false;
});
return true;
}
);
});

/* Add a button to reset all fields in log form. */
$(function() {
Expand Down

0 comments on commit d8c48af

Please sign in to comment.