Skip to content

Commit 3dc4755

Browse files
committed
Adapt Edit Snippets page layout to Mantis 2.x style
Fixes #62
1 parent 469171b commit 3dc4755

File tree

2 files changed

+130
-106
lines changed

2 files changed

+130
-106
lines changed

files/snippets.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ table#snippets-list-footer {
4141
background-color: transparent !important;
4242
margin-bottom: 0 !important;
4343
}
44+
45+
tr.spacer > td {
46+
border-bottom-width: 0 !important;
47+
}

pages/snippet_list_action.php

Lines changed: 126 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -4,176 +4,196 @@
44
# Copyright (c) 2012 - 2021 MantisBT Team - [email protected]
55
# Licensed under the MIT license
66

7-
form_security_validate("plugin_Snippets_list_action");
7+
form_security_validate( "plugin_Snippets_list_action" );
88

9-
$global = gpc_get_bool("global");
9+
$global = gpc_get_bool( "global" );
1010

11-
if ($global) {
12-
access_ensure_global_level(plugin_config_get("edit_global_threshold"));
11+
if( $global ) {
12+
access_ensure_global_level( plugin_config_get( "edit_global_threshold" ) );
1313
$user_id = 0;
14-
} else {
15-
access_ensure_global_level(plugin_config_get("edit_own_threshold"));
14+
}
15+
else {
16+
access_ensure_global_level( plugin_config_get( "edit_own_threshold" ) );
1617
$user_id = auth_get_current_user_id();
1718
}
1819

19-
$action = gpc_get_string("action");
20+
$action = gpc_get_string( "action" );
21+
$snippet_list = gpc_get_int_array( "snippet_list", array() );
2022

21-
$snippet_list = gpc_get_int_array("snippet_list", array());
23+
$t_redirect_page = plugin_page( "snippet_list", true ) . Snippet::global_url( $global );
2224

23-
if (count($snippet_list) < 1) {
24-
form_security_purge("plugin_Snippets_list_action");
25+
if( count( $snippet_list ) < 1 ) {
26+
form_security_purge( "plugin_Snippets_list_action" );
2527
helper_ensure_confirmed(
2628
plugin_lang_get( 'action_nothing_to_do' ),
2729
lang_get( 'ok' )
2830
);
29-
print_header_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
31+
print_header_redirect( $t_redirect_page );
3032
}
3133

32-
$snippets = Snippet::load_by_id($snippet_list, $user_id);
33-
34-
function array_object_properties($arr, $prop) {
35-
$props = array();
36-
foreach($arr as $key => $obj) {
37-
$props[$key] = $obj->$prop;
38-
}
39-
return $props;
40-
}
34+
$snippets = Snippet::load_by_id( $snippet_list, $user_id );
35+
$single = count( $snippets ) == 1;
4136

4237
### DELETE
43-
if ($action == "delete") {
44-
$snippet_names = array_object_properties(Snippet::clean($snippets), "name");
38+
if( $action == "delete" ) {
39+
$snippet_names = array_column( Snippet::clean( $snippets ), 'name' );
4540
helper_ensure_confirmed(
46-
plugin_lang_get("action_delete_confirm")
41+
plugin_lang_get( "action_delete_confirm" )
4742
. "<br>" . implode( ", ", $snippet_names ),
48-
plugin_lang_get("action_delete")
43+
plugin_lang_get( "action_delete" )
4944
);
50-
Snippet::delete_by_id(array_keys($snippets), $user_id);
45+
Snippet::delete_by_id( array_keys( $snippets ), $user_id );
5146

52-
form_security_purge("plugin_Snippets_list_action");
53-
print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
47+
form_security_purge( "plugin_Snippets_list_action" );
48+
print_successful_redirect( $t_redirect_page );
5449

5550
### EDIT
56-
} elseif ($action == "edit") {
57-
$snippets = Snippet::clean($snippets, Snippet::TARGET_FORM);
51+
} elseif( $action == "edit" ) {
52+
$snippets = Snippet::clean( $snippets, Snippet::TARGET_FORM );
5853
layout_page_header();
5954
layout_page_begin();
60-
?>
61-
62-
<br/>
6355

64-
<div id="snippet-div" class="form-container">
65-
<form action="<?php echo plugin_page( 'snippet_list_action' ) ?>" method="post">
66-
<?php echo form_security_field("plugin_Snippets_list_action") ?>
67-
<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
68-
<input type="hidden" name="action" value="update"/>
69-
70-
<div class="widget-box widget-color-blue2">
71-
<div class="widget-header widget-header-small">
72-
<h4 class="widget-title lighter">
73-
<i class="ace-icon fa fa-user"></i>
74-
<?php echo plugin_lang_get( $global ? 'edit_global_title' : 'edit_title' ) ?>
75-
</h4>
76-
</div>
77-
<div class="widget-body">
78-
<div class="widget-main no-padding">
79-
<div class="table-responsive">
80-
<table class="table table-bordered table-condensed table-striped">
56+
$t_page_name = basename( __FILE__, '.php' );
57+
print_account_menu( $t_page_name );
58+
?>
8159

82-
<fieldset>
60+
<div class="col-md-12 col-xs-12">
61+
<div class="space-10"></div>
8362

63+
<div id="snippet-div" class="form-container">
64+
<form action="<?php echo plugin_page( 'snippet_list_action' ) ?>"
65+
method="post">
66+
<?php echo form_security_field( "plugin_Snippets_list_action" ) ?>
67+
<input type="hidden" name="action" value="update"/>
8468
<?php
85-
$first = true;
86-
$single = count( $snippets ) == 1;
87-
88-
foreach( $snippets as $snippet ) {
89-
if ( !$first ) {
69+
if( $global ) {
9070
?>
91-
<tr class="spacer"><td></td></tr>
71+
<input type="hidden" name="global" value="true"/>
9272
<?php
93-
}
73+
}
9474
?>
9575

96-
<tr>
76+
<div class="widget-box widget-color-blue2">
77+
<div class="widget-header widget-header-small">
78+
<h4 class="widget-title lighter">
79+
<i class="ace-icon fa fa-file-o"></i>
80+
<?php echo plugin_lang_get( $global ? 'edit_global_title' : 'edit_title' ) ?>
81+
</h4>
82+
</div>
83+
<div class="widget-body">
84+
<div class="widget-main no-padding table-responsive">
85+
<table class="table table-bordered table-condensed table-striped">
86+
<?php
87+
foreach( $snippets as $snippet ) {
88+
?>
89+
<tr>
9790
<?php
9891
# Hide checkbox when operating on a single Snippet
9992
if( !$single ) {
10093
?>
101-
<td class="center" rowspan="2">
102-
<!--suppress HtmlFormInputWithoutLabel -->
103-
<input type="checkbox" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/>
104-
</td>
94+
<td class="category center"
95+
rowspan="2">
96+
<!--suppress HtmlFormInputWithoutLabel -->
97+
<input type="checkbox"
98+
name="snippet_list[]"
99+
class="ace"
100+
value="<?php echo $snippet->id ?>"
101+
checked="checked"
102+
/>
103+
<span class="lbl"></span>
104+
</td>
105105
<?php
106106
}
107107
?>
108-
<td class="category">
108+
<th>
109109
<?php
110110
# Add hidden field with Snippet id
111111
if( $single ) {
112112
?>
113-
<input type="hidden" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/>
113+
<input type="hidden"
114+
name="snippet_list[]"
115+
value="<?php echo $snippet->id ?>"
116+
checked="checked"
117+
/>
114118
<?php
115119
}
116-
echo plugin_lang_get("edit_name")
120+
echo plugin_lang_get( "edit_name" );
121+
$t_textarea = 'value_' . $snippet->id;
117122
?>
118-
</td>
119-
<td>
120-
<!--suppress HtmlFormInputWithoutLabel -->
121-
<input type="text" name="name_<?php echo $snippet->id ?>" size="40" value="<?php echo $snippet->name ?>"/>
122-
</td>
123-
</tr>
124-
125-
<tr>
126-
<td class="category">
127-
<label for="value_<?php echo $snippet->id ?>">
128-
<?php echo plugin_lang_get("edit_value") ?>
129-
</label>
130-
</td>
131-
<td class="snippetspatternhelp">
132-
<textarea id="value_<?php echo $snippet->id ?>" name="value_<?php echo $snippet->id ?>"
133-
cols="80" rows="6"><?php echo $snippet->value ?></textarea>
134-
</td>
135-
</tr>
123+
</th>
124+
<td>
125+
<!--suppress HtmlFormInputWithoutLabel -->
126+
<input type="text"
127+
name="name_<?php echo $snippet->id ?>"
128+
size="40"
129+
value="<?php echo $snippet->name ?>"
130+
/>
131+
</td>
132+
</tr>
133+
134+
<tr>
135+
<th>
136+
<label for="<?php echo $t_textarea; ?>">
137+
<?php echo plugin_lang_get( "edit_value"
138+
) ?>
139+
</label>
140+
</th>
141+
<td class="snippetspatternhelp">
142+
<textarea id="<?php echo $t_textarea; ?>"
143+
name="<?php echo $t_textarea; ?>"
144+
cols="80"
145+
rows="6"><?php echo $snippet->value ?></textarea>
146+
</td>
147+
</tr>
136148

137149
<?php
138-
$first = false;
139-
}
150+
# Add a spacer if processing more than one Snippet
151+
if( !$single ) {
152+
?>
153+
<tr class="spacer"><td></td></tr>
154+
<tr></tr>
155+
<?php
156+
}
157+
} # foreach
140158
?>
141159

142-
<tfoot>
143-
<tr>
144-
<td class="center" colspan="3"><input type="submit" value="<?php echo plugin_lang_get("action_edit") ?>"/></td>
145-
</tr>
146-
</tfoot>
160+
</table>
161+
</div>
162+
163+
<div class="widget-toolbox padding-8 clearfix">
164+
<button type="submit"
165+
class="btn btn-primary btn-white btn-round">
166+
<?php echo plugin_lang_get( "action_update" ) ?>
167+
</button>
168+
</div>
169+
</div>
170+
</div>
171+
</form>
172+
</div>
147173

148-
</fieldset>
149-
</table>
150-
</form>
151174
</div>
152175

153176
<?php
154177
layout_page_end();
155178

156179
### UPDATE
157-
} elseif ($action == "update") {
158-
foreach($snippets as $snippet_id => $snippet) {
159-
$new_name = gpc_get_string("name_{$snippet_id}");
160-
$new_value = gpc_get_string("value_{$snippet_id}");
161-
162-
if ($snippet->name != $new_name
163-
|| $snippet->value != $new_value)
164-
{
165-
if (!is_blank($new_name)) {
180+
} elseif( $action == "update" ) {
181+
foreach( $snippets as $snippet_id => $snippet ) {
182+
$new_name = gpc_get_string( "name_$snippet_id" );
183+
$new_value = gpc_get_string( "value_$snippet_id" );
184+
185+
if( $snippet->name != $new_name || $snippet->value != $new_value ) {
186+
if( !is_blank( $new_name ) ) {
166187
$snippet->name = $new_name;
167188
}
168-
if (!is_blank($new_value)) {
189+
if( !is_blank( $new_value ) ) {
169190
$snippet->value = $new_value;
170191
}
171192

172193
$snippet->save();
173194
}
174195
}
175196

176-
form_security_purge("plugin_Snippets_list_action");
177-
print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
178-
197+
form_security_purge( "plugin_Snippets_list_action" );
198+
print_successful_redirect( $t_redirect_page );
179199
}

0 commit comments

Comments
 (0)