Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8791af6
Add files for movie model, collection, and relevant views
vsawchuk Dec 18, 2017
678370f
add ul and movie template to index.html
vsawchuk Dec 18, 2017
ae298db
Add necessary code to render list of movies once it's called from the…
vsawchuk Dec 18, 2017
deb05bc
render rental library when click on rental library button
vsawchuk Dec 18, 2017
a5df649
Rental library renders as a list
vsawchuk Dec 18, 2017
323c516
Display picture in movie template, remove extraneous console.log
vsawchuk Dec 18, 2017
519f4c9
Move event listening onto instance of movie list view instead of init…
vsawchuk Dec 18, 2017
f10233b
Add instace of MovieList for search results. Add method to MovieList …
enigmagnetic Dec 18, 2017
dffd82a
Build custom event to handle an IMDB query
vsawchuk Dec 18, 2017
dc1cf9e
Implement event handling with a form for searching IMDB movies
vsawchuk Dec 19, 2017
a0f9179
Prevent automatic rendering of rental library
vsawchuk Dec 19, 2017
bb91138
Add separate template for library movies and search movies
vsawchuk Dec 19, 2017
88146c6
Add styling. Add events and slide animation for details and add renta…
enigmagnetic Dec 19, 2017
4072930
Remove duration argument from toggle function to make it run at defau…
enigmagnetic Dec 19, 2017
f19d8c9
Remove height property on product cards and replace with min height, …
vsawchuk Dec 19, 2017
23f27db
Styling changes
enigmagnetic Dec 19, 2017
02c4715
Add events for adding a rental to the rental library from the IMDB li…
enigmagnetic Dec 19, 2017
5d8691e
Display details on library movies
vsawchuk Dec 19, 2017
de4c807
Prevent render errors caused by null release dates from API, add addi…
vsawchuk Dec 19, 2017
d246f77
Remove duplicate listing of release date for library movies
vsawchuk Dec 19, 2017
aed70d5
Send post request and add new movie to collection when user adds inve…
vsawchuk Dec 19, 2017
bfd89af
Merge branch 'add-inventory'
vsawchuk Dec 19, 2017
5b67e9d
Add navigation and divs for rentals and customers. Add display-none c…
enigmagnetic Dec 20, 2017
def1f5f
Merge branch 'add-inventory'
enigmagnetic Dec 20, 2017
0d9de1e
Add logic to switch between pages.
enigmagnetic Dec 20, 2017
a4a0fc3
Add customer model, collection, view, and list view. Instantiate cust…
enigmagnetic Dec 20, 2017
fdbe9fe
Adjust html to have $ in front of account credit, show registration y…
enigmagnetic Dec 20, 2017
c6a2e57
Add radio buttons to movie search form
vsawchuk Dec 20, 2017
6e88f15
Create a rental display list, use the rental list as the referencelis…
vsawchuk Dec 20, 2017
6bdb153
Choose between imdb and rental library for searching purposes
vsawchuk Dec 20, 2017
09344f1
Adjust styling for customers and movie lists.
enigmagnetic Dec 21, 2017
3af31ea
Set a min-width to the listing-info div for uniform appearance.
enigmagnetic Dec 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 103 additions & 13 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,105 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Backbone Baseline</title>
</head>
<body>
<main id="main-content">

</main>

<script src="/app.bundle.js"></script>

</body>
</html>
<head>
<meta charset="utf-8">
<title>Hometown Video</title>

<link href="https://fonts.googleapis.com/css?family=Bungee+Inline" rel="stylesheet">

</head>
<body>
<header>
<div id="logo" class="columns small-6">
<h1>Hometown</h1>
<p>Video Store</p>
</div>
<nav class="columns small-6">
<a href="#" id="movies-link">Movies</a> | <a href="#" id="customers-link">Customers</a> | <a href="#" id="rentals-link">Rentals</a>
</nav>
</header>

<main id="main-content">
<div id='movies-container'>
<div class="actions">
<button id='show-rental-library' class='button'>Rental Library</button>
<form id='search-movies'>
<input type="radio" id="library-radio" name="searchList" value="library" checked="checked"/>
<label for="library-radio">Rental Library</label>

