[interchange-cvs] interchange - heins modified 3 files
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Sun Dec 2 10:45:04 EST 2007
User: heins
Date: 2007-12-02 15:45:04 GMT
Modified: lib/Vend Config.pm Form.pm
Added: code/Widget ynzero.widget
Log:
* Add ability to set attrDefault for the Widget codedef type, which
then transmits that to the opt hash prior to widget routine call.
* Add new ynzero widget, which does a 1/0 yes/no for integer type
fields. Uses the new attrDefault capability.
Revision Changes Path
1.1 interchange/code/Widget/ynzero.widget
rev 1.1, prev_rev 1.0
Index: ynzero.widget
===================================================================
# Copyright 2005-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: ynzero.widget,v 1.1 2007/12/02 15:45:04 mheins Exp $
CodeDef ynzero Widget 1
CodeDef ynzero attrDefault no_value 0
CodeDef ynzero Description Yes/No (Yes=1, No=0 -- default=No)
CodeDef ynzero MapRoutine Vend::Form::yesno
2.227 +27 -5 interchange/lib/Vend/Config.pm
rev 2.227, prev_rev 2.226
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.226
retrieving revision 2.227
diff -u -r2.226 -r2.227
--- Config.pm 2 Dec 2007 13:40:32 -0000 2.226
+++ Config.pm 2 Dec 2007 15:45:04 -0000 2.227
@@ -1,6 +1,6 @@
# Vend::Config - Configure Interchange
#
-# $Id: Config.pm,v 2.226 2007/12/02 13:40:32 mheins Exp $
+# $Id: Config.pm,v 2.227 2007/12/02 15:45:04 mheins Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -54,7 +54,7 @@
use Vend::Data;
use Vend::Cron;
-$VERSION = substr(q$Revision: 2.226 $, 10);
+$VERSION = substr(q$Revision: 2.227 $, 10);
my %CDname;
my %CPname;
@@ -4768,9 +4768,9 @@
}
sub map_widgets {
- my $ref;
- my $return = ($ref = $Vend::Cfg->{CodeDef}{Widget})
- ? $ref->{Routine}
+ my $gref;
+ my $return = ($gref = $Vend::Cfg->{CodeDef}{Widget})
+ ? $gref->{Routine}
: {};
if(my $ref = $Global::CodeDef->{Widget}{Routine}) {
while ( my ($k, $v) = each %$ref) {
@@ -4785,6 +4785,27 @@
$return->{$k} = \&{"$v"};
}
}
+ if(my $ref = $Global::CodeDef->{Widget}{attrDefault}) {
+ no strict 'refs';
+ while ( my ($k, $v) = each %$ref) {
+ next if $return->{$k};
+ $return->{$k} = \&{"$v"};
+ }
+ }
+ return $return;
+}
+
+sub map_widget_defaults {
+ my $gref;
+ my $return = ($gref = $Vend::Cfg->{CodeDef}{Widget})
+ ? $gref->{attrDefault}
+ : {};
+ if(my $ref = $Global::CodeDef->{Widget}{attrDefault}) {
+ while ( my ($k, $v) = each %$ref) {
+ next if $return->{$k};
+ $return->{$k} = $v;
+ }
+ }
return $return;
}
@@ -4860,6 +4881,7 @@
Widget => sub {
return unless $Vend::Cfg;
$Vend::UserWidget = map_widgets();
+ $Vend::UserWidgetDefault = map_widget_defaults();
},
UserTag => sub {
return if $C;
2.73 +17 -5 interchange/lib/Vend/Form.pm
rev 2.73, prev_rev 2.72
Index: Form.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Form.pm,v
retrieving revision 2.72
retrieving revision 2.73
diff -u -r2.72 -r2.73
--- Form.pm 9 Nov 2007 03:08:31 -0000 2.72
+++ Form.pm 2 Dec 2007 15:45:04 -0000 2.73
@@ -1,6 +1,6 @@
# Vend::Form - Generate Form widgets
#
-# $Id: Form.pm,v 2.72 2007/11/09 03:08:31 pajamian Exp $
+# $Id: Form.pm,v 2.73 2007/12/02 15:45:04 mheins Exp $
#
# Copyright (C) 2002-2007 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -39,7 +39,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.72 $, 10);
+$VERSION = substr(q$Revision: 2.73 $, 10);
@EXPORT = qw (
display
@@ -863,15 +863,19 @@
sub yesno {
my $opt = shift;
$opt->{value} = is_yes($opt->{value});
+ my $yes = defined $opt->{yes_value} ? $opt->{yes_value} : 1;
+ my $no = defined $opt->{no_value} ? $opt->{no_value} : '';
+ my $yes_title = defined $opt->{yes_title} ? $opt->{yes_title} : errmsg('Yes');
+ my $no_title = defined $opt->{no_title} ? $opt->{no_title} : errmsg('No');
my @opts;
my $routine = $opt->{subwidget} || \&dropdown;
if($opt->{variant} eq 'checkbox') {
- @opts = [1, ' '];
+ @opts = [$yes, ' '];
}
else {
@opts = (
- ['', errmsg('No')],
- ['1', errmsg('Yes')],
+ [$no, $no_title],
+ [$yes, $yes_title],
);
}
return $routine->($opt, \@opts);
@@ -1338,6 +1342,7 @@
# Optimization for large lists, we cache the widgets
$Vend::UserWidget ||= Vend::Config::map_widgets();
+ $Vend::UserWidgetDefault ||= Vend::Config::map_widget_defaults();
my $sub = $Vend::UserWidget->{$type};
if(! $sub and $Global::AccumulateCode) {
@@ -1347,6 +1352,13 @@
# Last in case "default" widget is removed
$sub ||= $Vend::UserWidget->{default} || \&template_sub;
+
+ if(my $attr = $Vend::UserWidgetDefault->{$type}) {
+ while (my ($k, $v) = each %$attr) {
+ next if defined $opt->{$k};
+ $opt->{$k} = $v;
+ }
+ }
if($opt->{variant}) {
#::logDebug("variant='$opt->{variant}'");
More information about the interchange-cvs
mailing list