source: trunk/grails-app/views/importer/common/_on_page.gsp @ 1335

Last change on this file since 1335 was 1335, checked in by t.w.abma@…, 10 years ago
  • added baseUrl variable to the add/modify... templateEditor selector initialization
File size: 2.8 KB
Line 
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$
21 * $Author$
22 * $Date$
23 */
24%>
25<script type="text/javascript">
26    // Initially called when starting the import wizard
27    function onPage() {
28
29    $(document).ready(function() {
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        return false;
43    });
44    });
45 }
46
47 
48/**
49 * Update one select based on another select
50 *
51 * @author
52 * @see     http://www.grails.org/Tag+-+remoteFunction
53 * @param   string  select (form) name
54 * @param   string  JSON data
55 * @param   boolean keep the first option
56 * @param   int     selected option
57 * @param   string  if null, show this as option instead
58 * @void
59 */
60function updateSelect(name,data,keepFirstOption,selected,presentNullAsThis) {
61    var rselect = $('#'+name).get(0)
62    var items = data
63
64    // If a study has been selected, don't show the "Choose study" field, otherwise do
65    if ($('#'+'entity :selected').text() == 'Study')
66      $('#studyfield').hide();
67    else $('#studyfield').show();
68
69    $('select[name=template_id]').attr('entity', $('#'+'entity').val());
70
71    if (items) {
72
73        // remove old options
74        var start = (keepFirstOption) ? 0 : -1;
75        var i = rselect.length
76
77        while (i > start) {
78            rselect.remove(i)
79            i--
80        }
81
82        // add new options
83        $.each(items,function() {
84            var i = rselect.options.length
85
86            rselect.options[i] = new Option(
87                (presentNullAsThis && this.name == null) ? presentNullAsThis : this.name,
88                this.id
89            );
90            if (this.id == selected) rselect.options[i].selected = true
91        });
92    }
93
94 // handle template selects
95  new SelectAddMore().init({
96       rel     : 'typetemplate',
97       url     : baseUrl + '/templateEditor',
98       vars    : 'entity', // can be a comma separated list of variable names to pass on
99       label   : 'add / modify ...',
100       style   : 'modify',
101       onClose : function(scope) {
102           location.reload();
103       }
104    });
105}
106
107</script>
108
Note: See TracBrowser for help on using the repository browser.