From 2cc1062af7579c825e7191ab19d4ed937505cb59 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 8 Nov 2014 20:41:08 +0100 Subject: [PATCH] allahu snackbar --- app/assets/javascripts/application.coffee | 32 ++++++++++++++++++++++- app/views/shared/_questionbox.html.haml | 8 +++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/application.coffee b/app/assets/javascripts/application.coffee index 1b4445c6..549d0699 100644 --- a/app/assets/javascripts/application.coffee +++ b/app/assets/javascripts/application.coffee @@ -8,4 +8,34 @@ #= require_tree . NProgress.configure - showSpinner: false \ No newline at end of file + showSpinner: false + +$(document).on "click", "button[name=qb-ask]", -> + btn = $(this) + btn.button "loading" + promote = btn[0].dataset.promote == "true" + $("textarea[name=qb-question]").attr "readonly", "readonly" + anonymousQuestion = if $("input[name=qb-anonymous]")[0] != undefined + $("input[name=qb-anonymous]")[0].checked + else + true + console.log "some AJAX magic should happen here!" + btn.button "reset" + $("textarea[name=qb-question]").removeAttr "readonly" + if true # data.success + $("textarea[name=qb-question]").val '' + if promote + $("div#question-box").hide() + $("div#question-box-promote").show() + else + $.snackbar # allahu snackbar + content: "Successfully asked question" + style: "snackbar" + timeout: 5000 + +$(document).on "click", "button#create-account", -> + Turbolinks.visit "/sign_up" + +$(document).on "click", "button#new-question", -> + $("div#question-box").show() + $("div#question-box-promote").hide() diff --git a/app/views/shared/_questionbox.html.haml b/app/views/shared/_questionbox.html.haml index 1c7c4ee2..f7108d66 100644 --- a/app/views/shared/_questionbox.html.haml +++ b/app/views/shared/_questionbox.html.haml @@ -6,17 +6,17 @@ #question-box.row .row .col-xs-12 - %textarea.form-control{:name => "qb_question", :placeholder => "Type your question here…"} + %textarea.form-control{:name => "qb-question", :placeholder => "Type your question here…"} .row{:style => "padding-top: 5px; padding-left: 5px; padding-right: 5px;"} .col-xs-6 - if user_signed_in? # and @user.allow_anonymous - %input{:name => "qb_hidename", :type => "checkbox"}/ + %input{:name => "qb-anonymous", :type => "checkbox"}/ Hide your name %br/ .col-xs-6 %p.pull-right - %input{:name => "qb_to", :type => "hidden", :value => @user.id}/ - %button#qb_ask.btn.btn-primary{"data-loading-text" => "Asking...", "data-promote" => user_signed_in? ? "true" : "false", :type => "button"} Ask + %input{name: 'qb-to', type: 'hidden', :value => @user.id}/ + %button.btn.btn-primary{name: 'qb-ask', 'data-loading-text' => "Asking...", "data-promote" => user_signed_in? ? "false" : "true", :type => "button"} Ask - unless user_signed_in? #question-box-promote.row{:style => "display: none;"} .row