-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-3.html
More file actions
146 lines (130 loc) · 4.98 KB
/
index-3.html
File metadata and controls
146 lines (130 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<title>Sort lists with Ember.ArrayController: Part 2</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Styles -->
<link href="stylesheets/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="stylesheets/bootstrap-responsive.min.css" rel="stylesheet">
<link href="stylesheets/main.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Ember.ArrayController</a>
</div>
</div>
</div>
<script type="text/x-handlebars">
<h1>Sort lists with Ember.ArrayController</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<p>
<label>Sort by: {{view Ember.Select contentBinding="sortOptions"
optionValuePath="content.value" optionLabelPath="content.label"
selectionBinding="currentSortOption"}}</label>
</p>
<ul>
{{#each controller}}
<li>
<h3>{{title}}</h3>
<time {{bindAttr datetime="published"}}>{{published}}</time>
{{{content}}}
</li>
{{/each}}
</ul>
</script>
<!-- Javascript (Placed at the end of the document so the pages load faster)
================================================== -->
<<<<<<< HEAD
<script src="assets/js/vendor/jquery-1.9.1.js"></script>
<script src="assets/js/vendor/handlebars-1.0.0-rc.4.js"></script>
<script src="assets/js/vendor/ember-1.0.0-rc.5.js"></script>
<script src="assets/js/application.js"></script>
=======
<script src="javascripts/vendor/jquery-1.9.1.js"></script>
<script src="javascripts/vendor/handlebars-1.0.0-rc.4.js"></script>
<script src="javascripts/vendor/ember-1.0.0-rc.5.js"></script>
<script src="javascripts/application.js"></script>
>>>>>>> gh-pages
<script>
/* Controllers */
App.IndexController = Ember.ArrayController.extend({
contentBinding: Ember.Binding.oneWay('App.Post.FIXTURES'),
/**
@property sortProperties
Property in Ember.SortableMixin, Specifies which properties dictate the arrangedContent's sort order.
*/
sortProperties: ['published', 'title'],
/**
@property sortAscending
Property in Ember.SortableMixin, Specifies the arrangedContent's sort direction
*/
sortAscending: false,
/**
@property sortOptions
The list of options to display inside an Ember.Select view
*/
sortOptions: [
Ember.Object.create({ label: "published (ascending)", sortAscending: true, value: "published-asc", property: "published" }),
Ember.Object.create({ label: "published (descending)", sortAscending: false, value: "published-desc", property: "published" }),
Ember.Object.create({ label: "title (ascending)", sortAscending: true, value: "title-asc", property: "title" }),
Ember.Object.create({ label: "title (descending)", sortAscending: false, value: "title-desc", property: "title" })
],
/**
@property currentSortOption
The currently selected sort option
*/
currentSortOption: null,
init: function() {
if (!this.get('currentSortOption')) {
// Set the default sort option to "published (descending)"
this.set('currentSortOption', this.get('sortOptions')[1]);
}
return this._super();
},
/**
@method
Fires whenever currentSortOption changes. Updates sortAscending and sortProperties
to trigger reordering
*/
currentSortOptionChanged: function() {
var sortOption = this.get('currentSortOption');
// Update the sortAscending property
this.set('sortAscending', sortOption.get('sortAscending'));
// Update the sortProperties array
var propertyName = sortOption.get('property'),
// Clone the sortProperties array
sortProperties = this.get('sortProperties').slice();
// Only need to update sortProperties if it's changed
if (sortProperties[0] !== propertyName) {
// Remove this property from the array
sortProperties.splice(sortProperties.indexOf(propertyName), 1);
// ... and add it back in at the beginning
sortProperties.unshift(propertyName);
// Update sortProperties
this.set('sortProperties', sortProperties);
}
}.observes('currentSortOption')
});
/* Views */
App.ApplicationView = Ember.View.extend({
tagName: 'section',
classNames: ['container']
});
App.IndexView = Ember.View.extend({
classNames: ['row-fluid']
});
</script>
</body>
</html>