Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-28-20-20-34
[civicrm-core.git] / templates / CRM / common / customData.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
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();
44 }
45 else {
46 cj('#customData').show();
47 }
48 if ( groupID ) {
49 dataUrl = dataUrl + '&groupID=' + groupID;
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;
70 }
71 else if ( cgCount >= 1 ) {
72 var prevCount = cgCount;
73 cgCount++;
74 }
75
76 dataUrl = dataUrl + '&cgcount=' + cgCount;
77
78
79 if ( isMultiple ) {
80 var fname = '#custom_group_' + groupID + '_' + prevCount;
81 if (cj(".add-more-link-" + groupID + "-" + prevCount ).length) {
82 cj(".add-more-link-" + groupID + "-" + prevCount).hide();
83 }
84 else {
85 cj("#add-more-link-"+prevCount).hide();
86 }
87 }
88 else {
89 if ( subName && subName != 'null' ) {
90 var fname = '#customData' + subName ;
91 }
92 else {
93 var fname = '#customData';
94 }
95 }
96
97 cj.ajax({
98 url: dataUrl,
99 dataType: 'html',
100 async: false,
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 });
126 };
127
128 </script>
129 {/literal}