From 3a47590d0610c11de81fd1f7dcbb70f4eb980d12 Mon Sep 17 00:00:00 2001
From: Dennis Collinson <dennis.collective@gmail.com>
Date: Wed, 7 Mar 2012 12:08:04 -0800
Subject: [PATCH] DG DC OMG FORMZ

---
 config/assets.yml                              |  2 ++
 public/javascripts/app/app.js                  |  1 +
 .../app/{views/post_form_view.js => forms.js}  | 18 ++----------------
 public/javascripts/app/forms/post_form_view.js | 16 ++++++++++++++++
 public/javascripts/app/pages/post-new.js       |  2 +-
 public/javascripts/app/views.js                |  5 ++++-
 .../app/views/aspects_dropdown_view.js         |  3 +++
 .../app/{views => forms}/post_form_spec.js     |  4 ++--
 spec/javascripts/support/jasmine.yml           |  2 ++
 9 files changed, 33 insertions(+), 20 deletions(-)
 rename public/javascripts/app/{views/post_form_view.js => forms.js} (59%)
 create mode 100644 public/javascripts/app/forms/post_form_view.js
 create mode 100644 public/javascripts/app/views/aspects_dropdown_view.js
 rename spec/javascripts/app/{views => forms}/post_form_spec.js (87%)

diff --git a/config/assets.yml b/config/assets.yml
index 570bcac7f8..5928969303 100644
--- a/config/assets.yml
+++ b/config/assets.yml
@@ -43,6 +43,7 @@ javascripts:
     - public/javascripts/app/helpers/*
     - public/javascripts/app/router.js
     - public/javascripts/app/views.js
+    - public/javascripts/app/forms.js
     - public/javascripts/app/models/post.js
     - public/javascripts/app/models/*
     - public/javascripts/app/pages/*
@@ -51,6 +52,7 @@ javascripts:
     - public/javascripts/app/views/content_view.js
     - public/javascripts/app/views/*.js
     - public/javascripts/app/views/**/*.js
