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: 1505 $ |
---|
21 | * $Author: t.w.abma@umcutrecht.nl $ |
---|
22 | * $Date: 2011-02-08 14:53:49 +0000 (di, 08 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 | $('#fuzzymatchselect').click(function() { |
---|
47 | refreshFlow() |
---|
48 | }); |
---|
49 | |
---|
50 | // attach function to clear button to reset all selects to "don't import" |
---|
51 | $('#clearselect').click(function() { |
---|
52 | // for each select field on the page |
---|
53 | $("select").each( function(){ |
---|
54 | // set its value to its first option |
---|
55 | $(this).val($('option:first', this).val()); |
---|
56 | }); |
---|
57 | }); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Update one select based on another select |
---|
62 | * |
---|
63 | * @author |
---|
64 | * @see http://www.grails.org/Tag+-+remoteFunction |
---|
65 | * @param string select (form) name |
---|
66 | * @param string JSON data |
---|
67 | * @param boolean keep the first option |
---|
68 | * @param int selected option |
---|
69 | * @param string if null, show this as option instead |
---|
70 | * @void |
---|
71 | */ |
---|
72 | function updateSelect(name, data, keepFirstOption, selected, presentNullAsThis) { |
---|
73 | var rselect = $('#' + name).get(0) |
---|
74 | var items = data |
---|
75 | |
---|
76 | // If a study has been selected, don't show the "Choose study" field, otherwise do |
---|
77 | if ($('#' + 'entity :selected').text() == 'Study') |
---|
78 | $('#studyfield').hide(); |
---|
79 | else $('#studyfield').show(); |
---|
80 | |
---|
81 | $('select[name=template_id]').attr('entity', $('#' + 'entity').val()); |
---|
82 | |
---|
83 | if (items) { |
---|
84 | |
---|
85 | // remove old options |
---|
86 | var start = (keepFirstOption) ? 0 : -1; |
---|
87 | var i = rselect.length |
---|
88 | |
---|
89 | while (i > start) { |
---|
90 | rselect.remove(i) |
---|
91 | i-- |
---|
92 | } |
---|
93 | |
---|
94 | // add new options |
---|
95 | $.each(items, function() { |
---|
96 | var i = rselect.options.length |
---|
97 | |
---|
98 | rselect.options[i] = new Option( |
---|
99 | (presentNullAsThis && this.name == null) ? presentNullAsThis : this.name, |
---|
100 | this.id |
---|
101 | ); |
---|
102 | if (this.id == selected) rselect.options[i].selected = true |
---|
103 | }); |
---|
104 | } |
---|
105 | |
---|
106 | // handle template selects |
---|
107 | new SelectAddMore().init({ |
---|
108 | rel : 'template', |
---|
109 | url : baseUrl + '/templateEditor', |
---|
110 | vars : 'entity', // can be a comma separated list of variable names to pass on |
---|
111 | label : 'add / modify ...', |
---|
112 | style : 'modify', |
---|
113 | onClose : function(scope) { |
---|
114 | refreshFlow() |
---|
115 | } |
---|
116 | }); |
---|
117 | } |
---|
118 | |
---|
119 | </script> |
---|
120 | |
---|