Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
232624b1 | 3 | | CiviCRM version 4.4 | |
6a488035 TO |
4 | +--------------------------------------------------------------------+ |
5 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
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. | | |
12 | | | | |
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. | | |
17 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {* handle common enable/disable actions *} | |
27 | <div id="enableDisableStatusMsg" class="success-status" style="display:none;"></div> | |
28 | {literal} | |
29 | <script type="text/javascript"> | |
30 | function modifyLinkAttributes( recordID, op, recordBAO, reloadPage, rowId ) { | |
31 | ||
32 | var selector = '#' + rowId + '_' + recordID; | |
33 | if (cj(selector).length ==0) | |
34 | selector = '#' + rowId + '-' + recordID; | |
35 | ||
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}; | |
51 | } | |
52 | ||
53 | //change html | |
54 | cj( fieldID ).html( htmlContent ); | |
55 | ||
56 | //change title | |
57 | cj( fieldID ).attr( 'title', newTitle ); | |
58 | //need to update js - change op from js to new allow operation. | |
59 | //set updated js | |
60 | var newAction = 'enableDisable( ' + recordID + ',"' + | |
61 | recordBAO + '","' + | |
62 | operation + '",' + | |
63 | reloadPage + ',"' + | |
64 | rowId + '"' + ' );'; | |
65 | cj( fieldID ).attr("onClick", newAction ); | |
66 | ||
67 | //set the updated status | |
68 | var fieldStatus = '#' + rowId + '_' + recordID + "_status"; | |
69 | cj( fieldStatus ).text( newText ); | |
70 | ||
71 | //finally change class to enable-action. | |
72 | cj( fieldID ).attr( 'class', newClass ); | |
73 | } | |
74 | ||
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"; | |
80 | } | |
81 | ||
82 | cj( fieldID ).html( '' ); | |
83 | ||
84 | } | |
85 | ||
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; | |
90 | } | |
91 | if (cj(elementID).length ==0 ) { | |
92 | document.location.reload( );//force update if can't find the row | |
93 | } | |
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"); | |
99 | } | |
100 | } | |
101 | ||
102 | function hideEnableDisableStatusMsg( ) { | |
103 | cj( '#enableDisableStatusMsg' ).hide( ); | |
104 | } | |
105 | ||
106 | cj( '#enableDisableStatusMsg' ).hide( ); | |
107 | function enableDisable( recordID, recordBAO, op, reloadPage, rowId ) { | |
108 | ||
109 | //CRM-7487 -need to have unique row id, | |
110 | //for multiple selectors on same page. | |
111 | if ( ! rowId ) rowId = 'row'; | |
112 | ||
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}; | |
117 | } | |
118 | ||
119 | cj("#enableDisableStatusMsg").show( ); | |
120 | cj("#enableDisableStatusMsg").dialog({ | |
121 | title: st, | |
122 | modal: true, | |
123 | bgiframe: true, | |
124 | position: "right", | |
125 | overlay: { | |
126 | opacity: 0.5, | |
127 | background: "black" | |
128 | }, | |
129 | ||
130 | open:function() { | |
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 ); | |
135 | } | |
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); | |
144 | } | |
145 | }); | |
146 | cj('#enableDisableStatusMsg').dialog('removebutton', 'Cancel'); | |
147 | cj('#enableDisableStatusMsg').dialog('removebutton', 'OK'); | |
148 | } | |
149 | }, 'json' ); | |
150 | }, | |
151 | ||
152 | buttons: { | |
153 | "Cancel": function() { | |
154 | cj(this).dialog("close"); | |
155 | }, | |
156 | "OK": function() { | |
157 | saveEnableDisable( recordID, recordBAO, op, reloadPage, rowId ); | |
158 | cj(this).dialog("close"); | |
159 | } | |
160 | } | |
161 | }); | |
162 | } | |
163 | ||
164 | //check is server properly processed post. | |
165 | var responseFromServer = false; | |
166 | ||
167 | function noServerResponse( ) { | |
168 | if ( !responseFromServer ) { | |
b7054e52 | 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>'; |
6a488035 TO |
170 | cj( '#enableDisableStatusMsg' ).show( ).html( serverError ); |
171 | } | |
172 | } | |
173 | ||
174 | function saveEnableDisable( recordID, recordBAO, op, reloadPage, rowId ) { | |
175 | cj( '#enableDisableStatusMsg' ).hide( ); | |
176 | var postUrl = {/literal}"{crmURL p='civicrm/ajax/ed' h=0 }"{literal}; | |
177 | ||
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; | |
181 | ||
182 | //this is custom status set when record update success. | |
183 | if ( html.status == 'record-updated-success' ) { | |
184 | ||
185 | if ( reloadPage ) { | |
186 | document.location.reload( ); | |
187 | } | |
188 | //change row class and show/hide action links. | |
189 | modifySelectorRow( recordID, op, rowId ); | |
190 | ||
191 | //modify action link html | |
192 | if ( recordBAO == 'CRM_Contribute_BAO_ContributionRecur' ) { | |
193 | removeLinkAttributes( recordID, op, rowId ); | |
194 | } else { | |
195 | modifyLinkAttributes( recordID, op, recordBAO, reloadPage, rowId ); | |
196 | } | |
197 | } | |
198 | ||
199 | //cj( '#enableDisableStatusMsg' ).show( ).html( successMsg ); | |
200 | }, 'json' ); | |
201 | ||
202 | //if no response from server give message to user. | |
203 | setTimeout( "noServerResponse( )", 1500 ); | |
204 | } | |
205 | </script> | |
206 | {/literal} |