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 => SL::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')
71 ->val('#draft_id', $draft->id)
79 if (!$allowed_modules{ $self->draft->module }) {
80 $::form->error(t8('Unknown module: #1', $self->draft->module));
83 require $allowed_modules{ $self->draft->module };
85 my $params = delete $::form->{form};
86 my $new_form = SL::YAML::Load($self->draft->form);
87 $::form->{$_} = $new_form->{$_} for keys %$new_form;
88 $::form->{"draft_$_"} = $self->draft->$_ for qw(id description);
90 if ($params && 'HASH' eq ref $params) {
91 $::form->{$_} = $params->{$_} for keys %$params;
93 $::form->{script} = $self->draft->module . '.pl';
100 $self->module($self->draft->module);
101 $self->submodule($self->draft->submodule);
103 if (!$self->draft->delete) {
104 flash('error', t8('There was an error deleting the draft'));
106 ->html('#save_draft', $self->dialog_html)
109 flash('info', t8('Draft deleted'));
112 ->html('#save_draft', $self->dialog_html)
122 my $last_index = max map { /form\[(\d+)\]/ ? $1 : 0 } keys %$::form;
125 for my $i (0..$last_index) {
126 SL::Request::_store_value($new_form, $::form->{"form[$i][name]"}, $::form->{"form[$i][value]"});
135 if ($::auth->assert('all_drafts_edit', 1)) {
136 my $result = selectall_hashref_query($::form, $::form->get_standard_dbh, <<SQL, $self->module, $self->submodule);
137 SELECT d.*, date(d.itime) AS date
140 AND (d.submodule = ?)
144 my $result = selectall_hashref_query($::form, $::form->get_standard_dbh, <<SQL, $self->module, $self->submodule, SL::DB::Manager::Employee->current->id);
145 SELECT d.*, date(d.itime) AS date
148 AND (d.submodule = ?)
149 AND (d.employee_id = ?)
158 $self->render('drafts/form', { layout => 0, output => 0 },
159 drafts_list => $self->draft_list
164 $::form->{module} or die 'need module';
168 $::form->{submodule} or die 'need submodule';
172 SL::DB::Manager::Draft->find_by(id => $::form->{id}) or die t8('Could not load this draft');
176 $::auth->assert('vendor_invoice_edit | invoice_edit | ap_transactions | ar_transactions');
187 SL::Controller::Draft
191 Encapsulates the old draft mechanism. Use and improvement are discuraged as
192 long as the storage is not upgrade safe.
196 - optional popup on entry
200 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>