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 | {* include wysiwyg related files*} | |
27 | {if !$includeWysiwygEditor} | |
28 | {include file="CRM/common/wysiwyg.tpl" includeWysiwygEditor=true} | |
29 | {/if} | |
30 | {literal} | |
31 | <script type="text/javascript"> | |
b8d5d263 | 32 | CRM.buildCustomData = function( type, subType, subName, cgCount, groupID, isMultiple ) { |
6a488035 TO |
33 | var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type; |
34 | ||
35 | if ( subType ) { | |
36 | dataUrl = dataUrl + '&subType=' + subType; | |
37 | } | |
38 | ||
39 | if ( subName ) { | |
40 | dataUrl = dataUrl + '&subName=' + subName; | |
41 | cj('#customData' + subName ).show(); | |
5b626f26 KJ |
42 | } |
43 | else { | |
6a488035 TO |
44 | cj('#customData').show(); |
45 | } | |
46 | if ( groupID ) { | |
5b626f26 | 47 | dataUrl = dataUrl + '&groupID=' + groupID; |
6a488035 TO |
48 | } |
49 | ||
50 | {/literal} | |
51 | {if $urlPathVar} | |
52 | dataUrl = dataUrl + '&' + '{$urlPathVar}' | |
53 | {/if} | |
54 | {if $groupID} | |
55 | dataUrl = dataUrl + '&groupID=' + '{$groupID}' | |
56 | {/if} | |
57 | {if $qfKey} | |
58 | dataUrl = dataUrl + '&qfKey=' + '{$qfKey}' | |
59 | {/if} | |
60 | {if $entityID} | |
61 | dataUrl = dataUrl + '&entityID=' + '{$entityID}' | |
62 | {/if} | |
63 | {literal} | |
64 | ||
65 | if ( !cgCount ) { | |
66 | cgCount = 1; | |
67 | var prevCount = 1; | |
5b626f26 KJ |
68 | } |
69 | else if ( cgCount >= 1 ) { | |
6a488035 TO |
70 | var prevCount = cgCount; |
71 | cgCount++; | |
72 | } | |
73 | ||
74 | dataUrl = dataUrl + '&cgcount=' + cgCount; | |
75 | ||
76 | ||
77 | if ( isMultiple ) { | |
5b626f26 | 78 | var fname = '#custom_group_' + groupID + '_' + prevCount; |
6a488035 TO |
79 | if (cj(".add-more-link-" + groupID + "-" + prevCount ).length) { |
80 | cj(".add-more-link-" + groupID + "-" + prevCount).hide(); | |
6a488035 | 81 | } |
5b626f26 KJ |
82 | else { |
83 | cj("#add-more-link-"+prevCount).hide(); | |
84 | } | |
85 | } | |
86 | else { | |
6a488035 TO |
87 | if ( subName && subName != 'null' ) { |
88 | var fname = '#customData' + subName ; | |
5b626f26 KJ |
89 | } |
90 | else { | |
6a488035 TO |
91 | var fname = '#customData'; |
92 | } | |
93 | } | |
94 | ||
95 | cj.ajax({ | |
96 | url: dataUrl, | |
97 | dataType: 'html', | |
9e1f1471 | 98 | async: false, |
6a488035 TO |
99 | success: function(response) { |
100 | var target = cj(fname); | |
101 | var storage = {}; | |
102 | target.children().each(function() { | |
103 | var id = cj(this).attr('id'); | |
104 | if (id) { | |
105 | // Help values survive storage | |
106 | cj('textarea', this).each(function() { | |
107 | cj(this).text(cj(this).val()); | |
108 | }); | |
b8d5d263 CW |
109 | cj('option:selected', this).attr('selected', 'selected'); |
110 | cj('option:not(:selected)', this).removeAttr('selected'); | |
6a488035 TO |
111 | storage[id] = cj(this).detach(); |
112 | } | |
113 | }); | |
b8d5d263 | 114 | target.html(response).trigger('crmLoad'); |
6a488035 TO |
115 | target.children().each(function() { |
116 | var id = cj(this).attr('id'); | |
117 | if (id && storage[id]) { | |
118 | cj(this).replaceWith(storage[id]); | |
119 | } | |
120 | }); | |
121 | storage = null; | |
122 | } | |
123 | }); | |
6a488035 TO |
124 | }; |
125 | ||
126 | </script> | |
127 | {/literal} |