Item8263: Extension to allow custom drop-down boxes with automatic updates when changed

pencil
Priority: Enhancement
Current State: Closed
Released In: n/a
Target Release:
Applies To: Extension
Component: ActionTrackerPlugin
Branches:
Reported By: Foswiki:Main.KentDozier
Waiting For:
Last Change By: CrawfordCurrie
(Copied from (tm)wiki.org by CrawfordCurrie - 03 Sep 2009)

I extended the action tracker plugin to allow all select boxes to be able to use the "state shortcut". With this added subroutine, one can create a custom select box with a set number of choices. The select box will be shown properly in all forms, with a fully populated dropdown, instead of just the text (which is the prior behavior). Also, the state shortcut is utilized so that when the user selects another value from the dropdown, it gets updated automatically just like when the user changes the state from open to closed.

I used the parameter that allows the state shortcut to determine whether or not to allow the select box shortcut. This could be extended to have its own parameter, but for my purposes it was sufficient.

The patch is:

--- lib/TWiki/Plugins/ActionTrackerPlugin/Action.pm.beforekent   2008-10-23 23:17:04.000000000 -0700
+++ lib/TWiki/Plugins/ActionTrackerPlugin/Action.pm   2009-08-17 17:32:29.000000000 -0700
@@ -634,6 +634,51 @@
     return formatTime( $this->{$fld}, 'string' );
 }
 
+# PRIVATE format the given select box type
+sub _formatType_select {
+    my ( $this, $fld, $args, $asHTML ) = @_;
+
+    # Old behavior is to simply return the text as usual.
+    # Do this anyway if the state field isn't being allowed
+    # to edit on the fly without going to edit mode.
+    require TWiki::Plugins::ActionTrackerPlugin::Options;
+    unless ($TWiki::Plugins::ActionTrackerPlugin::Options::options{ENABLESTATESHORTCUT}) {
+      return (defined $this->{$fld}) ? $this->{$fld} : '';
+    }
+
+    # Turn the select into a fully populated drop down box
+    my $type = $this->getType( $fld );
+    my $size = $type->{size};
+    my $fields = '';
+    my $any_selected = 0;
+    foreach my $option ( @{$type->{values}} ) {
+      my @extras = ();
+      if ( defined( $this->{$fld} ) &&
+      $this->{$fld} eq $option ) {
+   push( @extras, selected => "selected" );
+   $any_selected = 1;
+      }
+      $fields .= CGI::option({ value=>$option, @extras }, $option);
+    }
+
+    # If nothing was selected, add an empty selection at the top
+    # That way, it can display a blank box, but can be changed.
+    # Ones with a value already can not be changed to blank.
+    if (!$any_selected) {
+      $fields = CGI::option({ value=>"NuLL", selected=>"selected" }, "") . $fields;
+    }
+
+    return CGI::Select(
+    { name => $fld,
+      size => $size,
+      onChange => 'atp_update(this, "%SCRIPTURLPATH{rest}%/ActionTrackerPlugin/update?topic='.
+        $this->{web}.'.'.$this->{topic}.
+        ';uid='.$this->{uid}.'", "' . $fld . '")',
+    },
+    $fields );
+
+}
+
 sub _formatField_formfield {
     my ( $this, $args, $asHTML ) = @_;
 

Added. Thanks, Kent!

-- CrawfordCurrie - 27 Jan 2011

 

ItemTemplate edit

Summary Extension to allow custom drop-down boxes with automatic updates when changed
ReportedBy Foswiki:Main.KentDozier
Codebase
SVN Range Foswiki-1.0.0, Thu, 08 Jan 2009, build 1878
AppliesTo Extension
Component ActionTrackerPlugin
Priority Enhancement
CurrentState Closed
WaitingFor
Checkins ActionTrackerPlugin:dee1e84a583f
ReleasedIn n/a
Topic revision: r4 - 27 Jan 2011, CrawfordCurrie - This page was cached on 17 Sep 2021 - 15:14.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy