Browse Source

Refactored ProjectModel

[#52044647]
pull/33/merge
Kurtis Seebaldt and Nick Street 13 years ago
parent
commit
ed58c82fd4
  1. 34
      _includes/widget_template.html
  2. 4
      _layouts/default.html
  3. 48
      js/projectDocumentationWidget.js
  4. 2
      js/test/spec/ProjectSpec.js

34
_includes/widget_template.html

@ -1,13 +1,25 @@ @@ -1,13 +1,25 @@
<script type="text/html" id="project-documentation-widget-template">
<%= name %>
<ul>
<% _.each(releases, function(release) { %>
<li>
<%= release.fullName %>
<i class="<%= release.statusIconClass %>"></i>
<a href='<%= release.refDocUrl %>'>Reference</a>
<a href='<%= release.apiDocUrl %>'>API</a>
</li>
<% }); %>
</ul>
<h3><%= name %></h3>
<table>
<thead>
<tr>
<th>Release</th>
<th>Documentation</th>
</tr>
</thead>
<tbody>
<% _.each(releases, function(release) { %>
<tr>
<td>
<%= release.fullName %>
<i class="<%= release.statusIconClass() %>"></i>
</td>
<td>
<a href='<%= release.refDocUrl %>'>Reference</a>
<a href='<%= release.apiDocUrl %>'>API</a>
</td>
</tr>
<% }); %>
</tbody>
</table>
</script>

4
_layouts/default.html

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
---
main_site_url: http://springframework.io
forum_url: http://forum.springframework.io
api_base_url: http://localhost:8080
---
<!DOCTYPE html>
@ -24,6 +25,9 @@ forum_url: http://forum.springframework.io @@ -24,6 +25,9 @@ forum_url: http://forum.springframework.io
<script type="text/javascript" src="js/backbone.js"></script>
<script type="text/javascript" src="js/projectDocumentationWidget.js"></script>
<script type="text/javascript" src="js/application.js"></script>
<script type="text/javascript">
var apiBaseUrl = "{{ page.api_base_url }}";
</script>
<meta name="google-site-verification" content="7qGntFPD9lWAVCtUu5U77v4l68PsTHf6xpzgjQv2j2M" />
</head>
<body>

48
js/projectDocumentationWidget.js

@ -2,10 +2,10 @@ window.Spring = window.Spring || {}; @@ -2,10 +2,10 @@ window.Spring = window.Spring || {};
Spring.ProjectDocumentationWidget = function() {
var projectId = $('[data-documentation-widget]').data('documentation-widget');
var project = new Spring.Project({id: projectId});
var projectUrl = apiBaseUrl + "/projects/" + projectId;
var promise = Spring.loadProject(projectUrl);
var promise = project.fetch();
promise.success(function() {
promise.then(function(project) {
new Spring.ProjectDocumentationWidgetView({
el: '[data-documentation-widget]',
model: project,
@ -14,6 +14,15 @@ Spring.ProjectDocumentationWidget = function() { @@ -14,6 +14,15 @@ Spring.ProjectDocumentationWidget = function() {
});
};
Spring.loadProject = function(url) {
return $.ajax(url, {
dataType: 'jsonp',
processData: false
}).then(function(value) {
return new Spring.Project(value);
});
}
Spring.Release = {
statusIconClass: function() {
if (this.preRelease) {
@ -26,31 +35,14 @@ Spring.Release = { @@ -26,31 +35,14 @@ Spring.Release = {
}
}
Spring.Project = Backbone.Model.extend({
urlRoot: "http://localhost:8080/projects",
sync: function(method, model, options) {
var params = _.extend({
type: 'GET',
dataType: 'jsonp',
url: model.url()+"?callback=?",
processData: false
}, options);
return $.ajax(params);
},
releases: function() {
return _.map(this.get('projectReleases'), function(r) {
return _.extend(r, Spring.Release);
});
},
Spring.Project = function(data) {
_.extend(this, data);
this.releases = _.map(this.projectReleases, function(r) {
return _.extend(r, Spring.Release);
});
data: function() {
return _.extend(this.attributes, {releases: this.releases()})
}
});
return this;
};
Spring.ProjectDocumentationWidgetView = Backbone.View.extend({
initialize: function() {
@ -60,7 +52,7 @@ Spring.ProjectDocumentationWidgetView = Backbone.View.extend({ @@ -60,7 +52,7 @@ Spring.ProjectDocumentationWidgetView = Backbone.View.extend({
render: function() {
this.$el.html(
this.template(this.model.data())
this.template(this.model)
);
return this;
}

2
js/test/spec/ProjectSpec.js

@ -17,7 +17,7 @@ describe("Project", function () { @@ -17,7 +17,7 @@ describe("Project", function () {
describe("releases", function() {
var releases;
beforeEach(function() {
releases = project.releases();
releases = project.releases;
});
it("has a release for each project release", function() {

Loading…
Cancel
Save