fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2012-02-10 05:01 am

[dw-free] Labels on /admin/eventoutput form fields are not helpful

[commit: http://hg.dwscoalition.org/dw-free/rev/e4135c489702]

http://bugs.dwscoalition.org/show_bug.cgi?id=4330

Make the form field labels specific to each event type.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/Controller/EventOutput.pm
  • cgi-bin/LJ/Event.pm
  • cgi-bin/LJ/Event/AddedToCircle.pm
  • cgi-bin/LJ/Event/Birthday.pm
  • cgi-bin/LJ/Event/CommunityInvite.pm
  • cgi-bin/LJ/Event/CommunityJoinApprove.pm
  • cgi-bin/LJ/Event/CommunityJoinReject.pm
  • cgi-bin/LJ/Event/CommunityJoinRequest.pm
  • cgi-bin/LJ/Event/ImportStatus.pm
  • cgi-bin/LJ/Event/InvitedFriendJoins.pm
  • cgi-bin/LJ/Event/JournalNewComment.pm
  • cgi-bin/LJ/Event/JournalNewEntry.pm
  • cgi-bin/LJ/Event/NewUserpic.pm
  • cgi-bin/LJ/Event/OfficialPost.pm
  • cgi-bin/LJ/Event/PollVote.pm
  • cgi-bin/LJ/Event/RemovedFromCircle.pm
  • cgi-bin/LJ/Event/SecurityAttributeChanged.pm
  • cgi-bin/LJ/Event/UserExpunged.pm
  • cgi-bin/LJ/Event/UserMessageRecvd.pm
  • cgi-bin/LJ/Event/UserMessageSent.pm
  • cgi-bin/LJ/Event/VgiftApproved.pm
  • cgi-bin/LJ/Event/XPostFailure.pm
  • cgi-bin/LJ/Event/XPostSuccess.pm
  • htdocs/stc/simple-form.css
  • views/admin/eventoutput-select.tt
  • views/admin/eventoutput-select.tt.text
--------------------------------------------------------------------------------
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/DW/Controller/EventOutput.pm
--- a/cgi-bin/DW/Controller/EventOutput.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/DW/Controller/EventOutput.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -45,15 +45,21 @@
     return $rv unless $ok;
 
     if ( $r->method eq "POST" ) {
-        return handle_post( %{ DW::Request->get->post_args } );
+        return handle_post( %{ $r->post_args } );
     } else {
-        my @event_classes = map { 
-                { id    => LJ::Event->event_to_etypeid( $_ ),
-                  name => $_ 
-                }
-            } sort LJ::Event->all_classes;
+        my $get = $r->get_args;
+
+        my @event_classes = map { $_ => $_ } sort LJ::Event->all_classes;
+        my %event_map = @event_classes;
+
+        my $event = LJ::trim( $get->{event} );
+        $event = undef unless $event_map{$event};
+
         my $vars = {
             eventtypes => \@event_classes,
+
+            event      => $event,
+            eventargs  => $event ? [ $event->arg_list ] : undef,
         };
         return DW::Template->render_template( 'admin/eventoutput-select.tt', $vars );
     }
@@ -65,7 +71,8 @@
     return error_ml( "error.invalidform" ) unless LJ::check_form_auth( $post{lj_form_auth} );
 
     my $ju = LJ::load_user( $post{eventuser} );
-    my $event = LJ::Event->new_from_raw_params( $post{eventtype}, $ju ? $ju->userid : 0, $post{arg1}, $post{arg2} );
+    my $eventtype = LJ::Event->event_to_etypeid( $post{event} );
+    my $event = LJ::Event->new_from_raw_params( $eventtype, $ju ? $ju->userid : 0, $post{arg1}, $post{arg2} );
 
     my $u = LJ::load_user( $post{subscr_user} );
 
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event.pm
--- a/cgi-bin/LJ/Event.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -68,6 +68,10 @@
     }, $class;
 }
 
+sub arg_list {
+    return ( "Arg 1", "Arg 2" );
+}
+
 # Class method
 sub new_from_raw_params {
     my (undef, $etypeid, $journalid, $arg1, $arg2) = @_;
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/AddedToCircle.pm
--- a/cgi-bin/LJ/Event/AddedToCircle.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/AddedToCircle.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -33,6 +33,10 @@
     return $class->SUPER::new( $u, $fromu->id, $actionid );
 }
 
