From 0e1c66f5b688a81cf4d0db664cc573b6f143e66c Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Wed, 23 May 2012 12:59:27 -0700
Subject: [PATCH] DG MS; only show applicable frames in the framer step

---
 app/assets/javascripts/app/models/post.js            |  9 ++++-----
 .../javascripts/app/models/post/template_picker.js   |  6 ++++++
 app/assets/javascripts/app/pages/framer.js           |  2 +-
 .../app/models/post/template_picker_spec.js          | 12 ++++++++++++
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js
index 5ec74b6ffd..71123457cf 100644
--- a/app/assets/javascripts/app/models/post.js
+++ b/app/assets/javascripts/app/models/post.js
@@ -19,6 +19,10 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
     this.set({frame_name : new app.models.Post.TemplatePicker(this).getFrameName()})
   },
 
+  applicableTemplates: function() {
+    return new app.models.Post.TemplatePicker(this).applicableTemplates()
+  },
+
   interactedAt : function() {
     return this.timeOf("interacted_at");
   },
@@ -59,12 +63,7 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
   headlineLimit : 118,
 
   frameMoods : [
- //   "Day",
- //   "Night",
     "Wallpaper",
- //   "Newspaper",
-
-    // NEW SHIT
     "Vanilla",
     "Typist",
     "Fridge"
diff --git a/app/assets/javascripts/app/models/post/template_picker.js b/app/assets/javascripts/app/models/post/template_picker.js
index c4a46bb844..faaa424a5d 100644
--- a/app/assets/javascripts/app/models/post/template_picker.js
+++ b/app/assets/javascripts/app/models/post/template_picker.js
@@ -25,5 +25,11 @@ _.extend(app.models.Post.TemplatePicker.prototype, {
 
   isWallpaper : function(){
     return this.model.get("photos").length == 1
+  },
+
+  applicableTemplates : function(){
+    /* don't show the wallpaper option if there is no image */
+    var moods = app.models.Post.frameMoods;
+    return (!this.isWallpaper() ? _.without(moods, "Wallpaper") : moods)
   }
 });
\ No newline at end of file
diff --git a/app/assets/javascripts/app/pages/framer.js b/app/assets/javascripts/app/pages/framer.js
index e22cbda6b7..2f4bc136f9 100644
--- a/app/assets/javascripts/app/pages/framer.js
+++ b/app/assets/javascripts/app/pages/framer.js
@@ -67,7 +67,7 @@ app.views.framerContent = app.views.Base.extend({
 
   presenter : function() {
     var selectedFrame = this.model.get("frame_name")
-      , templates = app.models.Post.frameMoods;
+      , templates = this.model.applicableTemplates();  //new app.models.Post.TemplatePicker(this.model).frameMoods;
 
     return _.extend(this.defaultPresenter(), {
       templates : _.map(templates, function(template) {
diff --git a/spec/javascripts/app/models/post/template_picker_spec.js b/spec/javascripts/app/models/post/template_picker_spec.js
index 56371d7750..aca0c74b7d 100644
--- a/spec/javascripts/app/models/post/template_picker_spec.js
+++ b/spec/javascripts/app/models/post/template_picker_spec.js
@@ -41,4 +41,16 @@ describe("app.models.Post.TemplatePicker", function(){
       })
     })
   })
+
+  describe("applicableTemplates", function(){
+    it("includes wallpaper if isWallpaper is true", function(){
+      spyOn(this.templatePicker, "isWallpaper").andReturn(true)
+      expect(_.include(this.templatePicker.applicableTemplates(), "Wallpaper")).toBeTruthy()
+    })
+
+    it("does not include wallpaper if isWallpaper is false", function(){
+      spyOn(this.templatePicker, "isWallpaper").andReturn(false)
+      expect(_.include(this.templatePicker.applicableTemplates(), "Wallpaper")).toBeFalsy()
+    })
+  })
 })
-- 
GitLab