This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for 'share message to friend', remove old facebook_share_wid…
…get.js file
- Loading branch information
Showing
10 changed files
with
438 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/assets/javascripts/facebook_share_widget/facebook_friend.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#= require underscore.js | ||
#= require backbone.js | ||
#= require handlebars-runtime.js | ||
|
||
$ -> | ||
class FacebookFriend extends Backbone.Model | ||
url: '/widget/facebook/share' | ||
|
||
isShared: -> | ||
@get('status') == 'shared' | ||
|
||
shared: -> | ||
@set('status': 'shared') | ||
|
||
isSharing: -> | ||
@get('status') == 'sharing' | ||
|
||
startSharing: -> | ||
@set('status': 'sharing') | ||
|
||
shareFailedBecause: (reason)-> | ||
@set('status': 'failed', 'reason': reason) | ||
|
||
isShareFailed: -> | ||
@get('status') == 'failed' | ||
|
||
share: (template) -> | ||
friend = this | ||
data = $.extend({}, $.parseJSON(template)) | ||
data.facebook_id = @id | ||
data.message = @messageModel.content() | ||
@startSharing() | ||
$.ajax | ||
url: @url | ||
type: "post" | ||
data: { post: data } | ||
success: (resp) => | ||
friend.shared() | ||
error: (jqXHR, textStatus, errorThrown) => | ||
json = $.parseJSON(jqXHR.responseText) | ||
friend.shareFailedBecause(json.message) | ||
|
||
setMessageModel: (model) -> | ||
@messageModel = model | ||
|
||
app.models.FacebookFriend = FacebookFriend |
50 changes: 50 additions & 0 deletions
50
app/assets/javascripts/facebook_share_widget/facebook_friend_view.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#= require underscore.js | ||
#= require backbone.js | ||
#= require handlebars-runtime.js | ||
|
||
$ -> | ||
class FacebookFriendView extends Backbone.View | ||
tagName: 'li' | ||
events: | ||
'click.share-button': 'shareToFriend' | ||
|
||
initialize: -> | ||
@model.on('change', @render, this) | ||
|
||
render: -> | ||
friend = @model.toJSON() | ||
$(@el).html(HandlebarsTemplates['facebook_share_widget/templates/friend'](friend)) | ||
if @model.isShared() | ||
@renderShared() | ||
else if @model.isSharing() | ||
@renderSharing() | ||
else if @model.isShareFailed() | ||
@renderFailed(friend) | ||
else | ||
@renderToShare(friend) | ||
this | ||
|
||
renderShared: -> | ||
$(@el).append("<div class='indicator'><img src='#{$('.tick img').attr('src')}'/> Shared</div>") | ||
this | ||
|
||
renderSharing: -> | ||
$(@el).append("<div class='indicator'><img src='#{$('.loader img').attr('src')}'/> Sharing</div>") | ||
this | ||
|
||
renderToShare: (friend) -> | ||
$(@el).append("<a class='share-button' data-facebook-id='#{friend.id}'>Share</a>") | ||
this | ||
|
||
renderFailed: (friend) -> | ||
$(@el).children('.error-message').text(friend.reason) | ||
this | ||
|
||
shareToFriend: (event) -> | ||
event.preventDefault() | ||
@model.share(@sharingTemplate()) | ||
|
||
sharingTemplate: -> | ||
$('.template').text() | ||
|
||
app.views.FacebookFriendView = FacebookFriendView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 0 additions & 111 deletions
111
app/assets/javascripts/facebook_share_widget/facebook_share_widget.js.coffee.erb
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
app/assets/javascripts/facebook_share_widget/sharing_message.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$ -> | ||
class SharingMessage extends Backbone.Model | ||
content: -> | ||
@get('msg') | ||
app.models.SharingMessage = SharingMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.