Difference between revisions of "Widget:PledgeTracker"

From Nottinghack Wiki
Jump to navigation Jump to search
(removed quotes around integers)
 
(25 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
You can insert a pledge tracker with the following wiki code:
 
You can insert a pledge tracker with the following wiki code:
  
  <nowiki>{{#widget:PledgeTracker|tableIndex=1|pledgeGoal=100|pledgeAmountColumn=2|pledgePaidColumn=3}}</nowiki>
+
  <nowiki>{{#widget:PledgeTracker|tableIndex=0|pledgeGoal=100|pledgeAmountColumn=1|pledgePaidColumn=2}}</nowiki>
  
 
=== Parameters ===
 
=== Parameters ===
 
;tableIndex
 
;tableIndex
:The index of the table on the page containing the pledges (1 = the first table). Default: <code>1</code>
+
:The index of the table on the page containing the pledges (0 = the first table). Default: <code>0</code>
  
 
;pledgeGoal
 
;pledgeGoal
Line 15: Line 15:
  
 
;pledgeAmountColumn
 
;pledgeAmountColumn
:The index of the column within the pledges table which contains the pledge amount (1 = the first column). Default: <code>2</code>
+
:The index of the column within the pledges table which contains the pledge amount (0 = the first column). Default: <code>1</code>
  
 
;pledgePaidColumn
 
;pledgePaidColumn
:The index of the column within the table which indicates if the pledge amount has been paid (1 = the first column). If the column contains 'yes' or 'y' (case insensitive) then the pledge amount is considered to have been paid, any other content is considered as not paid.  Default: <code>3</code>
+
:The index of the column within the table which indicates if the pledge amount has been paid (0 = the first column). If the column contains 'yes' or 'y' (case insensitive) then the pledge amount is considered to have been paid, any other content is considered as not paid.  Default: <code>2</code>
  
 
== Example ==
 
== Example ==
 +
<nowiki>{{#widget:PledgeTracker|pledgeGoal=100}}</nowiki>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 29: Line 30:
 
! Method Paid
 
! Method Paid
 
|-
 
|-
| Bob || £30 || Yes || BACS
+
| Alice || £30 || Yes || BACS
 
|-
 
|-
| Alice || £50 || Yes || CASH
+
| Bob  || £50 || Yes || CASH
 
|-
 
|-
| Carol || £25 || No || BACS
+
| Carol || £25 || No ||  
 
|}
 
|}
  
{{#widget:PledgeTracker|tableIndex=1|pledgeGoal=100|pledgeAmountColumn=2|pledgePaidColumn=3}}
+
{{#widget:PledgeTracker|pledgeGoal=100}}
  
 +
[[Category:Widget]]
 
</noinclude>
 
</noinclude>
 
<includeonly>
 
<includeonly>
Line 45: Line 47:
  
 
   <script type="text/javascript">
 
   <script type="text/javascript">
     $(document).ready(function () {
+
     function defer(method) {
      var tableIndex = <!--{$tableIndex|validate:int|default:0}-->;
+
        if (window.jQuery)
 +
            method();
 +
        else
 +
            setTimeout(function() { defer(method) }, 50);
 +
    }   
 +
 
 +
 
 +
    defer(function() {
 +
    //jQuery(document).ready(function () {
 
       var pledgeGoalAmount = <!--{$pledgeGoal|validate:int|default:0}-->;
 
       var pledgeGoalAmount = <!--{$pledgeGoal|validate:int|default:0}-->;
      var pledgeAmountColIndex = <!--{$pledgeAmountColumn|validate:int|default:2}-->;
 
      var pledgePaidColIndex = <!--{$pledgePaidColumn|validate:int|default:3}-->;
 
 
       var amountPledged = 0;
 
       var amountPledged = 0;
 
       var amountCollected = 0;
 
       var amountCollected = 0;
       $('.wikitable:eq(' + tableIndex + ') tr:gt(0)').each(
+
       jQuery('.wikitable:eq(<!--{$tableIndex|validate:int|default:0}-->) tr:gt(0)').each(
 
         function(index, value) {
 
         function(index, value) {
 
           var cols = $(value).children();
 
           var cols = $(value).children();
           var pledgeAmountCol = cols.eq(pledgeAmountColIndex - 1);
+
           var pledgeAmountCol = cols.eq(<!--{$pledgeAmountColumn|validate:int|default:1}-->);
           var pledgeAmountValue = parseFloat(pledgeAmountCol.text().substring(2)) || 0;
+
           var pledgeAmountValue = parseFloat(pledgeAmountCol.text().trim().substring(1)) || 0;
           var pledgePaidCol = cols.eq(pledgePaidColIndex - 1);
+
           var pledgePaidCol = cols.eq(<!--{$pledgePaidColumn|validate:int|default:2}-->);
 
           var pledgePaidValue = pledgePaidCol.text().trim().toLowerCase();
 
           var pledgePaidValue = pledgePaidCol.text().trim().toLowerCase();
 
            
 
            
Line 66: Line 74:
 
         }
 
         }
 
       )
 
       )
       $("<p><b>Pledges Raised:</b> £" + amountPledged + " / £" + pledgeGoalAmount + " (" + ((amountPledged / pledgeGoalAmount) * 100).toFixed(2) + "%)</p>").appendTo('#pledgeTracker<!--{$pledgeTrackerDivId|escape:'html'}-->');
+
       jQuery("<p><b>Pledges Raised:</b> £" + amountPledged.toFixed(2) + <!--{if $pledgeGoal>0}-->" / £" + pledgeGoalAmount.toFixed(2) + " (" + ((amountPledged / pledgeGoalAmount) * 100).toFixed(2) + "%)" + <!--{/if}-->"</p>").appendTo('#pledgeTracker<!--{$pledgeTrackerDivId|escape:'html'}-->');
       $("<p><b>Pledges Collected:</b> £" + amountCollected + " / £" + amountPledged + " (" + ((amountCollected / amountPledged) * 100).toFixed(2) + "%)</p>").appendTo('#pledgeTracker<!--{$pledgeTrackerDivId|escape:'html'}-->');
+
       jQuery("<p><b>Pledges Collected:</b> £" + amountCollected.toFixed(2) + " / £" + amountPledged.toFixed(2) + " (" + ((amountCollected / amountPledged) * 100).toFixed(2) + "%)</p>").appendTo('#pledgeTracker<!--{$pledgeTrackerDivId|escape:'html'}-->');
 +
    //});
 
     });
 
     });
 
   </script>
 
   </script>
 
   <!-- PledgeTracker code ends here -->
 
   <!-- PledgeTracker code ends here -->
 
</includeonly>
 
</includeonly>

Latest revision as of 15:59, 29 March 2019

This widget tracks the current amount pledged and collected for a pledge drive on a wiki page which makes use of table with specific columns.

Using this widget

You can insert a pledge tracker with the following wiki code:

{{#widget:PledgeTracker|tableIndex=0|pledgeGoal=100|pledgeAmountColumn=1|pledgePaidColumn=2}}

Parameters

tableIndex
The index of the table on the page containing the pledges (0 = the first table). Default: 0
pledgeGoal
The goal amount for the pledge drive. Default: 0
pledgeAmountColumn
The index of the column within the pledges table which contains the pledge amount (0 = the first column). Default: 1
pledgePaidColumn
The index of the column within the table which indicates if the pledge amount has been paid (0 = the first column). If the column contains 'yes' or 'y' (case insensitive) then the pledge amount is considered to have been paid, any other content is considered as not paid. Default: 2

Example

{{#widget:PledgeTracker|pledgeGoal=100}}
Who Amount Paid? Method Paid
Alice £30 Yes BACS
Bob £50 Yes CASH
Carol £25 No