Skip to content
Browse files

Submit codemarklet via AJAX, response with success code, show success…

… message and then close window
  • Loading branch information...
1 parent 92c01c4 commit 4d9f29a7ee489305174c1f8c0c4d7e1fd5679cda Geoff Massanek committed Apr 19, 2012
View
26 app/assets/coffeescripts/codemarklet.coffee
@@ -0,0 +1,26 @@
+window.Codemarklet =
+ closeWindowOnEscape: ->
+ $(document).keyup (event) ->
+ if (event.keyCode == 27)
+ window.close()
+
+ setupSubmit: ->
+ $("#codemark_form").submit (event) ->
+ event.preventDefault()
+ $cm_form = $(event.currentTarget)
+ data = $cm_form.serialize()
+ url = $cm_form.attr('action')
+ $.post url, data, Codemarklet.successfulPost, 'SCRIPT'
+
+ successfulPost: (response) ->
+ console.log response
+ $('.cm_notice').show()
+ delay = (ms, func) -> setTimeout func, ms
+ delay 1000, -> window.close()
+
+
+ bootstrap: ->
+ $ ->
+ Codemarklet.closeWindowOnEscape()
+ Codemarklet.setupSubmit()
+ window.CodemarkForm.bootstrap()
View
5 app/controllers/codemarks_controller.rb
@@ -20,7 +20,10 @@ def create
current_user,
:new_topic_titles => new_topic_titles)
- redirect_to :back, :notice => 'Thanks!'
+ respond_to do |format|
+ format.html { redirect_to :back, :notice => 'Thanks!' }
+ format.js { render :text => '', :status => :ok }
+ end
end
def public
View
10 app/views/codemarklet/new.html.haml
@@ -1,13 +1,5 @@
:javascript
- $(document).ready(function() {
- CodemarkForm.bootstrap();
-
- $(document).keyup(function(event) {
- if (event.keyCode == 27) {
- window.close();
- }
- });
- });
+ window.Codemarklet.bootstrap();
#codemarklet
.cm_notice
View
2 app/views/layouts/codemarklet.html.haml
@@ -4,7 +4,9 @@
= stylesheet_link_tag 'application'
= stylesheet_link_tag 'codemarklet'
= javascript_include_tag 'application'
+
= javascript_include_tag 'codemark_form'
+ = javascript_include_tag 'codemarklet'
%title Codemarks
= csrf_meta_tags
%body

0 comments on commit 4d9f29a

Please sign in to comment.
Something went wrong with that request. Please try again.