diff --git a/AndorsTrailEdit/AndorsTrailEditor.js b/AndorsTrailEdit/AndorsTrailEditor.js index 8c2489f9e..3a146810e 100644 --- a/AndorsTrailEdit/AndorsTrailEditor.js +++ b/AndorsTrailEdit/AndorsTrailEditor.js @@ -36,13 +36,16 @@ function openTabForObject(obj, dataStore) { function bindObjectsToItemList(itemListDiv, dataStore) { itemListDiv.children().remove(); - var addToList = function(obj) { - //var item = $("
  • " + obj[dataStore.nameField] + "
  • "); + 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'); @@ -53,11 +56,14 @@ function bindObjectsToItemList(itemListDiv, dataStore) { 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); + } }; } diff --git a/AndorsTrailEdit/DataStore.js b/AndorsTrailEdit/DataStore.js index 71cab3959..aa85ca7c9 100644 --- a/AndorsTrailEdit/DataStore.js +++ b/AndorsTrailEdit/DataStore.js @@ -49,7 +49,7 @@ function DataStore(input) { } this.onAdded = function(obj) { } - this.onNameChanged = function(obj, name) { } + this.onPropertyChanged = function(obj, propertyName, value) { } this.onDeserialized = function() { } this.deserialize = function(str) { diff --git a/AndorsTrailEdit/EditorFunctions.js b/AndorsTrailEdit/EditorFunctions.js index 154ff2eda..65f0aa462 100644 --- a/AndorsTrailEdit/EditorFunctions.js +++ b/AndorsTrailEdit/EditorFunctions.js @@ -59,7 +59,9 @@ function applyEditorBindingsForObject(div, obj) { 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()); + }); } }