Changeset 2160
- Timestamp:
- Feb 3, 2012, 2:04:04 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/generic/AjaxController.groovy
r2151 r2160 19 19 class AjaxController { 20 20 def authenticationService 21 def ajaxService 21 22 22 23 /** … … 92 93 93 94 def studyCount = { 94 def matched = true95 95 def user = authenticationService.getLoggedInUser() 96 def studies = Study.giveReadableStudies(user) 97 def matchedStudies = [] 98 99 // closure to transform criteria arguments to an array of Longs 100 def getAsArray = { paramText -> 101 def result = [] 102 103 if (paramText == null) { 104 result = [] 105 } else if (paramText.toString().contains(",")) { 106 result = paramText.collect { it as Long } 107 } else { 108 result = [paramText as Long] 109 } 110 111 return result 112 } 113 114 // define criteria arrays based on JSON arguments 115 def uniqueSpecies = (params.containsKey('uniqueSpecies[]')) ? getAsArray(params['uniqueSpecies[]']) : [] 116 def uniqueEventTemplateNames = (params.containsKey('uniqueEventTemplateNames[]')) ? getAsArray(params['uniqueEventTemplateNames[]']) : [] 117 def uniqueSamplingEventTemplateNames = (params.containsKey('uniqueSamplingEventTemplateNames[]')) ? getAsArray(params['uniqueSamplingEventTemplateNames[]']) : [] 118 119 // iterate through readable studies for this user 120 studies.each { study -> 121 matched = true 122 123 // match to selection criteria 124 // 1. if any species were selected, see if this study contains any subject of this species 125 matched = (matched && (!uniqueSpecies.size() || study.subjects.find{uniqueSpecies.contains(it.species.id)})) ? true : false; 126 // 2. if any eventTemplateNames were selected, see if this study contains any of these 127 matched = (matched && (!uniqueEventTemplateNames.size() || study.events.find{uniqueEventTemplateNames.contains(it.template.id)})) ? true : false; 128 // 3. if any samplingEventTemplateNames were selected, see if this study contains any of these 129 matched = (matched && (!uniqueSamplingEventTemplateNames.size() || study.samplingEvents.find{uniqueSamplingEventTemplateNames.contains(it.template.id)})) ? true : false; 130 131 // if criteria are met, add this study to the matchedStudies array 132 if (matched) matchedStudies.add(study) 133 } 96 def total = Study.giveReadableStudies(user).size() 97 def studies = ajaxService.getStudiesByCriteriaForCurrentUser(params) 134 98 135 99 // define json result 136 def result = ['total':studies.size(),'matched':matchedStudies.size()]; 100 def result = ['total':total,'matched':studies.size()] 101 102 // set output header to json 103 response.contentType = 'application/json' 104 105 // render result 106 if (params.callback) { 107 render "${params.callback}(${result as JSON})" 108 } else { 109 render result as JSON 110 } 111 } 112 113 def studies = { 114 def studies = ajaxService.getStudiesByCriteriaForCurrentUser(params) 115 116 // define json result 117 def result = ['studies':studies.collect{ it.title }] 137 118 138 119 // set output header to json -
trunk/grails-app/views/studyCompare/pages/_page_one.gsp
r2151 r2160 31 31 } 32 32 33 console.log(criteria);34 35 36 33 $.getJSON( 37 34 baseUrl + "/ajax/studyCount", … … 42 39 ); 43 40 44 // $.ajax({45 // url: baseUrl + "/ajax/studyCount",46 // dataType: 'json',47 // data: criteria,48 // success: function(data) {49 // $('#matchedStudies').html(data.matched+' of '+data.total+' readable studies matched your criteria');50 // }51 // });52 /*53 var check = $(event);54 var value = check.attr('value');55 var parent = check.parent();56 var parentId = parent.attr('id');57 if (criteria[parentId] == undefined) criteria[parentId] = [];58 var c = criteria[parentId];59 60 // add or remove data61 if (check.is(':checked') && c.indexOf(value) < 0) {62 c.push(value);63 } else if (c.indexOf(value) >= 0) {64 c.splice(c.indexOf(value),1);65 }66 67 console.log(criteria);68 69 // ajax call70 41 $.getJSON( 71 "<g:createLink controller="ajax" action="studyCount"/>",42 baseUrl + "/ajax/studies", 72 43 criteria, 73 44 function(data) { 74 $('#matchedStudies').html(data.count+' studies matched your criteria'); 45 var studies = ''; 46 for (var i=0; i<data.studies.length; i++) { 47 studies = studies + data.studies[i] + '<br/>'; 48 } 49 $('#studyOverview').html(studies); 75 50 } 76 51 ); 77 78 $.ajax({79 url: baseUrl + "/ajax/studyCount",80 dataType: 'json',81 data: data,82 success: function(data) {83 $('#matchedStudies').html(data.count+' studies matched your criteria');84 }85 });86 */87 88 52 } 89 53 </script> 90 91 54 92 55 <div class="selector"> … … 96 59 </div> 97 60 <div id="matchedStudies"></div> 61 <div id="studyOverview" style="margin-top:20px;border: 1px solid blue;"></div> 98 62 99 63 </af:page>
Note: See TracChangeset
for help on using the changeset viewer.