]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Update image icons in left list when icon changes.
authorOskar Wiksten <oskar.wiksten@gmail.com>
Tue, 10 Jul 2012 17:28:00 +0000 (19:28 +0200)
committerOskar Wiksten <oskar.wiksten@gmail.com>
Tue, 10 Jul 2012 17:30:15 +0000 (19:30 +0200)
AndorsTrailEdit/AndorsTrailEditor.js
AndorsTrailEdit/DataStore.js
AndorsTrailEdit/EditorFunctions.js

index 8c2489f9e0a543fd05594a1e809f2d93d99d4e69..3a146810e449ff963d35ee489bfc858e2242402e 100644 (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);
+               }
        };
 }
 
index 71cab395966f1bde228c05917034c0db555fff1d..aa85ca7c9f96b9bbe86f6e166615c7bfa987421a 100644 (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) {
index 154ff2edaca451b0731e93b3cb27cadc67171c60..65f0aa462ee828daacc58af51b96a8cdc1bbb0c5 100644 (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()); 
+               });
        }
 }