+sub arg_list {
+    return ( "From userid", "Action (1=T,2=W)" );
+}
+
 sub is_common { 0 }
 
 my @_ml_strings_en = qw(
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/Birthday.pm
--- a/cgi-bin/LJ/Event/Birthday.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/Birthday.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,10 @@
     return $class->SUPER::new($u);
 }
 
+sub arg_list {
+    return ();
+}
+
 sub bdayuser {
     my $self = shift;
     return $self->event_journal;
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/CommunityInvite.pm
--- a/cgi-bin/LJ/Event/CommunityInvite.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/CommunityInvite.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -26,6 +26,10 @@
     return $class->SUPER::new($u, $fromu->{userid}, $commu->{userid});
 }
 
+sub arg_list {
+    return ( "From userid", "Comm userid" );
+}
+
 sub is_common { 0 }
 
 my @_ml_strings = (
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/CommunityJoinApprove.pm
--- a/cgi-bin/LJ/Event/CommunityJoinApprove.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/CommunityJoinApprove.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,11 @@
     return $class->SUPER::new($u, $cu->{userid});
 }
 
+sub arg_list {
+    return ( "Comm userid" );
+}
+
+
 sub is_common { 1 } # As seen in LJ/Event.pm, event fired without subscription
 
 # Override this with a false value make subscriptions to this event not show up in normal UI
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/CommunityJoinReject.pm
--- a/cgi-bin/LJ/Event/CommunityJoinReject.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/CommunityJoinReject.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,11 @@
     return $class->SUPER::new($u, $cu->{userid});
 }
 
+sub arg_list {
+    return ( "Comm userid" );
+}
+
+
 sub is_common { 1 } # As seen in LJ/Event.pm, event fired without subscription
 
 # Override this with a false value make subscriptions to this event not show up in normal UI
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/CommunityJoinRequest.pm
--- a/cgi-bin/LJ/Event/CommunityJoinRequest.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/CommunityJoinRequest.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -28,6 +28,10 @@
     return $class->SUPER::new($u, $requestor->{userid}, $comm->{userid});
 }
 
+sub arg_list {
+    return ( "Requestor userid", "Comm userid" );
+}
+
 sub is_common { 0 }
 
 sub comm {
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/ImportStatus.pm
--- a/cgi-bin/LJ/Event/ImportStatus.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/ImportStatus.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -61,6 +61,11 @@
     return undef;
 }
 
+sub arg_list {
+    return ( "Type id", "Import status id" );
+}
+
+
 # always subscribed, you can't unsubscribe, send to everybody, and don't
 # give the user any options.  (we assume that if they're importing things,
 # they want to know how it went.)
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/InvitedFriendJoins.pm
--- a/cgi-bin/LJ/Event/InvitedFriendJoins.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/InvitedFriendJoins.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -25,6 +25,10 @@
     return $class->SUPER::new($u, $friendu->{userid});
 }
 
+sub arg_list {
+    return ( "Friend userid" );
+}
+
 sub is_common { 0 }
 
 my @_ml_strings = (
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/JournalNewComment.pm
--- a/cgi-bin/LJ/Event/JournalNewComment.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/JournalNewComment.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -28,6 +28,10 @@
     return $class->SUPER::new($comment->journal, $comment->jtalkid);
 }
 
+sub arg_list {
+    return ( "Comment jtalkid" );
+}
+
 sub related_events {
     return map { $_->etypeid } ( $_[0], "LJ::Event::JournalNewComment::TopLevel", "LJ::Event::JournalNewComment::Edited" );
 }
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/JournalNewEntry.pm
--- a/cgi-bin/LJ/Event/JournalNewEntry.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/JournalNewEntry.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -28,6 +28,10 @@
     return $class->SUPER::new($entry->journal, $entry->ditemid);
 }
 
+sub arg_list {
+    return ( "Entry ditemid" );
+}
+
 sub is_common { 1 }
 
 sub entry {
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/NewUserpic.pm
--- a/cgi-bin/LJ/Event/NewUserpic.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/NewUserpic.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,10 @@
     return $class->SUPER::new($up->owner, $up->id);
 }
 
+sub arg_list {
+    return ( "Icon id" );
+}
+
 sub as_string {
     my $self = shift;
 
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/OfficialPost.pm
--- a/cgi-bin/LJ/Event/OfficialPost.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/OfficialPost.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,10 @@
     return $class->SUPER::new($entry->journal, $entry->ditemid);
 }
 
