<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/models/task_customer.rb</filename>
    </added>
    <added>
      <filename>app/views/tasks/_task_customer.html.erb</filename>
    </added>
    <added>
      <filename>db/migrate/20090630082324_create_task_customers.rb</filename>
    </added>
    <added>
      <filename>lib/active_record_extensions.rb</filename>
    </added>
    <added>
      <filename>test/fixtures/task_customers.yml</filename>
    </added>
    <added>
      <filename>test/unit/task_customer_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1480,6 +1480,18 @@ class TasksController &lt; ApplicationController
     render(:partial =&gt; &quot;notification&quot;, :locals =&gt; { :notification =&gt; user })
   end
 
+  def add_client
+    @task = current_user.company.tasks.new
+    if !params[:id].blank?
+      @task = current_user.company.tasks.find(params[:id])
+    end
+
+    customer = current_user.company.customers.find(params[:client_id])
+    @task.task_customers.build(:customer =&gt; customer)
+    
+    render(:partial =&gt; &quot;task_customer&quot;, :locals =&gt; { :task_customer =&gt; customer })
+  end
+
   def update_work_log
     log = current_user.company.work_logs.find(params[:id])
     updated = log.update_attributes(params[:work_log])</diff>
      <filename>app/controllers/tasks_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,9 @@ class Customer &lt; ActiveRecord::Base
   has_many      :users, :order =&gt; &quot;lower(name)&quot;
   has_many      :resources
 
+  has_many :task_customers, :dependent =&gt; :destroy
+  has_many :tasks, :through =&gt; :task_customers
+
   has_many      :organizational_units 
 
   validates_length_of           :name,  :maximum=&gt;200</diff>
      <filename>app/models/customer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,6 +44,10 @@ class Task &lt; ActiveRecord::Base
 
   has_many :task_property_values, :dependent =&gt; :destroy
 
+  has_many :task_customers, :dependent =&gt; :destroy
+  has_many :customers, :through =&gt; :task_customers, :order =&gt; &quot;customers.name asc&quot;
+  adds_and_removes_using_params :customers
+
   has_one       :ical_entry
 
   has_many      :todos, :order =&gt; &quot;completed_at IS NULL desc, completed_at desc, position&quot;</diff>
      <filename>app/models/task.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,13 @@
 &lt;fieldset id=&quot;task_notify&quot; style=&quot;padding-right:0;&quot;&gt;
   &lt;legend&gt;&lt;%=_ 'Notifications' %&gt;&lt;/legend&gt;
 
+  &lt;label for=&quot;clients&quot;&gt;&lt;%=_ &quot;Clients&quot; %&gt;&lt;/label&gt;
+  &lt;%= text_field_with_auto_complete(:customer, :name, 
+      { :size =&gt; 12, :value =&gt; &quot;&quot; }, :after_update_element =&gt; &quot;addCustomerToTask&quot;) %&gt;
+  &lt;div id=&quot;task_customers&quot;&gt;
+    &lt;%= render :partial =&gt; &quot;task_customer&quot;, :collection =&gt; @task.customers %&gt;
+  &lt;/div&gt;
+
   &lt;label for=&quot;task_requested_by&quot;&gt;&lt;%=_ 'Requested By' %&gt;&lt;/label&gt;
   &lt;%= text_field 'task', 'requested_by', {:size =&gt; 12}.merge(perms['edit']) %&gt;
   &lt;br/&gt;</diff>
      <filename>app/views/tasks/_notifications.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -100,6 +100,7 @@ ActionController::Base.session_options[:session_expires]= Time.local(2015,&quot;jan&quot;)
 # end
 
 require File.join(File.dirname(__FILE__), '../lib/rails_extensions')
+require File.join(&quot;#{ RAILS_ROOT }/lib/active_record_extensions&quot;)
 
 load File.join(File.dirname(__FILE__), 'environment.local.rb')
 require File.join(File.dirname(__FILE__), '../lib/misc.rb')</diff>
      <filename>config/environment.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version =&gt; 20090626005038) do
+ActiveRecord::Schema.define(:version =&gt; 20090630082324) do
 
   create_table &quot;activities&quot;, :force =&gt; true do |t|
     t.integer  &quot;user_id&quot;,       :default =&gt; 0,  :null =&gt; false
@@ -596,6 +596,16 @@ ActiveRecord::Schema.define(:version =&gt; 20090626005038) do
 
   add_index &quot;tags&quot;, [&quot;company_id&quot;, &quot;name&quot;], :name =&gt; &quot;index_tags_on_company_id_and_name&quot;
 
+  create_table &quot;task_customers&quot;, :force =&gt; true do |t|
+    t.integer  &quot;customer_id&quot;
+    t.integer  &quot;task_id&quot;
+    t.datetime &quot;created_at&quot;
+    t.datetime &quot;updated_at&quot;
+  end
+
+  add_index &quot;task_customers&quot;, [&quot;customer_id&quot;], :name =&gt; &quot;fk_task_customers_customer_id&quot;
+  add_index &quot;task_customers&quot;, [&quot;task_id&quot;], :name =&gt; &quot;fk_task_customers_task_id&quot;
+
   create_table &quot;task_owners&quot;, :force =&gt; true do |t|
     t.integer &quot;user_id&quot;
     t.integer &quot;task_id&quot;</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -684,11 +684,7 @@ function addUserToTask(input, li) {
     var userId = jQuery(li).find(&quot;.complete_value&quot;).text();
     var taskId = jQuery(&quot;#task_id&quot;).val();
 
-    var url = document.location.toString();
-    url = url.replace(&quot;/edit/&quot;, &quot;/add_notification/&quot;);
-    url = url.replace(&quot;#&quot;, &quot;&quot;);
     var url = &quot;/tasks/add_notification&quot;;
-
     var params = { user_id : userId, id : taskId }
     jQuery.get(url, params, function(data) {
 	jQuery(&quot;#task_notify&quot;).append(data);
@@ -697,6 +693,22 @@ function addUserToTask(input, li) {
 }
 
 /*
+  Adds the selected customer to the current task list of clients
+*/
+function addCustomerToTask(input, li) {
+    jQuery(input).val(&quot;&quot;);
+
+    var clientId = jQuery(li).find(&quot;.complete_value&quot;).text();
+    var taskId = jQuery(&quot;#task_id&quot;).val();
+
+    var url = &quot;/tasks/add_client&quot;;
+    var params = { client_id : clientId, id : taskId }
+    jQuery.get(url, params, function(data) {
+	jQuery(&quot;#task_customers&quot;).append(data);
+    });
+}
+
+/*
   Highlights any notification users who will be receiving an email
   about this task.
 */</diff>
      <filename>public/javascripts/cit.js</filename>
    </modified>
    <modified>
      <diff>@@ -1420,7 +1420,13 @@ a.description {
     margin-top: 0px;
     padding: 0px;
 }
-#taskform .user .removeLink {
+#taskform #task_customers {
+    clear: both;
+}
+#taskform #task_customers .customer {
+    clear: both;
+}
+#taskform .user .removeLink, #taskform #task_customers .removeLink {
     float: right
 }
 #taskform .user.will_notify {</diff>
      <filename>public/stylesheets/cit.css</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,9 @@ require File.dirname(__FILE__) + '/../test_helper'
 class CustomerTest &lt; ActiveRecord::TestCase
   fixtures :companies, :customers
 
+  should_have_many :task_customers, :dependent =&gt; :destroy
+  should_have_many :tasks, :through =&gt; :task_customers
+
   def setup
     @internal = customers(:internal_customer)
     @external = customers(:external_customer)</diff>
      <filename>test/unit/customer_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,9 @@ require File.dirname(__FILE__) + '/../test_helper'
 class TaskTest &lt; ActiveRecord::TestCase
   fixtures :tasks, :projects, :users, :companies, :customers, :properties, :property_values
 
+  should_have_many :task_customers, :dependent =&gt; :destroy
+  should_have_many :customers, :through =&gt; :task_customers
+
   def setup
     @task = tasks(:normal_task)
   end
@@ -322,4 +325,29 @@ class TaskTest &lt; ActiveRecord::TestCase
     @task.task_property_values.clear
     assert @task.valid?
   end
+
+  context &quot;a normal task&quot; do
+    setup do
+      @task = Task.first
+    end
+
+    should &quot;add and remove task customers using customer_attributes=&quot; do
+      c1 = Customer.first
+      c2 = Customer.last
+      assert_not_equal c1, c2
+
+      assert_equal 0, @task.customers.length
+      @task.customer_attributes = { 
+        c1.id =&gt; { &quot;member&quot; =&gt; &quot;1&quot; },
+        c2.id =&gt; { &quot;member&quot; =&gt; &quot;1&quot; } 
+      }
+      assert_equal 2, @task.customers.length
+
+      @task.customer_attributes = { 
+        c1.id =&gt; { &quot;add&quot; =&gt; &quot;1&quot; }
+      }
+      assert_equal 1, @task.customers.length
+      assert_equal c1, @task.task_customers.first.customer
+    end
+  end
 end</diff>
      <filename>test/unit/task_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ee4358382d3e7aaaeea4afbebe58d2bfe7c76bf4</id>
    </parent>
  </parents>
  <author>
    <name>Brad Wilson</name>
    <email>brad@lucky-dip.net</email>
  </author>
  <url>http://github.com/ari/clockingit/commit/1f2579583a934138381f21e711a575a96af3637d</url>
  <id>1f2579583a934138381f21e711a575a96af3637d</id>
  <committed-date>2009-07-01T01:02:49-07:00</committed-date>
  <authored-date>2009-07-01T01:02:49-07:00</authored-date>
  <message>can add/remove customers to tasks</message>
  <tree>be25cdad4a7046400dc7cf4e435f80ec15438b09</tree>
  <committer>
    <name>Brad Wilson</name>
    <email>brad@lucky-dip.net</email>
  </committer>
</commit>
