喜欢功能的提交

This commit is contained in:
yafeilee 2014-03-31 00:17:06 +08:00
parent a253f8bf50
commit c1cb4930ad
10 changed files with 58 additions and 17 deletions

View File

@ -1,9 +1,10 @@
#= require angular #= require angular
#= require angular-cookies
#= require angular-resource #= require angular-resource
#= require_self #= require_self
#= require_tree ./angularjs #= require_tree ./angularjs
@app = angular.module('app', []) @app = angular.module('app', ['ngCookies'])
@app.config(["$httpProvider", (provider) -> @app.config(["$httpProvider", (provider) ->
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content') provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')

View File

@ -1,4 +1,4 @@
@app.controller 'CommentsController', ($scope, $http, $location, $timeout)-> @app.controller 'CommentsController', ($scope, $http, $location)->
url = $location.absUrl() + "/comments" url = $location.absUrl() + "/comments"
$http.get(url).success (data)-> $http.get(url).success (data)->

View File

@ -0,0 +1,27 @@
@app.controller 'LikesController', ($scope, $http, $location, $cookies)->
url = $location.absUrl() + "/likes"
$scope.count = 0
$scope.get_count = ->
$http.get url
.success (res)->
$scope.count = res.count
$scope.get_count()
$scope.like = $cookies.like
$scope.submit = ->
$http.post url
.success (res)->
if res.success
$scope.count += 1
$scope.like = $cookies.like = res.id
$scope.cancel = ->
$http.delete url + "/" + $scope.like
# anyway, clear cookie
delete $cookies["like"]
$scope.like = null
$scope.get_count()

View File

@ -1191,15 +1191,15 @@
@import 'foundation'; @import 'foundation';
@import 'foundation-icons'; @import 'foundation-icons';
#like-button { .like-button {
color: #eaa296; color: #eaa296 !important;
background-color: transparent; background-color: transparent !important;
border: 1px solid #e79385; border: 1px solid #e79385 !important;
border-radius: 10rem; border-radius: 10rem;
&:hover { &:hover {
background-color: #FCFF9E; background-color: #FCFF9E !important;
} }
&:focus { &:focus {
outline-style: none; outline-style: none !important;
} }
} }

View File

@ -0,0 +1,5 @@
.like-button {
span {
margin-left: 0.23rem;
}
}

View File

@ -11,7 +11,7 @@ class LikesController < ApplicationController
like = Like.new like = Like.new
like.post = post like.post = post
if like.save if like.save
render :json=> { success: true } render :json=> { success: true, id: like.id.to_s }
else else
render :json=> { success: false } render :json=> { success: false }
end end

View File

@ -1,2 +1,5 @@
module ApplicationHelper module ApplicationHelper
def format_date(time)
time.strftime("%Y-%m-%d")
end
end end

View File

@ -1,4 +1,4 @@
.row ng-app="app" ng-controller="CommentsController" .row ng-controller="CommentsController"
.small-12.large-8.columns .small-12.large-8.columns
form novalidate='' name='form' form novalidate='' name='form'
.row .row

View File

@ -1,9 +1,9 @@
h2.blog-title hello h2.blog-title #{post.title}
p.ptag p.ptag
| 分类: i.fi-list
span 技术 span 技术
p.ptag p.ptag
| 标签: i.fi-pricetag-multiple
span 生活, 感悟 span 生活, 感悟
.content.markdown .content.markdown
@ -11,6 +11,11 @@ p.ptag
p.ptag p.ptag
| 发表于: | 发表于:
span 2014-2-14 span #{format_date(post.created_at)}
p p ng-controller="LikesController"
button#like-button Like button.like-button ng-show="! like " ng-click="submit()"
|{{ count }}
span Like
button.like-button ng-show=" like " ng-click="cancel()"
|{{ count }}
span Liked

View File

@ -51,7 +51,7 @@ html
= link_to about_path do = link_to about_path do
i.fi-torso i.fi-torso
| 关于我 | 关于我
section.main-section section.main-section ng-app="app"
= yield = yield
= render "layouts/footer" = render "layouts/footer"
a.exit-off-canvas a.exit-off-canvas