+sub arg_list {
+    return ( "Entry ditemid" );
+}
+
 sub entry {
     my $self = shift;
     my $ditemid = $self->arg1;
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/PollVote.pm
--- a/cgi-bin/LJ/Event/PollVote.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/PollVote.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -30,6 +30,10 @@
     return $class->SUPER::new($owner, $voter->userid, $poll->id);
 }
 
+sub arg_list {
+    return ( "Voter userid", "Poll id" );
+}
+
 sub matches_filter {
     my $self = shift;
 
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/RemovedFromCircle.pm
--- a/cgi-bin/LJ/Event/RemovedFromCircle.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/RemovedFromCircle.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -33,6 +33,10 @@
     return $class->SUPER::new( $u, $fromu->id, $actionid );
 }
 
+sub arg_list {
+    return ( "From userid", "Action (1=T,2=W)" );
+}
+
 sub is_common { 0 }
 
 my @_ml_strings_en = qw(
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/SecurityAttributeChanged.pm
--- a/cgi-bin/LJ/Event/SecurityAttributeChanged.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/SecurityAttributeChanged.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -113,6 +113,10 @@
         $class->SUPER::new($u,$action,$actions{$opts->{action}}[1]->($u,$action,$opts));
 }
 
+sub arg_list {
+    return ( "Action", "(depends on action)" );
+}
+
 sub is_common { 1 } # As seen in LJ/Event.pm, event fired without subscription
 
 # Override this with a false value make subscriptions to this event not show up in normal UI
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/UserExpunged.pm
--- a/cgi-bin/LJ/Event/UserExpunged.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/UserExpunged.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -23,6 +23,10 @@
     return $class->SUPER::new($u);
 }
 
+sub arg_list {
+    return ();
+}
+
 sub as_string {
     my $self = shift;
     return $self->event_journal->display_username . " has been purged.";
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/UserMessageRecvd.pm
--- a/cgi-bin/LJ/Event/UserMessageRecvd.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/UserMessageRecvd.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -27,6 +27,10 @@
     return $class->SUPER::new($u, $msgid, $other_u->{userid});
 }
 
+sub arg_list {
+    return ( "Message id", "Sender userid" );
+}
+
 sub is_common { 1 }
 
 sub as_email_subject {
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/UserMessageSent.pm
--- a/cgi-bin/LJ/Event/UserMessageSent.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/UserMessageSent.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -27,6 +27,10 @@
     return $class->SUPER::new($u, $msgid, $other_u->{userid});
 }
 
+sub arg_list {
+    return ( "Message id", "Recipient userid" );
+}
+
 # TODO Should this return 1?
 sub is_common { 1 }
 
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/VgiftApproved.pm
--- a/cgi-bin/LJ/Event/VgiftApproved.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/VgiftApproved.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -31,6 +31,10 @@
     return $class->SUPER::new( $u, $fromu->id, $vgift->id );
 }
 
+sub arg_list {
+    return ( "From userid", "Vgift id" );
+}
+
 # access args
 sub fromuid { return $_[0]->arg1 }
 
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/XPostFailure.pm
--- a/cgi-bin/LJ/Event/XPostFailure.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/XPostFailure.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -45,6 +45,10 @@
     return undef;
 }
 
+sub arg_list {
+    return ( "Import status id" );
+}
+
 sub is_common { 1 }
 
 sub is_visible { 1 }
diff -r 19ef41b78730 -r e4135c489702 cgi-bin/LJ/Event/XPostSuccess.pm
--- a/cgi-bin/LJ/Event/XPostSuccess.pm	Fri Feb 10 12:40:00 2012 +0800
+++ b/cgi-bin/LJ/Event/XPostSuccess.pm	Fri Feb 10 13:00:37 2012 +0800
@@ -24,6 +24,10 @@
     return $class->SUPER::new( $u, $acctid, $ditemid );
 }
 
+sub arg_list {
+    return ( "Ext. account id", "Entry ditemid" );
+}
+
 sub is_common { 0 }
 
 sub is_visible { 1 }
diff -r 19ef41b78730 -r e4135c489702 htdocs/stc/simple-form.css
--- a/htdocs/stc/simple-form.css	Fri Feb 10 12:40:00 2012 +0800
+++ b/htdocs/stc/simple-form.css	Fri Feb 10 13:00:37 2012 +0800
@@ -130,3 +130,4 @@
     background-color: transparent;
 }
 
