Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0a66686
Showing
47 changed files
with
7,082 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
web: node server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
before('protect from forgery', function () { | |||
protectFromForgery('5d016d2ae47dfb552e63b831eb9cecd809d60ed8'); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,78 @@ | |||
load('application'); | |||
|
|||
before(loadBook, {only: ['show', 'edit', 'update', 'destroy']}); | |||
|
|||
action('new', function () { | |||
this.title = 'New book'; | |||
this.book = new Book; | |||
render(); | |||
}); | |||
|
|||
action(function create() { | |||
Book.create(req.body.Book, function (err, book) { | |||
if (err) { | |||
flash('error', 'Book can not be created'); | |||
render('new', { | |||
book: book, | |||
title: 'New book' | |||
}); | |||
} else { | |||
flash('info', 'Book created'); | |||
redirect(path_to.books); | |||
} | |||
}); | |||
}); | |||
|
|||
action(function index() { | |||
this.title = 'Books index'; | |||
Book.all(function (err, books) { | |||
render({ | |||
books: books | |||
}); | |||
}); | |||
}); | |||
|
|||
action(function show() { | |||
this.title = 'Book show'; | |||
render(); | |||
}); | |||
|
|||
action(function edit() { | |||
this.title = 'Book edit'; | |||
render(); | |||
}); | |||
|
|||
action(function update() { | |||
this.book.updateAttributes(body.Book, function (err) { | |||
if (!err) { | |||
flash('info', 'Book updated'); | |||
redirect(path_to.book(this.book)); | |||
} else { | |||
flash('error', 'Book can not be updated'); | |||
this.title = 'Edit book details'; | |||
render('edit'); | |||
} | |||
}.bind(this)); | |||
}); | |||
|
|||
action(function destroy() { | |||
this.book.destroy(function (error) { | |||
if (error) { | |||
flash('error', 'Can not destroy book'); | |||
} else { | |||
flash('info', 'Book successfully removed'); | |||
} | |||
send("'" + path_to.books + "'"); | |||
}); | |||
}); | |||
|
|||
function loadBook() { | |||
Book.find(params.id, function (err, book) { | |||
if (err) { | |||
redirect(path_to.books); | |||
} else { | |||
this.book = book; | |||
next(); | |||
} | |||
}.bind(this)); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,91 @@ | |||
load('application'); | |||
|
|||
before(loadBook); | |||
before(loadChapter, {only: ['show', 'edit', 'update', 'destroy']}); | |||
|
|||
action('new', function () { | |||
this.title = 'New chapter'; | |||
this.chapter = new Chapter; | |||
render(); | |||
}); | |||
|
|||
action(function create() { | |||
this.book.chapters.create(req.body.Chapter, function (err, chapter) { | |||
if (err) { | |||
flash('error', 'Chapter can not be created'); | |||
render('new', { | |||
chapter: chapter, | |||
title: 'New chapter' | |||
}); | |||
} else { | |||
flash('info', 'Chapter created'); | |||
redirect(path_to.book_chapters(this.book)); | |||
} | |||
}.bind(this)); | |||
}); | |||
|
|||
action(function index() { | |||
this.title = 'Chapters index'; | |||
this.book.chapters(function (err, chapters) { | |||
render({ | |||
chapters: chapters | |||
}); | |||
}); | |||
}); | |||
|
|||
action(function show() { | |||
this.title = 'Chapter show'; | |||
render(); | |||
}); | |||
|
|||
action(function edit() { | |||
this.title = 'Chapter edit'; | |||
render(); | |||
}); | |||
|
|||
action(function update() { | |||
this.chapter.updateAttributes(body.Chapter, function (err) { | |||
if (!err) { | |||
flash('info', 'Chapter updated'); | |||
redirect(path_to.chapter(this.chapter)); | |||
} else { | |||
flash('error', 'Chapter can not be updated'); | |||
this.title = 'Edit chapter details'; | |||
render('edit'); | |||
} | |||
}.bind(this)); | |||
}); | |||
|
|||
action(function destroy() { | |||
this.chapter.destroy(function (error) { | |||
if (error) { | |||
flash('error', 'Can not destroy chapter'); | |||
} else { | |||
flash('info', 'Chapter successfully removed'); | |||
} | |||
send("'" + path_to.chapters + "'"); | |||
}); | |||
}); | |||
|
|||
function loadChapter() { | |||
this.book.chapters.find(params.id, function (err, chapter) { | |||
if (err) { | |||
console.log(err); | |||
redirect(path_to.book_chapters(this.book)); | |||
} else { | |||
this.chapter = chapter; | |||
next(); | |||
} | |||
}.bind(this)); | |||
} | |||
|
|||
function loadBook() { | |||
var self = this; | |||
Book.find(params.book_id, function (err, book) { | |||
if (err) return next(err); | |||
if (!book) return next(new Error(404)); | |||
self.book = book; | |||
next(); | |||
}); | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module.exports = { | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module.exports = { | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
Book.hasMany(Chapter, {as: 'chapters', foreignKey: 'bookId'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
Chapter.belongsTo(Book, {as: 'book', foreignKey: 'bookId'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
<div class="control-group"> | |||
<%- form.label("name", false, {class: "control-label"}) %> | |||
<div class="controls"> | |||
<%- form.input("name") %> | |||
</div> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<div class="page-header"><h1>Edit book</h1></div> | |||
|
|||
<% form_for(book, {action: path_to.book(book), method: 'PUT', id: "book_form", class: 'form-horizontal'}, function (form) { %> | |||
<%- partial('books/form.ejs', {locals: {form: form, book: book}}) %> | |||
<div class="form-actions"> | |||
<%- form.submit('<i class="icon-ok icon-white"></i> Update book', {class: 'btn btn-primary'}) %> or | |||
<%- link_to('Cancel', path_to.book(book), {class: 'btn'}) %> | |||
</div> | |||
<% });%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
<div class="page-header"> | |||
<h1>My Books</h1> | |||
</div> | |||
|
|||
<div class="row"> | |||
<div class="span12"> | |||
<p><%- link_to('<i class="icon-plus icon-white"></i> Add Book', path_to.new_book, {class: 'btn btn-primary'}) %></> | |||
</div> | |||
</div> | |||
|
|||
<div class="row"> | |||
<div class="span12"> | |||
<% if (books.length > 0) { %> | |||
<table class="table table-striped"> | |||
<thead> | |||
<tr> | |||
<th>ID</th> | |||
<th>Actions</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<% books.forEach(function (book) { %> | |||
<tr> | |||
<td><strong><%- linkTo(book.name, path_to.book(book)) %></strong></td> | |||
<td> | |||
<%- link_to('<i class="icon-edit"></i> Edit', path_to.edit_book(book), {class: 'btn btn-mini'}) %> | |||
<%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.book(book), {class: 'btn btn-mini btn-danger', method: 'delete', remote: true, jsonp: '(function (u) {location.href = u;})'}) %> | |||
</td> | |||
</tr> | |||
<% }); %> | |||
</tbody> | |||
</table> | |||
<% } else { %> | |||
<p class="alert alert-block alert-info"> | |||
<strong>No books were found.</strong> | |||
</p> | |||
<% } %> | |||
</div> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
<div class="page-header"> | |||
<h1>New book</h1> | |||
</div> | |||
|
|||
<% form_for(book, {action: path_to.books, method: 'POST', id: "book_form", class: 'form-horizontal'}, function (form) { %> | |||
<%- partial('books/form.ejs', {locals: {form: form, book: book}}) %> | |||
<div class="form-actions"> | |||
<%- form.submit('<i class="icon-ok icon-white"></i> Create book', {class: 'btn btn-primary'}) %> or | |||
<%- link_to('Cancel', path_to.books, {class: 'btn'}) %> | |||
</div> | |||
<% });%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
<div class="page-header"> | |||
<h1>Details of book</h1> | |||
</div> | |||
|
|||
|
|||
<table class="table table-bordered"> | |||
<tbody> | |||
<tr><th>name</th><td><%= book.name %></td></tr> | |||
</tbody> | |||
</table> | |||
|
|||
<div class="well"> | |||
<%- link_to('<i class="icon-edit icon-white"></i> Edit', path_to.edit_book(book), {class: 'btn btn-primary'}) %> | |||
<%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.book(book), {class: 'btn btn-danger', method: 'delete', remote: true, jsonp: '(function (u) { location.href = u; })'}) %> | |||
or | |||
<%- link_to('Back to index', path_to.books) %> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
<div class="control-group"> | |||
<%- form.label("title", false, {class: "control-label"}) %> | |||
<div class="controls"> | |||
<%- form.input("title") %> | |||
</div> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<div class="page-header"><h1>Edit chapter</h1></div> | |||
|
|||
<% form_for(chapter, {action: path_to.book_chapter(book, chapter), method: 'PUT', id: "chapter_form", class: 'form-horizontal'}, function (form) { %> | |||
<%- partial('chapters/form.ejs', {locals: {form: form, chapter: chapter}}) %> | |||
<div class="form-actions"> | |||
<%- form.submit('<i class="icon-ok icon-white"></i> Update chapter', {class: 'btn btn-primary'}) %> or | |||
<%- link_to('Cancel', path_to.book_chapter(book, chapter), {class: 'btn'}) %> | |||
</div> | |||
<% });%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
<div class="page-header"> | |||
<h1>Chapters of Book <%- book.title || book.name %></h1> | |||
</div> | |||
|
|||
<div class="row"> | |||
<div class="span12"> | |||
<p><%- link_to('<i class="icon-plus icon-white"></i> New chapter', path_to.new_book_chapter(book), {class: 'btn btn-primary'}) %></> | |||
</div> | |||
</div> | |||
|
|||
<div class="row"> | |||
<div class="span12"> | |||
<% if (chapters.length > 0) { %> | |||
<table class="table table-striped"> | |||
<thead> | |||
<tr> | |||
<th>ID</th> | |||
<th>Actions</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<% chapters.forEach(function (chapter, i) { %> | |||
<tr> | |||
<td><strong><%- link_to('chapter #' + (i + 1) + '. ' + chapter.title, path_to.book_chapter(book, chapter)) %></strong></td> | |||
<td> | |||
<%- link_to('<i class="icon-edit"></i> Edit', path_to.edit_book_chapter(book, chapter), {class: 'btn btn-mini'}) %> | |||
<%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.book_chapter(book, chapter), {class: 'btn btn-mini btn-danger', method: 'delete', remote: true, jsonp: '(function (u) {location.href = u;})'}) %> | |||
</td> | |||
</tr> | |||
<% }); %> | |||
</tbody> | |||
</table> | |||
<% } else { %> | |||
<p class="alert alert-block alert-info"> | |||
<strong>No chapters were found.</strong> | |||
</p> | |||
<% } %> | |||
</div> | |||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
<div class="page-header"> | |||
<h1>New chapter</h1> | |||
</div> | |||
|
|||
<% form_for(chapter, {action: path_to.book_chapters(book), method: 'POST', id: "chapter_form", class: 'form-horizontal'}, function (form) { %> | |||
<%- partial('chapters/form.ejs', {locals: {form: form, chapter: chapter}}) %> | |||
<div class="form-actions"> | |||
<%- form.submit('<i class="icon-ok icon-white"></i> Create chapter', {class: 'btn btn-primary'}) %> or | |||
<%- link_to('Cancel', path_to.book_chapters(book), {class: 'btn'}) %> | |||
</div> | |||
<% });%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
<div class="page-header"> | |||
<h1>Details of chapter</h1> | |||
</div> | |||
|
|||
|
|||
<table class="table table-bordered"> | |||
<tbody> | |||
<tr><th>title</th><td><%= chapter.title %></td></tr> | |||
</tbody> | |||
</table> | |||
|
|||
<div class="well"> | |||
<%- link_to('<i class="icon-edit icon-white"></i> Edit', path_to.edit_book_chapter(book, chapter), {class: 'btn btn-primary'}) %> | |||
<%- link_to('<i class="icon-remove icon-white"></i> Delete', path_to.book_chapter(book, chapter), {class: 'btn btn-danger', method: 'delete', remote: true, jsonp: '(function (u) { location.href = u; })'}) %> | |||
or | |||
<%- link_to('Back to index', path_to.book_chapters(book)) %> | |||
</div> |
Oops, something went wrong.