Javascript's flexible typing and giant hash object reference model(?) lets you do some neat tricks to reuse code. Essentially you can pass in the string names of attributes or functions to be acted on, rather than defining interfaces as you would in Java. For example, weapons and armor have a similar structure, and the edit UI for both behaves in exactly the same way. Some stuff about the code below.
function populate_data_part(chardata, data_name, id_name) {
for (var j in chardata[data_name]) {
var item = window[data_name].first( {
id : chardata[data_name][j][id_name + '_id']
});
$("#" + id_name + "_" + j + " option[id='" + id_name + "_" + j + "_option_" + item.id + "']").attr("selected", true);
// TODO - this part might be better in recalc
for(var i in window[id_name + "_edit_data"]) {
var edit_attr_name = window[id_name + "_edit_data"][i];
var value = chardata[data_name][j][edit_attr_name] == null ? item[edit_attr_name] : chardata[data_name][j][edit_attr_name];
$("#" + id_name + "_" + j + edit_attr_name).val(value == null ? "" : value);
}
}
}
For 0.4, I'll refactor the steaming pile that is feats.