Skip to content

Commit 54a5ce4

Browse files
committed
add success-error flow for discussion posts
1 parent c167050 commit 54a5ce4

File tree

6 files changed

+78
-29
lines changed

6 files changed

+78
-29
lines changed

pyhackers/static/coffee/app/discuss.coffee

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class @Discuss
1010
if !@discussion_id?
1111
return
1212

13-
13+
$(document).on("ajax:success","#discussion-message", @onDiscussionMessage)
14+
$(document).on("ajax:error","#discussion-message", @onDiscussionMessageError)
1415
window.setInterval(@reload, 10000)
1516
do @reload
1617

@@ -27,6 +28,25 @@ class @Discuss
2728
))
2829
)
2930

31+
onDiscussionMessageError: (event) ->
32+
Messenger().post
33+
message:"Something went wrong! Try again"
34+
type:"error"
35+
36+
onDiscussionMessage : (event, data) ->
37+
unless data.id
38+
Messenger().post
39+
message:"Something went wrong! Try again"
40+
type:"error"
41+
return
42+
43+
$form = $(event.currentTarget)
44+
$form.find("textarea").val("")
45+
Messenger().post
46+
message:"Message has been sent!"
47+
type:"success"
48+
49+
3050
discussDialog: () =>
3151
$template = $($("#discuss-template").html())
3252

pyhackers/static/coffee/app/main.coffee

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Application = {
126126
formSubmitter : () ->
127127

128128
$('form[data-remote]').submit (evt) ->
129+
$form = $(@)
129130
evt.preventDefault()
130131
evt.stopPropagation()
131132
Application.captureSubmit($(evt.currentTarget))
@@ -138,10 +139,13 @@ Application = {
138139
action = $this.attr("action")
139140
postData = $this.serializeArray()
140141

141-
$.post(action, postData)
142+
$.post(action, postData,)
143+
.done((data) ->
144+
$form.trigger("ajax:success", [data])
145+
).fail( () ->
146+
$form.trigger("ajax:error", [])
147+
)
142148

143-
144-
$('[data-toggle="tooltip"]').tooltip()
145149
}
146150

147151

pyhackers/static/js/app/discuss.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyhackers/static/js/app/main.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyhackers/templates/discussion.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2>
2626
<div class="linklist links clearfix">
2727
<div class="messages clearfix">
2828
<div class="clearfix">
29-
<form class="form-inline" action="/ajax/discuss/message/new" data-remote="true"
29+
<form id="discussion-message" class="form-inline" action="/ajax/discuss/message/new" data-remote="true"
3030
method="post">
3131
<div class="input-group">
3232
<textarea name='text' class="form-control input" rows="1"
@@ -43,8 +43,6 @@ <h2>
4343
<hr/>
4444
<div class="posts">
4545
</div>
46-
47-
4846
</div>
4947

5048
<div class="footer">

pyhackers/worker/github_worker.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def get_starred_projects(self):
6868
hide=False,
6969
)
7070

71-
#print s.full_name, s.watchers
72-
71+
#print s.full_name, s.watchers
7372

7473
self.github_user_detail.starred = projects
7574
self.github_user_detail.save()
@@ -116,28 +115,26 @@ def save_discovered_users(self):
116115
#return
117116

118117
for nick in missing_ids:
119-
120118
user = self.g.get_user(nick)
121119

122120
logging.warn("Creating user [{}]".format(nick))
123121

124-
125122
GithubUser(nick=user.login,
126123
id=user.id,
127-
email=user.email,
128-
followers=user.followers,
129-
following=user.following,
130-
image=user.avatar_url,
131-
blog=user.blog,
132-
bio=user.bio,
133-
company=user.company,
134-
location=user.location,
135-
name=user.name,
136-
url=user.url,
137-
utype=user.type,
138-
public_repos=user.public_repos,
139-
public_gists=user.public_gists,).save()
140-
#ghuser.save()
124+
email=user.email,
125+
followers=user.followers,
126+
following=user.following,
127+
image=user.avatar_url,
128+
blog=user.blog,
129+
bio=user.bio,
130+
company=user.company,
131+
location=user.location,
132+
name=user.name,
133+
url=user.url,
134+
utype=user.type,
135+
public_repos=user.public_repos,
136+
public_gists=user.public_gists, ).save()
137+
141138
logging.warn("User[{}]created".format(nick))
142139

143140

0 commit comments

Comments
 (0)