Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
117 lines (95 sloc) 3.06 KB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>bla</h1>
</div>
<div class="row main-app">
</div>
</div>
<script type="text/template" id="filtro-template">
<div class="input-group input-group-lg">
<span class="input-group-addon" id="sizing-addon1">@</span>
<input id="input-busca" type="text" class="form-control" placeholder="Nome da organização" aria-describedby="sizing-addon1">
</div>
<div id="results">
</div>
</script>
<script type="text/template" id="projects-template">
<div class="page-header">
<h1>Repositórios</h1>
</div>
<div class="row">
<% _.each(repos, function(val){ %>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading"><%=val.full_name%></div>
<div class="panel-body">
<p>
<span class="label label-primary">Forks: <%= val.forks %></span>
<span class="label label-info">Watchers: <%= val.watchers %></span>
<span class="label label-danger">Open Issues: <%= val.open_issues %></span>
</p>
</div>
</div>
</div>
<% }); %>
</div>
</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script type="text/javascript">
(function () {
// VIEW DO FORMULARIO DE BUSCA
FormBuscaView = Backbone.View.extend({
el: ".main-app",
events: {
'change #input-busca': 'updateRepositoryList'
},
updateRepositoryList: function(e) {
var repositories = new RepositoryCollection( { repositoryName: $(e.target).val() } )
new ProjectListView({ collection: repositories });
repositories.fetch();
},
render: function() {
this.$el.html($("#filtro-template").html());
}
});
// VIEW RESULTADOS
ProjectListView = Backbone.View.extend({
el: '#results',
initialize: function(){
_.bindAll(this, 'render');
this.collection.bind('reset', this.render);
},
render: function() {
var template = _.template($("#projects-template").html());
this.$el.html(template({ repos: this.collection.toJSON() }));
}
});
// MODEL REPOSITORY
Repository = Backbone.Model.extend({});
// REPOSITORY COLLECTION
RepositoryCollection = Backbone.Collection.extend({
model: Repository,
repositoryName: "",
initialize: function(options) {
options || (options = {});
this.repositoryName = options.repositoryName;
},
url: function() {
return 'http://api.github.com/orgs/' + this.repositoryName + '/repos'
}
});
new FormBuscaView().render();
})();
</script>
</body>
</html>