Changeset 449


Ignore:
Timestamp:
May 20, 2010, 2:56:52 PM (13 years ago)
Author:
tabma
Message:
  • first page of simple import wizard working with entity-/templatefilter
Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy

    r417 r449  
    2929import dbnp.studycapturing.TemplateFieldType
    3030import dbnp.studycapturing.TemplateField
     31import grails.converters.JSON
    3132
    3233class ImporterController {
    33     def ImporterService
     34    def ImporterService   
    3435
    3536    /**
     
    4041
    4142    def simplewizard = {
    42         def entities = ["Subject", "Event", "Sample"]
    43         render(view:"index_simple", model:[studies:Study.list(), entities:entities])
     43        render(view:"index_simple", model:[studies:Study.list(), entities: grailsApplication.config.gscf.domain.importableEntities])
    4444    }
    4545
     
    160160        render(view:"step4")
    161161    }
     162
     163    /**
     164    * Return templates which belong to a certain entity type
     165    *
     166    * @param entity entity name string (Sample, Subject, Study et cetera)
     167    * @return JSON object containing the found templates
     168    */
     169    def ajaxGetTemplatesByEntity = {
     170        def entityClass = grailsApplication.config.gscf.domain.importableEntities.get(params.entity).entity
     171
     172        // fetch all templates for a specific entity
     173        def templates = Template.findAllByEntity(Class.forName(entityClass, true, this.getClass().getClassLoader()))
     174
     175        println templates
     176       
     177        // render as JSON
     178        render templates as JSON
     179    }
    162180}
  • trunk/grails-app/views/importer/index_simple.gsp

    r417 r449  
    55
    66<%@ page contentType="text/html;charset=UTF-8" %>
     7<g:setProvider library="jquery"/>
    78
    89<html>
     
    1011    <meta name="layout" content="main"/>
    1112    <title>Importer wizard (simple)</title>
    12   </head>
     13
     14<g:javascript>
     15/**
     16 * Update one select based on another select
     17 *
     18 * @author
     19 * @see     http://www.grails.org/Tag+-+remoteFunction
     20 * @param   string  select (form) name
     21 * @param   string  JSON data
     22 * @param   boolean keep the first option
     23 * @param   int     selected option
     24 * @param   string  if null, show this as option instead
     25 * @void
     26 */
     27function updateSelect(name,data,keepFirstOption,selected,presentNullAsThis) {   
     28    var rselect = $('#'+name).get(0)
     29    var items = data
     30
     31    if (items) {
     32
     33        // remove old options
     34        var start = (keepFirstOption) ? 0 : -1;
     35        var i = rselect.length
     36
     37        while (i > start) {
     38            rselect.remove(i)
     39            i--
     40        }
     41
     42        // add new options
     43        $.each(items,function() {
     44            var i = rselect.options.length
     45
     46            rselect.options[i] = new Option(
     47                (presentNullAsThis && this.name == null) ? presentNullAsThis : this.name,
     48                this.id
     49            );
     50            if (this.id == selected) rselect.options[i].selected = true
     51        });
     52    }
     53}
     54</g:javascript>
     55</head>
    1356  <body>
    1457    <h1>Importer wizard (simple)</h1>
     
    3780            </td>
    3881            <td>
    39                 <g:select name="entity" from="${entities}"/>
     82                <g:select
     83                name="entity"
     84                from="${entities}"             
     85                optionValue="${{it.value.name}}"
     86                optionKey="key"
     87                noSelection="['':'-Choose type of data-']"
     88                onChange="${remoteFunction( controller: 'importer',
     89                                            action:'ajaxGetTemplatesByEntity',
     90                                            params: '\'entity=\'+escape(this.value)',
     91                                            onSuccess:'updateSelect(\'template_id\',data,false,false,\'default\')')}" />
    4092            </td>
    4193        </tr>
     94        <tr>
     95            <td>
     96                Choose type of data template:
     97            </td>
     98            <td>
     99                <g:select name="template_id" optionKey="id" optionValue="name" from="[]" />
     100            </td>
     101        </tr>
     102
     103
    42104        <tr>
    43105            <td colspan="2">
Note: See TracChangeset for help on using the changeset viewer.