function bindObjectsToItemList(itemListDiv, dataStore) {
itemListDiv.children().remove();
- var addToList = function(obj) {
- //var item = $("<li>" + obj[dataStore.nameField] + "</li>");
+ var createListItem = function(obj) {
var item = $( Mustache.to_html( $('#listitem').html(), { name: obj[dataStore.nameField] } ) );
if (dataStore.iconField) {
var elem = $( 'img', item );
imageSelector.setImage( elem , obj[dataStore.iconField] , 0.7);
}
+ return item;
+ };
+ var addToList = function(obj) {
+ var item = createListItem(obj);
item.click(function() { openTabForObject(obj, dataStore); });
itemListDiv.append(item);
item.hide().fadeIn('slow');
bindObjectsToItemList(itemListDiv, dataStore);
// TODO: Should also close all tabs.
};
- dataStore.onNameChanged = function(obj, name) {
- $("li:eq(" + dataStore.items.indexOf(obj) + ")", itemListDiv).html(name);
- //TODO: Should this really be in the same function?
- // (splitting the left part from the tab controls would reduce coupling, which would be a good thing.)
- tabs.renameTabForObject(obj, name);
+ dataStore.onPropertyChanged = function(obj, propertyName, value) {
+ var listItem = $("li:eq(" + dataStore.items.indexOf(obj) + ")", itemListDiv);
+ listItem.html( createListItem(obj).html() );
+ if (propertyName == dataStore.nameField) {
+ //TODO: Should this really be in the same function?
+ // (splitting the left part from the tab controls would reduce coupling, which would be a good thing.)
+ tabs.renameTabForObject(obj, value);
+ }
};
}
function applyCommonEditorBindings(div, obj, dataStore) {
applyEditorBindingsForObject(div, obj);
if (dataStore) {
- div.find("#" + dataStore.nameField).change(function() { dataStore.onNameChanged(obj, $(this).val()); });
+ div.find("input").change(function() {
+ dataStore.onPropertyChanged(obj, $(this).attr('id'), $(this).val());
+ });
}
}