         first
         :profiles))
 
+(defn handle-change [owner key e]
+  (let [value (.-value (.-target e))]
+    (om/set-state! owner [:profile_data key] value)))
+
+(defn text-control [data state owner key label]
+  [:div.form-group
+   [:label.control-label {:for (name key)} label]
+   (if (:editing state)
+     [:div
+      [:input {:defaultValue (get data key "")
+               :class "form-control"
+               :on-change #(handle-change owner key %1)
+               :type "text"
+               :id (name key)}]]
+     [:p {:class "form-control-static col-md-10"} (get data key "")])])
+
+(defn text-area-control [data state owner key title]
+  (let [text (get data key)]
+    (if (:editing state)
+      [:div
+       [:div.form-group
+        [:label.control-label  title]
+        [:form {:role "form"}
+         [:textarea.form-control {:on-change #(handle-change owner key %1) :rows 2} text]]]]
+      (if (and text (re-find #"\w" text))
+        [:div [:h3 title]
+         [:p text]]
+        [:div {:class "hidden"} [:p {:class "form-control-static col-md-10"} text]]))))
+
 (defn format-time-inst [t format]
   (if (nil? t)
     "Undated"

            [:div {:class (profile-column-width)}
             (bs/panel
              "Energy"
              [:dl
               [:dt "DER (kgCO2/m2/yr)"] [:dd (display profile_data :der)]
               [:dt "TER (kgCO2/m2/yr)"] [:dd (display profile_data :ter)]
               [:dt "Total Primary Energy Requirement"] [:dd (display profile_data :primary_energy_requirement)]
               [:dt "Space Heating Requirement"] [:dd (display profile_data :space_heating_requirement)]
               [:dt "Annual Space Heating Requirement"] [:dd (display profile_data :annual_space_heating_requirement)]
               ;; hot water?
               [:dt "Renewable Contribution Heat"] [:dd (display profile_data :renewable_contribution_heat)]
               [:dt "Renewable Contribution Elec"] [:dd (display profile_data :renewable_contribution_elec)]

               [:dt "Electricity Meter Type"] [:dd (display profile_data :electricity_meter_type)]
               [:dt "Linked to Mains Gas Supply"] [:dd (display profile_data :mains_gas)]
               [:dt "Electricity Storage Present"] [:dd (display profile_data :electricity_storage_present)]
               [:dt "Heat Storage Present"] [:dd (display profile_data :heat_storage_present)]])]))]))))


(defn profile-rows [profiles owner]

            [:div {:class (profile-column-width)}
             (bs/panel
              "Occupancy"
              [:div
               (text-control profile_data state owner :occupancy_under_18 "Occupancy Under 18")
               (text-control profile_data state owner :occupancy_18_to_60 "Occupancy 18 To 60")
               (text-control profile_data state owner :occupancy_over_60 "Occupancy Over 60")
               (text-control profile_data state owner :occupant_change "Occupant Change")])]))]))))

(defn measurements-row [profiles owner]
  (reify
    om/IRenderState
    (render-state [_ state]
