1 | <!-- |
---|
2 | To change this template, choose Tools | Templates |
---|
3 | and open the template in the editor. |
---|
4 | --> |
---|
5 | |
---|
6 | <%@ page contentType="text/html;charset=UTF-8" %> |
---|
7 | |
---|
8 | <html> |
---|
9 | <head> |
---|
10 | <meta name="layout" content="main"/> |
---|
11 | <title>Importer wizard (simple)</title> |
---|
12 | <link rel="stylesheet" href="${resource(dir: 'css', file: 'importer.css')}"/> |
---|
13 | |
---|
14 | <g:javascript library="jquery" plugin="jquery"/> |
---|
15 | |
---|
16 | <g:javascript> |
---|
17 | /** |
---|
18 | * Update one select based on another select |
---|
19 | * |
---|
20 | * @author |
---|
21 | * @see http://www.grails.org/Tag+-+remoteFunction |
---|
22 | * @param string select (form) name |
---|
23 | * @param string JSON data |
---|
24 | * @param boolean keep the first option |
---|
25 | * @param int selected option |
---|
26 | * @param string if null, show this as option instead |
---|
27 | * @void |
---|
28 | */ |
---|
29 | function updateSelect(name,data,keepFirstOption,selected,presentNullAsThis) { |
---|
30 | var rselect = $('#'+name).get(0) |
---|
31 | var items = data |
---|
32 | |
---|
33 | if (items) { |
---|
34 | |
---|
35 | // remove old options |
---|
36 | var start = (keepFirstOption) ? 0 : -1; |
---|
37 | var i = rselect.length |
---|
38 | |
---|
39 | while (i > start) { |
---|
40 | rselect.remove(i) |
---|
41 | i-- |
---|
42 | } |
---|
43 | |
---|
44 | // add new options |
---|
45 | $.each(items,function() { |
---|
46 | var i = rselect.options.length |
---|
47 | |
---|
48 | rselect.options[i] = new Option( |
---|
49 | (presentNullAsThis && this.name == null) ? presentNullAsThis : this.name, |
---|
50 | this.id |
---|
51 | ); |
---|
52 | if (this.id == selected) rselect.options[i].selected = true |
---|
53 | }); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | $(document).ready(function() { |
---|
58 | |
---|
59 | $('#simplewizardform').submit(function() { |
---|
60 | if ($('#file').val() == "") { |
---|
61 | alert ("Please choose your Excel file to import."); |
---|
62 | return false |
---|
63 | } else |
---|
64 | if ($('#entity').val() == "") { |
---|
65 | $('#datatemplate').addClass("validationfail"); |
---|
66 | return false |
---|
67 | } else |
---|
68 | $('#simplewizardform').submit(); |
---|
69 | |
---|
70 | return false; |
---|
71 | }); |
---|
72 | }); |
---|
73 | |
---|
74 | </g:javascript> |
---|
75 | </head> |
---|
76 | <body> |
---|
77 | <h1>Importer wizard (simple)</h1> |
---|
78 | <p>You can import your Excel data to the server by choosing a file from your local harddisk in the form below.</p> |
---|
79 | <form id="simplewizardform" controller="importer" method="post" action="upload_simple" enctype="multipart/form-data"> |
---|
80 | <table border="0"> |
---|
81 | <tr> |
---|
82 | <td width="100px"> |
---|
83 | Choose your Excel file to import: |
---|
84 | </td> |
---|
85 | <td width="100px"> |
---|
86 | <input id="file" type="file" name="importfile"/> |
---|
87 | </td> |
---|
88 | </tr> |
---|
89 | <tr> |
---|
90 | <td width="100px"> |
---|
91 | Use data from sheet: |
---|
92 | </td> |
---|
93 | <td width="100px"> |
---|
94 | <g:select name="sheetindex" from="${1..10}"/> |
---|
95 | </td> |
---|
96 | </tr> |
---|
97 | <tr> |
---|
98 | <td width="100px"> |
---|
99 | Columnheader starts at row: |
---|
100 | </td> |
---|
101 | <td width="100px"> |
---|
102 | <g:select name="headerrow" from="${1..10}"/> |
---|
103 | </td> |
---|
104 | </tr> |
---|
105 | <tr> |
---|
106 | <td width="100px"> |
---|
107 | Data starts at row: |
---|
108 | </td> |
---|
109 | <td width="100px"> |
---|
110 | <g:select name="datamatrix_start" from="${2..10}"/> |
---|
111 | </td> |
---|
112 | </tr> |
---|
113 | <tr> |
---|
114 | <td> |
---|
115 | Choose your study: |
---|
116 | </td> |
---|
117 | <td> |
---|
118 | <g:select name="study.id" from="${studies}" optionKey="id"/> |
---|
119 | </td> |
---|
120 | </tr> |
---|
121 | <tr> |
---|
122 | <td> |
---|
123 | Choose type of data: |
---|
124 | </td> |
---|
125 | <td> |
---|
126 | <g:select |
---|
127 | name="entity" |
---|
128 | id="entity" |
---|
129 | from="${entities}" |
---|
130 | optionValue="${{it.value.name}}" |
---|
131 | optionKey="key" |
---|
132 | noSelection="['':'-Choose type of data-']" |
---|
133 | onChange="${remoteFunction( controller: 'importer', |
---|
134 | action:'ajaxGetTemplatesByEntity', |
---|
135 | params: '\'entity=\'+escape(this.value)', |
---|
136 | onSuccess:'updateSelect(\'template_id\',data,false,false,\'default\')')}" /> |
---|
137 | </td> |
---|
138 | </tr> |
---|
139 | <tr> |
---|
140 | <td> |
---|
141 | <div id="datatemplate">Choose type of data template:</div> |
---|
142 | </td> |
---|
143 | <td> |
---|
144 | <g:select name="template_id" optionKey="id" optionValue="name" from="[]" /> |
---|
145 | </td> |
---|
146 | </tr> |
---|
147 | |
---|
148 | |
---|
149 | <tr> |
---|
150 | <td colspan="2"> |
---|
151 | <input type="submit" value="Next"/> |
---|
152 | </td> |
---|
153 | </tr> |
---|
154 | </table> |
---|
155 | </form> |
---|
156 | |
---|
157 | </body> |
---|
158 | </html> |
---|