1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
14 require "bin/mozilla/common.pl";
19 $main::lxdebug->enter_sub();
21 my $form = $main::form;
22 my %myconfig = %main::myconfig;
23 my $locale = $main::locale;
25 if (!$form->{draft_id} && !$form->{draft_description}) {
26 restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
27 delete $form->{SAVED_FORM};
29 $form->{SAVED_FORM} = save_form(qw(login password));
30 $form->{remove_draft} = 1;
33 print($form->parse_html_template("drafts/save_new"));
35 return $main::lxdebug->leave_sub();
38 my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
40 restore_form($form->{SAVED_FORM}, 1);
41 delete $form->{SAVED_FORM};
43 Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
45 $form->{saved_message} = $locale->text("Draft saved.");
49 $main::lxdebug->leave_sub();
53 $main::lxdebug->enter_sub();
55 my $form = $main::form;
56 my %myconfig = %main::myconfig;
58 Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
60 delete @{$form}{qw(draft_id draft_description)};
62 $main::lxdebug->leave_sub();
65 sub load_draft_maybe {
66 $main::lxdebug->enter_sub();
68 my $form = $main::form;
69 my %myconfig = %main::myconfig;
71 $main::lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
73 my ($draft_nextsub) = @_;
75 my @drafts = Drafts->list(\%myconfig, $form);
77 $main::lxdebug->leave_sub() and return 0 unless (@drafts);
79 $draft_nextsub = "add" unless ($draft_nextsub);
81 delete $form->{action};
82 my $saved_form = save_form(qw(login password));
85 print($form->parse_html_template("drafts/load",
86 { "DRAFTS" => \@drafts,
87 "SAVED_FORM" => $saved_form,
88 "draft_nextsub" => $draft_nextsub }));
90 $main::lxdebug->leave_sub();
96 $main::lxdebug->enter_sub();
98 my $form = $main::form;
100 my $draft_nextsub = $form->{draft_nextsub} || "add";
102 restore_form($form->{SAVED_FORM}, 1);
103 delete $form->{SAVED_FORM};
105 $form->{DONT_LOAD_DRAFT} = 1;
107 call_sub($draft_nextsub);
109 $main::lxdebug->leave_sub();
113 $main::lxdebug->enter_sub();
115 my $form = $main::form;
116 my %myconfig = %main::myconfig;
118 my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
121 $old_form = YAML::Load($old_form);
123 my %dont_save_vars = map { $_ => 1 } Drafts->dont_save;
124 my @restore_vars = grep { !$dont_save_vars{$_} } keys %{ $old_form };
126 @{$form}{@restore_vars} = @{$old_form}{@restore_vars};
128 $form->{draft_id} = $id;
129 $form->{draft_description} = $description;
130 $form->{remove_draft} = 'checked';
132 # Ich vergesse bei Rechnungsentwürfe das Rechnungsdatum zu ändern. Dadurch entstehen
133 # ungültige Belege. Vielleicht geht es anderen ähnlich jan 19.2.2011
134 $form->{invdate} = $form->current_date(\%myconfig); # Aktuelles Rechnungsdatum ...
135 $form->{duedate} = $form->current_date(\%myconfig); # Aktuelles Fälligkeitsdatum ...
138 $main::lxdebug->leave_sub();
142 $main::lxdebug->enter_sub();
144 my $form = $main::form;
145 my %myconfig = %main::myconfig;
148 foreach (keys %{$form}) {
149 push @ids, $1 if (/^checked_(.*)/ && $form->{$_});
151 Drafts->remove(\%myconfig, $form, @ids) if (@ids);
153 restore_form($form->{SAVED_FORM}, 1);
154 delete $form->{SAVED_FORM};
158 $main::lxdebug->leave_sub();
161 sub draft_action_dispatcher {
162 $main::lxdebug->enter_sub();
164 my $form = $main::form;
165 my $locale = $main::locale;
167 if ($form->{draft_action} eq $locale->text("Skip")) {
170 } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
174 $main::lxdebug->leave_sub();