1 | <% |
---|
2 | /** |
---|
3 | * wizard refresh flow action |
---|
4 | * |
---|
5 | * When a page (/ partial) is rendered, any DOM event handlers need to be |
---|
6 | * (re-)attached. The af:ajaxButton, af:ajaxSubmitJs and af:redirect tags |
---|
7 | * supports calling a JavaScript after the page has been rendered by passing |
---|
8 | * the 'afterSuccess' argument. |
---|
9 | * |
---|
10 | * Example: af:redirect afterSuccess="onPage();" |
---|
11 | * af:redirect afterSuccess="console.log('redirecting...');" |
---|
12 | * |
---|
13 | * Generally one would expect this code to add jQuery event handlers to |
---|
14 | * DOM objects in the rendered page (/ partial). |
---|
15 | * |
---|
16 | * @author Jeroen Wesbeek |
---|
17 | * @since 20101206 |
---|
18 | * |
---|
19 | * Revision information: |
---|
20 | * $Rev: 1555 $ |
---|
21 | * $Author: t.w.abma@umcutrecht.nl $ |
---|
22 | * $Date: 2011-02-24 10:15:00 +0000 (do, 24 feb 2011) $ |
---|
23 | */ |
---|
24 | %> |
---|
25 | <script type="text/javascript"> |
---|
26 | // Initially called when starting the import wizard |
---|
27 | function onPage() { |
---|
28 | // GENERAL |
---|
29 | onStudyWizardPage(); |
---|
30 | |
---|
31 | $('#simplewizardform').submit(function() { |
---|
32 | if ($('#file').val() == "") { |
---|
33 | alert("Please choose your Excel file to import."); |
---|
34 | return false |
---|
35 | } else |
---|
36 | if ($('#entity').val() == "") { |
---|
37 | $('#datatemplate').addClass("validationfail"); |
---|
38 | return false |
---|
39 | } else { |
---|
40 | $('#simplewizardform').submit(); |
---|
41 | } |
---|
42 | |
---|
43 | return false; |
---|
44 | }); |
---|
45 | |
---|
46 | // attach event to apply fuzzy matching |
---|
47 | $('#fuzzymatchselect').click(function() { |
---|
48 | $("#fuzzymatching").val("true") |
---|
49 | refreshFlow() |
---|
50 | }); |
---|
51 | |
---|
52 | // open load box |
---|
53 | $('#loadpropertiesbutton').click(function() { |
---|
54 | $("#loadmapping").toggle("scale") |
---|
55 | if ($("#importmapping_id").val()) refreshFlow() |
---|
56 | }); |
---|
57 | |
---|
58 | // open save box |
---|
59 | $('#savepropertiesbutton').click(function() { |
---|
60 | var width = 500 |
---|
61 | var height = 200 |
---|
62 | var vars = "" |
---|
63 | |
---|
64 | $("#savemapping").toggle("scale") |
---|
65 | |
---|
66 | if ($("#mappingname").val()) refreshFlow(); |
---|
67 | |
---|
68 | // get all properties |
---|
69 | //$('select[name^=columnproperty.index.]').each ( function() { |
---|
70 | //} |
---|
71 | |
---|
72 | /*$('#propertiesManager').dialog({ |
---|
73 | title : "Properties manager", |
---|
74 | autoOpen : true, |
---|
75 | width : width, |
---|
76 | vars : vars, |
---|
77 | height : height, |
---|
78 | modal : true, |
---|
79 | position : 'center', |
---|
80 | buttons : { |
---|
81 | Save : function() { |
---|
82 | //alert($(this).parent().$('input[name="mappingname"]').val()) |
---|
83 | alert($(this)) |
---|
84 | var p = $(this).parent().parent().parent() |
---|
85 | console.log(p.('input[name="mappingname"]').val()) |
---|
86 | //alert(vars) |
---|
87 | $(this).dialog('close'); } |
---|
88 | }, |
---|
89 | close : function() { |
---|
90 | //onClose(this); |
---|
91 | refreshFlow() |
---|
92 | } |
---|
93 | }).width(width - 10).height(height) |
---|
94 | */ |
---|
95 | |
---|
96 | }); |
---|
97 | |
---|
98 | |
---|
99 | // Disable Enter key |
---|
100 | function stopRKey(evt) { |
---|
101 | var evt = (evt) ? evt : ((event) ? event : null); |
---|
102 | var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); |
---|
103 | if ((evt.keyCode == 13) && (node.type=="text")) {return false;} |
---|
104 | } |
---|
105 | document.onkeypress = stopRKey; |
---|
106 | |
---|
107 | |
---|
108 | // attach function to clear button to reset all selects to "don't import" |
---|
109 | $('#clearselect').click(function() { |
---|
110 | // for each select field on the page |
---|
111 | $("select").each( function(){ |
---|
112 | // set its value to its first option |
---|
113 | $(this).val($('option:first', this).val()); |
---|
114 | }); |
---|
115 | }); |
---|
116 | |
---|
117 | // attach change event function to prevent duplicate selection of properties |
---|
118 | $('select[name^=columnproperty.index.]').each ( function() { |
---|
119 | $(this).bind('change', function(e) { |
---|
120 | //console.log($(this).val()) |
---|
121 | var selection = $(this) |
---|
122 | |
---|
123 | $('select[name^=columnproperty.index.] option:selected').each ( function() { |
---|
124 | var selector = $(this) |
---|
125 | |
---|
126 | if (selection.attr('id') != selector.parent().attr('id') && (selection.val()!="dontimport")) |
---|
127 | if ($(this).val() == selection.val()) { |
---|
128 | selection.val($('option:first', selection).val()); |
---|
129 | |
---|
130 | alert("Property is already set for an other column, please choose a different property.") |
---|
131 | return false |
---|
132 | } |
---|
133 | }); |
---|
134 | }); |
---|
135 | }); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * Update one select based on another select |
---|
140 | * |
---|
141 | * @author |
---|
142 | * @see http://www.grails.org/Tag+-+remoteFunction |
---|
143 | * @param string select (form) name |
---|
144 | * @param string JSON data |
---|
145 | * @param boolean keep the first option |
---|
146 | * @param int selected option |
---|
147 | * @param string if null, show this as option instead |
---|
148 | * @void |
---|
149 | */ |
---|
150 | function updateSelect(name, data, keepFirstOption, selected, presentNullAsThis) { |
---|
151 | var rselect = $('#' + name).get(0) |
---|
152 | var items = data |
---|
153 | |
---|
154 | // If a study has been selected, don't show the "Choose study" field, otherwise do |
---|
155 | if ($('#' + 'entity :selected').text() == 'Study') |
---|
156 | $('#studyfield').hide(); |
---|
157 | else $('#studyfield').show(); |
---|
158 | |
---|
159 | $('select[name=template_id]').attr('entity', $('#' + 'entity').val()); |
---|
160 | |
---|
161 | if (items) { |
---|
162 | |
---|
163 | // remove old options |
---|
164 | var start = (keepFirstOption) ? 0 : -1; |
---|
165 | var i = rselect.length |
---|
166 | |
---|
167 | while (i > start) { |
---|
168 | rselect.remove(i) |
---|
169 | i-- |
---|
170 | } |
---|
171 | |
---|
172 | // add new options |
---|
173 | $.each(items, function() { |
---|
174 | var i = rselect.options.length |
---|
175 | |
---|
176 | rselect.options[i] = new Option( |
---|
177 | (presentNullAsThis && this.name == null) ? presentNullAsThis : this.name, |
---|
178 | this.id |
---|
179 | ); |
---|
180 | if (this.id == selected) rselect.options[i].selected = true |
---|
181 | }); |
---|
182 | } |
---|
183 | |
---|
184 | // handle template selects |
---|
185 | new SelectAddMore().init({ |
---|
186 | rel : 'template', |
---|
187 | url : baseUrl + '/templateEditor', |
---|
188 | vars : 'entity', // can be a comma separated list of variable names to pass on |
---|
189 | label : 'add / modify ...', |
---|
190 | style : 'modify', |
---|
191 | onClose : function(scope) { |
---|
192 | refreshFlow() |
---|
193 | } |
---|
194 | }); |
---|
195 | } |
---|
196 | |
---|
197 | </script> |
---|