Skip to content

Commit

Permalink
Item868: use JQueryPlugin to provide a much improved editing experience
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/ActionTrackerPlugin@10625 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jan 28, 2011
1 parent 177fedc commit 5869561
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 224 deletions.
7 changes: 1 addition & 6 deletions data/System/ActionTrackerPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ You can also override the default =EDITBOXWIDTH= and =EDITBOXHEIGHT= settings ju
| =ACTIONTRACKERPLUGIN_EDITBOXWIDTH= | =%EDITBOXWIDTH%= |
| =ACTIONTRACKERPLUGIN_EDITBOXHEIGHT= | =%EDITBOXHEIGHT%= |

If you prefer the action editor to use the same browser window to edit an action, or you don't have Javascript, set this to =0=. If set to 1 will edit an action in a separate browser window.

| *Preference* | *Default* |
| =ACTIONTRACKERPLUGIN_USENEWWINDOW= | =1= |

If you want the action editor to offer a 'Preview Changes' button, instead of the usual 'Save Changes', set this to =0=. If this is set, and =USENEWWINDOW= is =1=, the subwindow _should_ close on save, but it won't because I haven't worked out how to do this safely in Java<nop>Script.

| *Preference* | *Default* |
Expand Down Expand Up @@ -488,7 +483,7 @@ Thanks are due to the following sponsors, who have helped make this plugin possi
| Copyright | Copyright &copy; 2002-2003 Motorola. All Rights Reserved.%BR% Copyright &copy; 2004-2011 Crawford Currie |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Change History: | |
| 27 Jan 2011 | Foswiki:Tasks/Item8263: Merged Kent Dozier's enhancement for display of select-type fields. Foswiki:Tasks/Item10282: Ensure a link to a missing action gives a meaningful error. Foswiki:Tasks/Item9636: correct parsing of manually-entered dates to default to international standards. Foswiki:Tasks/Item8564: numeric-sort in columns containing numeric data. Foswiki:Tasks/Item10190: support plain-text output from ACTIONSEARCH |
| 27 Jan 2011 | Foswiki:Tasks/Item8263: Merged Kent Dozier's enhancement for display of select-type fields. Foswiki:Tasks/Item10282: Ensure a link to a missing action gives a meaningful error. Foswiki:Tasks/Item9636: correct parsing of manually-entered dates to default to international standards. Foswiki:Tasks/Item8564: numeric-sort in columns containing numeric data. Foswiki:Tasks/Item10190: support plain-text output from ACTIONSEARCH. Foswiki:Tasks/Item868: Use JQueryPlugin to streamline action editing (including refreshing the topic when an edited action is saved) |
| 04 Nov 2010 | Foswiki:Tasks/Item1187: Improved the fix for unwanted date changes when you create or edit an action. Now it should also work for servers west of Greenwich. |
| 03 Nov 2010 | Foswiki:Tasks/Item9083: Ensure there's at least one newline at the end of the topic text after an action edit, and always one empty line between topic content and meta; otherwise attachment meta-data may get eaten |
| 17 Oct 2010 | Foswiki:Tasks/Item9825: Update for Foswiki 1.1.0 compatibility. No other fixes in this revision |
Expand Down
148 changes: 59 additions & 89 deletions lib/Foswiki/Plugins/ActionTrackerPlugin.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Copyright (C) 2002 Motorola - All rights reserved
# Copyright (C) 2004-2009 Crawford Currie http://c-dot.co.uk
# Copyright (C) 2004-2011 Crawford Currie http://c-dot.co.uk
#
# Extension that adds tags for action tracking
#
Expand All @@ -27,24 +27,24 @@ use Foswiki::Plugins ();
our $VERSION = '$Rev$';
our $RELEASE = '04 Nov 2010';
our $SHORTDESCRIPTION =
'Adds support for action tags in topics, and automatic notification of action statuses';
'Adds support for action tags in topics, and automatic notification of action statuses';
our $initialised = 0;

my $doneHeader = 0;
my $actionNumber = 0;
my $defaultFormat;

# Map default options
my $options;
our $options;

