GrantProgram.tpl 7.06 KB
Newer Older
1 2
{*
 +--------------------------------------------------------------------+
Edselopez's avatar
Edselopez committed
3
 | CiviCRM version 4.4                                                |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 +--------------------------------------------------------------------+
 | Copyright CiviCRM LLC (c) 2004-2011                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
*}
{if $action eq 1 or $action eq 2 or $action eq 8}
   {include file="CRM/Grant/Form/GrantProgram.tpl"}
{elseif $action eq 4}
   {include file="CRM/Grant/Form/GrantProgramView.tpl"}
{else}
Pradeep Nayak's avatar
Pradeep Nayak committed
31
{if $programs}
32 33 34
<div id="ltype">
<p></p>
    <div class="form-item">
Pradeep Nayak's avatar
Pradeep Nayak committed
35
    {if $action ne 1 and $action ne 2 and $context ne 'dashboard'}
36 37 38
	    <div class="action-link">
    	<a href="{crmURL q="action=add&reset=1"}" id="grant_program" class="button"><span><div class="icon add-icon"></div>{ts}Add Grant Program{/ts}</span></a>
        </div>
Pradeep Nayak's avatar
Pradeep Nayak committed
39
    {/if}
40
    {strip}
41 42 43 44 45 46 47 48
        <table cellpadding="0" cellspacing="0" border="0">
           <thead class="sticky">
            <th>{ts}Name{/ts}</th>
            <th>{ts}Type{/ts}</th>
            <th>{ts}Description{/ts}</th>
            <th>{ts}Total{/ts}</th>
            <th>{ts}Status{/ts}</th>
	    <th>{ts}Allocation Date{/ts}</th>
Monish Deb's avatar
Monish Deb committed
49
	    <th>{ts}Enabled?{/ts}</th>
50 51
            <th></th>
          </thead>
Pradeep Nayak's avatar
Pradeep Nayak committed
52
         {foreach from=$programs item=row}
53
        <tr id="row_{$row.id}"class="{cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
Monish Deb's avatar
Monish Deb committed
54
	        <td>{$row.label}</td>
55 56 57 58 59 60 61 62 63 64 65 66
	        <td>{$row.grant_type_id}</td>
            	<td>{$row.description}</td>
	        <td>{$row.total_amount}</td>
	        <td>{$row.status_id}</td>
		<td>{$row.allocation_date|truncate:10:''|crmDate}</td>
	        <td>{if $row.is_active}{ts}Yes{/ts}{else}{ts}No{/ts}{/if}</td>
	        <td>{$row.action|replace:'xx':$row.id}</td>
        </tr>
        {/foreach}
         </table>
        {/strip}

Pradeep Nayak's avatar
Pradeep Nayak committed
67
        {if $action ne 1 and $action ne 2 and $context ne 'dashboard'}
68 69 70 71 72 73 74 75 76 77 78
	    <div class="action-link">
    	<a href="{crmURL q="action=add&reset=1"}" id="grant_program" class="button"><span><div class="icon add-icon"></div>{ts}Add Grant Program{/ts}</span></a>
        </div>
        {/if}
    </div>
</div>
{else}
    <div class="messages status">
        <div class="icon inform-icon"></div>
        {capture assign=crmURL}{crmURL q="action=add&reset=1"}{/capture}
        {ts 1=$crmURL}There are no Grant Programs entered. You can <a href='%1'>add one</a>.{/ts}
Monish Deb's avatar
Monish Deb committed
79
    </div>
80
{/if}
Pradeep Nayak's avatar
Pradeep Nayak committed
81
{/if}
Monish Deb's avatar
Monish Deb committed
82
<div id="actionDialog" class="crm-container" style="display:none;"></div>
Pradeep Nayak's avatar
Pradeep Nayak committed
83

84
{if $action neq 4}{literal}
Pradeep Nayak's avatar
Pradeep Nayak committed
85 86 87
<script type="text/javascript">