+    - public/javascripts/app/forms/*.js
 
     - public/javascripts/diaspora.js
     - public/javascripts/helpers/*.js
diff --git a/public/javascripts/app/app.js b/public/javascripts/app/app.js
index 3f019e0f1a..962c7a181b 100644
--- a/public/javascripts/app/app.js
+++ b/public/javascripts/app/app.js
@@ -4,6 +4,7 @@ var app = {
   helpers: {},
   views: {},
   pages: {},
+  forms: {},
 
   user: function(userAttrs) {
     if(userAttrs) { return this._user = new app.models.User(userAttrs) }
diff --git a/public/javascripts/app/views/post_form_view.js b/public/javascripts/app/forms.js
similarity index 59%
rename from public/javascripts/app/views/post_form_view.js
rename to public/javascripts/app/forms.js
index eea8a58057..0aceb159b2 100644
--- a/public/javascripts/app/views/post_form_view.js
+++ b/public/javascripts/app/forms.js
@@ -1,22 +1,8 @@
-app.views.PostForm = app.views.Base.extend({
-  templateName : "post-form",
-
+app.forms.Base = app.views.Base.extend({
   events :{
     'submit form' : 'setModelAttributes'
   },
 
-//  subviews : {
-//    ".aspect_form" : "aspectDropdown"
-//  },
-
-  formAttrs : {
-    ".text" : "text"
-  },
-
-//  initialize : function(){
-////    this.aspectsDropdown = new app.views.AspectDropdown()
-//  },
-
   setModelAttributes : function(evt){
     if(evt){ evt.preventDefault(); }
 
@@ -30,4 +16,4 @@ app.views.PostForm = app.views.Base.extend({
     this.model.set(_.inject(this.formAttrs, setValueFromField, {}))
     this.model.trigger("setFromForm")
   }
-});
\ No newline at end of file
+})
diff --git a/public/javascripts/app/forms/post_form_view.js b/public/javascripts/app/forms/post_form_view.js
new file mode 100644
index 0000000000..3c2a84edb9
--- /dev/null
+++ b/public/javascripts/app/forms/post_form_view.js
@@ -0,0 +1,16 @@
+app.forms.Post = app.forms.Base.extend({
+  templateName : "post-form",
+
+  subviews : {
+    ".aspect_selector" : "aspectsDropdown"
+  },
+
+  formAttrs : {
+    ".text" : "text",
+//    ".aspect_ids" : "aspect_ids"
+  },
+
+  initialize : function(){
+    this.aspectsDropdown = new app.views.AspectsDropdown()
+  }
+});
\ No newline at end of file
diff --git a/public/javascripts/app/pages/post-new.js b/public/javascripts/app/pages/post-new.js
index 0e2e446d1b..3315e6911d 100644
--- a/public/javascripts/app/pages/post-new.js
+++ b/public/javascripts/app/pages/post-new.js
@@ -5,7 +5,7 @@ app.pages.PostNew = app.views.Base.extend({
 
   initialize : function(){
     this.model = new app.models.StatusMessage()
-    this.postForm = new app.views.PostForm({model : this.model})
+    this.postForm = new app.forms.Post({model : this.model})
 
     this.model.bind("setFromForm", this.saveModel, this)
   },
diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js
index 6ebd412e0b..095b0e5cf2 100644
--- a/public/javascripts/app/views.js
+++ b/public/javascripts/app/views.js
@@ -9,7 +9,10 @@ app.views.Base = Backbone.View.extend({
   },
 
   setupRenderEvents : function(){
-    this.model.bind('remove', this.remove, this);
+    if(this.model) {
+      //this should be in streamobjects view
+      this.model.bind('remove', this.remove, this);
+    }
 
     // this line is too generic.  we usually only want to re-render on
     // feedback changes as the post content, author, and time do not change.
diff --git a/public/javascripts/app/views/aspects_dropdown_view.js b/public/javascripts/app/views/aspects_dropdown_view.js
new file mode 100644
index 0000000000..805beb259e
--- /dev/null
+++ b/public/javascripts/app/views/aspects_dropdown_view.js
@@ -0,0 +1,3 @@
+app.views.AspectsDropdown = app.views.Base.extend({
+  templateName : "aspects-dropdown"
+})
\ No newline at end of file
diff --git a/spec/javascripts/app/views/post_form_spec.js b/spec/javascripts/app/forms/post_form_spec.js
similarity index 87%
rename from spec/javascripts/app/views/post_form_spec.js
rename to spec/javascripts/app/forms/post_form_spec.js
index ff6fea7ed7..a560c63226 100644
--- a/spec/javascripts/app/views/post_form_spec.js
+++ b/spec/javascripts/app/forms/post_form_spec.js
@@ -1,7 +1,7 @@
-describe("app.views.PostForm", function(){
+describe("app.forms.Post", function(){
   beforeEach(function(){
     this.post = new app.models.Post();
-    this.view = new app.views.PostForm({model : this.post})
+    this.view = new app.forms.Post({model : this.post})
   })
 
   describe("rendering", function(){
diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml
index 9c29ffafdc..0bf5fd76af 100644
--- a/spec/javascripts/support/jasmine.yml
+++ b/spec/javascripts/support/jasmine.yml
@@ -46,6 +46,7 @@ src_files:
   - public/javascripts/app/helpers/*
   - public/javascripts/app/router.js
   - public/javascripts/app/views.js
+  - public/javascripts/app/forms.js
   - public/javascripts/app/models/post.js
   - public/javascripts/app/models/*
   - public/javascripts/app/collections/*
@@ -54,6 +55,7 @@ src_files:
   - public/javascripts/app/views/*.js
   - public/javascripts/app/views/**/*.js
   - public/javascripts/app/pages/**/*.js
+  - public/javascripts/app/forms/**/*.js
 
   - public/javascripts/mobile.js
   - public/javascripts/contact-list.js
-- 
GitLab