Skip to content

Commit 21b7383

Browse files
committed
Hide checkbox when editing a single Snippet
Fixes #13
1 parent 8beafea commit 21b7383

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

pages/snippet_list_action.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,38 @@ function array_object_properties($arr, $prop) {
7373

7474
<fieldset>
7575

76-
<?php $first = true; foreach ($snippets as $snippet): ?>
77-
<?php if (!$first): ?><tr class="spacer"><td></td></tr><?php endif ?>
76+
<?php
77+
$first = true;
78+
$single = count( $snippets ) == 1;
79+
80+
foreach( $snippets as $snippet ) {
81+
if ( !$first ) {
82+
?>
83+
<tr class="spacer"><td></td></tr>
84+
<?php
85+
}
86+
?>
7887

7988
<tr>
89+
<?php
90+
# Hide checkbox when operating on a single Snippet
91+
if( !$single ) {
92+
?>
8093
<td class="center" rowspan="2"><input type="checkbox" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/></td>
81-
<td class="category"><?php echo plugin_lang_get("edit_name") ?></td>
94+
<?php
95+
}
96+
?>
97+
<td class="category">
98+
<?php
99+
# Add hidden field with Snippet id
100+
if( $single ) {
101+
?>
102+
<input type="hidden" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/>
103+
<?php
104+
}
105+
echo plugin_lang_get("edit_name")
106+
?>
107+
</td>
82108
<td><input type="text" name="name_<?php echo $snippet->id ?>" size="40" value="<?php echo $snippet->name ?>"/></td>
83109
</tr>
84110

@@ -87,7 +113,10 @@ function array_object_properties($arr, $prop) {
87113
<td class="snippetspatternhelp"><textarea name="value_<?php echo $snippet->id ?>" cols="80" rows="6"><?php echo $snippet->value ?></textarea></td>
88114
</tr>
89115

90-
<?php $first = false; endforeach ?>
116+
<?php
117+
$first = false;
118+
}
119+
?>
91120

92121
<tfoot>
93122
<tr>
@@ -127,5 +156,3 @@ function array_object_properties($arr, $prop) {
127156
print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
128157

129158
}
130-
131-

0 commit comments

Comments
 (0)