1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
14 require "bin/mozilla/common.pl";
17 $lxdebug->enter_sub();
19 if (!$form->{draft_id} && !$form->{draft_description}) {
20 restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
21 delete $form->{SAVED_FORM};
23 $form->{SAVED_FORM} = save_form();
24 $form->{remove_draft} = 1;
27 print($form->parse_html_template("drafts/save_new"));
29 return $lxdebug->leave_sub();
32 my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
34 restore_form($form->{SAVED_FORM}, 1);
35 delete $form->{SAVED_FORM};
37 Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
39 $form->{saved_message} = $locale->text("Draft saved.");
43 $lxdebug->leave_sub();
47 $lxdebug->enter_sub();
49 Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
51 delete @{$form}{qw(draft_id draft_description)};
53 $lxdebug->leave_sub();
56 sub load_draft_maybe {
57 $lxdebug->enter_sub();
59 $lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
61 my ($draft_nextsub) = @_;
63 my @drafts = Drafts->list(\%myconfig, $form);
65 $lxdebug->leave_sub() and return 0 unless (@drafts);
67 $draft_nextsub = "add" unless ($draft_nextsub);
69 delete $form->{action};
70 my $saved_form = save_form();
73 print($form->parse_html_template("drafts/load",
74 { "DRAFTS" => \@drafts,
75 "SAVED_FORM" => $saved_form,
76 "draft_nextsub" => $draft_nextsub }));
78 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 my $draft_nextsub = $form->{draft_nextsub} || "add";
88 restore_form($form->{SAVED_FORM}, 1);
89 delete $form->{SAVED_FORM};
91 $form->{DONT_LOAD_DRAFT} = 1;
93 call_sub($draft_nextsub);
95 $lxdebug->leave_sub();
99 $lxdebug->enter_sub();
101 my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
104 $old_form = YAML::Load($old_form);
106 @{$form}{keys %{ $old_form } } = @{$old_form}{keys %{ $old_form } };
108 $form->{draft_id} = $id;
109 $form->{draft_description} = $description;
110 $form->{remove_draft} = 'checked';
115 $lxdebug->leave_sub();
119 $lxdebug->enter_sub();
122 foreach (keys %{$form}) {
123 push @ids, $1 if (/^checked_(.*)/ && $form->{$_});
125 Drafts->remove(\%myconfig, $form, @ids) if (@ids);
127 restore_form($form->{SAVED_FORM}, 1);
128 delete $form->{SAVED_FORM};
132 $lxdebug->leave_sub();
135 sub draft_action_dispatcher {
136 $lxdebug->enter_sub();
138 if ($form->{draft_action} eq $locale->text("Skip")) {
141 } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
145 $lxdebug->leave_sub();