Changeset 31

Show
Ignore:
Timestamp:
07/25/08 15:07:42 (1 month ago)
Author:
simon
Message:

The big move from "songs" to "items" in the projector view. This just leaves drag-and-drop to be refactored.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • chrome/songbee/songbee-sql.js

    r30 r31  
    181181 
    182182PlayItem.prototype.song = function() { 
    183         if (!this.type == "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); } 
     183        if (this.type() != "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); } 
    184184        var songlist = doSQL("SELECT song.id, song_key, title, first_line, xml FROM song  WHERE id = "+this._song, Song); 
    185185        if (songlist.length < 1 )  { alert("Retrieving song not in database: has it been deleted?"); } 
     
    194194                fallback: function () { return "<p>[Don't know how to transform object of type "+this.type+"]</p>" } 
    195195        }, 
     196        postDisplayHook: { 
     197//              song: function () { return this.song().played() }, 
     198                fallback: function () {} 
     199        }, 
    196200        title: { 
    197201                song: function () { return this.song().title() }, 
  • chrome/songbee/songbee.js

    r26 r31  
    1010var state = { 
    1111    paused: 0, 
    12     currentSongIndex: 0, 
     12    currentItemIndex: 0, 
    1313    currentSectionIndex: 0, 
    1414    consoleColor: exposedColor, 
     
    2626// Utility functions 
    2727 
    28 function currentSong() { 
    29     if (state.currentSongIndex < 0) { state.currentSongIndex = 0 } 
    30     if (state.currentSongIndex > plData.songs.length - 1) {  
    31         state.currentSongIndex = plData.songs.length - 1; 
    32     } 
    33     return plData.songs[state.currentSongIndex]; 
    34 } 
    35 function nextSong() { return plData.songs[state.currentSongIndex+1] } 
     28function currentItem() { 
     29    if (state.currentItemIndex < 0) { state.currentItemIndex = 0 } 
     30    if (state.currentItemIndex > plData.items.length - 1) {  
     31        state.currentItemIndex = plData.items.length - 1; 
     32    } 
     33    return plData.items[state.currentItemIndex]; 
     34} 
     35function nextItem() { return plData.items[state.currentItemIndex+1] } 
    3636function projectorSections() { return windows.projector.document.getElementById("song").getElementsByTagName("div") } 
    3737function consoleSections()  {return windows.thisSong.contentDocument.getElementById("song").getElementsByTagName("div"); } 
     
    5757    windows.console.addEventListener("keypress", onKeyPress,  false); 
    5858    plData.playlist = Playlist.retrieve(window.arguments[0]); 
    59     plData.songs = plData.playlist.songs(function(s) { 
     59    plData.items = plData.playlist.items(function(s) { 
    6060        var li = document.createElementNS(htmlNS, "html:li"); 
    6161        var label = document.createElement("label"); 
    6262        label.setAttribute("value", s.title()); 
    6363        li.appendChild(label); 
    64         li.setAttribute("onclick", "switchSong("+c+")"); 
     64        li.setAttribute("onclick", "switchItem("+c+")"); 
    6565        playlistLI.appendChild(li); 
    6666        c++; 
     
    7474                addUserStylesheet(windows.projector.document); 
    7575        } 
    76     switchSong(0,1); 
    77 } 
    78  
    79 function switchSong(s, firstTime) { 
    80     state.currentSongIndex = s; 
     76    switchItem(0,1); 
     77} 
     78 
     79function switchItem(s, firstTime) { 
     80    state.currentItemIndex = s; 
    8181    if (!firstTime) 
    8282        unhighlightSection(); 
    83     displaySong(currentSong()); 
    84 } 
    85  
    86 function displaySong(song) {  
    87     // Display song in browser windows 
    88     putSongInDoc(song, windows.projector.document); 
     83    displayItem(currentItem()); 
     84} 
     85 
     86function displayItem(item) {  
     87    // Display item in browser windows 
     88    putItemInDoc(item, windows.projector.document); 
    8989    cleanProjectorWindow(); // Do this as quickly as possible 
    90     putSongInDoc(song, windows.thisSong.contentDocument); 
    91     putSongInDoc(nextSong(), windows.nextSong.contentDocument); 
    92  
    93     // Increment the counter 
    94     song.played(); 
    95  
    96     // Set up data structure for easy access 
    97     state.verses = []; 
    98     var cs = consoleSections(); 
    99     for (var i = 0; i < cs.length; i++) { 
    100         var section = cs[i]; 
    101         section.addEventListener("click", mkChangeSection(i), true); 
    102         if (section.className == "verse") { state.verses.push(i) } 
    103     } 
    104     // Set up the "natural order" 
    105     state.naturalOrder = determineNaturalOrder(song); 
    106     if (state.naturalOrder.length && state.naturalOrder[0] == 0) { state.naturalOrder.shift() } 
    107     //jsdump("Natural order was: "); 
    108     //for (var i in state.naturalOrder) { jsdump(state.naturalOrder[i]) }; 
     90    putItemInDoc(item, windows.thisSong.contentDocument); 
     91    putItemInDoc(nextItem(), windows.nextSong.contentDocument); 
     92 
     93    item.postDisplayHook(); 
     94 
     95        if (item.type() == "song") { 
     96            // Set up data structure for easy access 
     97            state.verses = []; 
     98            var cs = consoleSections(); 
     99            for (var i = 0; i < cs.length; i++) { 
     100                var section = cs[i]; 
     101                section.addEventListener("click", mkChangeSection(i), true); 
     102                if (section.className == "verse") { state.verses.push(i) } 
     103            } 
     104            // Set up the "natural order" 
     105            state.naturalOrder = determineNaturalOrder(item); 
     106            if (state.naturalOrder.length && state.naturalOrder[0] == 0) { state.naturalOrder.shift() } 
     107            //jsdump("Natural order was: "); 
     108            //for (var i in state.naturalOrder) { jsdump(state.naturalOrder[i]) };               
     109        } 
    109110 
    110111    // Scroll things back to the beginnng 
     
    116117function mkChangeSection(i) { return function () { changeSection(i) } } 
    117118 
    118 function putSongInDoc(song, doc) { 
     119function putItemInDoc(item, doc) { 
    119120    var song_place = doc.getElementById("song"); 
    120121    song_place.innerHTML = ""; 
    121     if (!song) { song_place.innerHTML="<p>End of playlist</p>"; return; } 
    122     var frag = transformDOM(song.xmlDOM(), stylesheet, doc); 
     122    if (!item) { song_place.innerHTML="<p>End of playlist</p>"; return; } 
     123    var frag = item.transformToHTML(stylesheet, doc); 
    123124    song_place.appendChild(frag); 
    124125} 
     
    274275        case e.DOM_VK_UP: handleUp(); return; 
    275276        case e.DOM_VK_DOWN: handleDown(); return; 
    276         case e.DOM_VK_LEFT: switchSong(state.currentSongIndex-1); return; 
    277         case e.DOM_VK_RIGHT: switchSong(state.currentSongIndex+1); return; 
     277        case e.DOM_VK_LEFT: switchItem(state.currentItemIndex-1); return; 
     278        case e.DOM_VK_RIGHT: switchItem(state.currentItemIndex+1); return; 
    278279        case e.DOM_VK_PAGE_DOWN: pageDown(); return; 
    279280        case e.DOM_VK_PAGE_UP: pageUp(); return;