Changeset 29
- Timestamp:
- 07/09/08 08:12:37 (2 months ago)
- Files:
-
- chrome/songbee/edit-pl.xul (modified) (6 diffs)
- chrome/songbee/export.js (modified) (1 diff)
- chrome/songbee/songbee-sql.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
chrome/songbee/edit-pl.xul
r25 r29 85 85 var initial_order = new Array; 86 86 87 pl. songs(function (s) {87 pl.items(function (i) { 88 88 var li = document.createElement("listitem"); 89 89 li.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 90 li.setAttribute("label", s.title()); 91 li.songId = s.id(); 90 li.setAttribute("label", i.title()); 91 li.playitem = i; 92 li.piType = i.type(); 93 li.piData = i.data(); 94 li.piSong = i.song()._id; 92 95 target.appendChild(li); 93 initial_order.push( li.songId);96 initial_order.push(i._id); 94 97 }); 95 98 … … 97 100 var dragging = 0; 98 101 var dragSetup = 0; 99 100 function jsdump(str)101 {102 Components.classes['@mozilla.org/consoleservice;1']103 .getService(Components.interfaces.nsIConsoleService)104 .logStringMessage(str);105 }106 102 107 103 function beginToDrag (t) { … … 123 119 124 120 function doTreeDoubleClick() { 125 addToPlaylist( "", selectedSong());126 } 127 128 function addToPlaylist( item, song) {121 addToPlaylist(selectedSong(), "song", ""); 122 } 123 124 function addToPlaylist(song, type, data) { 129 125 // Convert to listitem 130 if (!item && !song) { return } 131 var s = Song.retrieve(song ? song : item.songId); 132 if (!s) { return } 133 var li = document.createElement("listitem"); 126 var li = document.createElement("listitem"); 134 127 li.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 135 li.setAttribute("label", s.title()); 136 li.songId = s.id(); 137 128 li.piType = type; 129 li.piData = data; 130 if (type == "song") { 131 var s = Song.retrieve(song); 132 li.setAttribute("label", s.title()); 133 if (!s) { alert("Bug: Couldn't get a song we've clicked on") } 134 li.piSong = s.id(); 135 } else { 136 alert("Bug: Need to represent a non-song item in the playlist"); 137 } 138 138 target.appendChild(li); 139 139 } … … 151 151 var newElem = document.createElement("listitem"); 152 152 newElem.setAttribute("label", dragging.label); 153 newElem.songId = dragging.songId;153 for (var a in ["piSong", "piData", "piType"]) newElem[a] = dragging[a]; 154 154 newElem.setAttribute("onmousedown", "myDragAndDrop.startDrag(event,liObserver);"); 155 155 dragSetup = 0; … … 182 182 if (children.length != initial_order.length) return 1; 183 183 for (var i =0; i < children.length; i++) { 184 if (children[i].songId != initial_order[i]) return 1; 184 if (!children[i].playitem) return 1; 185 if (children[i].playitem._id != initial_order[i]) return 1; 185 186 } 186 187 return 0; … … 204 205 pl.tidy_up(); 205 206 for (var i =0; i < target.childNodes.length; i++) { 206 var song = target.childNodes[i].songId;207 pl.add_item( song, i+1);208 window.arguments[1].setup();209 } 207 var node = target.childNodes[i] 208 pl.add_item(node.piSong, i+1, node.piType, node.piData); 209 } 210 window.arguments[1].setup(); // Redraw the main (playlist list) window 210 211 } 211 212 chrome/songbee/export.js
r1 r29 27 27 var stylesheet = getXSLT(); 28 28 29 pl.songs(function (s) { 30 var frag = transformDOM(s.xmlDOM(), stylesheet, save); 31 var head = save.createElement("h1"); head.innerHTML = s.title(); 29 pl.items(function (i) { 30 var head = save.createElement("h1"); head.innerHTML = i.title(); 32 31 song_place.appendChild(head); 33 song_place.appendChild( frag);32 song_place.appendChild(i.transformToHTML(stylesheet, save)); 34 33 }); 35 34 var serializer = new XMLSerializer(); chrome/songbee/songbee-sql.js
r24 r29 35 35 doSQLStatement("INSERT INTO songbee_system (schema_version) VALUES (2.0)"); 36 36 doSQLStatement("ALTER TABLE play_item ADD COLUMN type"); 37 doSQLStatement("UPDATE play_item SET type='song'"); 37 38 doSQLStatement("ALTER TABLE play_item ADD COLUMN data"); 38 39 doSQLStatement("ALTER TABLE playlist ADD COLUMN css"); … … 131 132 132 133 function doSQLStatement(sql, params) { 133 var statement = mDBConn.createStatement(sql) 134 var statement; 135 try { statement = mDBConn.createStatement(sql); } catch (e) { alert("SQL setup failed: "+sql); } 134 136 if (params) { 135 137 for (var i =0; i < params.length; i++) … … 159 161 } 160 162 161 Playlist.prototype.songs = function (callback) {162 return doSQL("SELECT song.id, song_key, title, first_line, xml FROM song, play_item WHERE play_item.playlist = "+this._id+" AND play_item.song = song.id ORDER BY play_item.position ", Song, callback);163 };164 165 Playlist.prototype.tidy_up = function () {166 doSQLStatement("DELETE FROM play_item WHERE playlist= (?1)", [this._id]);167 };168 169 Playlist.prototype.add_item = function(song, position) {170 doSQLStatement("INSERT INTO play_item (playlist, song, position) VALUES ((?1), (?2), (?3))", [this._id, song, position]);171 };172 173 163 Song.prototype.xmlDOM = function () { 174 164 var parsed = (new DOMParser()).parseFromString(this.xml(), "text/xml"); 175 165 return parsed; 176 166 }; 167 168 Playlist.prototype.items = function (callback) { 169 return doSQL("SELECT id, playlist, song, position, type, data FROM play_item WHERE play_item.playlist = "+this._id+" ORDER BY position ", PlayItem, function (pi) { pi.specialize(); if (callback) callback(pi); }); 170 }; 171 172 Playlist.prototype.tidy_up = function () { 173 doSQLStatement("DELETE FROM play_item WHERE playlist= (?1)", [this._id]); 174 }; 175 176 Playlist.prototype.add_item = function(song, position, type, data) { 177 if (!type) type = "song"; 178 if (!data) data = ""; 179 if (type == "song" and !song) { alert("Bug: No song ID given for song item."); return; } 180 doSQLStatement("INSERT INTO play_item (playlist, song, position, type, data) VALUES ((?1), (?2), (?3),(?4),(?5))", [this._id, song, position, type, data]); 181 }; 182 183 PlayItem.prototype.song = function() { 184 if (!this.type == "song") { alert("Bug: song called on playitem "+this._id+" which has type ["+this.type+"]"); } 185 var songlist = doSQL("SELECT song.id, song_key, title, first_line, xml FROM song WHERE id = "+this._song, Song); 186 if (songlist.length < 1 ) { alert("Retrieving song not in database: has it been deleted?"); } 187 return songlist[0] 188 } 189 190 /* PlayItem function dispatchers. We are faking specialization here. */ 191 192 var PlayItemDispatchers = { 193 transformToHTML: { 194 song: function (stylesheet, doc) { return transformDOM(this.song().xmlDOM(), stylesheet, doc) }, 195 fallback: function () { return "<p>[Don't know how to transform object of type "+this.type+"]</p>" } 196 }, 197 title: { 198 song: function () { return this.song().title() }, 199 fallback: function() { return "[PlayItem "+this._id+"/"+this.type()+"]" } 200 } 201 }; 202 203 PlayItem.prototype.specialize = function () { 204 for (var handle in PlayItemDispatchers) { 205 this[handle] = PlayItemDispatchers[handle][this.type()] || PlayItemDispatchers[handle]["fallback"]; 206 } 207 }
