Commit cb6f2292 authored by myk%mozilla.org's avatar myk%mozilla.org

Fix for bug 97739: Confirms deletion of an attachment status in browsers with no-JS/JS-off.

Patch by Jeff Hedlund <jeff.hedlund@matrixsi.com>. r=myk,gerv
parent 496013d2
...@@ -87,11 +87,16 @@ elsif ($action eq "update") ...@@ -87,11 +87,16 @@ elsif ($action eq "update")
validateSortKey(); validateSortKey();
update(); update();
} }
elsif ($action eq "delete") elsif ($action eq "confirmdelete")
{ {
validateID(); validateID();
deleteStatus(); confirmDelete();
} }
elsif ($action eq "delete")
{
validateID();
deleteStatus();
}
else else
{ {
DisplayError("I could not figure out what you wanted to do.") DisplayError("I could not figure out what you wanted to do.")
...@@ -174,14 +179,18 @@ sub list ...@@ -174,14 +179,18 @@ sub list
# Retrieve a list of attachment status flags and create an array of hashes # Retrieve a list of attachment status flags and create an array of hashes
# in which each hash contains the data for one flag. # in which each hash contains the data for one flag.
SendSQL("SELECT id, name, description, sortkey, product SendSQL("SELECT id, name, description, sortkey, product, count(statusid)
FROM attachstatusdefs ORDER BY sortkey"); FROM attachstatusdefs LEFT JOIN attachstatuses
ON attachstatusdefs.id=attachstatuses.statusid
GROUP BY id
ORDER BY sortkey");
my @statusdefs; my @statusdefs;
while ( MoreSQLData() ) while ( MoreSQLData() )
{ {
my ($id, $name, $description, $sortkey, $product) = FetchSQLData(); my ($id, $name, $description, $sortkey, $product, $attachcount) = FetchSQLData();
push @statusdefs, { 'id' => $id , 'name' => $name , 'description' => $description , push @statusdefs, { 'id' => $id , 'name' => $name , 'description' => $description ,
'sortkey' => $sortkey , 'product' => $product }; 'sortkey' => $sortkey , 'product' => $product,
'attachcount' => $attachcount };
} }
# Define the variables and functions that will be passed to the UI template. # Define the variables and functions that will be passed to the UI template.
...@@ -293,6 +302,34 @@ sub update ...@@ -293,6 +302,34 @@ sub update
list("The attachment status has been updated."); list("The attachment status has been updated.");
} }
sub confirmDelete
{
# check if we need confirmation to delete:
SendSQL("SELECT COUNT(attach_id), name
FROM attachstatusdefs LEFT JOIN attachstatuses
ON attachstatuses.statusid=attachstatusdefs.id
WHERE statusid = $::FORM{'id'}
GROUP BY attachstatuses.statusid;");
my ($attachcount, $name) = FetchSQLData();
if ($attachcount > 0) {
$vars->{'id'} = $::FORM{'id'};
$vars->{'attachcount'} = $attachcount;
$vars->{'name'} = $name;
print "Content-type: text/html\n\n";
$template->process("attachstatus/delete.atml", $vars)
|| DisplayError("Template process failed: " . & $template->error())
&& exit;
}
else {
deleteStatus();
}
}
sub deleteStatus sub deleteStatus
{ {
......
...@@ -44,8 +44,14 @@ ...@@ -44,8 +44,14 @@
<td>[% statusdef.sortkey %]</td> <td>[% statusdef.sortkey %]</td>
<td>[% statusdef.product %]</td> <td>[% statusdef.product %]</td>
<td> <td>
<a href="editattachstatuses.cgi?action=edit&id=[% statusdef.id %]">Edit</a> <a href="editattachstatuses.cgi?action=edit&id=[% statusdef.id %]">
<a href="editattachstatuses.cgi?action=delete&id=[% statusdef.id %]" onclick="return confirmDelete();">Delete</a> Edit</a>
&nbsp;|&nbsp;
<a href="editattachstatuses.cgi?action=confirmdelete&id=[% statusdef.id %]"
onclick="return confirmDelete([% statusdef.attachcount %],
'[% statusdef.name FILTER js %]',
[% statusdef.id %]);">
Delete</a>
</td> </td>
</tr> </tr>
...@@ -59,13 +65,23 @@ ...@@ -59,13 +65,23 @@
</tr> </tr>
</table> </table>
<script language="JavaScript"> <script language="JavaScript">
function confirmDelete() function confirmDelete(attachcount, name, id)
{ {
return confirm('Are you sure you want to permanently delete ' + if (attachcount > 0) {
'this attachment status? All attachments ' + msg = attachcount + ' attachments have the status ' +
'with this status will have it unset.'); name + '. If you delete it, those attachments ' +
'will lose this status. Do you really want to ' +
'delete this status?';
}
else {
msg = 'Are you sure you want to delete attachment status ' +
name + '?';
}
if (confirm(msg)) {
location.href = "editattachstatuses.cgi?action=delete&id=" + id;
}
return false;
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment