--- /dev/null
+package SL::Controller::CustomVariableConfig;
+
+use strict;
+
+use parent qw(SL::Controller::Base);
+
+use SL::DB::CustomVariableConfig;
+
+__PACKAGE__->run_before('check_auth');
+
+#
+# actions
+#
+
+sub action_reorder {
+ my ($self) = @_;
+
+ my @ids = @{ $::form->{cvarcfg_id} || [] };
+ my $result = SL::DB::CustomVariableConfig->new->db->do_transaction(sub {
+ foreach my $idx (0 .. scalar(@ids) - 1) {
+ SL::DB::CustomVariableConfig->new(id => $ids[$idx])->load->update_attributes(sortkey => $idx + 1);
+ }
+ });
+
+ $self->render(type => 'js', inline => '1;');
+}
+
+#
+# filters
+#
+
+sub check_auth {
+ $::auth->assert('config');
+}
+
+1;
my @configs = @{ CVar->get_configs(module => $form->{module}) };
- my $previous_config;
-
foreach my $config (@configs) {
$config->{type_tr} = $translations{$config->{type}};
-
- if ($previous_config) {
- $previous_config->{next_id} = $config->{id};
- $config->{previous_id} = $previous_config->{id};
- }
-
- $previous_config = $config;
}
$form->{title} = $locale->text('List of custom variables');
$main::lxdebug->leave_sub();
}
-sub swap_cvar_configs {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
-
- AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs');
-
- list_cvar_configs();
-
- $main::lxdebug->leave_sub();
-}
-
sub dispatcher {
my $form = $main::form;
my $locale = $main::locale;
-[%- USE T8 %]
-[% USE HTML %]<body>
+[%- USE T8 %][% USE LxERP %][% USE L %]
+[% USE HTML %]
+
+<script type="text/javascript" src="js/jquery-ui.js"></script>
+
+<body>
[% IF MESSAGE %]<p>[% MESSAGE %]</p>[% END %]
</p>
<p>
- <table width="100%">
- <tr>
- <td class="listheading" width="0%"></td>
- <td class="listheading" width="0%"></td>
- <td class="listheading" width="20%">[% 'Name' | $T8 %]</td>
- <td class="listheading" width="20%">[% 'Description' | $T8 %]</td>
- <td class="listheading" width="20%">[% 'Type' | $T8 %]</td>
- <td class="listheading" width="20%">[% 'Searchable' | $T8 %]</td>
- <td class="listheading" width="20%">[% 'Includeable in reports' | $T8 %]</td>
+ <table width="100%" id="cvarcfg_list">
+ <tr class="listheading">
+ <th align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
+ <th width="20%">[% 'Name' | $T8 %]</th>
+ <th width="20%">[% 'Description' | $T8 %]</th>
+ <th width="20%">[% 'Type' | $T8 %]</th>
+ <th width="20%">[% 'Searchable' | $T8 %]</th>
+ <th width="20%">[% 'Includeable in reports' | $T8 %]</th>
[%- IF module == 'IC' %]
- <td class="listheading" width="20%">[% 'Editable' | $T8 %]</td>
+ <th width="20%">[% 'Editable' | $T8 %]</th>
[%- END %]
</tr>
[%- FOREACH cfg = CONFIGS %]
- <tr class="listrow[% loop.count % 2 %]">
- <td>
- [%- IF cfg.previous_id %]
- <a href="amcvar.pl?action=swap_cvar_configs&module=[% HTML.url(module) %]&id1=[% HTML.url(cfg.previous_id) %]&id2=[% HTML.url(cfg.id) %]">
- <img border="0" src="image/up.png"></a>
- [%- END %]
- </td>
-
- <td>
- [%- IF cfg.next_id %]
- <a href="amcvar.pl?action=swap_cvar_configs&module=[% HTML.url(module) %]&id1=[% HTML.url(cfg.next_id) %]&id2=[% HTML.url(cfg.id) %]">
- <img border="0" src="image/down.png"></a>
- [%- END %]
- </td>
+ <tr class="listrow[% loop.count % 2 %]" id="cvarcfg_id_[% cfg.id %]">
+ <td align="center"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
<td>
<a href="amcvar.pl?action=edit_cvar_config&module=[% HTML.url(module) %]&id=[% HTML.url(cfg.id) %]&callback=[% HTML.url(callback) %]">
</p>
</form>
+ [% L.sortable_element('#cvarcfg_list tbody', 'url' => 'controller.pl?action=CustomVariableConfig/reorder', 'with' => 'cvarcfg_id') %]
+
</body>
</html>