[Bps-public-commit] RT-Extension-FeaturedTickets branch, master, updated. ad7ba9f3f171dc4f01ef8e7abd197d868424f5bd

? sunnavy sunnavy at bestpractical.com
Fri Jul 13 17:15:00 EDT 2018


The branch, master has been updated
       via  ad7ba9f3f171dc4f01ef8e7abd197d868424f5bd (commit)
       via  c79259d0c7dfc01cef3f6a6a639317821df3aad0 (commit)
       via  557d0ad961792552c37cd6a7837616ce32d2bb36 (commit)
       via  37ad2ddefad245429c78de36bd20433ca21e6e69 (commit)
       via  33030e0d8eb2b31780ad81c08d7315bf9e16ce89 (commit)
      from  0180d6512b7b766f83760000b0271ef25b110a97 (commit)

Summary of changes:
 html/NoAuth/Featured/index.html |   3 +-
 html/NoAuth/Helpers/NewSponsor  | 150 ++++++++++++++++++++++++----------------
 static/css/featured-tickets.css |  41 ++++++++++-
 static/js/featured-tickets.js   |  28 +++++---
 4 files changed, 151 insertions(+), 71 deletions(-)

- Log -----------------------------------------------------------------
commit 33030e0d8eb2b31780ad81c08d7315bf9e16ce89
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 14 01:16:50 2018 +0800

    Fix the issue of missing "Details" buttons on Safari

