1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
12 require "bin/mozilla/common.pl";
15 $lxdebug->enter_sub();
17 if (!$form->{draft_id} && !$form->{draft_description}) {
18 restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
19 delete($form->{SAVED_FORM});
20 $form->{SAVED_FORM} = save_form();
23 print($form->parse_html_template("drafts/save_new"));
24 return $lxdebug->leave_sub();
27 my ($draft_id, $draft_description) =
28 ($form->{draft_id}, $form->{draft_description});
30 restore_form($form->{SAVED_FORM}, 1);
31 delete($form->{SAVED_FORM});
33 Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
35 $form->{saved_message} = $locale->text("Draft saved.");
39 $lxdebug->leave_sub();
43 $lxdebug->enter_sub();
45 Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
47 delete($form->{draft_id});
48 delete($form->{draft_description});
50 $lxdebug->leave_sub();
53 sub load_draft_maybe {
54 $lxdebug->enter_sub();
56 $lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
58 my ($draft_nextsub) = @_;
60 my @drafts = Drafts->list(\%myconfig, $form);
62 $lxdebug->leave_sub() and return 0 unless (@drafts);
64 $draft_nextsub = "add" unless ($draft_nextsub);
66 delete($form->{action});
67 my $saved_form = save_form();
70 print($form->parse_html_template("drafts/load",
71 { "DRAFTS" => \@drafts,
72 "SAVED_FORM" => $saved_form,
73 "draft_nextsub" => $draft_nextsub }));
75 $lxdebug->leave_sub();
81 $lxdebug->enter_sub();
83 my $draft_nextsub = $form->{draft_nextsub};
84 $draft_nextsub = "add" unless ($form->{draft_nextsub});
85 restore_form($form->{SAVED_FORM}, 1);
86 delete($form->{SAVED_FORM});
87 delete($form->{action});
88 $form->{DONT_LOAD_DRAFT} = 1;
90 &{ $draft_nextsub }();
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
98 my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
100 restore_form($old_form, 1);
101 $form->{draft_id} = $id;
102 $form->{draft_description} = $description;
103 $form->{remove_draft} = 'checked';
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
115 foreach (keys(%{$form})) {
116 push(@ids, $1) if (/^checked_(.*)/ && $form->{$_});
118 Drafts->remove(\%myconfig, $form, @ids) if (@ids);
119 restore_form($form->{SAVED_FORM}, 1);
120 delete($form->{SAVED_FORM});
124 $lxdebug->leave_sub();
127 sub draft_action_dispatcher {
128 $lxdebug->enter_sub();
130 if ($form->{draft_action} eq $locale->text("Skip")) {
132 } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
136 $lxdebug->leave_sub();