Update image icons in left list when icon changes.

This commit is contained in:
Oskar Wiksten
2012-07-10 19:28:00 +02:00
parent d7064fd589
commit cbcf97252f
3 changed files with 17 additions and 9 deletions

View File

@@ -36,13 +36,16 @@ function openTabForObject(obj, dataStore) {
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');
@@ -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);
}
};
}

View File

@@ -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) {

View File

@@ -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());
});
}
}