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