+
diff -r 19ef41b78730 -r e4135c489702 views/admin/eventoutput-select.tt
--- a/views/admin/eventoutput-select.tt	Fri Feb 10 12:40:00 2012 +0800
+++ b/views/admin/eventoutput-select.tt	Fri Feb 10 13:00:37 2012 +0800
@@ -11,39 +11,60 @@
 %]
 
 [%- sections.title = '.title' | ml -%]
+[%- dw.need_res(
+    "stc/simple-form.css"
+) -%]
+
 [%- sections.head  = BLOCK %]
     <style type="text/css">
-    #event label { float: left; width: 10em; clear: left;}
-    #event input, #event select, #event p { float: left; }
-    #event input.submit { clear: left; width: 30em; }
-    #event { overflow: auto;}
+    .simple-form { max-width: 40em; }
     </style>
 [% END %]
-<form method="POST" id="event">
+
+<form method="GET" class='simple-form'>
+    <fieldset>
+    <legend><span>[% '.subtitle.eventtype' | ml %]</span></legend>
+    <ul><li>
+    [%- label = ".form.label.eventtype" | ml;
+    form.select( label = "$label:"
+        name = "event"
+        id = "event"
+
+        items = eventtypes
+        default = event
+    ) -%]
+    </li></ul>
+    </fieldset>
+    <fieldset class='submit'>[% form.submit %]</fieldset>
+</form>
+
+[%- IF event -%]
+<form method="POST" class='simple-form'>
     [%- dw.form_auth -%]
-    <div class="formfield">
-        <label for="eventtype">[% ".form.label.eventtype" | ml %]:</label> <select id="eventtype" name="eventtype">
-            [% FOREACH eventtype = eventtypes %]
-                <option value="[% eventtype.id %]">[%eventtype.name %]</option>
-            [% END %]
-        </select>
-    </div>
+    <fieldset>
+    <legend><span>[% '.subtitle.details' | ml %]</span></legend>
+    <ul>
+    <li>
+        <label for="eventtype">[% ".form.label.eventtype" | ml %]:</label><span id="eventtype">[%event%]</span>
+        [% form.hidden( name = "event", value = event ) %]
+    </li>
 
-    <div class="formfield">
+    <li>
         <label for="eventuser">[% ".form.label.eventuser" | ml %]:</label> <input type="text" name="eventuser" id="eventuser" />
-    </div>
+    </li>
 
-    <div class="formfield">
+    <li>
         <label for="subscr_user">[% ".form.label.subscr_user" | ml %]:</label> <input type="text" name="subscr_user" id="subscr_user" />
-    </div>
+    </li>
 
-    <div class="formfield">
-        <label for="arg1">[% ".form.label.arg1" | ml %]:</label> <input type="text" name="arg1" id="arg1" /> <p class='note'>[% ".form.optional" | ml %]</p>
-    </div>
+    [%- FOREACH arg = eventargs -%]
+    <li>
+        <label for="arg[%loop.count%]">[% arg %]:</label> <input type="text" name="arg[%loop.count%]" id="arg[%loop.count%]" />[% note %]
+    </li>
+    [%- END -%]
+    </ul>
+    </fieldset>
 
-    <div class="formfield">
-        <label for="arg2">[% ".form.label.arg2" | ml %]:</label> <input type="text" name="arg2" id="arg2" /> <p class='note'>[% ".form.optional" | ml %]</p>
-    </div>
-
-    <input type="submit" class='submit' />
+    <fieldset class='submit'>[% form.submit %]</fieldset>
 </form>
+[% END %]
diff -r 19ef41b78730 -r e4135c489702 views/admin/eventoutput-select.tt.text
--- a/views/admin/eventoutput-select.tt.text	Fri Feb 10 12:40:00 2012 +0800
+++ b/views/admin/eventoutput-select.tt.text	Fri Feb 10 13:00:37 2012 +0800
@@ -3,17 +3,15 @@
 
 .admin.text=Quick overview of an event in various output formats.
 
-.form.label.arg1=First Argument
-
-.form.label.arg2=Second Argument
-
 .form.label.eventtype=Event Type
 
 .form.label.eventuser=Event Journal
 
 .form.label.subscr_user=Subscriber
 
-.form.optional=(optional)
+.subtitle.details=Event Details
 
-.title=Select Event to Preview
+.subtitle.eventtype=Event Type
 
+.title=Event Output Tool
+
--------------------------------------------------------------------------------