Skip to content

Commit

Permalink
Scaffolds rest of starter code
Browse files Browse the repository at this point in the history
  • Loading branch information
RealWeeks committed Oct 25, 2016
1 parent 7145d81 commit 86dc1ad
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
13 changes: 11 additions & 2 deletions assets/scripts/books/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

// const app = require('../app.js');
const app = require('../app.js');

module.exports = true;
const index = function () {
return $.ajax({
url: app.host + '/books',
method: 'GET',
});
};

module.exports = {
index
};
18 changes: 15 additions & 3 deletions assets/scripts/books/events.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
'use strict';

// const booksApi = require('./api.js');
// const booksUi = require('./ui.js');
const booksApi = require('./api.js');
const booksUi = require('./ui.js');

module.exports = {
// get in the habit of naming your handlers, it eases debugging.
//
// also, follow a convention for handlers. here, I name my handler
// beginning with 'on' to denote that it is done when the GET /books
// button is clicked
const onGetBooks = function (event) {
event.preventDefault();
booksApi.index()
.then(booksUi.onSuccess)
.catch(booksUi.onError);
};

module.exports = {
onGetBooks,
};
15 changes: 14 additions & 1 deletion assets/scripts/books/ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
'use strict';

module.exports = {
const onSuccess = function (data) {
if (data.book) {
console.log(data.book);
} else {
console.table(data.books);
}
};

const onError = function (response) {
console.error(response);
};

module.exports = {
onSuccess,
onError,
};
5 changes: 1 addition & 4 deletions assets/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ const bookEvents = require('./books/events');

// On document ready
$(() => {
$('.books').on('submit', function(e){
e.preventDefault();
debugger;
})
$('.books').on('submit', bookEvents.onGetBooks)
});
6 changes: 1 addition & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ <h1>Example</h1>
est laborum.</p>

<form class='books'>
<div class="form-group">
<label for="resource">Resource</label>
<input type="text" class="form-control" id="resource" placeholder="Resource?">
</div>
<button type="submit" class="btn btn-default">Submit</button>
<button type="submit" class="btn btn-default">Get all Books</button>
</form>

</body>
Expand Down

0 comments on commit 86dc1ad

Please sign in to comment.