Skip to content

Commit

Permalink
working with form to send kindle book.
Browse files Browse the repository at this point in the history
  • Loading branch information
diegorubin committed Jan 31, 2016
1 parent 3e11bad commit 3b2e2ce
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/assets/javascripts/kindle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//= require_self
function Kindle() {
var _this = this;

_this.init = function() {
document.getElementById("send-kindle").onclick = function(event) {
event.preventDefault();
_this.getForm();

};
};

_this.openDialog = function(html) {
var overlay = document.getElementById('overlay-kindle');
overlay.innerHTML = html;
_this.setSendButton();
};

_this.setSendButton = function() {
var button = document.getElementById('send-kindle-button');
button.onclick = function(event) {
event.preventDefault();
};
}

_this.sendData = function() {
};

_this.getForm = function() {

var xmlhttp = new XMLHttpRequest();
var url = "/kindle/new";

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
_this.openDialog(xmlhttp.responseText);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
};

};

Empty file.
14 changes: 14 additions & 0 deletions app/views/kindle/_button.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- content_for(:javascript) do
= javascript_include_tag 'kindle'
%script
var kindle = new Kindle();
kindle.init();

- content_for(:stylesheet) do
= stylesheet_link_tag 'kindle'

%a#send-kindle{href: '#'}
Enviar Para Kindle

#overlay-kindle

12 changes: 12 additions & 0 deletions app/views/kindle/new.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%h3
Enviar artigo para o Kindle

Para que o arquivo possa ser enviado é preciso autorizar o email:
= ActionMailer::Base.smtp_settings[:user_name]

%form{action: '/kindle', method: 'post'}
%label
Seu email kindle:
%input{type: 'email', placeholder: 'user@kindle.com'}
%input#send-kindle-button{type: 'submit'}

2 changes: 2 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

gallery.css gallery.js

kindle.css kindle.js

presentation.css presentation.js
comments.js
)
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
:as => "gallery",
:date => /\d{4}(\/\d{2}){2}/

# Kindle
resources :kindle, only: [:new, :create]

# Pages
get "/pages/:slug" => "pages#show", :as => "page"

Expand Down

0 comments on commit 3b2e2ce

Please sign in to comment.