| 1 | package WWW::Garden::Design::Controller::Design; | ||
| 2 | |||
| 3 | use Mojo::Base 'Mojolicious::Controller'; | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | |||
| 7 | use WWW::Garden::Design::Util::ValidateForm | ||
| 8 | |||
| 9 | our $VERSION = '0.97'; | ||
| 10 | |||
| 11 | # ----------------------------------------------- | ||
| 12 | |||
| 13 | sub format_details | ||
| 14 | { | ||
| 15 | my($self, $item) = @_; | ||
| 16 | |||
| 17 | $self -> app -> log -> debug('Details.format_details(...)'); | ||
| 18 | |||
| 19 | my($html) = "<tr>\n"; | ||
| 20 | |||
| 21 | for my $name (qw/property_name garden_name/) | ||
| 22 | { | ||
| 23 | $html .= "<td class = 'generic_border'>$$item{$name}</td>\n"; | ||
| 24 | } | ||
| 25 | |||
| 26 | $html .= "</tr>\n"; | ||
| 27 | |||
| 28 | return $html; | ||
| 29 | |||
| 30 | } # End of format_details. | ||
| 31 | |||
| 32 | # ----------------------------------------------- | ||
| 33 | |||
| 34 | sub format_errors | ||
| 35 | { | ||
| 36 | my($self, $params) = @_; | ||
| 37 | |||
| 38 | $self -> app -> log -> debug('Details.format_errors(...)'); | ||
| 39 | |||
| 40 | my($html) = ''; | ||
| 41 | |||
| 42 | my($errors); | ||
| 43 | |||
| 44 | for my $name (sort keys %{$$params{errors} }) | ||
| 45 | { | ||
| 46 | $errors = $$params{errors}{$name}; | ||
| 47 | $html .= <<EOS; | ||
| 48 | <tr> | ||
| 49 | <td class = 'generic_border'>$name</td> | ||
| 50 | <td class = 'generic_border'>$$errors[0]</td> | ||
| 51 | <td class = 'generic_border'>$$errors[1]</td> | ||
| 52 | <td class = 'generic_border'>$$errors[2]</td> | ||
| 53 | </tr> | ||
| 54 | EOS | ||
| 55 | } | ||
| 56 | |||
| 57 | return $html; | ||
| 58 | |||
| 59 | } # End of format_errors. | ||
| 60 | |||
| 61 | # ----------------------------------------------- | ||
| 62 | |||
| 63 | sub process | ||
| 64 | { | ||
| 65 | my($self) = @_; | ||
| 66 | |||
| 67 | $self -> app -> log -> debug('Design.process()'); | ||
| 68 | |||
| 69 | my($defaults) = $self -> app -> defaults; | ||
| 70 | my($validator) = WWW::Garden::Design::Util::ValidateForm -> new; | ||
| 71 | my($params) = $validator -> design_details($self, $defaults); | ||
| 72 | |||
| 73 | if ($$params{success}) | ||
| 74 | { | ||
| 75 | # $$defaults{db} -> add_design($params); | ||
| 76 | |||
| 77 | $self -> stash(error => undef); | ||
| 78 | $self -> stash(details => $self -> format_details($params) ); | ||
| 79 | $self -> stash(message => $$params{message}); | ||
| 80 | } | ||
| 81 | else | ||
| 82 | { | ||
| 83 | $self -> stash(error => $self -> format_errors($params) ); | ||
| 84 | $self -> stash(details => undef); | ||
| 85 | $self -> stash(message => $$params{message}); | ||
| 86 | $self -> app -> log -> error($$params{message}); | ||
| 87 | } | ||
| 88 | |||
| 89 | $self -> render; | ||
| 90 | |||
| 91 | } # End of process. | ||
| 92 | |||
| 93 | # ----------------------------------------------- | ||
| 94 | |||
| 95 | 1; | ||
| 96 | |||
| 97 | =pod | ||
| 98 | |||
| 99 | =head1 NAME | ||
| 100 | |||
| 101 | WWW::Garden::Design::Controller::Design - Manage the 'flowers' database | ||
| 102 | |||
| 103 | =head1 Machine-Readable Change Log | ||
| 104 | |||
| 105 | The file Changes was converted into Changelog.ini by L<Module::Metadata::Changes>. | ||
| 106 | |||
| 107 | =head1 Version Numbers | ||
| 108 | |||
| 109 | Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. | ||
| 110 | |||
| 111 | =head1 Repository | ||
| 112 | |||
| 113 | L<https://github.com/ronsavage/WWW-Garden-Design> | ||
| 114 | |||
| 115 | =head1 Support | ||
| 116 | |||
| 117 | Email the author, or log a bug on RT: | ||
| 118 | |||
| 119 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=WWW::Garden::Design>. | ||
| 120 | |||
| 121 | =head1 Author | ||
| 122 | |||
| 123 | L<WWW::Garden::Design> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2014. | ||
| 124 | |||
| 125 | My homepage: L<https://savage.net.au/>. | ||
| 126 | |||
| 127 | =head1 Copyright | ||
| 128 | |||
| 129 | Australian copyright (c) 2018, Ron Savage. | ||
| 130 | |||
| 131 | All Programs of mine are 'OSI Certified Open Source Software'; | ||
| 132 | you can redistribute them and/or modify them under the terms of | ||
| 133 | The Perl License, a copy of which is available at: | ||
| 134 | http://dev.perl.org/licenses/ | ||
| 135 | |||
| 136 | =cut |