Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
5 | | This work is published under the GNU AGPLv3 license with some | |
6 | | permitted exceptions and without any warranty. For full license | | |
7 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | ||
11 | <tr> | |
12 | <td class="label">{$form.option_type.label}</td> | |
13 | <td class="html-adjust">{$form.option_type.html}<br /> | |
14 | <span class="description">{ts}You can create new result options for this survey, or select an existing survey result set which you've already created for another survey.{/ts}</span> | |
15 | </td> | |
16 | </tr> | |
17 | ||
18 | <tr id="option_group" {if !$form.option_group_id}class="hiddenElement"{/if}> | |
19 | <td class="label">{$form.option_group_id.label}</td> | |
20 | <td class="html-adjust">{$form.option_group_id.html}</td> | |
21 | </tr> | |
22 | ||
23 | <tr id="multiple"> | |
24 | <td colspan="2" class="html-adjust"> | |
25 | <fieldset><legend>{ts}Result Options{/ts}</legend> | |
26 | <span class="description"> | |
27 | {ts}Enter up to ten (10) multiple choice options in this table (click 'another choice' for each additional choice).You can use existing result set options by selecting survey result set.{/ts} | |
28 | </span> | |
29 | <br /> | |
30 | {strip} | |
31 | <table id="optionField"> | |
32 | <tr> | |
33 | <th> </th> | |
34 | <th> {ts}Default{/ts}</th> | |
35 | <th> {ts}Label{/ts}</th> | |
36 | <th> {ts}Value{/ts}</th> | |
37 | <th> {ts}Recontact Interval{/ts}</th> | |
7ecddde4 | 38 | <th> {ts}Order{/ts}</th> |
6a488035 TO |
39 | </tr> |
40 | ||
41 | {section name=rowLoop start=1 loop=12} | |
42 | {assign var=index value=$smarty.section.rowLoop.index} | |
43 | <tr id="optionField_{$index}" class="form-item {cycle values="odd-row,even-row"}"> | |
44 | <td> | |
45 | {if $index GT 1} | |
5451b0f8 | 46 | <a onclick="showHideRow({$index}); return false;" name="optionField_{$index}" href="#" class="form-link"><i class="crm-i fa-trash" title="{ts}hide field or section{/ts}"></i></a> |
6a488035 TO |
47 | {/if} |
48 | </td> | |
49 | <td> | |
50 | <div id="radio{$index}"> | |
51 | {$form.default_option[$index].html} | |
52 | </div> | |
53 | ||
54 | </td> | |
55 | <td> {$form.option_label.$index.html}</td> | |
56 | <td> {$form.option_value.$index.html}</td> | |
57 | <td> {$form.option_interval.$index.html}</td> | |
58 | <td> {$form.option_weight.$index.html}</td> | |
59 | </tr> | |
60 | {/section} | |
61 | </table> | |
62 | <div id="optionFieldLink" class="add-remove-link"> | |
5451b0f8 | 63 | <a onclick="showHideRow(); return false;" name="optionFieldLink" href="#" class="form-link"><i class="crm-i fa-plus-circle"></i> {ts}add another choice{/ts}</a> |
6a488035 TO |
64 | </div> |
65 | <span id="additionalOption" class="description"> | |
66 | {ts}If you need additional options - you can add them after you Save your current entries.{/ts} | |
67 | </span> | |
68 | {/strip} | |
69 | ||
70 | </fieldset> | |
71 | </td> | |
72 | </tr> | |
73 | ||
74 | <script type="text/javascript"> | |
ae8f569f CW |
75 | var showRows = [{$showBlocks}]; |
76 | var hideBlocks = [{$hideBlocks}]; | |
6a488035 TO |
77 | var rowcounter = 0; |
78 | var surveyId = {if $surveyId}{$surveyId}{else}''{/if}; | |
79 | ||
80 | {literal} | |
81 | if (navigator.appName == "Microsoft Internet Explorer") { | |
82 | for ( var count = 0; count < hideBlocks.length; count++ ) { | |
83 | var r = document.getElementById(hideBlocks[count]); | |
84 | r.style.display = 'none'; | |
85 | } | |
86 | } | |
87 | ||
88 | function showOptionSelect( ) { | |
89 | if ( document.getElementsByName("option_type")[0].checked ) { | |
90 | cj('#option_group').hide(); | |
91 | cj('#default_option').val(''); | |
92 | } else { | |
93 | cj('#option_group').show(); | |
94 | loadOptionGroup( ); | |
95 | } | |
96 | } | |
97 | ||
98 | function resetResultSet( ) { | |
99 | for( i=1; i<=11; i++ ) { | |
100 | cj('#option_label_'+ i).val(''); | |
101 | cj('#option_value_'+ i).val(''); | |
102 | cj('#option_weight_'+ i).val(''); | |
103 | cj('#option_interval_'+ i).val(''); | |
104 | if ( i > 2 ) { | |
105 | showHideRow(i); | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | function loadOptionGroup( ) { | |
111 | var data = new Object; | |
112 | ||
113 | resetResultSet( ); | |
114 | if ( cj('#option_group_id').val() ) { | |
115 | data['option_group_id'] = cj('#option_group_id').val(); | |
116 | data['survey_id'] = surveyId; | |
117 | } else { | |
118 | return false; | |
119 | } | |
120 | ||
121 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Campaign_Page_AJAX&fnName=loadOptionGroupDetails' }"{literal} | |
122 | ||
123 | // build new options | |
124 | cj.post( dataUrl, data, function( opGroup ) { | |
125 | if ( opGroup.status == 'success' ) { | |
126 | var result = opGroup.result; | |
127 | var countRows = 1; | |
128 | for( key in result ) { | |
129 | cj('#option_label_'+ countRows).val( result[key].label); | |
130 | cj('#option_value_'+ countRows).val( result[key].value); | |
131 | cj('#option_weight_'+ countRows).val( result[key].weight); | |
132 | ||
133 | if ( surveyId && result[key].interval ) { | |
134 | cj('#option_interval_'+ countRows).val( result[key].interval); | |
135 | } | |
136 | ||
137 | if ( result[key].is_default == 1 ) { | |
8539f25d | 138 | cj('#radio'+countRows+' input').prop('checked', true); |
6a488035 TO |
139 | } |
140 | ||
141 | if ( countRows > 1 ) { | |
142 | showHideRow( ); | |
143 | } | |
144 | countRows +=1; | |
145 | } | |
146 | } | |
147 | }, "json" ); | |
148 | } | |
149 | ||
32678ccb | 150 | CRM.$(function($) { |
6a488035 TO |
151 | showOptionSelect( ); |
152 | }); | |
153 | ||
154 | {/literal} | |
155 | on_load_init_blocks( showRows, hideBlocks, '' ); | |
156 | </script> | |
157 |