2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
26 {* handle common enable/disable actions *}
27 <div id="enableDisableStatusMsg" class="success-status" style="display:none;"></div>
29 <script type="text/javascript">
30 function modifyLinkAttributes( recordID, op, recordBAO, reloadPage, rowId ) {
32 var selector = '#' + rowId + '_' + recordID;
33 if (cj(selector).length ==0)
34 selector = '#' + rowId + '-' + recordID;
36 //we changed record from enable to disable
37 if ( op == 'enable-disable' ) {
38 var fieldID = selector + " a." + "disable-action";
39 var operation = "disable-enable";
40 var htmlContent = {/literal}'{ts escape="js"}Enable{/ts}'{literal};
41 var newClass = 'action-item enable-action';
42 var newTitle = {/literal}'{ts escape="js"}Enable{/ts}'{literal};
43 var newText = {/literal}' {ts escape="js"}No{/ts} '{literal};
44 } else if ( op == 'disable-enable' ) {
45 var fieldID = selector + " a." + "enable-action";
46 var operation = "enable-disable";
47 var htmlContent = {/literal}'{ts escape="js"}Disable{/ts}'{literal};
48 var newClass = 'action-item disable-action';
49 var newTitle = {/literal}'{ts escape="js"}Disable{/ts}'{literal};
50 var newText = {/literal}' {ts escape="js"}Yes{/ts} '{literal};
54 cj( fieldID ).html( htmlContent );
57 cj( fieldID ).attr( 'title', newTitle );
58 //need to update js - change op from js to new allow operation.
60 var newAction = 'enableDisable( ' + recordID + ',"' +
65 cj( fieldID ).attr("onClick", newAction );
67 //set the updated status
68 var fieldStatus = '#' + rowId + '_' + recordID + "_status";
69 cj( fieldStatus ).text( newText );
71 //finally change class to enable-action.
72 cj( fieldID ).attr( 'class', newClass );
75 function removeLinkAttributes( recordID, op, rowId ) {
76 if ( op == 'enable-disable' ) {
77 var fieldID = '#' + rowId + '_' + recordID + " a." + "disable-action";
78 } else if ( op == 'disable-enable' ) {
79 var fieldID = '#' + rowId + '_' + recordID + " a." + "enable-action";
82 cj( fieldID ).html( '' );
86 function modifySelectorRow( recordID, op, rowId ) {
87 var elementID = '#' + rowId + '_' + recordID;
88 if (cj(elementID).length ==0 ) { // trying the new syntax {EntityName}-{ID}
89 elementID = '#' + rowId + '-' + recordID;
91 if (cj(elementID).length ==0 ) {
92 document.location.reload( );//force update if can't find the row
94 if ( op == "disable-enable" ) {
95 cj( elementID ).removeClass("disabled");
96 } else if ( op == "enable-disable" ) {
97 //we are disabling record.
98 cj( elementID ).addClass("disabled");
102 function hideEnableDisableStatusMsg( ) {
103 cj( '#enableDisableStatusMsg' ).hide( );
106 cj( '#enableDisableStatusMsg' ).hide( );
107 function enableDisable( recordID, recordBAO, op, reloadPage, rowId ) {
109 //CRM-7487 -need to have unique row id,
110 //for multiple selectors on same page.
111 if ( ! rowId ) rowId = 'row';
113 if ( op == 'enable-disable' ) {
114 var st = {/literal}'{ts escape="js"}Disable Record{/ts}'{literal};
115 } else if ( op == 'disable-enable' ) {
116 var st = {/literal}'{ts escape="js"}Enable Record{/ts}'{literal};
119 cj("#enableDisableStatusMsg").show( );
120 cj("#enableDisableStatusMsg").dialog({
131 var postUrl = {/literal}"{crmURL p='civicrm/ajax/statusmsg' h=0 }"{literal};
132 cj.post( postUrl, { recordID: recordID, recordBAO: recordBAO, op: op }, function( statusMessage ) {
133 if ( statusMessage.status ) {
134 cj( '#enableDisableStatusMsg' ).show( ).html( statusMessage.status );
136 if ( statusMessage.show == "noButton" ) {
137 cj('#enableDisableStatusMsg').dialog('option', 'position', "centre");
138 cj('#enableDisableStatusMsg').data("width.dialog", 630);
139 cj.extend( cj.ui.dialog.prototype, {
140 'removebutton': function(buttonName) {
141 var buttons = this.element.dialog('option', 'buttons');
142 delete buttons[buttonName];
143 this.element.dialog('option', 'buttons', buttons);
146 cj('#enableDisableStatusMsg').dialog('removebutton', 'Cancel');
147 cj('#enableDisableStatusMsg').dialog('removebutton', 'OK');
153 "Cancel": function() {
154 cj(this).dialog("close");
157 saveEnableDisable( recordID, recordBAO, op, reloadPage, rowId );
158 cj(this).dialog("close");
164 //check is server properly processed post.
165 var responseFromServer = false;
167 function noServerResponse( ) {
168 if ( !responseFromServer ) {
169 var serverError = '{/literal}{ts escape="js"}There is no response from server therefore selected record is not updated.{/ts}{literal}' + ' <a href="#" onclick="hideEnableDisableStatusMsg(); return false;"><img title="{/literal}{ts escape="js"}close{/ts}{literal}" src="' +resourceBase+'i/close.png"/></a>';
170 cj( '#enableDisableStatusMsg' ).show( ).html( serverError );
174 function saveEnableDisable( recordID, recordBAO, op, reloadPage, rowId ) {
175 cj( '#enableDisableStatusMsg' ).hide( );
176 var postUrl = {/literal}"{crmURL p='civicrm/ajax/ed' h=0 }"{literal};
178 //post request and get response
179 cj.post( postUrl, { recordID: recordID, recordBAO: recordBAO, op:op, key: {/literal}"{crmKey name='civicrm/ajax/ed'}"{literal} }, function( html ){
180 responseFromServer = true;
182 //this is custom status set when record update success.
183 if ( html.status == 'record-updated-success' ) {
186 document.location.reload( );
188 //change row class and show/hide action links.
189 modifySelectorRow( recordID, op, rowId );
191 //modify action link html
192 if ( recordBAO == 'CRM_Contribute_BAO_ContributionRecur' ) {
193 removeLinkAttributes( recordID, op, rowId );
195 modifyLinkAttributes( recordID, op, recordBAO, reloadPage, rowId );
199 //cj( '#enableDisableStatusMsg' ).show( ).html( successMsg );
202 //if no response from server give message to user.
203 setTimeout( "noServerResponse( )", 1500 );