From a4edb4147d879349450dedd29457f42f4c8531b1 Mon Sep 17 00:00:00 2001 From: nilsding Date: Tue, 9 Dec 2014 23:37:44 +0100 Subject: [PATCH] generating questions is great --- app/assets/javascripts/inbox.coffee | 16 ++++++++++++++++ app/views/inbox/show.html.haml | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/inbox.coffee b/app/assets/javascripts/inbox.coffee index 18feea79..c6d13d4b 100644 --- a/app/assets/javascripts/inbox.coffee +++ b/app/assets/javascripts/inbox.coffee @@ -1,3 +1,19 @@ +($ document).on "click", "button#ib-generate-question", -> + btn = ($ this) + btn.button "loading" + $.ajax + url: '/ajax/generate_question' + type: 'POST' + dataType: 'json' + success: (data, status, jqxhr) -> + if data.success + ($ "div#entries").prepend(data.render) # TODO: slideDown or something + error: (jqxhr, status, error) -> + console.log jqxhr, status, error + showNotification "An error occurred, a developer should check the console for details", false + complete: (jqxhr, status) -> + btn.button "reset" + $(document).on "keydown", "textarea[name=ib-answer]", (evt) -> iid = $(this)[0].dataset.id if evt.keyCode == 13 and evt.ctrlKey diff --git a/app/views/inbox/show.html.haml b/app/views/inbox/show.html.haml index aa224aab..eb60e335 100644 --- a/app/views/inbox/show.html.haml +++ b/app/views/inbox/show.html.haml @@ -1,12 +1,14 @@ .container.j2-page = render 'layouts/messages' + %button.btn.btn-default{type: :button, id: 'ib-generate-question'} Get new question + #entries - @inbox.each do |i| = render 'inbox/entry', i: i - - if @inbox.empty? + - if @inbox.empty? - Nothing to see here. + Nothing to see here. = render "shared/links" - @inbox.update_all(new: false) \ No newline at end of file