Created
January 24, 2016 09:56
-
-
Save anonymous/00c7cde7c4817f67b566 to your computer and use it in GitHub Desktop.
Ember Starter Kit // source http://jsbin.com/pubazuyoyi
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
| <meta charset="utf-8"> | |
| <title>Ember Starter Kit</title> | |
| <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"> | |
| <script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.5.1/ember.js"></script> | |
| <style id="jsbin-css"> | |
| .base-div-stlyle { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| body { | |
| background: #fcfcfc; | |
| color: #333333; | |
| } | |
| .sortandfilter-page-wrapper { | |
| margin-top: 25px; | |
| } | |
| .person-form { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| text-align: center; | |
| } | |
| .person-form input { | |
| margin-bottom: 5px; | |
| } | |
| .person-form button { | |
| width: 300px; | |
| font-weight: bold; | |
| background: #464848; | |
| color: #ffffff; | |
| } | |
| .person-form button:hover { | |
| background: #535555; | |
| color: #ffffff; | |
| } | |
| .results-table { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| .results-table table th span { | |
| color: #e3e3e3; | |
| } | |
| .results-table .sorted { | |
| color: #000000; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script type="text/x-handlebars" data-template-name="application"> | |
| {{outlet}} | |
| </script> | |
| <script type="text/x-handlebars" data-template-name="index"> | |
| <div class="col-md-4"> | |
| <form class="person-form"> | |
| <h3>Add a Person</h3> | |
| {{input class="id form-control" type="text" placeholder="ID" value=id}} | |
| {{input class="firstName form-control" type="text" placeholder="First Name" value=firstName}} | |
| {{input class="lastName form-control" type="text" placeholder="Last Name" value=lastName}} | |
| {{input class="knownFor form-control" type="text" placeholder="Known For" value=knownFor}} | |
| <button class="submit btn btn-default" {{action "addPerson"}}>Add</button> | |
| </form> | |
| </div> | |
| <div class="col-md-8"> | |
| <div class="results-table"> | |
| {{input class="form-control filter-input" value=theFilter type='text' placeholder='Filter'}} | |
| <table class="table table-striped"> | |
| <thead> | |
| <tr> | |
| <th class="id-col-head" {{action "sortBy" "id"}}>ID <span {{bind-attr class="sortedOnID:sorted glyphiconDirection :glyphicon"}}></th> | |
| <th class="first-col-head" {{action "sortBy" "firstName"}}>First Name <span {{bind-attr class="sortedOnFirstName:sorted glyphiconDirection :glyphicon"}}</th> | |
| <th class="last-col-head" {{action "sortBy" "lastName"}}>Last Name <span {{bind-attr class="sortedOnLastName:sorted glyphiconDirection :glyphicon"}}</th> | |
| <th class="know-col-head" {{action "sortBy" "knownFor"}}>Known For <span {{bind-attr class="sortedOnKnownFor:sorted glyphiconDirection :glyphicon"}}</th> | |
| <tr> | |
| </thead> | |
| <tbody> | |
| {{#each person in filterPeople}} | |
| <tr> | |
| <td>{{person.id}}</td> | |
| <td>{{person.firstName}}</td> | |
| <td>{{person.lastName}}</td> | |
| <td>{{person.knownFor}}</td> | |
| </tr> | |
| {{/each}} | |
| </tbody> | |
| </table> | |
| </div><!-- End results-table --> | |
| </div><!-- End col-md-8 --> | |
| </script> | |
| <script id="jsbin-javascript"> | |
| var App; | |
| App = Ember.Application.create(); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function() { | |
| return [ | |
| { | |
| id: 1, | |
| firstName: 'Bram', | |
| lastName: 'Moolenaar', | |
| knownFor: "Vim" | |
| }, { | |
| id: 2, | |
| firstName: 'Richard', | |
| lastName: 'Stallman', | |
| knownFor: "GNU" | |
| }, { | |
| id: 3, | |
| firstName: 'Dennis', | |
| lastName: 'Ritchie', | |
| knownFor: "C" | |
| }, { | |
| id: 4, | |
| firstName: 'Rich', | |
| lastName: 'Hickey', | |
| knownFor: "Clojure" | |
| }, { | |
| id: 5, | |
| firstName: 'Guido', | |
| lastName: 'Van Rossum', | |
| knownFor: "Python" | |
| }, { | |
| id: 6, | |
| firstName: 'Linus', | |
| lastName: 'Torvalds', | |
| knownFor: "Linux" | |
| }, { | |
| id: 7, | |
| firstName: 'Yehuda', | |
| lastName: 'Katz', | |
| knownFor: "Ember" | |
| } | |
| ]; | |
| } | |
| }); | |
| App.IndexController = Ember.ArrayController.extend({ | |
| sortProperties: ['id'], | |
| sortAscending: true, | |
| theFilter: "", | |
| filterPeople: (function() { | |
| return this.get("arrangedContent").filter((function(_this) { | |
| return function(theObject, index, enumerable) { | |
| if (_this.get("theFilter")) { | |
| return _this.checkFilterMatch(theObject, _this.get("theFilter")); | |
| } else { | |
| return true; | |
| } | |
| }; | |
| })(this)); | |
| }).property("theFilter", "sortProperties", "sortAscending", "content.@each"), | |
| sortedOnID: (function() { | |
| return this.get("sortProperties").get("0") === "id"; | |
| }).property("sortProperties"), | |
| sortedOnFirstName: (function() { | |
| return this.get("sortProperties").get("0") === "firstName"; | |
| }).property("sortProperties"), | |
| sortedOnLastName: (function() { | |
| return this.get("sortProperties").get("0") === "lastName"; | |
| }).property("sortProperties"), | |
| sortedOnKnownFor: (function() { | |
| return this.get("sortProperties").get("0") === "knownFor"; | |
| }).property("sortProperties"), | |
| glyphiconDirection: (function() { | |
| if (this.get("sortAscending")) { | |
| return "glyphicon-chevron-down"; | |
| } else { | |
| return "glyphicon-chevron-up"; | |
| } | |
| }).property("sortAscending"), | |
| checkFilterMatch: function(theObject, str) { | |
| var field, match; | |
| match = false; | |
| for (field in theObject) { | |
| if (theObject[field].toString().slice(0, str.length) === str) { | |
| match = true; | |
| } | |
| } | |
| return match; | |
| }, | |
| clearForm: function() { | |
| this.set("id", ""); | |
| this.set("lastName", ""); | |
| this.set("firstName", ""); | |
| return this.set("knownFor", ""); | |
| }, | |
| actions: { | |
| sortBy: function(property) { | |
| if (this.get("sortProperties")[0] === property) { | |
| this.toggleProperty("sortAscending"); | |
| } else { | |
| this.set("sortAscending", true); | |
| this.set("sortProperties", [property]); | |
| } | |
| }, | |
| addPerson: function() { | |
| var person; | |
| person = { | |
| id: this.get('id'), | |
| firstName: this.get('firstName'), | |
| lastName: this.get('lastName'), | |
| knownFor: this.get('knownFor') | |
| }; | |
| this.content.pushObject(person); | |
| return this.clearForm(); | |
| } | |
| } | |
| }); | |
| </script> | |
| <script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery.min.js"><\/script> | |
| <link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
| <meta charset="utf-8"> | |
| <title>Ember Starter Kit</title> | |
| <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"> | |
| <script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"><\/script> | |
| <script src="http://builds.emberjs.com/tags/v1.5.1/ember.js"><\/script> | |
| </head> | |
| <body> | |
| <script type="text/x-handlebars" data-template-name="application"> | |
| {{outlet}} | |
| <\/script> | |
| <script type="text/x-handlebars" data-template-name="index"> | |
| <div class="col-md-4"> | |
| <form class="person-form"> | |
| <h3>Add a Person</h3> | |
| {{input class="id form-control" type="text" placeholder="ID" value=id}} | |
| {{input class="firstName form-control" type="text" placeholder="First Name" value=firstName}} | |
| {{input class="lastName form-control" type="text" placeholder="Last Name" value=lastName}} | |
| {{input class="knownFor form-control" type="text" placeholder="Known For" value=knownFor}} | |
| <button class="submit btn btn-default" {{action "addPerson"}}>Add</button> | |
| </form> | |
| </div> | |
| <div class="col-md-8"> | |
| <div class="results-table"> | |
| {{input class="form-control filter-input" value=theFilter type='text' placeholder='Filter'}} | |
| <table class="table table-striped"> | |
| <thead> | |
| <tr> | |
| <th class="id-col-head" {{action "sortBy" "id"}}>ID <span {{bind-attr class="sortedOnID:sorted glyphiconDirection :glyphicon"}}></th> | |
| <th class="first-col-head" {{action "sortBy" "firstName"}}>First Name <span {{bind-attr class="sortedOnFirstName:sorted glyphiconDirection :glyphicon"}}</th> | |
| <th class="last-col-head" {{action "sortBy" "lastName"}}>Last Name <span {{bind-attr class="sortedOnLastName:sorted glyphiconDirection :glyphicon"}}</th> | |
| <th class="know-col-head" {{action "sortBy" "knownFor"}}>Known For <span {{bind-attr class="sortedOnKnownFor:sorted glyphiconDirection :glyphicon"}}</th> | |
| <tr> | |
| </thead> | |
| <tbody> | |
| {{#each person in filterPeople}} | |
| <tr> | |
| <td>{{person.id}}</td> | |
| <td>{{person.firstName}}</td> | |
| <td>{{person.lastName}}</td> | |
| <td>{{person.knownFor}}</td> | |
| </tr> | |
| {{/each}} | |
| </tbody> | |
| </table> | |
| </div><\!-- End results-table --> | |
| </div><\!-- End col-md-8 --> | |
| <\/script> | |
| </body> | |
| </html> | |
| </script> | |
| <script id="jsbin-source-css" type="text/css">.base-div-stlyle { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| body { | |
| background: #fcfcfc; | |
| color: #333333; | |
| } | |
| .sortandfilter-page-wrapper { | |
| margin-top: 25px; | |
| } | |
| .person-form { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| text-align: center; | |
| } | |
| .person-form input { | |
| margin-bottom: 5px; | |
| } | |
| .person-form button { | |
| width: 300px; | |
| font-weight: bold; | |
| background: #464848; | |
| color: #ffffff; | |
| } | |
| .person-form button:hover { | |
| background: #535555; | |
| color: #ffffff; | |
| } | |
| .results-table { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| .results-table table th span { | |
| color: #e3e3e3; | |
| } | |
| .results-table .sorted { | |
| color: #000000; | |
| } | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var App; | |
| App = Ember.Application.create(); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function() { | |
| return [ | |
| { | |
| id: 1, | |
| firstName: 'Bram', | |
| lastName: 'Moolenaar', | |
| knownFor: "Vim" | |
| }, { | |
| id: 2, | |
| firstName: 'Richard', | |
| lastName: 'Stallman', | |
| knownFor: "GNU" | |
| }, { | |
| id: 3, | |
| firstName: 'Dennis', | |
| lastName: 'Ritchie', | |
| knownFor: "C" | |
| }, { | |
| id: 4, | |
| firstName: 'Rich', | |
| lastName: 'Hickey', | |
| knownFor: "Clojure" | |
| }, { | |
| id: 5, | |
| firstName: 'Guido', | |
| lastName: 'Van Rossum', | |
| knownFor: "Python" | |
| }, { | |
| id: 6, | |
| firstName: 'Linus', | |
| lastName: 'Torvalds', | |
| knownFor: "Linux" | |
| }, { | |
| id: 7, | |
| firstName: 'Yehuda', | |
| lastName: 'Katz', | |
| knownFor: "Ember" | |
| } | |
| ]; | |
| } | |
| }); | |
| App.IndexController = Ember.ArrayController.extend({ | |
| sortProperties: ['id'], | |
| sortAscending: true, | |
| theFilter: "", | |
| filterPeople: (function() { | |
| return this.get("arrangedContent").filter((function(_this) { | |
| return function(theObject, index, enumerable) { | |
| if (_this.get("theFilter")) { | |
| return _this.checkFilterMatch(theObject, _this.get("theFilter")); | |
| } else { | |
| return true; | |
| } | |
| }; | |
| })(this)); | |
| }).property("theFilter", "sortProperties", "sortAscending", "content.@each"), | |
| sortedOnID: (function() { | |
| return this.get("sortProperties").get("0") === "id"; | |
| }).property("sortProperties"), | |
| sortedOnFirstName: (function() { | |
| return this.get("sortProperties").get("0") === "firstName"; | |
| }).property("sortProperties"), | |
| sortedOnLastName: (function() { | |
| return this.get("sortProperties").get("0") === "lastName"; | |
| }).property("sortProperties"), | |
| sortedOnKnownFor: (function() { | |
| return this.get("sortProperties").get("0") === "knownFor"; | |
| }).property("sortProperties"), | |
| glyphiconDirection: (function() { | |
| if (this.get("sortAscending")) { | |
| return "glyphicon-chevron-down"; | |
| } else { | |
| return "glyphicon-chevron-up"; | |
| } | |
| }).property("sortAscending"), | |
| checkFilterMatch: function(theObject, str) { | |
| var field, match; | |
| match = false; | |
| for (field in theObject) { | |
| if (theObject[field].toString().slice(0, str.length) === str) { | |
| match = true; | |
| } | |
| } | |
| return match; | |
| }, | |
| clearForm: function() { | |
| this.set("id", ""); | |
| this.set("lastName", ""); | |
| this.set("firstName", ""); | |
| return this.set("knownFor", ""); | |
| }, | |
| actions: { | |
| sortBy: function(property) { | |
| if (this.get("sortProperties")[0] === property) { | |
| this.toggleProperty("sortAscending"); | |
| } else { | |
| this.set("sortAscending", true); | |
| this.set("sortProperties", [property]); | |
| } | |
| }, | |
| addPerson: function() { | |
| var person; | |
| person = { | |
| id: this.get('id'), | |
| firstName: this.get('firstName'), | |
| lastName: this.get('lastName'), | |
| knownFor: this.get('knownFor') | |
| }; | |
| this.content.pushObject(person); | |
| return this.clearForm(); | |
| } | |
| } | |
| }); | |
| </script></body> | |
| </html> |
This file contains hidden or 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
| .base-div-stlyle { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| body { | |
| background: #fcfcfc; | |
| color: #333333; | |
| } | |
| .sortandfilter-page-wrapper { | |
| margin-top: 25px; | |
| } | |
| .person-form { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| text-align: center; | |
| } | |
| .person-form input { | |
| margin-bottom: 5px; | |
| } | |
| .person-form button { | |
| width: 300px; | |
| font-weight: bold; | |
| background: #464848; | |
| color: #ffffff; | |
| } | |
| .person-form button:hover { | |
| background: #535555; | |
| color: #ffffff; | |
| } | |
| .results-table { | |
| background: #f4f4f4; | |
| border: 1px solid #cecece; | |
| border-radius: 3px; | |
| padding: 5px; | |
| } | |
| .results-table table th span { | |
| color: #e3e3e3; | |
| } | |
| .results-table .sorted { | |
| color: #000000; | |
| } |
This file contains hidden or 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
| var App; | |
| App = Ember.Application.create(); | |
| App.IndexRoute = Ember.Route.extend({ | |
| model: function() { | |
| return [ | |
| { | |
| id: 1, | |
| firstName: 'Bram', | |
| lastName: 'Moolenaar', | |
| knownFor: "Vim" | |
| }, { | |
| id: 2, | |
| firstName: 'Richard', | |
| lastName: 'Stallman', | |
| knownFor: "GNU" | |
| }, { | |
| id: 3, | |
| firstName: 'Dennis', | |
| lastName: 'Ritchie', | |
| knownFor: "C" | |
| }, { | |
| id: 4, | |
| firstName: 'Rich', | |
| lastName: 'Hickey', | |
| knownFor: "Clojure" | |
| }, { | |
| id: 5, | |
| firstName: 'Guido', | |
| lastName: 'Van Rossum', | |
| knownFor: "Python" | |
| }, { | |
| id: 6, | |
| firstName: 'Linus', | |
| lastName: 'Torvalds', | |
| knownFor: "Linux" | |
| }, { | |
| id: 7, | |
| firstName: 'Yehuda', | |
| lastName: 'Katz', | |
| knownFor: "Ember" | |
| } | |
| ]; | |
| } | |
| }); | |
| App.IndexController = Ember.ArrayController.extend({ | |
| sortProperties: ['id'], | |
| sortAscending: true, | |
| theFilter: "", | |
| filterPeople: (function() { | |
| return this.get("arrangedContent").filter((function(_this) { | |
| return function(theObject, index, enumerable) { | |
| if (_this.get("theFilter")) { | |
| return _this.checkFilterMatch(theObject, _this.get("theFilter")); | |
| } else { | |
| return true; | |
| } | |
| }; | |
| })(this)); | |
| }).property("theFilter", "sortProperties", "sortAscending", "content.@each"), | |
| sortedOnID: (function() { | |
| return this.get("sortProperties").get("0") === "id"; | |
| }).property("sortProperties"), | |
| sortedOnFirstName: (function() { | |
| return this.get("sortProperties").get("0") === "firstName"; | |
| }).property("sortProperties"), | |
| sortedOnLastName: (function() { | |
| return this.get("sortProperties").get("0") === "lastName"; | |
| }).property("sortProperties"), | |
| sortedOnKnownFor: (function() { | |
| return this.get("sortProperties").get("0") === "knownFor"; | |
| }).property("sortProperties"), | |
| glyphiconDirection: (function() { | |
| if (this.get("sortAscending")) { | |
| return "glyphicon-chevron-down"; | |
| } else { | |
| return "glyphicon-chevron-up"; | |
| } | |
| }).property("sortAscending"), | |
| checkFilterMatch: function(theObject, str) { | |
| var field, match; | |
| match = false; | |
| for (field in theObject) { | |
| if (theObject[field].toString().slice(0, str.length) === str) { | |
| match = true; | |
| } | |
| } | |
| return match; | |
| }, | |
| clearForm: function() { | |
| this.set("id", ""); | |
| this.set("lastName", ""); | |
| this.set("firstName", ""); | |
| return this.set("knownFor", ""); | |
| }, | |
| actions: { | |
| sortBy: function(property) { | |
| if (this.get("sortProperties")[0] === property) { | |
| this.toggleProperty("sortAscending"); | |
| } else { | |
| this.set("sortAscending", true); | |
| this.set("sortProperties", [property]); | |
| } | |
| }, | |
| addPerson: function() { | |
| var person; | |
| person = { | |
| id: this.get('id'), | |
| firstName: this.get('firstName'), | |
| lastName: this.get('lastName'), | |
| knownFor: this.get('knownFor') | |
| }; | |
| this.content.pushObject(person); | |
| return this.clearForm(); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment