MS DC You can has choose a template

This commit is contained in:
Dennis Collinson 2012-03-22 16:58:07 -07:00
parent 11eb1eb7d8
commit 775eca0026
9 changed files with 25 additions and 17 deletions

View file

@ -21,7 +21,7 @@ class StatusMessage < Post
# therefore, we put the validation in a before_destory callback instead of a validation
before_destroy :presence_of_content
attr_accessible :text, :provider_display_name
attr_accessible :text, :provider_display_name, :frame_name
attr_accessor :oembed_url
after_create :create_mentions

View file

@ -23,7 +23,7 @@ class PostPresenter
:reshares => self.reshares,
:comments => self.comments,
:participations => self.participations,
:templateName => template_name,
:frame_name => self.post.frame_name || template_name,
:title => title
})
end

View file

@ -0,0 +1,5 @@
class AddTemplateNameToPosts < ActiveRecord::Migration
def change # thanks josh susser
add_column :posts, :frame_name, :string
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120301143226) do
ActiveRecord::Schema.define(:version => 20120322223517) do
create_table "account_deletions", :force => true do |t|
t.string "diaspora_handle"
@ -334,6 +334,7 @@ ActiveRecord::Schema.define(:version => 20120301143226) do
t.integer "o_embed_cache_id"
t.integer "reshares_count", :default => 0
t.datetime "interacted_at"
t.string "frame_name"
end
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true

View file

@ -22,7 +22,7 @@ app.pages.Framer = app.views.Base.extend({
postView : function(){
//we might be leaky like cray cray with this
var templateType = this.model.get("templateName")
var templateType = this.model.get("frame_name")
this._postView = new app.views.Post({
model : this.model,

View file

@ -25,11 +25,13 @@ app.pages.PostViewer = app.views.Base.extend({
this.authorView = new app.views.PostViewerAuthor({ model : this.model });
this.interactionsView = new app.views.PostViewerInteractions({ model : this.model });
this.navView = new app.views.PostViewerNav({ model : this.model });
var frameName = this.model.get("frame_name")
this.postView = new app.views.Post({
model : this.model,
className : this.model.get("templateName") + " post loaded",
templateName : "post-viewer/content/" + this.model.get("templateName"),
attributes : {"data-template" : this.model.get("templateName")}
className : frameName + " post loaded",
templateName : "post-viewer/content/" + frameName,
attributes : {"data-template" : frameName}
});
this.render();

View file

@ -2,7 +2,7 @@ app.views.TemplatePicker = app.views.Base.extend({
templateName : "template-picker",
initialize : function(){
this.model.set({templateName : 'status'})
this.model.set({frame_name : 'status'})
},
events : {
@ -10,11 +10,11 @@ app.views.TemplatePicker = app.views.Base.extend({
},
postRenderTemplate : function(){
this.$("select[name=template]").val(this.model.get("templateName"))
this.$("select[name=template]").val(this.model.get("frame_name"))
},
setModelTemplate : function(evt){
this.model.set({"templateName": this.$("select[name=template]").val()})
this.model.set({"frame_name": this.$("select[name=template]").val()})
},
presenter : function() {

View file

@ -1,12 +1,12 @@
describe("app.views.TemplatePicker", function(){
beforeEach(function(){
this.model = factory.statusMessage({templateName: undefined})
this.model = factory.statusMessage({frame_name: undefined})
this.view = new app.views.TemplatePicker({model : this.model })
})
describe("initialization", function(){
it("sets the post_type of the model to 'status' by default", function(){
expect(this.view.model.get("templateName")).toBe("status")
it("sets the frame_name of the model to 'status' by default", function(){
expect(this.view.model.get("frame_name")).toBe("status")
})
})
@ -15,14 +15,14 @@ describe("app.views.TemplatePicker", function(){
this.view.render()
})
it("selects the model's templateName from the dropdown", function(){
it("selects the model's frame_name from the dropdown", function(){
expect(this.view.$("select[name=template]").val()).toBe("status")
})
it("changes the templateName on the model when is is selected", function(){
it("changes the frame_name on the model when is is selected", function(){
this.view.$("select[name=template]").val("note")
this.view.$("select[name=template]").trigger("change")
expect(this.model.get("templateName")).toBe('note')
expect(this.model.get("frame_name")).toBe('note')
})
})
})