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