1 package SL::Controller::Draft;
5 use parent qw(SL::Controller::Base);
7 use SL::Helper::Flash qw(flash);
8 use SL::Locale::String qw(t8);
11 use SL::DBUtils qw(selectall_hashref_query);
13 use List::Util qw(max);
15 use Rose::Object::MakeMethods::Generic (
17 'scalar --get_set_init' => [ qw(module submodule draft) ],
20 __PACKAGE__->run_before('check_auth');
22 my %allowed_modules = map { $_ => "bin/mozilla/$_.pl" } qw(is ir ar ap gl);
28 sub action_draft_dialog {
32 html => $self->dialog_html,
35 title => t8('Drafts'),
44 my $id = $::form->{id};
45 my $description = $::form->{description} or die 'need description';
46 my $form = $self->_build_form;
48 my $draft = SL::DB::Manager::Draft->find_by_or_create(id => $id);
50 $draft->id($self->module . '-' . $self->submodule . '-' . Common::unique_id()) unless $draft->id;
52 $draft->assign_attributes(
53 module => $self->module,
54 submodule => $self->submodule,
55 description => $description,
56 form => YAML::Dump($form),
57 employee_id => SL::DB::Manager::Employee->current->id,
63 flash('error', t8('There was an error saving the draft'));
65 ->html('#save_draft', $self->dialog_html)
69 ->flash('info', t8("Draft saved."))
70 ->dialog->close('#save_draft')
78 if (!$allowed_modules{ $self->draft->module }) {
79 $::form->error(t8('Unknown module: #1', $self->draft->module));
82 require $allowed_modules{ $self->draft->module };
86 my $params = delete $::form->{form};
87 my $new_form = YAML::Load($self->draft->form);
88 $::form->{$_} = $new_form->{$_} for keys %$new_form;
89 $::form->{"draft_$_"} = $self->draft->$_ for qw(id description);
91 if ($params && 'HASH' eq ref $params) {
92 $::form->{$_} = $params->{$_} for keys %$params;
95 $::form->{script} = $self->draft->module . '.pl';
102 $self->module($self->draft->module);
103 $self->submodule($self->draft->submodule);
105 if (!$self->draft->delete) {
106 flash('error', t8('There was an error deleting the draft'));
108 ->html('#save_draft', $self->dialog_html)
111 flash('info', t8('Draft deleted'));
114 ->html('#save_draft', $self->dialog_html)
124 my $last_index = max map { /form\[(\d+)\]/ ? $1 : 0 } keys %$::form;
127 for my $i (0..$last_index) {
128 SL::Request::_store_value($new_form, $::form->{"form[$i][name]"}, $::form->{"form[$i][value]"});
137 my $result = selectall_hashref_query($::form, $::form->get_standard_dbh, <<SQL, $self->module, $self->submodule);
138 SELECT d.*, date(d.itime) AS date, e.name AS employee_name
140 LEFT JOIN employee e ON d.employee_id = e.id
141 WHERE (d.module = ?) AND (d.submodule = ?)
149 $self->render('drafts/form', { layout => 0, output => 0 },
150 drafts_list => $self->draft_list
155 $::form->{module} or die 'need module';
159 $::form->{submodule} or die 'need submodule';
163 SL::DB::Manager::Draft->find_by(id => $::form->{id}) or die t8('Could not load this draft');
167 $::auth->assert('vendor_invoice_edit | invoice_edit | ap_transactions | ar_transactions');
178 SL::Controller::Draft
182 Encapsulates the old draft mechanism. Use and improvement are discuraged as
183 long as the storage is not upgrade safe.
187 - optional popup on entry
191 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>