diff --git a/static/css/featured-tickets.css b/static/css/featured-tickets.css
index 4a67495..c468280 100644
--- a/static/css/featured-tickets.css
+++ b/static/css/featured-tickets.css
@@ -214,6 +214,7 @@ p.featured-tickets-paragraph {
 
 .featured-tickets-button-page {
     margin-top: -120px;
+    position: relative;
 }
 
 .featured-tickets-information-head {

commit 37ad2ddefad245429c78de36bd20433ca21e6e69
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 14 03:32:17 2018 +0800

    Refactor code to validate inputs and show user errors if there are any

diff --git a/html/NoAuth/Featured/index.html b/html/NoAuth/Featured/index.html
index 8fe2cff..d35b90b 100644
--- a/html/NoAuth/Featured/index.html
+++ b/html/NoAuth/Featured/index.html
@@ -58,6 +58,7 @@
                 <h4><div id="featured-tickets-description"></div></h4>
                 <h4><div id="featured-tickets-details"></div></h4>
                 <h4><div id="featured-tickets-goal"></div></h4>
+                <div class="error"></div>
                 <fieldset class="featured-tickets-inputs">
                     <div class="pure-control-group">
                         <label for="featured-tickets-name">Name</label>
diff --git a/html/NoAuth/Helpers/NewSponsor b/html/NoAuth/Helpers/NewSponsor
index 006b08c..9c1cacb 100644
--- a/html/NoAuth/Helpers/NewSponsor
+++ b/html/NoAuth/Helpers/NewSponsor
@@ -1,63 +1,97 @@
-% $r->content_type('application/json; charset=utf-8');
-<% JSON( \@msgs ) |n %>
-% $m->abort;
-<%args>
-$ticket_id  => undef
-</%args>
-
 <%init>
-my @msgs;
-if( $ARGS{Email} ){
-    my $queue = RT::Queue->new(RT->SystemUser);
-    my ($ret, $msg) = $queue->Load(RT->Config->Get('FeaturedTicketsQueue'));
-    return ($ret, $msg) unless $ret;
-
-    my $ticket = RT::Ticket->new(RT->SystemUser);
-
-    my $parent_ticket = RT::Ticket->new(RT->SystemUser);
-    ($ret, $msg) = $parent_ticket->Load( $ARGS{ticket_id} );
-
-    # If ticket fails to load, just load the page - bogus id
-    if ( $ret ) {
-
-        my $user = RT::User->new(RT->SystemUser);
-        ($ret, $msg) = $user->LoadByEmail($ARGS{Email});
-
-        if ( !$ret ) {
-            ($ret, $msg) = $user->Create(
-                    RealName           => $ARGS{Name},
-                    EmailAddress       => $ARGS{Email},
-            );
-        return ($ret, $msg) unless $ret;
-        }
-
-        if ( $ARGS{Amount} > 0 ) {
-            ($ret, $msg) = $ticket->Create(
-                Subject       => $ARGS{Name} . "\'s Sponsor Ticket For: \"". $parent_ticket->Subject ."\"",
-                Queue         => RT->Config->Get('SponsorsQueue'),
-                DependedOnBy  => $ARGS{ticket_id},
-                'CustomField-' . $ticket->LoadCustomFieldByIdentifier('Amount')->Id => $ARGS{Amount},
-                Requestor     => $user->EmailAddress,
-            );
-            RT::Logger->error('Could Not Create Linked Ticket') unless $ret;
-        }
-
-        my $new_amount = $ARGS{Amount} + $parent_ticket->FirstCustomFieldValue('Amount');
-
-        ($ret, $msg) = $parent_ticket->AddCustomFieldValue( Field => $parent_ticket->LoadCustomFieldByIdentifier('Amount')->Id, Value => $new_amount );
-        RT::Logger->error('Could Not Set Parent Ticket New Amount Value') unless $ret;
-
-        if ( $new_amount >= $parent_ticket->FirstCustomFieldValue('Goal') ) {
-            ($ret, $msg) = $parent_ticket->AddCustomFieldValue( Field => $parent_ticket->LoadCustomFieldByIdentifier('Funded')->Id, Value => 'Funded' );
-            RT::Logger->error('Failed To Updated Funded Custom Field') unless $ret;
-        }
-
-        ($ret, $msg) = $parent_ticket->Comment(
-            Content  => 'New sponsor ' . $ARGS{Email} . ', has committed $' . $ARGS{Amount},
-        );
-        RT::Logger->error('Could not comment on Ticket') unless $ret;
+$r->content_type('application/json; charset=utf-8');
+
+for my $field ( qw/ticket_id Email Amount/ ) {
+    if ( !$ARGS{$field} ) {
+        $m->out( JSON( { status => 'error', message => loc( 'Missing argument [_1]', loc( $field ) ) } ) );
+        $m->abort;
     }
-    push @msgs, "Success" unless !$ret;
 }
 
+if ( $ARGS{Amount} =~ qr/^\s*(\d+(?:\.\d*)?)\s*$/ ) {
+    $ARGS{Amount} = $1;
+    $ARGS{Amount} =~ s!\.$!!;    # remove trailing dot
+    if ( $ARGS{Amount} <= 0 ) {
+        $m->out( JSON( { status => 'error', message => loc( 'Invalid argument [_1]', loc( 'Amount' ) ) } ) );
+        $m->abort;
+    }
+}
+else {
+    $m->out( JSON( { status => 'error', message => loc( 'Invalid argument [_1]', loc( 'Amount' ) ) } ) );
+    $m->abort;
+}
+
+my @addresses = Email::Address::List->parse( $ARGS{Email} );
+
+if ( @addresses == 1 && Scalar::Util::blessed( $addresses[ 0 ]->{value} ) ) {
+    $ARGS{Email} = $addresses[ 0 ]->{value}->address;
+}
+else {
+    $m->out( JSON( { status => 'error', message => loc( 'Invalid argument [_1]', loc( 'Email' ) ) } ) );
+    $m->abort;
+}
+
+my $parent_ticket = RT::Ticket->new( RT->SystemUser );
+my $ret           = $parent_ticket->Load( $ARGS{ticket_id} );
+unless ( $ret ) {
+    $m->out( JSON( { status => 'error', message => loc( 'Invalid argument [_1]', loc( 'ticket_id' ) ) } ) );
+    $m->abort;
+}
+
+for my $queue_config ( qw/SponsorsQueue FeaturedTicketsQueue/ ) {
+    my $queue = RT::Queue->new( RT->SystemUser );
+    $ret = $queue->Load( RT->Config->Get( $queue_config ) );
+    unless ( $ret ) {
+        RT->Logger->error( "Invalid config $queue_config" );
+        $m->out( JSON( { status => 'error', message => loc( 'Invalid config [_1]', $queue_config ) } ) );
+        $m->abort;
+    }
+}
+
+my $user = RT::User->new( RT->SystemUser );
+( $ret, my $msg ) = $user->LoadOrCreateByEmail(
+    EmailAddress => $ARGS{Email},
+    RealName     => $ARGS{Name},
+    Comments     => 'Autocreated as a sponsor',
+);
+unless ( $ret ) {
+    RT->Logger->error( "Could not create user $ARGS{Email}: $msg" );
+    $m->out( JSON( { status => 'error', message => loc( 'Could not create [_1]', loc( 'User' ) ) } ) );
+    $m->abort;
+}
+
+my $ticket = RT::Ticket->new( RT->SystemUser );
+( $ret, $msg ) = $ticket->Create(
+    Subject => ( $ARGS{Name} || $ARGS{Email} ) . "\'s Sponsor Ticket For: \"" . $parent_ticket->Subject . "\"",
+    Queue                                                                 => RT->Config->Get( 'SponsorsQueue' ),
+    DependedOnBy                                                          => $ARGS{ticket_id},
+    'CustomField-' . $ticket->LoadCustomFieldByIdentifier( 'Amount' )->Id => $ARGS{Amount},
+    Requestor                                                             => $user->EmailAddress,
+);
+
+unless ( $ret ) {
+    RT->Logger->error( "Could not create ticket: $msg" );
+    $m->out( JSON( { status => 'error', message => loc( 'Could not create [_1]', loc( 'Ticket' ) ) } ) );
+    $m->abort;
+}
+
+# Once the ticket is created, I think it's fine to tell user the sponsorship is successful.
+# Maybe the following code should be done in Scrips?
+my $new_amount = $ARGS{Amount} + ( $parent_ticket->FirstCustomFieldValue('Amount') // 0 );
+
+($ret, $msg) = $parent_ticket->AddCustomFieldValue( Field => $parent_ticket->LoadCustomFieldByIdentifier('Amount')->Id, Value => $new_amount );
+RT::Logger->error("Could not update parent ticket Amount: $msg") unless $ret;
+
+if ( $new_amount >= $parent_ticket->FirstCustomFieldValue('Goal') ) {
+    ($ret, $msg) = $parent_ticket->AddCustomFieldValue( Field => $parent_ticket->LoadCustomFieldByIdentifier('Funded')->Id, Value => 'Funded' );
+    RT::Logger->error("Could not update parent ticket Funded: $msg") unless $ret;
+}
+
+($ret, $msg) = $parent_ticket->Comment(
+    Content  => 'New sponsor ' . $ARGS{Email} . ', has committed $' . $ARGS{Amount},
+);
+RT::Logger->error("Could not comment on parent ticket: $msg") unless $ret;
+
+$m->out( JSON( { status => 'success' } ) );
+$m->abort;
 </%init>
diff --git a/static/css/featured-tickets.css b/static/css/featured-tickets.css
index c468280..fb7b105 100644
--- a/static/css/featured-tickets.css
+++ b/static/css/featured-tickets.css
@@ -395,5 +395,13 @@ p.featured-tickets-paragraph {
     -webkit-box-shadow: 0px 0px 3px rgba(51, 30, 170, 0.3);
     -moz-box-shadow: 0px 0px 3px rgba(51, 30, 170, 0.3);
     box-shadow: 0px 0px 3px rgba(51, 30, 170, 0.3);
-    }
+}
+
+div.featured-tickets-modal div.error {
+    border: 2px solid #aa0000;
+    border-top: 1px solid #bb0000;
+    border-left: 1px solid #bb0000;
+    background-color: #fcc;
+    padding: 10px;
+    display: none;
 }
diff --git a/static/js/featured-tickets.js b/static/js/featured-tickets.js
index e81bb3e..281d4dc 100644
--- a/static/js/featured-tickets.js
+++ b/static/js/featured-tickets.js
@@ -7,19 +7,27 @@ function NewSponsor() {
 
     data = { "Name" : sponsor_name.value, "Email" : email.value, "Amount" : amount.value, "ticket_id" : ticket_id.value };
 
+    jQuery('div.featured-tickets-modal div.error').text('').hide();
+
     jQuery.ajax({
-            type: 'POST',
-            url: "/NoAuth/Helpers/NewSponsor",
-            dataType: "json",
-            data: data,
-            success: function( data ) {
+        type: 'POST',
+        url: "/NoAuth/Helpers/NewSponsor",
+        dataType: "json",
+        data: data,
+        success: function( data ) {
+            if ( data.status == 'success' ) {
                 // console.log('AJAX call to NewSponsor created new sponsor ticket');
-            },
-            error: function () {
-                // console.log('An error occured with NewSponsor create');
+                jQuery('div.featured-tickets-modal div.error').text('').fadeOut();
+                FeaturedTicketsSubmitSponsor();
+            }
+            else {
+                jQuery('div.featured-tickets-modal div.error').text(data.message).fadeIn();
             }
+        },
+        error: function () {
+            // console.log('An error occured with NewSponsor create');
+        }
     });
-    FeaturedTicketsSubmitSponsor();
 }
 
 function FeaturedTicketsSubmitSponsor() {

commit 557d0ad961792552c37cd6a7837616ce32d2bb36
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 14 05:02:41 2018 +0800

    Add spinner to tell user the submission is still going on

diff --git a/static/css/featured-tickets.css b/static/css/featured-tickets.css
index fb7b105..4bacb32 100644
--- a/static/css/featured-tickets.css
+++ b/static/css/featured-tickets.css
@@ -405,3 +405,29 @@ div.featured-tickets-modal div.error {
     padding: 10px;
     display: none;
 }
+
+.featured-tickets-inputs {
+    position: relative;
+}
+
+/* https://stephanwagner.me/only-css-loading-spinner */
+ at keyframes spinner {
+  to {transform: rotate(360deg);}
+}
+
+.spinner:before {
+  content: '';
+  box-sizing: border-box;
+  position: absolute;
+  top: 40%;
+  left: 50%;
+  width: 20px;
+  height: 20px;
+  margin-top: -10px;
+  margin-left: -10px;
+  border-radius: 50%;
+  border-top: 2px solid #07d;
+  border-right: 2px solid transparent;
+  animation: spinner .6s linear infinite;
+  z-index: 2;
+}
diff --git a/static/js/featured-tickets.js b/static/js/featured-tickets.js
index 281d4dc..14457f4 100644
--- a/static/js/featured-tickets.js
+++ b/static/js/featured-tickets.js
@@ -8,6 +8,7 @@ function NewSponsor() {
     data = { "Name" : sponsor_name.value, "Email" : email.value, "Amount" : amount.value, "ticket_id" : ticket_id.value };
 
     jQuery('div.featured-tickets-modal div.error').text('').hide();
+    jQuery('.featured-tickets-inputs').addClass('spinner');
 
     jQuery.ajax({
         type: 'POST',
@@ -15,6 +16,7 @@ function NewSponsor() {
         dataType: "json",
         data: data,
         success: function( data ) {
+            jQuery('.featured-tickets-inputs').removeClass('spinner');
             if ( data.status == 'success' ) {
                 // console.log('AJAX call to NewSponsor created new sponsor ticket');
                 jQuery('div.featured-tickets-modal div.error').text('').fadeOut();

commit c79259d0c7dfc01cef3f6a6a639317821df3aad0
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 14 05:11:46 2018 +0800

    Update links to respect WebPath

diff --git a/html/NoAuth/Featured/index.html b/html/NoAuth/Featured/index.html
index d35b90b..f690e28 100644
--- a/html/NoAuth/Featured/index.html
+++ b/html/NoAuth/Featured/index.html
@@ -21,7 +21,7 @@
             <link rel="stylesheet" href="/combo/1.18.13?/css/layouts/pricing-old-ie.css">
         <![endif]-->
         <!--[if gt IE 8]><!-->
-            <link rel="stylesheet" href="/static/css/featured-tickets.css">
+            <link rel="stylesheet" href="<% RT->Config->Get('WebPath') %>/static/css/featured-tickets.css">
         <!--<![endif]-->
     <!--[if lt IE 9]>
         <script src="http://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.js"></script>
diff --git a/static/js/featured-tickets.js b/static/js/featured-tickets.js
index 14457f4..8c3275d 100644
--- a/static/js/featured-tickets.js
+++ b/static/js/featured-tickets.js
@@ -12,7 +12,7 @@ function NewSponsor() {
 
     jQuery.ajax({
         type: 'POST',
-        url: "/NoAuth/Helpers/NewSponsor",
+        url: RT.Config.WebPath + "/NoAuth/Helpers/NewSponsor",
         dataType: "json",
         data: data,
         success: function( data ) {

commit ad7ba9f3f171dc4f01ef8e7abd197d868424f5bd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 14 05:12:20 2018 +0800

    Consistently use relative urls in css

diff --git a/static/css/featured-tickets.css b/static/css/featured-tickets.css
index 4bacb32..b29c26d 100644
--- a/static/css/featured-tickets.css
+++ b/static/css/featured-tickets.css
@@ -68,10 +68,10 @@ p.featured-tickets-paragraph {
 
 .featured-tickets-banner {
     background: transparent 
-     url('/static/images/rawpixel-com-250087-unsplash.jpg') 0 0 no-repeat fixed;
+     url('../../../static/images/rawpixel-com-250087-unsplash.jpg') 0 0 no-repeat fixed;
     text-align: center;
     background-size: cover;
-    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/static/images/rawpixel-com-250087-unsplash.jpg', sizingMethod='scale');
+    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../static/images/rawpixel-com-250087-unsplash.jpg', sizingMethod='scale');
     height: 400px;
     width: 100%;
     margin-bottom: 3em;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list