sub initPlugin {

# COVERAGE OFF standard plugin code

if ( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning(
'Version mismatch between ActionTrackerPlugin and Plugins.pm $Foswiki::Plugins::VERSION. 1.026 required.'
);
'Version mismatch between ActionTrackerPlugin and Plugins.pm $Foswiki::Plugins::VERSION. 1.026 required.'
);
}

# COVERAGE ON
Expand All @@ -55,71 +55,55 @@ sub initPlugin {
Foswiki::Func::registerRESTHandler( 'update', \&_updateRESTHandler );

Foswiki::Func::registerTagHandler( 'ACTIONSEARCH', \&_handleActionSearch,
'context-free' );
'context-free' );

return 1;
}

sub _addCSSAndJS {
my $debug = '';
$debug = '_src' if DEBUG;

Foswiki::Func::addToHEAD( 'ACTIONTRACKERPLUGIN_CSS', <<HERE);
<link rel="stylesheet" href="$options->{CSS}" type="text/css" media="all" />
HERE
Foswiki::Func::addToHEAD( 'ACTIONTRACKERPLUGIN_JS', <<HERE);
<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/ActionTrackerPlugin/atp$debug.js'></script>
HERE
}

sub commonTagsHandler {
my ( $otext, $topic, $web, $meta ) = @_;

return unless ( $_[0] =~ m/%ACTION.*{.*}%/o );

return unless lazyInit( $web, $topic );

_addCSSAndJS();

# Format actions in the topic.
# Done this way so we get tables built up by
# collapsing successive actions.
my $as =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $web, $topic,
$otext, 1 );
my $as = Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load(
$web, $topic, $otext, 1 );
my $actionGroup;
my $text = '';

foreach my $entry ( @{ $as->{ACTIONS} } ) {
if ( ref($entry) ) {
if ( !$actionGroup ) {
$actionGroup =
new Foswiki::Plugins::ActionTrackerPlugin::ActionSet();
new Foswiki::Plugins::ActionTrackerPlugin::ActionSet();
}
$actionGroup->add($entry);
}
elsif ( $entry =~ /(\S|\n\s*\n)/s ) {
if ($actionGroup) {
$text .=
$actionGroup->formatAsHTML( $defaultFormat, 'name',
$options->{USENEWWINDOW}, 'atpDef' );
$actionGroup->formatAsHTML(
$defaultFormat, 'name', 'atpDef' );
$actionGroup = undef;
}
$text .= $entry;
}
}
if ($actionGroup) {
$text .=
$actionGroup->formatAsHTML( $defaultFormat, 'name',
$options->{USENEWWINDOW}, 'atpDef' );
$actionGroup->formatAsHTML( $defaultFormat, 'name', 'atpDef' );
}

$_[0] = $text;

# COVERAGE OFF debug only
if ( $options->{DEBUG} ) {
$_[0] =~
s/%ACTIONNOTIFICATIONS{(.*?)}%/_handleActionNotify($web, $1)/geo;
s/%ACTIONNOTIFICATIONS{(.*?)}%/_handleActionNotify($web, $1)/geo;
}

# COVERAGE ON
Expand Down Expand Up @@ -157,8 +141,8 @@ sub _beforeNormalEdit {
return unless lazyInit( $_[2], $_[1] );

my $as =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $_[2], $_[1],
$_[0], 1 );
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $_[2], $_[1],
$_[0], 1 );
$_[0] = $as->stringify();
}
}
Expand All @@ -183,13 +167,13 @@ sub _beforeActionEdit {
# as %TEXT%. This is done so we can use the standard template mechanism
# without screwing up the content of the subtemplate.
my $tmpl =
Foswiki::Func::readTemplate( 'actionform', Foswiki::Func::getSkin() );
Foswiki::Func::readTemplate( 'actionform', Foswiki::Func::getSkin() );

# Here we want to show the current time in same time format as the user
# sees elsewhere in his browser on Foswiki.
my $date =
Foswiki::Func::formatTime( time(), undef,
$Foswiki::cfg{DisplayTimeValues} );
Foswiki::Func::formatTime( time(), undef,
$Foswiki::cfg{DisplayTimeValues} );

die unless ($date);

Expand All @@ -208,13 +192,13 @@ sub _beforeActionEdit {
# write in hidden fields
if ($meta) {
$meta->forEachSelectedValue( qr/FIELD/, undef, \&_hiddenMeta,
{ text => \$fields } );
{ text => \$fields } );
}

# Find the action.
my $as =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $web, $topic,
$text, 1 );
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $web, $topic,
$text, 1 );

