From e0b18f5d6c45051c9ebc100e78fdcb691d257ff6 Mon Sep 17 00:00:00 2001
From: Dennis Collinson <dennis.collective@gmail.com>
Date: Tue, 20 Mar 2012 17:18:21 -0700
Subject: [PATCH] MS DC template picker override

---
 public/javascripts/app/pages/framer.js        | 19 ++++++++---
 .../app/templates/template-picker.handlebars  |  5 +++
 .../app/views/template_picker_view.js         | 33 +++++++++++++++++++
 spec/javascripts/app/pages/framer_spec.js     |  8 +++++
 .../app/views/template_picker_view_spec.js    | 28 ++++++++++++++++
 5 files changed, 88 insertions(+), 5 deletions(-)
 create mode 100644 public/javascripts/app/views/template_picker_view.js
 create mode 100644 spec/javascripts/app/views/template_picker_view_spec.js

diff --git a/public/javascripts/app/pages/framer.js b/public/javascripts/app/pages/framer.js
index 0b44630d07..7c6d57e75d 100644
--- a/public/javascripts/app/pages/framer.js
+++ b/public/javascripts/app/pages/framer.js
@@ -8,24 +8,33 @@ app.pages.Framer = app.views.Base.extend({
   },
 
   subviews : {
-    ".post-view" : "postView"
+    ".post-view" : "postView",
+    ".template-picker" : "templatePicker"
   },
 
   initialize : function(){
     this.model = app.frame
 
-    var templateType = "status"
+    this.model.bind("change", this.render, this)
+    this.templatePicker = new app.views.TemplatePicker({ model: this.model })
+  },
 
-    this.model.authorIsNotCurrentUser = function(){ return false }
+  postView : function(){
+    //we might be leaky like cray cray with this
+
+    var templateType = this.model.get("templateName")
 
-    this.postView = new app.views.Post({
+    var postView = new app.views.Post({
       model : this.model,
       className : templateType + " post loaded",
       templateName : "post-viewer/content/" + templateType,
       attributes : {"data-template" : templateType}
     });
 
-    this.postView.feedbackView = new Backbone.View
+    postView.feedbackView = new Backbone.View
+    this.model.authorIsNotCurrentUser = function(){ return false }
+
+    return postView
   },
 
   saveFrame : function(){
diff --git a/public/javascripts/app/templates/template-picker.handlebars b/public/javascripts/app/templates/template-picker.handlebars
index e69de29bb2..9617e86f21 100644
--- a/public/javascripts/app/templates/template-picker.handlebars
+++ b/public/javascripts/app/templates/template-picker.handlebars
@@ -0,0 +1,5 @@
+<select name="template">
+    {{#each templates}}
+        <option value="{{.}}">{{.}}</option>
+    {{/each}}
+</select>
\ No newline at end of file
diff --git a/public/javascripts/app/views/template_picker_view.js b/public/javascripts/app/views/template_picker_view.js
new file mode 100644
index 0000000000..5d55a87f46
--- /dev/null
+++ b/public/javascripts/app/views/template_picker_view.js
@@ -0,0 +1,33 @@
+app.views.TemplatePicker = app.views.Base.extend({
+  templateName : "template-picker",
+
+  initialize : function(){
+    this.model.set({templateName : 'status'})
+  },
+
+  events : {
+    "change select" : "setModelTemplate"
+  },
+
+  postRenderTemplate : function(){
+    this.$("select[name=template]").val(this.model.get("templateName"))
+  },
+
+  setModelTemplate : function(evt){
+    this.model.set({"templateName": this.$("select[name=template]").val()})
+  },
+
+  presenter : function() {
+    return _.extend(this.defaultPresenter(), {
+      templates : [
+        "status-with-photo-backdrop",
+        "note",
+        "rich-media",
+        "multi-photo",
+        "photo-backdrop",
+        "activity-streams-photo",
+        "status"
+      ]
+    })
+  }
+})
\ No newline at end of file
diff --git a/spec/javascripts/app/pages/framer_spec.js b/spec/javascripts/app/pages/framer_spec.js
index 0e3d30e87c..4175ed2400 100644
--- a/spec/javascripts/app/pages/framer_spec.js
+++ b/spec/javascripts/app/pages/framer_spec.js
@@ -5,6 +5,14 @@ describe("app.pages.Framer", function(){
     this.page = new app.pages.Framer();
   });
 
+  it("passes the model down to the template picker", function(){
+    expect(this.page.templatePicker.model).toBe(app.frame)
+  });
+
+  it("passes the model down to the post view", function(){
+    expect(this.page.postView.model).toBe(app.frame)
+  });
+
   describe("rendering", function(){
     beforeEach(function(){
       this.page.render();
diff --git a/spec/javascripts/app/views/template_picker_view_spec.js b/spec/javascripts/app/views/template_picker_view_spec.js
new file mode 100644
index 0000000000..b9979668ed
--- /dev/null
+++ b/spec/javascripts/app/views/template_picker_view_spec.js
@@ -0,0 +1,28 @@
+describe("app.views.TemplatePicker", function(){
+  beforeEach(function(){
+    this.model = factory.statusMessage({templateName: 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")
+    })
+  })
+
+  describe("rendering", function(){
+    beforeEach(function(){
+      this.view.render()
+    })
+
+    it("selects the model's templateName 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(){
+      this.view.$("select[name=template]").val("note")
+      this.view.$("select[name=template]").trigger("change")
+      expect(this.model.get("templateName")).toBe('note')
+    })
+  })
+})
\ No newline at end of file
-- 
GitLab