Changeset 527 for trunk/grails-app/taglib
- Timestamp:
- Jun 4, 2010, 12:15:24 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r519 r527 136 136 // change form if a form attribute is present 137 137 if (attrs.get('form')) { 138 button = button.replaceFirst(/this\.form/, 138 // Old way 139 /* 140 button = button.replaceFirst(/this\.form/, 139 141 "\\\$('" + attrs.get('form') + "')" 142 ) 143 */ 144 145 button = button.replace("jQuery(this).parents('form:first')", 146 "\$('" + attrs.get('form') + "')" 140 147 ) 141 148 } … … 1023 1030 out << '</form>'; 1024 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 ); };' 1025 1033 out << ' iField = $( "#' + attrs.get( 'name' ) + '" );'; 1026 out << ' new PublicationChooser().initAutocomplete( iField );';1034 out << ' new PublicationChooser().initAutocomplete( iField, { "select" : onSelect } );'; 1027 1035 out << '</script>'; 1028 1036 } … … 1067 1075 ids = ''; 1068 1076 } 1069 out << '<input type="hidden" name="' + attrs.name + '_ids" value="' + ids + '" id="' + attrs.name + '_ids" value="' + ids + '">';1077 out << '<input type="hidden" name="' + attrs.name + '_ids" value="' + ids + '" id="' + attrs.name + '_ids">'; 1070 1078 } 1071 1079 … … 1078 1086 out << '</div>'; 1079 1087 out << '<script type="text/javascript">'; 1080 out << ' $("#' + attrs.name + '_dialog").dialog({'; 1081 out << ' title : "Add publication",'; 1082 out << ' autoOpen: false,'; 1083 out << ' width : 800,'; 1084 out << ' height : 400,'; 1085 out << ' modal : true,'; 1086 out << ' position: "center",'; 1087 out << ' buttons : {'; 1088 out << ' Add : function() { addPublication( "' + attrs.name + '" ); $(this).dialog("close"); },'; 1089 out << ' Close : function() { $(this).dialog("close"); }'; 1090 out << ' },'; 1091 out << ' close : function() {'; 1092 out << ' /* closeFunc(this); */'; 1093 out << ' }'; 1094 out << ' }).width(790).height(400);'; 1088 out << ' createPublicationDialog( "' + attrs.name + '" );' 1095 1089 out << '</script>'; 1096 1090 1097 out << '<input type="button" onClick=" var field = $( \'#' + attrs.name + '\' ); field.autocomplete( \'close\' ); field.val( \'\' );$( \'#' + attrs.name + '_dialog\' ).dialog( \'open\' ); field.focus();" value="Add Publication">';1091 out << '<input type="button" onClick="openPublicationDialog(\'' + attrs.name + '\' );" value="Add Publication">'; 1098 1092 } 1099 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 /** 1187 * Person select element 1188 * @param Map attributes 1189 */ 1190 def _personSelect = { attrs -> 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 1205 /** 1206 * Role select element 1207 * @param Map attributes 1208 */ 1209 def _roleSelect = { attrs -> 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 } 1100 1224 }
Note: See TracChangeset
for help on using the changeset viewer.