pages wip

This commit is contained in:
danielgrippi 2012-02-18 22:55:06 -08:00
parent 7acbfe1b78
commit c0eeb7680b
12 changed files with 113 additions and 96 deletions

View file

@ -19,29 +19,7 @@
%i.icon-time %i.icon-time
= time_ago_in_words(@post.created_at) + ' ago' = time_ago_in_words(@post.created_at) + ' ago'
#container
#post-content
- if current_user
#user-controls
= link_to "#", :class => "label", do
%i.icon-user.icon-white
= link_to "#", :class => "label" do
%i.icon-heart.icon-white
= link_to "#", :class => "label" do
%i.icon-plus.icon-white
= link_to "#", :class => "label" do
%i.icon-retweet.icon-white
= link_to "#", :class => "label", do
%i.icon-comment.icon-white
= link_to image_tag('arrow-left.png'), '#', :class => 'nav-arrow left', :id => 'forward'
= link_to image_tag('arrow-right.png'), '#', :class => 'nav-arrow right', :id => 'back'
#comment.modal.fade #comment.modal.fade
.modal-header .modal-header

View file

@ -24,6 +24,7 @@ javascripts:
- public/javascripts/app/views.js - public/javascripts/app/views.js
- public/javascripts/app/models/post.js - public/javascripts/app/models/post.js
- public/javascripts/app/models/* - public/javascripts/app/models/*
- public/javascripts/app/pages/*
- public/javascripts/app/collections/* - public/javascripts/app/collections/*
- public/javascripts/app/views/stream_object_view.js - public/javascripts/app/views/stream_object_view.js
- public/javascripts/app/views/content_view.js - public/javascripts/app/views/content_view.js

BIN
public/images/arrow.psd Normal file

Binary file not shown.

View file

@ -3,6 +3,7 @@ var app = {
models: {}, models: {},
helpers: {}, helpers: {},
views: {}, views: {},
pages: {},
user: function(userAttrs) { user: function(userAttrs) {
if(userAttrs) { return this._user = new app.models.User(userAttrs) } if(userAttrs) { return this._user = new app.models.User(userAttrs) }

View file

@ -0,0 +1,55 @@
app.pages.PostViewer = app.views.Base.extend({
templateName: "post-viewer",
subviews : {
"#post-content" : "postView",
"#post-nav" : "navView",
"#post-feedback" : "feedbackView"
// "#post-author" : "authorView"
},
postView : function(){
return new app.views.Post({
model : this.model,
className : "loaded",
templateName : this.options.postTemplateName
})
},
navView : function() {
return new app.views.PostViewerNav({ model : this.model })
},
feedbackView : function() {
if(!window.app.user()) { return null }
return new app.views.PostViewerFeedback({ model : this.model })
},
postRenderTemplate : function() {
this.setKeyMappings();
},
setKeyMappings : function() {
var nextPostLocation = this.model.get("next_post");
var previousPostLocation = this.model.get("previous_post");
var doc = $(document);
/* focus modal */
doc.keypress(function(){
$('#text').focus();
$('#comment').modal();
});
/* navagation hooks */
doc.keydown(function(e){
if (e.keyCode == 37 && nextPostLocation) {
window.location = nextPostLocation
}else if(e.keyCode == 39 && previousPostLocation) {
window.location = previousPostLocation
}
})
}
})

View file

@ -41,14 +41,13 @@ app.Router = Backbone.Router.extend({
singlePost : function(id) { singlePost : function(id) {
new app.models.Post({id : id}).fetch({success : function(resp){ new app.models.Post({id : id}).fetch({success : function(resp){
var postAttrs = resp.get("post"); var postAttrs = resp.get("post");
var templateName = resp.get("templateName");
var view = new app.views.SinglePost({ var page = new app.pages.PostViewer({
model : new app.models.Post(postAttrs), model : new app.models.Post(postAttrs),
templateName : templateName postTemplateName : resp.get("templateName")
}).render(); }).render();
$("#post-content").html(view.el); $("#container").html(page.el);
}}) }})
} }
}); });

View file

@ -0,0 +1,17 @@
<div id="user-controls">
<a href="#" class="label">
<i class="icon-user icon-white"></i>
</a>
<a href="#" class="label">
<i class="icon-heart icon-white"></i>
</a>
<a href="#" class="label">
<i class="icon-plus icon-white"></i>
</a>
<a href="#" class="label">
<i class="icon-retweet icon-white"></i>
</a>
<a href="#" class="label">
<i class="icon-comment icon-white"></i>
</a>
</div>

View file

@ -0,0 +1,7 @@
<a href="#" class="nav-arrow left" id="forward">
<img src="/images/arrow-left.png" />
</a>
<a href="#" class="nav-arrow right" id="back">
<img src="/images/arrow-right.png" />
</a>

View file

@ -0,0 +1,3 @@
<div id="post-content"></div>
<div id="post-nav"></div>
<div id="post-feedback"></div>

View file

@ -0,0 +1,6 @@
app.views.PostViewerFeedback = app.views.Base.extend({
templateName: "post-viewer-feedback"
})

View file

@ -0,0 +1,19 @@
app.views.PostViewerNav = app.views.Base.extend({
templateName: "post-viewer-nav",
postRenderTemplate : function() {
var mappings = {"#forward" : "next_post",
"#back" : "previous_post"};
_.each(mappings, function(attribute, selector){
this.setArrow(this.$(selector), this.model.get(attribute))
}, this);
},
setArrow : function(arrow, loc) {
loc ? arrow.attr('href', loc) : arrow.remove()
}
})

View file

@ -1,69 +0,0 @@
app.views.SinglePost = app.views.Post.extend({
/* SINGLE POST SHOULD BE BROKEN OUT INTO A PAGE VIEW!!!! */
className : "loaded",
postRenderTemplate : function() {
/* nav should be a subview! and tested! (this is some prototyping stuff right here... */
this.setNav();
/* post author info should be a subview! and tested! */
this.setAuthor();
/* post author info should be a subview! and tested! */
this.setFeedback();
},
setNav : function() {
var mappings = {"#forward" : "next_post",
"#back" : "previous_post"};
_.each(mappings, function(attribute, selector){
this.setArrow($(selector), this.model.get(attribute))
}, this);
this.setMappings();
},
setArrow : function(arrow, loc) {
loc ? arrow.attr('href', loc) : arrow.remove()
},
setMappings : function() {
var nextPostLocation = this.model.get("next_post");
var previousPostLocation = this.model.get("previous_post");
var doc = $(document);
/* focus modal */
doc.keypress(function(event){
$('#text').focus();
$('#comment').modal();
});
/* navagation hooks */
doc.keydown(function(e){
if (e.keyCode == 37 && nextPostLocation) {
window.location = nextPostLocation
}else if(e.keyCode == 39 && previousPostLocation) {
window.location = previousPostLocation
}
})
},
setAuthor : function() {
// author avatar
// time of post
// reshared via... (if appliciable)
},
setFeedback : function() {
// go back to profile (app.user())
// liking
// following
// resharing
// commenting
}
});