my ( $action, $pre, $post ) = $as->splitOnAction($uid);
# Make sure the action currently exists
Expand All @@ -233,30 +217,14 @@ sub _beforeActionEdit {

my $submitCmd = "preview";
my $submitCmdName = "Preview";
my $submitScript = "";
my $cancelScript = "";
my $submitCmdOpt = "";

if ( $options->{NOPREVIEW} ) {
$submitCmd = "save";
$submitCmdName = "Save";
$submitCmdOpt = "?unlock=on";
if ( $options->{USENEWWINDOW} ) {

# I'd like close the subwindow here, but not sure how. Like this,
# the ONCLICK overrides the ACTION and closes the window before
# the POST is done. All the various solutions I've found on the
# web do something like "wait x seconds" before closing the
# subwindow, but this seems very risky.
#$submitScript = "onclick=\"document.form.submit();window.close();return true\"";
}
}
if ( $options->{USENEWWINDOW} ) {
$cancelScript = "onclick=\"window.close();\"";
}

$tmpl =~ s/%CANCELSCRIPT%/$cancelScript/go;
$tmpl =~ s/%SUBMITSCRIPT%/$submitScript/go;
$tmpl =~ s/%SUBMITCMDNAME%/$submitCmdName/go;
$tmpl =~ s/%SUBMITCMDOPT%/$submitCmdOpt/go;
$tmpl =~ s/%SUBMITCOMMAND%/$submitCmd/go;
Expand All @@ -266,7 +234,7 @@ sub _beforeActionEdit {
$options->{EDITFORMAT},
$options->{EDITORIENT},
"", ""
);
);
my $editable = $action->formatForEdit($fmt);
$tmpl =~ s/%EDITFIELDS%/$editable/o;