<input type="radio" id="imdb-radio" name="searchList" value="imdb">
<label for="imdb-radio">IMDB</label>

<label>Search Titles</label>
<input type='text' id='searchTerm'/>
<input type='submit' class='button' id='search' value='Search'></input>
</form>
</div>
<section id='movies'>
</section>
</div>

<div id="customers-container" class="display-none">
<ul id="customers">
</ul>
</div>

<div id="rentals-container" class="display-none">
<p>No rentals yet</p>
</div>

</main>

<script type="text/template" id="library-movie-template">
<span>
<img src='<%- image_url %>' alt='<%- title %>'/>
</span>
<div class="listing-info">
<h3><%- title %></h3>
<p><%- release_date.slice(0, 4) %></p>
<button class='button show-details'>Show Details</button>
</div>
<div class="details slide">
<h5>Overview</h5>
<p><%- overview %></p>
</div>
</script>

<script type="text/template" id="imdb-movie-template">
<span>
<img src='<%- image_url %>' alt='<%- title %>'/>
</span>
<div class="listing-info">
<h3><%- title %></h3>
<p><%- release_date.slice(0, 4) %></p>
<button class='button show-details'>Show Details</button>
<button class='button show-form'>Add to Rental Library</button>
</div>
<div class="details slide">
<h5>Overview</h5>
<p><%- overview %></p>
</div>
<div class="add-rental-form slide">
<h5>Add Movie to Inventory</h5>
<form id="add-rental">
<label>Quantity</label>
<input type="text" name="inventory" value="qty"></input>
<input type="submit" class="button" value="Order Movie"></input>
</form>
</div>
</script>

<script type="text/template" id="customer-template">
<h4><%- name %></h4>
<p>Member Since: <%- registered_at.slice(0, 4) %></p>
<p>Account Credit: $<%- account_credit %></p>
<p>Number of Movies Checked Out: <%- movies_checked_out_count %></p>
<p>Phone: <%- phone %></p>
<p>Address:</p>
<p><%- address %> <br>
<%- city %>, <%- state %> <%- postal_code %></p>
</script>

<script src="/app.bundle.js"></script>

</body>
</html>
77 changes: 73 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,83 @@
// Import jQuery & Underscore
import $ from 'jquery';
import _ from 'underscore';
import Backbone from 'backbone';

// Import collections and views
import MovieList from 'collections/movie_list';
import MovieListView from 'views/movie_list_view';
import CustomerList from 'collections/customer_list';
import CustomerListView from 'views/customer_list_view';

import 'css/_settings.css';
import 'foundation-sites/dist/css/foundation.css';
import './css/styles.css';

// Import jQuery & Underscore
import $ from 'jquery';
import _ from 'underscore';

let eventBus = {};
eventBus = _.extend(eventBus, Backbone.Events);

// ready to go
$(document).ready(function() {

$('#main-content').append('<p>Hello World!</p>');
const rentalLibraryList = new MovieList();
rentalLibraryList.bus = eventBus;
rentalLibraryList.fetch();

const rentalDisplayList = new MovieList();
rentalDisplayList.bus = eventBus;

const rentalLibraryListView = new MovieListView({
model: rentalDisplayList,
template: _.template($('#library-movie-template').html()),
el: 'main',
bus: eventBus,
referenceList: rentalLibraryList,
});
rentalLibraryListView.listenTo(eventBus, 'showRentalLibrary', rentalLibraryListView.completeList);
rentalLibraryListView.listenTo(eventBus, 'addInventory', rentalLibraryListView.addRental);
rentalLibraryListView.listenTo(eventBus, 'searchlibrary', rentalLibraryListView.searchLibrary);

const searchList = new MovieList();
searchList.bus = eventBus;

const searchListView = new MovieListView({
model: searchList,
template: _.template($('#imdb-movie-template').html()),
el: 'main',
bus: eventBus,
});
searchListView.listenTo(eventBus, 'searchimdb', searchListView.searchIMDB)
searchListView.listenTo(searchListView.model, 'update', searchListView.render);

const customerList = new CustomerList();
customerList.bus = eventBus;

const customerListView = new CustomerListView({
model: customerList,
template: _.template($('#customer-template').html()),
el: 'main',
bus: eventBus,
});
customerList.fetch();

$('#show-rental-library').on('click', function(event) {
event.preventDefault();
eventBus.trigger('showRentalLibrary');
});

$('#search-movies').on('submit', function(event) {
event.preventDefault();
const location = $('#search-movies [name="searchList"]:checked').val();
const searchTerm = $('#searchTerm').val();
eventBus.trigger(`search${location}`, searchTerm);
});

$('nav a').click(function() {
let divId = $(this).attr('id');
let n = divId.indexOf('-');
divId = `${divId.substring(0, n)}-container`;

$(`#${divId}`).removeClass('display-none').siblings().addClass('display-none');
});
});
9 changes: 9 additions & 0 deletions src/collections/customer_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Backbone from 'backbone';
import Customer from 'models/customer';

