Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

continue refactoring to CS

  • Loading branch information...
commit 08d8d75994c90f0a766753f0a50331e326193933 1 parent 89f10af
@podviaznikov authored
View
4 public/js/app/ui.app.coffee
@@ -145,11 +145,11 @@ exports.VisualizationView = class VisualizationView extends Backbone.View
el: $("#playing_visualization")
tplId: "visualization_tpl"
- show: ->
+ show: =>
@el.show()
@render()
- hide: ->
+ hide: =>
@el.hide()
render: =>
View
59 public/js/app/ui.details.coffee
@@ -8,38 +8,37 @@ DetailsView = exports.DetailsView = class DetailsView extends Backbone.View
initialize: ->
Backbone.View::initialize.apply this, arguments
- _.bindAll this, "showAlbums", "showAlbum", "showPlayList", "handleDragStart", "showBio", "hideBio"
@artistBioView = new ArtistBioView()
- showBio: (artist) ->
+ showBio: (artist) =>
@artistBioPanel.show()
@artistBioView.setArtistModel artist
@artistBioView.render()
@libDetailsPanel.hide()
- hideBio: ->
+ hideBio: =>
@artistBioPanel.hide()
@artistBioView.clear()
@libDetailsPanel.show()
@libDetailsPanel.empty()
- showAlbums: (albumsModels, songs) ->
+ showAlbums: (albumsModels, songs) =>
@hideBio()
albumsModels.each @showAlbum if albumsModels
@songs = songs
- showAlbum: (albumModel) ->
+ showAlbum: (albumModel) =>
@hideBio()
@songs = albumModel.get("songs")
albumView = new AlbumView(model: albumModel)
@libDetailsPanel.append albumView.render().el
- showPlayList: (playList) ->
+ showPlayList: (playList) =>
@hideBio()
playListView = new PlayListFullView(model: playList)
@libDetailsPanel.append playListView.render().el
- handleDragStart: (e) ->
+ handleDragStart: (e) =>
event = e.originalEvent
dataTransferObj = event.dataTransfer
songId = event.srcElement.dataset.id
@@ -54,30 +53,29 @@ class ArtistBioView extends Backbone.View
tplId: "artist_bio_tpl"
initialize: ->
Backbone.View::initialize.apply this, arguments
- _.bindAll this, "setArtistModel", "renderArtistBio", "clear"
- setArtistModel: (artist) ->
+ setArtistModel: (artist) =>
@model = artist
- render: ->
+ render: =>
dataService.getArtistBio @model.get("name"), @renderArtistBio if @model
- this
+ @
- renderArtistBio: (data) ->
+ renderArtistBio: (data) =>
@renderTpl
bio: unescape(data.summary)
profiles: data.profile or {}
- clear: ->
- $(@el).html ""
+ clear: => $(@el).html ""
class AlbumView extends Backbone.View
className: "lib_item_full_info_panel"
tagName: "article"
+
initialize: ->
- Backbone.View::initialize.apply this, arguments
+ super
- render: ->
+ render: =>
@albumInfoView = new AlbumInfoView(model: @model)
$(@el).append @albumInfoView.render().el
@model.get("songs").each @addSong if @model.get("songs")
@@ -100,21 +98,20 @@ class PlayListFullView extends Backbone.View
click: "playSongs"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "addSong", "renderPlayListInfo", "playSongs"
+ super
- render: ->
+ render: =>
@model.findImage @renderPlayListInfo
- this
+ @
- renderPlayListInfo: (image) ->
+ renderPlayListInfo: (image) =>
@renderTpl
image: image
name: @model.get("name")
_.each @model.get("songs"), @addSong
- addSong: (songData, key) ->
+ addSong: (songData, key) =>
song = new Song(songData)
view = new SongView(
model: song
@@ -125,8 +122,7 @@ class PlayListFullView extends Backbone.View
song.albumView = view
$(@el).append view.render().el
- playSongs: ->
- AppController.playlistView.setSongsAndPlay @model.get("songs")
+ playSongs: -> AppController.playlistView.setSongsAndPlay @model.get("songs")
class AlbumInfoView extends Backbone.View
className: "detailed_album_info_panel box"
@@ -136,7 +132,7 @@ class AlbumInfoView extends Backbone.View
click: "playSongs"
initialize: ->
- Backbone.View::initialize.apply this, arguments
+ super
renderAlbumInfo: (data) =>
@renderTpl
@@ -160,10 +156,9 @@ class SongView extends Backbone.View
"dblclick .song": "playSongs"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "selectSong", "deleteSong", "onDeleteSong", "playSongs", "render"
+ super
- render: ->
+ render: =>
@el.draggable = true
@el.dataset.songname = @model.get("title")
@el.dataset.id = @model.id
@@ -174,19 +169,19 @@ class SongView extends Backbone.View
this
- selectSong: ->
+ selectSong: =>
$(".song-data").removeClass "selected_song"
$(@el).addClass "selected_song"
- deleteSong: ->
+ deleteSong: =>
@model.bind "destroy", @onDeleteSong
@model.remove()
- onDeleteSong: ->
+ onDeleteSong: =>
view = @model.albumView
view.remove() if view
- playSongs: ->
+ playSongs: =>
songs = @options.songs
@selectSong()
AppController.playlistView.setSongsAndPlay songs
View
115 public/js/app/ui.library.coffee
@@ -1,7 +1,8 @@
ArtistsList = require("./models").ArtistsList
PlayLists = require("./models").PlayLists
AlbumList = require("./models").AlbumList
-LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
+
+LibraryMenu = exports.LibraryMenu = class LibraryMenu extends Backbone.View
el: $("#library_menu")
searchField: $("#library_menu header input")
artistsContent: $("#artists_library_content")
@@ -17,39 +18,32 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
"keyup input": "keyPressed"
initialize: ->
- Backbone.View::initialize.apply this, arguments
+ super
@artists = new ArtistsList()
@playLists = new PlayLists()
@albums = new AlbumList()
@tabName = "artists"
- _.bindAll this, "addArtist", "addPlayList", "addPlayLists", "addAlbum", "addSoundCloudTrack", "addSoundCloudTracks", "showArtists", "showPlayLists", "showAlbums", "showSoundCloud", "allArtistsLoaded", "filterLibrary", "keyPressed", "showSoundCloudMenu"
@artists.bind "add", @addArtist
@artists.bind "reset", @allArtistsLoaded
@playLists.bind "add", @addPlayList
@playLists.bind "reset", @addPlayLists
- @artists.fetch
- success: (o) ->
- console.log "xxx"
-
- error: (o) ->
- console.log "xxx1"
+ @artists.fetch success: -> console.log "artists was fetched"
- showSoundCloudMenu: ->
+ showSoundCloudMenu: =>
@$("#show_soundcloud").removeClass "hidden"
- keyPressed: (event) ->
+ keyPressed: (event) =>
keyCode = event.keyCode
@filterLibrary() if keyCode is 13
- allArtistsLoaded: ->
- console.log "arts", @artists
+ allArtistsLoaded: =>
@artists.each @addArtist
lastArtist = AppController.settings.getLastArtist()
if lastArtist
lastPlayedArtist = @artists.forName(lastArtist)
lastPlayedArtist.view.selectArtist() if lastPlayedArtist and lastPlayedArtist.view
- showArtists: ->
+ showArtists: =>
@tabName = "artists"
@$(@searchField).attr "placeholder", "Search artist"
@artistsContent.show()
@@ -57,7 +51,7 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
@playListsContent.hide()
@soundCloudContent.hide()
- showAlbums: ->
+ showAlbums: =>
@tabName = "albums"
@$(@searchField).attr "placeholder", "Search album"
@albumsContent.show()
@@ -65,7 +59,7 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
@playListsContent.hide()
@soundCloudContent.hide()
- showPlayLists: ->
+ showPlayLists: =>
@tabName = "playlists"
@$(@searchField).attr "placeholder", "Search play list"
@playListsContent.show()
@@ -73,7 +67,7 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
@albumsContent.hide()
@soundCloudContent.hide()
- showSoundCloud: ->
+ showSoundCloud: =>
@tabName = "soundcloud"
@$(@searchField).attr "placeholder", "Search tracks"
@soundCloudContent.show()
@@ -81,7 +75,7 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
@artistsContent.hide()
@albumsContent.hide()
- addAlbum: (album) ->
+ addAlbum: (album) =>
unless @albums.isExist(album)
@albums.add album
view = new AlbumMenuView(model: album)
@@ -91,7 +85,7 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
albumFromList.get("songs").add album.get("songs").models
albumFromList.trigger "add"
- addArtist: (artist) ->
+ addArtist: (artist) =>
self = this
if artist.get("name") and not artist.get("isDeleted")
artist.albumsModels.bind "reset", ->
@@ -101,21 +95,21 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
view = new ArtistMenuView(model: artist)
@artistsContent.append view.render().el
- addPlayList: (playList) ->
+ addPlayList: (playList) =>
view = new PlayListMenuView(model: playList)
@playListsContent.append view.render().el
- addSoundCloudTrack: (soundCloudTrack) ->
+ addSoundCloudTrack: (soundCloudTrack) =>
view = new SoundCloudTrackMenuView(model: soundCloudTrack)
@soundCloudContent.append view.render().el
- addSoundCloudTracks: ->
+ addSoundCloudTracks: =>
@soundCloudTracks.each @addSoundCloudTrack
- addPlayLists: ->
+ addPlayLists: =>
@playLists.each @addPlayList
- filterLibrary: ->
+ filterLibrary: =>
filterValue = @searchField.val()
containerItems = @artists
if @tabName is "soundcloud"
@@ -132,8 +126,8 @@ LibraryMenu = exports.LibraryMenu = Backbone.View.extend(
item.view.show() if item.view
else
item.view.hide() if item.view
-)
-ArtistMenuView = Backbone.View.extend(
+
+class ArtistMenuView extends Backbone.View
className: "lib-item-data box"
tagName: "article"
tplId: "artist_tpl"
@@ -147,19 +141,18 @@ ArtistMenuView = Backbone.View.extend(
dragstart: "handleDragStart"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "render", "selectArtist", "playArtistSongs", "deleteArtist", "selectAlbum", "playAlbumSongs", "showArtistBio", "handleDragStart"
+ super
@model.songs.bind "all", @render
@model.bind "change", @render
@model.view = this
- render: ->
+ render: =>
@renderTpl()
@el.draggable = true
@el.dataset.artist = @model.get("name")
this
- handleDragStart: (e) ->
+ handleDragStart: (e) =>
event = e.originalEvent
dataTransferObj = event.dataTransfer
artist = event.srcElement.dataset.artist
@@ -167,35 +160,35 @@ ArtistMenuView = Backbone.View.extend(
dataTransferObj.effectAllowed = "move"
dataTransferObj.setData "text/plain", dataTransfer.toString()
- selectArtist: ->
+ selectArtist: =>
$(".lib-item-data").removeClass "selected-lib-item"
$(@el).addClass "selected-lib-item"
AppController.detailsView.showAlbums @model.albumsModels, @model.songs
- playArtistSongs: ->
+ playArtistSongs: =>
@selectArtist()
AppController.playlistView.setSongsAndPlay @model.songs
- playAlbumSongs: (e) ->
+ playAlbumSongs: (e) =>
album = e.currentTarget.dataset.album
albumSongs = @model.songs.forAlbum(album)
AppController.detailsView.songs.reset albumSongs
AppController.playlistView.setSongsAndPlay albumSongs
- deleteArtist: ->
+ deleteArtist: =>
@model.set isDeleted: true
@model.save()
@$(@el).remove()
- selectAlbum: (e) ->
+ selectAlbum: (e) =>
album = e.currentTarget.dataset.album
albumModel = @model.songs.buildAlbumModel(album, @model.get("name"))
AppController.detailsView.showAlbum albumModel
- showArtistBio: ->
+ showArtistBio: =>
AppController.detailsView.showBio @model
-)
-AlbumMenuView = Backbone.View.extend(
+
+class AlbumMenuView extends Backbone.View
className: "lib-item-data box"
tagName: "article"
tplId: "album_lib_tpl"
@@ -205,22 +198,19 @@ AlbumMenuView = Backbone.View.extend(
dragstart: "handleDragStart"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "selectAlbum", "playAlbumSongs", "handleDragStart"
+ super
@model.bind "change", @render
@model.bind "add", @render
@model.view = this
- render: ->
- self = this
- @model.findImage ->
- self.renderTpl()
+ render: =>
+ @model.findImage => @renderTpl()
@el.draggable = true
@el.dataset.album = @model.get("name")
- this
+ @
- handleDragStart: (e) ->
+ handleDragStart: (e) =>
event = e.originalEvent
dataTransferObj = event.dataTransfer
album = event.srcElement.dataset.album
@@ -228,17 +218,17 @@ AlbumMenuView = Backbone.View.extend(
dataTransferObj.effectAllowed = "move"
dataTransferObj.setData "text/plain", dataTransfer.toString()
- playAlbumSongs: (e) ->
+ playAlbumSongs: (e) =>
@selectAlbum()
AppController.playlistView.setSongsAndPlay @model.get("songs")
- selectAlbum: ->
+ selectAlbum: =>
$(".lib-item-data").removeClass "selected-lib-item"
$(@el).addClass "selected-lib-item"
albumSongs = @model.get("songs")
AppController.detailsView.showAlbum @model
-)
-PlayListMenuView = Backbone.View.extend(
+
+class PlayListMenuView extends Backbone.View
className: "lib-item-data box"
tagName: "article"
tplId: "saved_playlist_tpl"
@@ -249,25 +239,24 @@ PlayListMenuView = Backbone.View.extend(
dragstart: "handleDragStart"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "render", "renderPlayListInfo", "selectPlayList", "playPlayList", "deletePlaylist", "handleDragStart"
+ super
@model.bind "change", @render
@model.view = this
- render: ->
+ render: =>
@model.findImage @renderPlayListInfo
@el.draggable = true
@el.dataset.playlist = @model.get("name")
this
- renderPlayListInfo: (image) ->
+ renderPlayListInfo: (image) =>
@renderTpl
image: image
name: @model.get("name")
genres: @model.findGenres()
songsCount: @model.get("songs").length
- handleDragStart: (e) ->
+ handleDragStart: (e) =>
event = e.originalEvent
dataTransferObj = event.dataTransfer
playlist = event.srcElement.dataset.playlist
@@ -275,20 +264,20 @@ PlayListMenuView = Backbone.View.extend(
dataTransferObj.effectAllowed = "move"
dataTransferObj.setData "text/plain", dataTransfer.toString()
- selectPlayList: ->
+ selectPlayList: =>
$(".lib-item-data").removeClass "selected-lib-item"
$(@el).addClass "selected-lib-item"
AppController.detailsView.showPlayList @model
- playPlayList: ->
+ playPlayList: =>
@selectPlayList()
AppController.playlistView.setSongsAndPlay @model.findSongs()
- deletePlaylist: ->
+ deletePlaylist: =>
@model.destroy()
@$(@el).remove()
-)
-SoundCloudTrackMenuView = Backbone.View.extend(
+
+class SoundCloudTrackMenuView extends Backbone.View
className: "lib-item-data box"
tagName: "article"
tplId: "sound_cloud_track_menu_tpl"
@@ -296,11 +285,9 @@ SoundCloudTrackMenuView = Backbone.View.extend(
click: "playTrack"
initialize: ->
- Backbone.View::initialize.apply this, arguments
- _.bindAll this, "playTrack"
+ super
@model.view = this
- playTrack: ->
+ playTrack: =>
AppController.playerCtrl.play @model.get("url")
-)
View
37 public/js/app/ui.playlist.coffee
@@ -16,33 +16,32 @@ PlayListView = exports.PlayListView = class PlayListView extends Backbone.View
initialize: ->
@songs = new SongsList()
- _.bindAll this, "addOne", "addAll", "currentSong", "currentSongIndex", "randomSong", "render", "clearPlaylist", "selectSong", "playSongModel", "savePlayList", "setPlayListModel", "removePlayListModel", "setSongsAndPlay"
@songs.bind "selected", @selectSong
@songs.bind "add", @addOne
@songs.bind "reset", @addAll
@songs.bind "all", @render
- render: ->
+ render: =>
@statEL.html _.template(@playlistStatTpl,
songsCount: @songs.length
)
this
- setSongsAndPlay: (songs) ->
+ setSongsAndPlay: (songs) =>
@songs.reset songs.models
firstSong = @songs.first()
firstSong.view.playSong() if firstSong
AppController.settings.savePlayList songs
- setPlayListModel: (playList) ->
+ setPlayListModel: (playList) =>
@playList = playList
@newPlayListName.val @playList.get("name")
- removePlayListModel: ->
+ removePlayListModel: =>
@playList = null
@newPlayListName.val "Unsaved list"
- savePlayList: ->
+ savePlayList: =>
newPlaylistName = @newPlayListName.val()
if newPlaylistName isnt "Unsaved list"
@playList = new PlayList() unless @playList
@@ -54,20 +53,20 @@ PlayListView = exports.PlayListView = class PlayListView extends Backbone.View
@playList.save()
AppController.libraryMenu.playLists.add @playList
- clearPlaylist: ->
+ clearPlaylist: =>
@songsEl.empty()
@songs.reset()
AppController.settings.savePlayList @songs
@render()
- addOne: (song) ->
+ addOne: (song) =>
if song.get("fileName")
@dropFileLabel.remove()
view = new SongMiniView(model: song)
song.view = view
@songsEl.append view.render().el
- addAll: ->
+ addAll: =>
if @songs.length isnt 0
@songsEl.empty()
@songs.each @addOne
@@ -103,24 +102,20 @@ PlayListView = exports.PlayListView = class PlayListView extends Backbone.View
else
AppController.appView.dropFiles e
- selectSong: (song) ->
+ selectSong: (song) =>
@selectedSong = song
- self = this
- song.findImage ->
- self.infoEl.html _.template(self.songInfoTpl, song.toJSON())
+ song.findImage => @infoEl.html _.template(@songInfoTpl, song.toJSON())
- randomSong: ->
+ randomSong: =>
randomSong = Math.floor(Math.random() * @songs.length)
return @randomSong() if randomSong is @currentSong()
randomSong
- currentSong: ->
- @songs.at @currentSongIndex()
+ currentSong: => @songs.at @currentSongIndex()
- currentSongIndex: ->
- @songs.indexOf @selectedSong
+ currentSongIndex: => @songs.indexOf @selectedSong
- next: (playSongFlag) ->
+ next: (playSongFlag) =>
playSong = not playSongFlag
nextSongId = -1
if playSong and AppController.settings.isShuffle()
@@ -135,14 +130,14 @@ PlayListView = exports.PlayListView = class PlayListView extends Backbone.View
console.log "Next song", nextSongId, nextSong
@playSongModel nextSong, playSong
- previous: (playSongFlag) ->
+ previous: (playSongFlag) =>
playSong = not playSongFlag
indexOfSelectedSong = @currentSongIndex()
indexOfSelectedSong = @songs.length if indexOfSelectedSong is 0
previousSong = @songs.at(indexOfSelectedSong - 1)
@playSongModel previousSong, playSong
- playSongModel: (song, playSong) ->
+ playSongModel: (song, playSong) =>
if playSong and song and song.view
song.view.playSong()
else song.view.selectSong() if not playSong and song and song.view
Please sign in to comment.
Something went wrong with that request. Please try again.