diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-01-24 00:48:47 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-01-24 00:48:47 +0000 |
commit | 029c34a8754728e0f1622ea56ac112941226ebd3 (patch) | |
tree | eab03dc6678e4bfcc38b54288807f4ef04ff6058 | |
parent | 67426720ad198d5689825c4173b68dad6cab75df (diff) | |
download | reaction-029c34a8754728e0f1622ea56ac112941226ebd3.tar.gz reaction-029c34a8754728e0f1622ea56ac112941226ebd3.zip |
basic is_modified support
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm | 5 | ||||
-rw-r--r-- | lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm | 12 | ||||
-rw-r--r-- | lib/Reaction/UI/ViewPort/Object/Mutable.pm | 8 |
3 files changed, 25 insertions, 0 deletions
diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm index f1704ad..59a97ad 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm @@ -18,6 +18,11 @@ has needs_sync => (is => 'rw', isa => 'Int', default => 0); has message => (is => 'rw', isa => 'Str', clearer => 'clear_message'); +has is_modified => ( + is => 'ro', writer => '_set_modified', + required => 1, default => 1, init_arg => undef +); + after clear_value => sub { my $self = shift; $self->clear_message if $self->has_message; diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm index e41f264..e19fa61 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm @@ -12,9 +12,21 @@ has value_string => ( clearer => 'clear_value', ); +has '+is_modified' => (default => 0); + around value_string => sub { my $orig = shift; my $self = shift; + if (@_) { + # recursive call. be VERY careful we don't go infinite here + my $old = $self->value_string; + my $new = $_[0]; + if ((defined $old xor defined $new) || (defined $old && $old ne $new)) { + $self->_set_modified(1); + } else { + return; + } + } if (@_ && defined($_[0]) && !ref($_[0]) && $_[0] eq '' && !$self->value_is_required) { $self->clear_value; diff --git a/lib/Reaction/UI/ViewPort/Object/Mutable.pm b/lib/Reaction/UI/ViewPort/Object/Mutable.pm index 797f8c6..e58f1b4 100644 --- a/lib/Reaction/UI/ViewPort/Object/Mutable.pm +++ b/lib/Reaction/UI/ViewPort/Object/Mutable.pm @@ -25,6 +25,14 @@ has model => ( required => 1, ); +sub is_modified { + my $self = shift; + foreach my $field (@{$self->fields}) { + return 1 if $field->is_modified; + } + return 0; +} + sub _build_fields_for_type_Num { my ($self, $attr, $args) = @_; $self->_build_simple_field(attribute => $attr, class => Number, %$args); |