Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

søk opp bok verk via isbn

  • Loading branch information...
commit 0a3ed971efaa367f776e80f135c150b35a59d4da 1 parent dee0e45
@boutros boutros authored
View
3  .gitignore
@@ -1,2 +1,3 @@
logs/*.log
-settings.rb
+settings.rb
+notes.rb
View
29 public/css/style.css
@@ -96,6 +96,8 @@ h1, h2, h3 { color :#333; line-height: 1.1em;}
.green { background: #71C120;}
+.loading-message { display: none;}
+
img.cover {
max-width: 150px;
height: 200px;
@@ -111,6 +113,16 @@ button.medium {
margin-right:0.5em;
}
+button.long {
+ padding: 4px;
+ width: 200px;
+ color: #fff;
+ border-radius: 3px;
+ border:0;
+ line-height:1.4em;
+ margin-right:0.5em;
+}
+
.book-cover {
text-align: center;
width: 150px;
@@ -120,11 +132,13 @@ button.medium {
p.error {
background: #F9D654;
padding: 15px;
- width: 980px;
+ width: 90%;
clear: both;
color: #222;
}
+label { font-weight: bold;}
+
/* tooltips */
.tooltip-content {
@@ -323,7 +337,18 @@ span.inner-navbutton {
#review-heading div { float:left;}
#review-heading p { margin-left:30px;}
-
+/* isbn search */
+.isbn-form { background-color:#eee; padding:15px; width:90%;}
+#isbn { margin:10px}
+#isbn-notfound { display: none;}
+#isbn-results { margin-top:20px; padding: 15px; border: 1px dashed #ccc;
+ height:265px; width:90%; display:none;}
+#isbn-results div { float: left; }
+#isbn-results p { margin-left: 30px;}
+#isbn-results button { margin: 50px;}
+.isbn-author { font-weight: bold; }
+.isbn-title { font-size: 1.5em;}
+.isbn-work-title { font-size:0.9em;}
/* search results */
a.work-link-big { text-decoration: none; color:#c12121; }
View
50 public/js/app.js
@@ -13,7 +13,55 @@ $(".tooltip-target").ezpz_tooltip({
offset:0
});
+ // loading animation
+var i = 0;
+setInterval(function() {
+ i = ++i % 4;
+ $("#loading").html(""+Array(i+1).join("."));
+}, 500);
+
// set tittel=forfatter som get parameter
$("#search-button").on('click', function() {
$("#search-input-copy").val($("#search-input").val());
-})
+});
+
+// Søk etter bok via ISBN
+$("#isbn-button").on('click', function() {
+ var isbn_input = $('#isbn').val();
+
+ if (isbn == "") {
+ return;
+ }
+
+ $('#isbn').val('');
+
+ var request = $.ajax({
+ url: '/work_by_isbn/',
+ type: "GET",
+ data: { isbn: isbn_input },
+ dataType: "json"
+ });
+
+ $('#isbn').prop("disabled", true);
+ $('.loading-message').show();
+ $('#isbn-results').hide()
+
+ request.done(function(data) {
+ $('#isbn').prop("disabled", false);
+ $('.loading-message').hide();
+ $('#isbn-notfound').hide();
+ $('#isbn-author').html(data.author);
+ $('#isbn-title').html(data.title);
+ $('#isbn-work-title').html("(originaltittel: "+data.work_title+")");
+ $('#isbn-cover').html("<img src='"+data.cover_url+"'>");
+ $('#isbn-results').show()
+ });
+
+ request.fail(function(jqXHR, textStatus, errorThrown) {
+ $('#isbn-error').html(isbn_input);
+ $('#isbn').prop("disabled", false);
+ $('.loading-message').hide();
+ $('#isbn-notfound').show();
+ });
+
+});
View
5 routes/works.rb
@@ -32,4 +32,9 @@ class BokanbefalingerApp < Sinatra::Application
end
end
+ get "/work_by_isbn/" do
+ halt 404 unless work = Work.find_by_isbn(params[:isbn])
+ work.to_json
+ end
+
end
View
30 views/find.erb
@@ -1,4 +1,26 @@
-<h2>Søk opp boka du vil anmelde</h2>
-<h3>ISBN</h3>
-<h3>Forfatter</h3>
-<h3>Tittel</h3>
+<div class="main-left">
+ <h2>Søk opp boka du vil anmelde</h2>
+ <div class="isbn-form">
+ <label>ISBN<input type="text" name="isbn" id="isbn"></label>
+ <button class="medium red" id="isbn-button">Søk</button>
+ <span class="loading-message">Vent litt, søker<span id="loading"></span><span>
+ </div>
+
+ <p class="error" id="isbn-notfound">
+ <strong>Beklager, finner ingen verk kyttet til dette ISBN-nummeret: </strong>
+ <span id="isbn-error"></span>
+ </p>
+ <div id="isbn-results">
+ <div class="book-cover" id="isbn-cover"></div>
+ <div>
+ <p class="isbn-title" id="isbn-title"></p>
+ <p class="isbn-work-title" id="isbn-work-title"></p>
+ <p class="isbn-author" id="isbn-author"></p>
+ <button class="long red">Anmeld denne boka</button>
+ </div>
+ </div>
+</div>
+
+<div class="main-right">
+ <%= erb :login %>
+</div>
View
2  views/layout.erb
@@ -51,7 +51,7 @@
<li <%= 'class="active"' if request.path_info == '/myreviews' %>>
<a href="/"><span class="inner-navbutton">Mine anbefalinger</span></a>
</li>
- <li <%= 'class="active"' if request.path_info =~ /\/ny$/ %>>
+ <li <%= 'class="active"' if request.path_info =~ /\/ny|finn$/ %>>
<a href="/finn"><span class="inner-navbutton">Skriv anbefaling</span></a>
</li>
<% end %>
Please sign in to comment.
Something went wrong with that request. Please try again.