1. roma milushov
  2. playlists

Commits

roma milushov  committed 815502c

bug fixes on page for creation playlist

Comments (0)

Files changed (7)

File app/assets/javascripts/backbone/routers/app_router.js.coffee Modified

View file
  • Ignore whitespace
  • Hide word diff
     # BUG: way, when i use fetch method for obtain comments - not work!
     if playlist.comments.length == 0
       playlist.fetch
-      @vk.getComments playlist.get('url'), 0, 10, (data)->
-        if not data.error       
-          playlist.comments.add data
-          playlist.comments.url = "#{playlist.url()}/comments"
-
-          $("#app").html( new Playlists.Views.Comments.IndexView(
-            playlist
-          ).render().el )
-          @ok()
-        else
-          notify data
-          @ok()
+      @vk.getComments playlist.get('url'), 0, 10, (data) ->
+        return notify data.error if data.error
+        
+        playlist.comments.add data if data.comments?.length != 0
+        playlist.comments.url = "#{playlist.url()}/comments"
+
+        $("#app").html( new Playlists.Views.Comments.IndexView(playlist).render().el)
+        @ok()
+       
       ,this  
     else
       $("#app").html( new Playlists.Views.Comments.IndexView(

File app/assets/javascripts/backbone/templates/playlists/new.jst.hamlc Modified

View file
  • Ignore whitespace
  • Hide word diff
 #right_block.fl_r
   #followers
     #title Слушатели
-      %a.follower{href: "/u/#{ @screen_name }"}
-        %img{src: "#{ @photo }"}
+    %a.follower{href: "/u/#{ @screen_name }"}
+      %img{src: "#{ @photo }"}

File app/assets/javascripts/backbone/views/playlists/new_view.js.coffee Modified

View file
  • Ignore whitespace
  • Hide word diff
 
     track_name = $('#track_seacher input').val()
     if track_name.length < 3
-      alert 'Название трека слишком короткое'
-      return
+      return notify 'Название трека слишком короткое'
 
     App.vk.searchTracks track_name, 0, (data)->
-      data.response.tracks?.splice 0, 1 # убираем первый элемент, который содержит кол-во найденных треков
-      window.a = tracks = data.response.tracks
-      if not tracks?
-        alert 'ни одного трека не найдено'
-        return
+      if data.response.tracks
+        data.response.tracks.splice 0, 1 # remove first element
+      tracks = data.response.tracks
+      
+      return notify 'Ни одного трека не найдено' unless tracks
+        
       $('#searched_tracks').html(new Playlists.Views.Tracks.FoundTracksView(tracks).render().el)
     ,this
 
       track.unset 'owner_id'
       track.unset 'aid'
 
+    name = $('#playlist_name').val()
+    if name.length < 3
+      return notify 'Слишком короткое название'
+
+    url = $('#playlist_url').val()
+    if name.length < 3
+      return notify 'Ссылка слишком короткая'
+
+    if not @image
+      return notify 'Загрузите изображение, визуализирующее тематику плейлиста'
+    image = 
+      image: @image.large_thumbnail
+      image_small: @image.small_square
+
+    tags = $("#edit_tags").tagit("assignedTags")
+    if tags.length == 0
+      return notify 'Добавьте хоть один тег'
+
+    description = $('#playlist_description').val()
+    if description.length < 10
+      return notify 'Описание слишком короткое'
+
+     
+    switch count = App.new_tracks.length
+      when 0 then return notify 'Добавьте треков в плейлист'
+      when 1, 2 then return notify 'Маловато треков для плейлиста'
+
     new_playlist = 
-      name: $('#playlist_name').val()
-      url: $('#playlist_url').val()
-      image:  'http://vk.com/images/camera_a.gif'
-      description: $('#playlist_description').val()
-      tags: $("#edit_tags").tagit("assignedTags")
+      name: name
+      url: url
+      image:  image
+      description: description
+      tags: tags
       creator: my_profile.user.id
       tracks: App.new_tracks.toJSON()
 
     new_playlist = JSON.stringify new_playlist
 
-    App.vk.saveNewPlaylist playlist: new_playlist, (data)->
-      if data.status
-        App.navigate(data.id, true)
-      else
-        alert 'что-то пошло не так'
-    , this
+    App.vk.saveNewPlaylist playlist: new_playlist, (data) ->
+      return notify data.error if data.error
+      App.navigate(data.id, true) if data.status  
+    ,this
 
   imageUploaded: (imageUploaded) ->
-    console.log imageUploaded
-    @image = imageUploaded
-    $('#photo img')[0].src = @image.upload.links.large_thumbnail
+    # console.log imageUploaded
+    @image = imageUploaded.upload.links
+    $('#photo img')[0].src = @image.large_thumbnail
 
   render: ->
     console.log 'Views.Playlists.NewView render()'

File app/assets/stylesheets/common.css.scss Modified

View file
  • Ignore whitespace
  • Hide word diff
       }
 
       div {
-        margin-top: 3px;
+        
       }
 
     }

File app/controllers/comments_controller.rb Modified

View file
  • Ignore whitespace
  • Hide word diff
 
     comments = Comment.where(playlist_id: pid).desc(:created_at).skip(page).limit(per).includes(:user).to_a
 
-    return error 'comments not found' if comments.empty?
+    return render json: { status: true, comments: [] } if comments.empty?
 
     comments.map! { |c| c[:user_data] = c.user.show; c }
 

File app/controllers/playlists_controller.rb Modified

View file
  • Ignore whitespace
  • Hide word diff
 
   # POST /playlists
   def create
-    playlist = JSON.parse params['playlist']
+    playlist = pick JSON.parse(params[:playlist]), :name, :url, :image, :description, :tags, :tracks
+    if playlist[:image]
+      playlist[:image_small] = playlist[:image]['image_small'] || nil
+      playlist[:image] = playlist[:image]['image'] || nil
+    end
+    playlist[:creator] = session[:user_id]
 
-    @playlist = Playlist.new(playlist)
+    @playlist = Playlist.new playlist
     
-    if @playlist.save
-      user = User.where(vk_id: session[:user_id].to_s).first
+    if status = @playlist.save
+      user = User.find session[:user_id].to_i
       user.follow @playlist
-      render json: {status: true, id: @playlist[:url]}, location: @playlist
+      render json: {status: status, id: @playlist[:url]}, location: @playlist
     else
-      error "#{playlist['name']} not created :-("
+      return error 'Плейлист не создан, т.к. одно из полей было заполненно неверно.'
     end
   end
 
     # @playlist.destroy
   end
 
-  private
-  
+private
+  def pick(hash, *keys)
+    filtered = {}
+    hash.each do |key, value| 
+      filtered[key.to_sym] = value if keys.include?(key.to_sym) 
+    end
+    filtered
+  end
+
   def do_follow undo = nil
     if user = User.find(session[:user_id].to_i)
       unless playlist = Playlist.any_of({url: params[:id]}, {_id: params[:id]}).first

File app/models/playlist.rb Modified

View file
  • Ignore whitespace
  • Hide word diff
   
   field :name, type: String
   field :image, type: String
+  field :image_small, type: String, default: nil
   field :description, type: String
 
   field :url, type: String