Я пытаюсь улучшить свой хакерский навык, и мне было интересно, как лучше реорганизовать два отдельных селектора:
<script type="text/javascript">
$(document).ready(function() {
$('.editable_row').editable('${context_path}/self_report_event/update_attribute', {
indicator : 'Saving...',
style : "inherit",
tooltip : 'click to edit...',
placeholder : '-',
submitdata : function() {
var eventId = $(this).parent('tr').attr("event_id");
var attrType = $(this).attr("attr_type");
return {event_id: eventId, attr_type: attrType};
},
callback : function(value, settings) {
//Do nothing if successful yet
},
onerror : function(value, settings, xhr) {
alert('Update failed for following reasons: '+xhr.responseText);
}
});
$('.edit_gender_select').editable('${context_path}/self_report_event/update_attribute', {
indicator : 'Saving...',
style : "inherit",
data : "{'M':'Male','F':'Female', '':'None'}",
type : 'select',
tooltip : 'click to edit...',
placeholder : '-',
submit : 'OK',
submitdata : function() {
var eventId = $(this).parent('td').parent('tr').attr("event_id");
var attrType = $(this).attr("attr_type");
return {event_id: eventId, attr_type: attrType};
},
callback : function(value, settings) {
//Do nothing if successful yet
},
onerror : function(value, settings, xhr) {
alert('Update failed for following reasons: '+xhr.responseText);
}
});
});
</script>
Для следующего html:
<tr event_id="${event.id}">
<td class="editable_row">${event.id!""}</td>
<td class="editable_row" attr_type="title">${event.title!""}</td>
<td class="editable_row" attr_type="age">${event.age!""}</td>
<td><span class="edit_gender_select" attr_type="gender">${event.gender!""}</span></td>
<td class="editable_row" attr_type="mnemonic">${event.mnemonic!""}</span></td>
</tr>