Changeset 539 for trunk/grails-app/taglib
- Timestamp:
- Jun 8, 2010, 11:18:27 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r527 r539 991 991 } 992 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 if( attrs.get( 'value' ) == null) {1018 1019 1020 if( attrs.get( 'description' ) == null) {1021 1022 1023 1024 1025 name: attrs.get( "name"),1026 1027 1028 993 def PublicationSelectElement = { attrs, body -> 994 995 attrs.description = 'Publications'; 996 // render list with publications currently available 997 baseElement.call( 998 '_publicationList', 999 attrs, 1000 body 1001 ) 1002 1003 attrs.description = ''; 1004 1005 // render 'Add publication button' 1006 baseElement.call( 1007 '_publicationAddButton', 1008 attrs, 1009 body 1010 ) 1011 } 1012 1013 /** 1014 * Renders a input box for publications 1015 */ 1016 def publicationSelect = { attrs, body -> 1017 if (attrs.get('value') == null) { 1018 attrs.value = []; 1019 } 1020 if (attrs.get('description') == null) { 1021 attrs.description = ''; 1022 } 1023 out << '<form id="' + attrs.name + '_form">'; 1024 out << textField( 1025 name: attrs.get("name"), 1026 value: '', 1027 rel: 'publication-pubmed', 1028 style: 'width: 400px;' 1029 1029 ); 1030 1031 1032 out << ' var onSelect = function( chooserObject, inputElement, event, ui ) { selectPubMedAdd( chooserObject, inputElement, event, ui ); enableButton( ".'+ attrs.name + '_publication_dialog", "Add", true ); };'1033 out << ' iField = $( "#' + attrs.get( 'name') + '" );';1034 1035 1036 1037 1038 1039 1040 if( !attrs.get( 'value' ) || attrs.get( 'value' ).size() == 0) {1041 display_none ='inline';1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 if( attrs.get( 'value' ) && attrs.get( 'value' ).size() > 0) {1058 1059 attrs.get( 'value').each {1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 if( attrs.get( 'value' ) && attrs.get( 'value' ).size() > 0) {1073 ids = attrs.get( 'value' ).id.join( ',')1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 out << publicationSelect( attrs, body);1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 if( !attrs.get( 'value' ) || attrs.get( 'value' ).size() == 0) {1136 display_none ='inline';1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 if( attrs.get( 'value' ) && attrs.get( 'value' ).size() > 0) {1153 1154 attrs.get( 'value').each {1155 1156 1157 1158 out << ' "' + it.person.lastName + ', ' + it.person.firstName + ( it.person.prefix ? ' ' + it.person.prefix : '') + '",';1159 1160 1161 1162 1163 1164 1165 1166 1167 if( attrs.get( 'value' ) && attrs.get( 'value' ).size() > 0) {1168 ids = attrs.get( 'value').collect { it.person.id + '-' + it.role.id }1169 ids = ids.join( ',');1170 1171 1172 1173 1174 1175 out << _personSelect( attrs ) + _roleSelect( attrs);1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1030 out << '</form>'; 1031 out << '<script type="text/javascript">'; 1032 out << ' var onSelect = function( chooserObject, inputElement, event, ui ) { selectPubMedAdd( chooserObject, inputElement, event, ui ); enableButton( ".' + attrs.name + '_publication_dialog", "Add", true ); };' 1033 out << ' iField = $( "#' + attrs.get('name') + '" );'; 1034 out << ' new PublicationChooser().initAutocomplete( iField, { "select" : onSelect } );'; 1035 out << '</script>'; 1036 } 1037 1038 def _publicationList = { attrs, body -> 1039 def display_none = 'none'; 1040 if (!attrs.get('value') || attrs.get('value').size() == 0) { 1041 display_none = 'inline'; 1042 } 1043 1044 // Add a unordered list 1045 out << '<ul class="publication_list" id="' + attrs.name + '_list">'; 1046 1047 out << '<li>'; 1048 out << '<span class="publication_none" id="' + attrs.name + '_none" style="display: ' + display_none + ';">'; 1049 out << 'No publications selected'; 1050 out << '</span>'; 1051 out << '</li>'; 1052 1053 out << '</ul>'; 1054 1055 // Add the publications using javascript 1056 out << '<script type="text/javascript">' 1057 if (attrs.get('value') && attrs.get('value').size() > 0) { 1058 def i = 0; 1059 attrs.get('value').each { 1060 out << 'showPublication( '; 1061 out << ' "' + attrs.name + '",'; 1062 out << ' ' + it.id + ','; 1063 out << ' "' + it.title + '",'; 1064 out << ' "' + it.authorsList + '",'; 1065 out << ' ' + i++; 1066 out << ');'; 1067 } 1068 } 1069 out << '</script>'; 1070 1071 def ids; 1072 if (attrs.get('value') && attrs.get('value').size() > 0) { 1073 ids = attrs.get('value').id.join(',') 1074 } else { 1075 ids = ''; 1076 } 1077 out << '<input type="hidden" name="' + attrs.name + '_ids" value="' + ids + '" id="' + attrs.name + '_ids">'; 1078 } 1079 1080 def _publicationAddButton = { attrs, body -> 1081 1082 // Output the dialog for the publications 1083 out << '<div id="' + attrs.name + '_dialog">'; 1084 out << '<p>Search for a publication on pubmed. You can search on a part of the title or authors. </p>'; 1085 out << publicationSelect(attrs, body); 1086 out << '</div>'; 1087 out << '<script type="text/javascript">'; 1088 out << ' createPublicationDialog( "' + attrs.name + '" );' 1089 out << '</script>'; 1090 1091 out << '<input type="button" onClick="openPublicationDialog(\'' + attrs.name + '\' );" value="Add Publication">'; 1092 } 1093 1094 def ContactSelectElement = { attrs, body -> 1095 1096 attrs.description = 'Contacts'; 1097 // render list with publications currently available 1098 baseElement.call( 1099 '_contactList', 1100 attrs, 1101 body 1102 ) 1103 1104 attrs.description = ''; 1105 1106 // render 'publications list' 1107 out << '<div id="' + attrs.name + '_dialog" class="contacts_dialog" style="display: none;">' 1108 baseElement.call( 1109 '_personSelect', 1110 attrs, 1111 body 1112 ) 1113 baseElement.call( 1114 '_roleSelect', 1115 attrs, 1116 body 1117 ) 1118 baseElement.call( 1119 '_contactAddButtonAddition', 1120 attrs, 1121 body 1122 ) 1123 out << '</div>'; 1124 1125 // render 'Add contact button' 1126 baseElement.call( 1127 '_contactAddDialogButton', 1128 attrs, 1129 body 1130 ) 1131 } 1132 1133 def _contactList = { attrs, body -> 1134 def display_none = 'none'; 1135 if (!attrs.get('value') || attrs.get('value').size() == 0) { 1136 display_none = 'inline'; 1137 } 1138 1139 // Add a unordered list 1140 out << '<ul class="contact_list" id="' + attrs.name + '_list">'; 1141 1142 out << '<li>'; 1143 out << '<span class="contacts_none" id="' + attrs.name + '_none" style="display: ' + display_none + ';">'; 1144 out << 'No contacts selected'; 1145 out << '</span>'; 1146 out << '</li>'; 1147 1148 out << '</ul>'; 1149 1150 // Add the contacts using javascript 1151 out << '<script type="text/javascript">' 1152 if (attrs.get('value') && attrs.get('value').size() > 0) { 1153 def i = 0; 1154 attrs.get('value').each { 1155 out << 'showContact( '; 1156 out << ' "' + attrs.name + '",'; 1157 out << ' "' + it.person.id + '-' + it.role.id + '",'; 1158 out << ' "' + it.person.lastName + ', ' + it.person.firstName + (it.person.prefix ? ' ' + it.person.prefix : '') + '",'; 1159 out << ' "' + it.role.name + '",'; 1160 out << ' ' + i++; 1161 out << ');'; 1162 } 1163 } 1164 out << '</script>'; 1165 1166 def ids = ''; 1167 if (attrs.get('value') && attrs.get('value').size() > 0) { 1168 ids = attrs.get('value').collect { it.person.id + '-' + it.role.id } 1169 ids = ids.join(','); 1170 } 1171 out << '<input type="hidden" name="' + attrs.name + '_ids" value="' + ids + '" id="' + attrs.name + '_ids">'; 1172 } 1173 1174 def _contactAddSelect = { attrs, body -> 1175 out << _personSelect(attrs) + _roleSelect(attrs); 1176 } 1177 1178 def _contactAddButtonAddition = { attrs, body -> 1179 out << '<input type="button" onClick="addContact ( \'' + attrs.name + '\' ); $(\'#' + attrs.name + '_dialog\').hide(); $( \'#' + attrs.name + '_dialogButton\' ).show();" value="Add">'; 1180 out << '<input type="button" onClick="$(\'#' + attrs.name + '_dialog\').hide(); $( \'#' + attrs.name + '_dialogButton\' ).show();" value="Close">'; 1181 } 1182 1183 def _contactAddDialogButton = { attrs, body -> 1184 out << '<input type="button" onClick="$( \'#' + attrs.name + '_dialog\' ).show(); $(this).hide();" id="' + attrs.name + '_dialogButton" value="Add Contact">'; 1185 } 1186 1186 /** 1187 1187 * Person select element … … 1189 1189 */ 1190 1190 def _personSelect = { attrs -> 1191 1192 1193 1194 def persons = Person.findAll().sort( { a, b -> a.lastName == b.lastName ? ( a.firstName <=> b.firstName ) : ( a.lastName <=> b.lastName ) } as Comparator);1195 selectAttrs.from = persons.collect { it.lastName + ', ' + it.firstName + ( it.prefix ? ' ' + it.prefix : '') }1196 1197 1198 1199 1200 1201 1202 1203 1191 def selectAttrs = new LinkedHashMap(); 1192 1193 // define 'from' 1194 def persons = Person.findAll().sort({ a, b -> a.lastName == b.lastName ? (a.firstName <=> b.firstName) : (a.lastName <=> b.lastName) } as Comparator); 1195 selectAttrs.from = persons.collect { it.lastName + ', ' + it.firstName + (it.prefix ? ' ' + it.prefix : '') } 1196 selectAttrs.keys = persons.id; 1197 1198 // add 'rel' attribute 1199 selectAttrs.rel = 'person' 1200 selectAttrs.name = attrs.name + '_person'; 1201 1202 out << "Person: " + select(selectAttrs) 1203 } 1204 1204 1205 1205 /** … … 1208 1208 */ 1209 1209 def _roleSelect = { attrs -> 1210 println( attrs);1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1210 println(attrs); 1211 def selectAttrs = new LinkedHashMap(); 1212 1213 // define 'from' 1214 def roles = PersonRole.findAll(); 1215 selectAttrs.from = roles.collect { it.name }; 1216 selectAttrs.keys = roles.id; 1217 1218 // add 'rel' attribute 1219 selectAttrs.rel = 'role' 1220 selectAttrs.name = attrs.name + '_role'; 1221 1222 out << "Role: " + select(selectAttrs) 1223 } 1224 1224 }
Note: See TracChangeset
for help on using the changeset viewer.