Merge pull request #159 from lcdservices/master
[civicrm-core.git] / templates / CRM / common / customData.tpl
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();
44 } else {
45 cj('#customData').show();
46 }
47 if ( groupID ) {
48 dataUrl = dataUrl + '&groupID=' + groupID;
49 }
50
51 {/literal}
52 {if $urlPathVar}
53 dataUrl = dataUrl + '&' + '{$urlPathVar}'
54 {/if}
55 {if $groupID}
56 dataUrl = dataUrl + '&groupID=' + '{$groupID}'
57 {/if}
58 {if $qfKey}
59 dataUrl = dataUrl + '&qfKey=' + '{$qfKey}'
60 {/if}
61 {if $entityID}
62 dataUrl = dataUrl + '&entityID=' + '{$entityID}'
63 {/if}
64 {literal}
65
66 if ( !cgCount ) {
67 cgCount = 1;
68 var prevCount = 1;
69 } else if ( cgCount >= 1 ) {
70 var prevCount = cgCount;
71 cgCount++;
72 }
73
74 dataUrl = dataUrl + '&cgcount=' + cgCount;
75
76
77 if ( isMultiple ) {
78 var fname = '#custom_group_' + groupID + '_' + prevCount;
79 if (cj(".add-more-link-" + groupID + "-" + prevCount ).length) {
80 cj(".add-more-link-" + groupID + "-" + prevCount).hide();
81 } else {
82 cj("#add-more-link-"+prevCount).hide();
83 }
84 } else {
85 if ( subName && subName != 'null' ) {
86 var fname = '#customData' + subName ;
87 } else {
88 var fname = '#customData';
89 }
90 }
91
92 cj.ajax({
93 url: dataUrl,
94 dataType: 'html',
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 });
105 cj('option:selected', this).attr('selected', 'selected');
106 cj('option:not(:selected)', this).removeAttr('selected');
107 storage[id] = cj(this).detach();
108 }
109 });
110 target.html(response);
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 });
120
121 };
122
123 </script>
124 {/literal}