Expand All @@ -286,9 +254,6 @@ sub _beforeActionEdit {

$_[0] = $tmpl;

# Add styles and javascript for the calendar
_addCSSAndJS();

use Foswiki::Contrib::JSCalendarContrib;
if ( $@ || !$Foswiki::Contrib::JSCalendarContrib::VERSION ) {
Foswiki::Func::writeWarning( 'JSCalendarContrib not found ' . $@ );
Expand Down Expand Up @@ -339,8 +304,8 @@ sub afterEditHandler {
}

my $action =
Foswiki::Plugins::ActionTrackerPlugin::Action::createFromQuery( $_[2],
$_[1], $an, $query );
Foswiki::Plugins::ActionTrackerPlugin::Action::createFromQuery( $_[2],
$_[1], $an, $query );

$action->populateMissingFields();

Expand Down Expand Up @@ -415,8 +380,8 @@ sub _addMissingAttributes {
my %seenUID;

my $as =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $_[2], $_[1],
$_[0], 1 );
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $_[2], $_[1],
$_[0], 1 );

foreach my $action ( @{ $as->{ACTIONS} } ) {
next unless ref($action);
Expand All @@ -442,8 +407,6 @@ sub _handleActionSearch {

return unless lazyInit( $web, $topic );

_addCSSAndJS();

# use default format unless overridden
my $fmt;
my $fmts = $attrs->remove('format');
Expand All @@ -458,23 +421,22 @@ sub _handleActionSearch {
$fmts = $defaultFormat->getFields() unless ( defined($fmts) );
$hdrs = $defaultFormat->getHeaders() unless ( defined($hdrs) );
$orient = $defaultFormat->getOrientation() unless ( defined($orient) );
$fmt = new Foswiki::Plugins::ActionTrackerPlugin::Format( $hdrs, $fmts,
$orient, $fmts, '' );
$fmt = new Foswiki::Plugins::ActionTrackerPlugin::Format(
$hdrs, $fmts, $orient, $fmts, '' );
}
else {
$fmt = $defaultFormat;
}

my $actions =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::allActionsInWebs( $web,
$attrs, 0 );
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::allActionsInWebs(
$web, $attrs, 0 );
$actions->sort( $sort, $reverse );
my $result;
if ($plain) {
$result = $actions->formatAsString( $fmt );
} else {
$result = $actions->formatAsHTML(
$fmt, 'href', $options->{USENEWWINDOW}, 'atpSearch' );
$result = $actions->formatAsHTML( $fmt, 'href', 'atpSearch' );
}
return $result;
}
Expand All @@ -485,27 +447,35 @@ sub lazyInit {

return 1 if $initialised;

eval {
require Foswiki::Attrs;
require Foswiki::Plugins::ActionTrackerPlugin::Options;
require Foswiki::Plugins::ActionTrackerPlugin::Action;
require Foswiki::Plugins::ActionTrackerPlugin::ActionSet;
require Foswiki::Plugins::ActionTrackerPlugin::Format;
};
if ($@) {
print STDERR "ActionTrackerPlugin: init failed $@\n";
Foswiki::Func::writeWarning("ActionTrackerPlugin: init failed $@");
return 0;
Foswiki::Plugins::JQueryPlugin::registerPlugin(
"ActionTracker",
'Foswiki::Plugins::ActionTrackerPlugin::JQuery');
unless( Foswiki::Plugins::JQueryPlugin::createPlugin(
"ActionTracker", $Foswiki::Plugins::SESSION )) {
die "Fucking POOF";
}

require Foswiki::Attrs;
require Foswiki::Plugins::ActionTrackerPlugin::Options;
require Foswiki::Plugins::ActionTrackerPlugin::Action;
require Foswiki::Plugins::ActionTrackerPlugin::ActionSet;
require Foswiki::Plugins::ActionTrackerPlugin::Format;

$options =
Foswiki::Plugins::ActionTrackerPlugin::Options::load( $web, $topic );
Foswiki::Plugins::ActionTrackerPlugin::Options::load( $web, $topic );

# Add the ATP CSS (conditionally included from $options, which is why
# it's not done in the JQuery plugin decl)
my $src = (DEBUG) ? '_src' : '';
Foswiki::Func::addToZone("head", "JQUERYPLUGIN::ActionTracker::CSS", <<"HERE");
<link rel='stylesheet' href='$Foswiki::Plugins::ActionTrackerPlugin::options->{CSS}' type='text/css' media='all' />
HERE

$defaultFormat = new Foswiki::Plugins::ActionTrackerPlugin::Format(
$options->{TABLEHEADER}, $options->{TABLEFORMAT},
$options->{TABLEORIENT}, $options->{TEXTFORMAT},
$options->{NOTIFYCHANGES}
);
);

if ( $options->{EXTRAS} ) {
my $e = Foswiki::Plugins::ActionTrackerPlugin::Action::extendTypes(
Expand Down Expand Up @@ -538,8 +508,8 @@ sub _handleActionNotify {
}

my $text =
Foswiki::Plugins::ActionTrackerPlugin::ActionNotify::doNotifications(
$web, $expr, 1 );
Foswiki::Plugins::ActionTrackerPlugin::ActionNotify::doNotifications(
$web, $expr, 1 );

$text =~ s/<html>/<\/pre>/gios;
$text =~ s/<\/html>/<pre>/gios;
Expand All @@ -556,10 +526,10 @@ sub _updateRESTHandler {
my $topic = $query->param('topic');
my $web;
( $web, $topic ) =
Foswiki::Func::normalizeWebTopicName( undef, $topic );
Foswiki::Func::normalizeWebTopicName( undef, $topic );
lazyInit( $web, $topic );
_updateSingleAction( $web, $topic, $query->param('uid'),
$query->param('field') => $query->param('value') );
$query->param('field') => $query->param('value') );
print CGI::header( 'text/plain', 200 ); # simple message
}
catch Error::Simple with {
Expand Down Expand Up @@ -588,8 +558,8 @@ sub _updateSingleAction {
my %seenUID;

my $as =
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $web, $topic,
$text, 1 );
Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $web, $topic,
$text, 1 );

foreach my $action ( @{ $as->{ACTIONS} } ) {
if ( ref($action) ) {
Expand All @@ -601,7 +571,7 @@ sub _updateSingleAction {
}
}
Foswiki::Func::saveTopic( $web, $topic, $meta, $as->stringify(),
{ comment => 'atp save' } );
{ comment => 'atp save' } );
}

1;
Loading

0 comments on commit 5869561

Please sign in to comment.