cj(document).ready(function(){
Mayur Jadhav's avatar
Mayur Jadhav committed
88
cj('ul.panel').css('width','250px');
Pradeep Nayak's avatar
Pradeep Nayak committed
89

90
cj('#allocation').click(function(event){
Monish Deb's avatar
Monish Deb committed
91 92
  actionTask('allocation');
  return false;
Pradeep Nayak's avatar
Pradeep Nayak committed
93 94
});

Monish Deb's avatar
Monish Deb committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
function actionTask(type) {
  if (task == 'allocation') {
    CRM.$('#actionDialog').dialog({
      title: {/literal}'{ts}Grant Allocation{/ts}'{literal},
      modal: true,
      open:function() {
        CRM.$('#actionDialog').show().html({/literal}"{ts escape='js'}Do you want to do a trial allocation?{/ts}"{literal});
      },
      buttons: {
        {/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
          CRM.$(this).dialog("close");
        },
        {/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
          CRM.$(this).dialog("close");
          var data = 'pid={/literal}{$id}{literal}&amount={/literal}{$total_amount}{literal}&remainder_amount={/literal}{$remainder_amount}{literal}&algorithm={/literal}{$grantProgramAlgorithm}{literal}';
          var dataURL = {/literal}"{crmURL p='civicrm/grant_program/allocate'}"{literal};
          window.location.href = dataURL;
          return;
        }
      }
    });
  }
}

119
cj('#finalize').click(function(event){
Pradeep Nayak's avatar
Pradeep Nayak committed
120 121 122
 var confirmed = 0;
 var totalAmounts = 0;
 var grantedAmount = 0;
123
 event.preventDefault();
Pradeep Nayak's avatar
Pradeep Nayak committed
124 125
 var data = 'pid={/literal}{$id}{literal}}&amount={/literal}{$total_amount}{literal}';
     var dataURL = {/literal}"{crmURL p='civicrm/grant_program/finalize'}"{literal};
Monish Deb's avatar
Monish Deb committed
126 127 128
     console.log(data);
     cj.ajax({
         url: dataURL,
Pradeep Nayak's avatar
Pradeep Nayak committed
129 130
         data: data,
         type: 'POST',
Monish Deb's avatar
Monish Deb committed
131 132
         success: function(output) {
           console.log(output);
Pradeep Nayak's avatar
Pradeep Nayak committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	 var result = eval('(' + output + ')');
	 cj.each( result, function( index, value ) {
alert(index);alert(value);
	 if( index == 'confirm' ) {
	   confirmed = value;
	 }
	 if( index == 'total_amount' ) {
	   totalAmounts = value;
	 }
	 if( index == 'amount_granted' ) {
	   grantedAmount = value;
	   var data = 'amount_granted = '+value;
	   alert(data);
	 }
         });
	 alert(data);
	 if (confirmed == 'confirm' ) {
	    var r=confirm("Do you want finalize the award of grants for this grant program to the amounts currently allocated?");
	    if (r==true)
Monish Deb's avatar
Monish Deb committed
152
  	    {
Pradeep Nayak's avatar
Pradeep Nayak committed
153
	    var dataURL = {/literal}"{crmURL p='civicrm/grant_program/processFinalization'}"{literal};
Monish Deb's avatar
Monish Deb committed
154 155
     	    cj.ajax({
              url: dataURL,
Pradeep Nayak's avatar
Pradeep Nayak committed
156 157
              data: data,
              type: 'POST',
Monish Deb's avatar
Monish Deb committed
158
              success: function(output) {
Pradeep Nayak's avatar
Pradeep Nayak committed
159 160 161 162 163 164 165 166
	      setTimeout("location.reload(true);",1500);
	      }
	      });
	    }
	 } else {
alert("The sum of the grants to be allocated ($"+grantedAmount+".00) is greater than the total amount available to be allocated by the program ($"+totalAmounts+"). Please reduce the amount granted in pending applications or increase the total amount available to be granted.");
	  }
	}
Monish Deb's avatar
Monish Deb committed
167
   });
Pradeep Nayak's avatar
Pradeep Nayak committed
168 169 170 171
});



172 173
cj('#reject').click(function(event){
  event.preventDefault();
Monish Deb's avatar
Monish Deb committed
174 175 176 177 178 179 180 181 182 183 184
  if (confirm("Do you want to reject all Pending grant applications for this Grant Program??") === true) {
    var data = 'pid={/literal}{$id}{literal}';
    var dataURL = {/literal}"{crmURL p='civicrm/grant_program/reject'}"{literal};
    cj.ajax({
      url: dataURL,
      data: data,
      type: 'POST',
      success: function(output) {
        setTimeout("location.reload(true);",1500);
      }
    });
Monish Deb's avatar
Monish Deb committed
185
  }
Pradeep Nayak's avatar
Pradeep Nayak committed
186 187 188 189 190 191
});

});

</script>
{/literal}
192
{/if}