Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Commit 65b01a5

Browse files
committed
Can add more destinations now.
1 parent 540a91d commit 65b01a5

File tree

6 files changed

+39
-33
lines changed

6 files changed

+39
-33
lines changed

app/assets/javascripts/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ require.config({
2424
require(['views/map', 'views/navbar', 'views/lhp'], function(Map, Navbar, Lhp){
2525
"use strict";
2626

27-
var map = new Map(),
28-
navbar = new Navbar(),
29-
lhp = new Lhp();
27+
var map = new Map({el: $("#map").get(0)}),
28+
navbar = new Navbar({el: $("#navbar").get(0)}),
29+
lhp = new Lhp({el: $('#lhp').get(0)});
3030

3131
map.render();
3232
navbar.render();

app/assets/javascripts/views/lhp.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,37 @@ function(_, $, Backbone, TextInput){
88
"use strict";
99

1010
var LHP = Backbone.View.extend({
11-
el: $('#lhp')[0],
12-
events: {},
11+
events: {
12+
'click div.add-destination': 'add_destination'
13+
},
14+
inputs: [],
1315
initialize: function(){
1416
var _this = this;
1517

16-
_this.inputs = []; //input array
17-
/* There is at leats one text input, lets create views for all of them */
18-
_this.$('input').each(function(index, el){
19-
var inpt = new TextInput(el);
20-
//_this.inputs.push(inpt);
21-
});
2218

2319
},
2420
render: function(){
25-
var _this = this;
21+
var
22+
_this = this,
23+
input = new TextInput();
24+
25+
_this.inputs.push(input); //TODO: Make it searchable & idexable, useless for now
26+
27+
_this.$el.find('form').prepend(input.render().el);
28+
29+
_this.$el.find('input').first().focus();
2630
_this.$el.fadeIn();
27-
_this.$el.find('input').first().focus()
31+
},
32+
add_destination: function(){
33+
var
34+
_this = this,
35+
input = new TextInput();
36+
37+
_this.inputs.push(input);
38+
39+
_this.$el.find('form > input').last().after(input.render().el);
40+
41+
2842
}
2943
});
3044

app/assets/javascripts/views/map.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function(_, $, Backbone, L){
88
"use strict";
99

1010
var Map = Backbone.View.extend({
11-
el: $("#map"),
1211
events: {
1312

1413
},

app/assets/javascripts/views/navbar.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function($, _, Backbone){
88
"use strict";
99

1010
var Navbar = Backbone.View.extend({
11-
el: $("#navbar")[0],
1211
events: {},
1312
initialize: function(){
1413

app/assets/javascripts/views/text_input.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@ define([
66
function(_, $, Backbone){
77
"use strict";
88

9-
var _input_template = '<input name="location" type="text" class="search-from" placeholder="Type in Location"/>';
9+
var
1010

11-
var TextInput = Backbone.View.extend({
12-
tagName: 'input',
13-
el: $('input').get(0),
14-
events: {
15-
16-
},
17-
template: _.template(_input_template),
18-
initialize: function(el){
19-
var _this = this;
20-
21-
if(!el){
22-
throw new Error("el is not defined")
23-
}
11+
//<input name="location" type="text" class="search-from" placeholder="Type in Location"/>
2412

25-
//_this.setElement(el)
26-
27-
},
13+
TextInput = Backbone.View.extend({
14+
tagName: 'input',
2815
render: function(){
16+
var $el = this.$el;
17+
18+
$el.addClass('search-from');
19+
$el.attr('name', 'location');
20+
$el.attr('type', 'text');
21+
$el.attr('placeholder', 'Type in Location');
2922

23+
return this;
3024
}
3125
});
3226

app/views/main/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div id="lhp-content">
22

33
<form class="pull-left">
4-
<input name="location" type="text" class="search-from" placeholder="Type in Location"/>
4+
55
<div class="add-destination">
66
<i class="icon-plus icon-white" style="cursor:pointer;"></i>
77
&nbsp;Add destination

0 commit comments

Comments
 (0)