Gtk2-Ex-DbLinker-DbTools

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/DbLinker/AbForm.pm  view on Meta::CPAN

    if ( $states{ $id}->{auto_apply} && $self->has_changed ) { $self->apply; }
    $self->_display_data( $dman{ $id }->first );
}

sub last {
    my $self = shift;
    my $id = id $self;
    if ( $states{ $id }->{auto_apply} && $self->has_changed ) { $self->apply; }
    $self->_display_data( $dman{ $id }->last );
}

sub _save_subforms {
    my ($self) = @_;
    my $id = id $self;
    return unless ( $states{$id }->{auto_apply} );
    foreach my $sf ( @{ $widgets{ $id }->{subform} } ) {
        $sf->apply if ( $sf->has_changed );
    }

}

sub set_widget_value {
    my ( $self, $wid, $x ) = @_;
    my $id = id $self;
    $log{ $id }->debug(
        "set_widget_value: " . $wid . " to " . ( defined $x ? $x : "null" ) );
    my $w = $widgets{ $id }->{builder}->get_object($wid);
    if ($w) {

        my %setter  = $child_class{ $id }->_get_setter;
        my $coderef = $setter{ $widgets{ $id }->{datawidgetsName}->{$wid} };

        #$wid used only by wxform
        &$coderef( $self, $w, $x, $wid );
    }

}

sub get_widget_value {
    my ( $self, $wid ) = @_;
    my $id = id $self;
    my $x;
    $log{ $id }->debug( "get_widget_value: " . $wid );
    my $w = $widgets{ $id }->{builder}->get_object($wid);
    $log{ $id }->debug("no widget found") unless ($w);
    if ( $w && $widgets{ $id }->{datawidgetsName} ) {
        my %getter  = $child_class{ $id }->_get_getter;
        my $coderef = $getter{ $widgets{ $id }->{datawidgetsName}->{$wid} };
        $x = &$coderef( $self, $w, $wid );
    }
    $log{ $id }->debug( "found: " . ( $x ? $x : " undef" ) );
    return ( $x ? $x : "" );
}

=head2 C<update()>

Reflect in the user interface the changes made after the data manager has been queried, or on the form creation

=cut

sub update {
    my ($self) = @_;
    my $id = id $self;
    my @col = $dman{ $id }->get_field_names;
    $log{ $id }->debug(
        "update cols are " . ( @col ? join( " ", @col ) : " cols undef " ) );
    my $pos;
    if ( $dman{ $id }->row_count > 0 ) {

        #$self->{rec_spinner}->set_value(1) if ($self->{rec_spinner});
        $pos = 0;

    } else {
        $pos = -1;
    }
    $self->_display_data($pos);
    my $first = ( $pos < 0 ? 0 : 1 );
    $self->_set_rs_range( $first, $dman{ $id }->row_count );
    my $coderef = $events{ $id }->{rec_spinner_callback};
    &$coderef($self);
}

#parameter $in_db is 0 or 1 :
# 0 we are reading from the db, and the format to use are at the pos 0 and 1 in the array of format for the field
# 1 we are writing to the db and the format are to use in a revers order
# $id is the field id
# $v the date string from the form (if in_db is 1) or from the db (if in_db is 0)
sub _format_date {
    my ( $self, $in_db, $idcol, $v ) = @_;
    my $id = id $self;
    $log{ $id }->debug( "format_date received date: " . $v );
    my ( $pos1, $pos2 ) = ( $in_db ? ( 1, 0 ) : ( 0, 1 ) );
    my $format = $widgets{ $id }->{date_formatters}->{$idcol}->[$pos1];
    my $f      = $self->_get_dateformatter($format);
    #my $dt     = $f->parse_datetime($v) or $log{ $id }->logcroak( $f->errmsg );
    my $dt     = $f->parse_datetime($v) or croak($log{ $id }->error( $f->errmsg ));
    $log{ $id }->debug( "format_date:  date time object ymd: " . $dt->ymd );
    $format = $widgets{ $id }->{date_formatters}->{$idcol}->[$pos2];
    $f      = $self->_get_dateformatter($format);
    # my $r = $f->format_datetime($dt) or $log{ $id }->logcroak( $f->errmsg );
     my $r = $f->format_datetime($dt) or croak($log{ $id }->error( $f->errmsg ));
    $log{ $id }->debug( "format_date formatted date: " . $r );

    return $r;

}

# create a formatter if none is found in the hash for the corresponding formatting string and store it for later use, and return it or
# return an existing formatter
sub _get_dateformatter {
    my ( $self, $format ) = @_;
    my $id = id $self;
    my %hf = %{ $widgets{ $id }->{dates_formatters} };
    my $f;
    if ( exists $hf{$format} ) {
        $log{ $id }->debug(
            "get_dateformatter : return an existing formatter for " . $format );
        $f = $hf{$format};
    } else {
        $log{ $id }
          ->debug( "get_dateformatter: new formatter for " . $format );



( run in 1.454 second using v1.01-cache-2.11-cpan-39bf76dae61 )