Changeset 449
- Timestamp:
- May 20, 2010, 2:56:52 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r417 r449 29 29 import dbnp.studycapturing.TemplateFieldType 30 30 import dbnp.studycapturing.TemplateField 31 import grails.converters.JSON 31 32 32 33 class ImporterController { 33 def ImporterService 34 def ImporterService 34 35 35 36 /** … … 40 41 41 42 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]) 44 44 } 45 45 … … 160 160 render(view:"step4") 161 161 } 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 } 162 180 } -
trunk/grails-app/views/importer/index_simple.gsp
r417 r449 5 5 6 6 <%@ page contentType="text/html;charset=UTF-8" %> 7 <g:setProvider library="jquery"/> 7 8 8 9 <html> … … 10 11 <meta name="layout" content="main"/> 11 12 <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 */ 27 function 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> 13 56 <body> 14 57 <h1>Importer wizard (simple)</h1> … … 37 80 </td> 38 81 <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\')')}" /> 40 92 </td> 41 93 </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 42 104 <tr> 43 105 <td colspan="2">
Note: See TracChangeset
for help on using the changeset viewer.