Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jessica and Gale - Carets #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Rename files
galestorm committed Dec 19, 2017
commit 55d7d85d6e89a347c6ca0a867507c93b9bedb67e
8 changes: 4 additions & 4 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -11,15 +11,15 @@ <h3>SEARCH FORM COMING SOON!</h3>
</section>
<section id="results-container">
<h3>DATABASE RESULTS</h3>
<ul id="results"><!-- result-template renders here--></ul>
</section>
<section id="movie-list">
<h3>RENTAL LIBRARY COMING SOON!</h3>
<section id="library">
<h3>RENTAL LIBRARY</h3>
<ul id="movie-list"><!-- result-template renders here--></ul>
</section>
</main>

<!-- UNDERSCORE TEMPLATES -->
<script type="text/template" id="result-template">
<script type="text/template" id="library-template">
<img src="<%- image_url %>" /><%- title %>
</script>

29 changes: 15 additions & 14 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import 'css/_settings.css';
import 'foundation-sites/dist/css/foundation.css';
import './css/styles.css';

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

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

// Models & Collections
import ResultList from './collections/result_list';
import ResultListView from './views/result_list_view';
import Library from './collections/library';
import LibraryView from './views/library_view';


const resultList = new ResultList();
const library = new Library();

// ready to go
$(document).ready(function() {
resultList.fetch();
library.fetch();

const resultListView = new ResultListView({
model: resultList,
template: _.template($('#result-template').html()),
el: '#results-container',
const libraryView = new LibraryView({
model: library,
template: _.template($('#library-template').html()),
el: '#library',
});
resultListView.render();

libraryView.render();

});
4 changes: 2 additions & 2 deletions src/collections/result_list.js → src/collections/library.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Backbone from 'backbone';
import Movie from '../models/movie';

const ResultList = Backbone.Collection.extend({
const Library= Backbone.Collection.extend({
model: Movie,
url: 'http://localhost:3000/movies',
});

export default ResultList;
export default Library;
26 changes: 26 additions & 0 deletions src/views/library_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Backbone from 'backbone';

import MovieView from './movie_view';

const LibraryView = Backbone.View.extend({
initialize(params) {
this.template = params.template;
this.model = params.model;
this.listenTo(this.model, 'update', this.render);
},
render() {
this.$('#movie-list').empty();
this.model.each((movie) => {
const movieView = new MovieView({
model: movie,
template: this.template,
tagName: 'li',
className: 'movie',
});
this.$('#movie-list').append(movieView.render().$el);
});
return this;
}
});

export default LibraryView;
4 changes: 2 additions & 2 deletions src/views/result_view.js → src/views/movie_view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Backbone from 'backbone';

const ResultView = Backbone.View.extend({
const MovieView = Backbone.View.extend({
initialize(params) {
this.template = params.template;
this.model = params.model;
@@ -12,4 +12,4 @@ const ResultView = Backbone.View.extend({
},
});

export default ResultView;
export default MovieView;
26 changes: 0 additions & 26 deletions src/views/result_list_view.js

This file was deleted.