const CustomerList = Backbone.Collection.extend({
model: Customer,
url: 'http://localhost:3000/customers/',
});

export default CustomerList;
13 changes: 13 additions & 0 deletions src/collections/movie_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Backbone from 'backbone';
import Movie from 'models/movie';

const MovieList = Backbone.Collection.extend({
model: Movie,
url: 'http://localhost:3000/movies/',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also make url a function like:

url() {
  return query ? `http://localhost:3000/movies/${query}`:  'http://localhost:3000/movies/';
}

baseUrl: 'http://localhost:3000/movies/search?query=',
resetUrl(query) {
this.url = this.baseUrl + query;
},
});

export default MovieList;
117 changes: 93 additions & 24 deletions src/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,44 +1,113 @@
@include foundation-everything;

main {
background: lightblue;
body {
background: #ececec;
}

header {
background-color: lightgreen;
padding: 0.5rem;
background: #2f2f2f;
color: #ffcf00;
padding: 1em;
}

#completed-checkbox {
display: inline;
header h1 {
margin-bottom: 0;
line-height: 1em;
font-family: 'Bungee Inline', cursive;
}

label {
display: inline;
header p {
margin-top: 0;
margin-left: 3px;
line-height: 1em;
}

button.success {
margin-right: 1.2rem;
display: inline;
nav {
text-align: right;
}

aside.create-tasklist {
background-color: navy;
color: #FFFFFF;
header a {
color: #ffcf00;
}
aside label {
color: #FFFFFF;

.display-none {
display: none;
}

.actions {
padding: 1em;
}

#show-rental-library {
display: inline-block;
margin: 1em;
}

#search-movies {
display: inline-block;
float: right;
margin: 1em;
width: 35%;
}

#movies {
clear: both;
margin: 0 auto;
}

.movie, .customer {
background: #2f2f2f;
border: solid 5px #ffcf00;
border-radius: 5px;
margin: 1em;
padding: 1em;
}

.movie {
min-height: 360px;
}

.completed {
text-decoration: line-through;
.customer {
color: #ffcf00;
}

div {
display: inline;
.movie img {
border: 4px solid white;
display: inline-block;
float: left;
margin: 1em;
}
/*
* {
border-style: solid;

.listing-info {
float: left;
margin: 1em 1em 1em .5em;
min-width: 35%;
}

.listing-info, .slide {
color: white;
display: inline-block;
}

.listing-info p, .customer p, #add-rental label {
color: #afafaf;
}

.listing-info button {
background: #ffcf00;
color: #2f2f2f;
margin: 4px;
}

.slide {
display: none;
padding: 1em;
}

.details {
overflow: scroll;
}

#add-rental input[name="inventory"] {
width: 3em;
}
*/
7 changes: 7 additions & 0 deletions src/models/customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Backbone from 'backbone';

const Customer = Backbone.Model.extend({

});

export default Customer;
13 changes: 13 additions & 0 deletions src/models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Backbone from 'backbone';

const Movie = Backbone.Model.extend({
initialize(params) {
this.title = params.title;
this.image_url = params.image_url;
this.release_date = params.release_date;
this.overview = params.overview;
this.bus = params.bus;
},
});

export default Movie;
Loading