Permalink
Browse files

Fix the task form and my tasks view

  • Loading branch information...
1 parent 8a78e3a commit 4ba3eda0b20cae9778d4045ea28066a44ecfacbd @jamesu committed Oct 2, 2011
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -568,3 +568,8 @@ div.billable span {
background: #FFFFFF;
color: #000;
}
+
+.loadingSpinner
+{
+ display: none;
+}
@@ -111,3 +111,11 @@ div.taskList .taskItemHandle div.inner {
cursor: move;
}
+
+div.taskList form.loading .loadingSpinner {
+ display: block;
+}
+
+div.taskList form.loading .buttons {
+ display: none;
+}
@@ -54,7 +54,7 @@ def show
respond_to do |format|
format.html { }
- format.js
+ f.js { respond_with_task(@task) }
format.xml { render :xml => @task.to_xml(:root => 'task') }
end
end
@@ -81,6 +81,11 @@ def edit
end
authorize! :edit, @task
+
+ respond_to do |f|
+ f.html
+ f.js { respond_with_task(@task, 'ajax_form') }
+ end
end
# POST /tasks
@@ -90,17 +95,17 @@ def create
@task = @task_list.tasks.build(params[:task])
@task.created_by = @logged_user
-
+
respond_to do |format|
if @task.save
Notifier.deliver_task(@task.user, @task) if params[:send_notification] and @task.user
flash[:notice] = 'ListItem was successfully created.'
format.html { redirect_back_or_default(task_lists_path) }
- format.js
+ format.js { respond_with_task(@task) }
format.xml { render :xml => @task.to_xml(:root => 'task'), :status => :created, :location => @task }
else
format.html { render :action => "new" }
- format.js
+ format.js { respond_with_task(@task) }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
@@ -124,11 +129,11 @@ def update
Notifier.deliver_task(@task.user, @task) if params[:send_notification] and @task.user
flash[:notice] = 'ListItem was successfully updated.'
format.html { redirect_back_or_default(task_lists_path) }
- format.js
+ format.js { respond_with_task(@task) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
- format.js
+ format.js { respond_with_task(@task) }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
end
end
@@ -150,6 +155,7 @@ def destroy
respond_to do |format|
format.html { redirect_back_or_default(task_lists_url) }
+ format.js { render :json => { :id => @task.id } }
format.xml { head :ok }
end
end
@@ -171,14 +177,23 @@ def status
respond_to do |format|
format.html { redirect_back_or_default(task_lists_url) }
- format.js
+ format.js { respond_with_task(@task) }
format.xml { head :ok }
end
end
protected
+ def respond_with_task(task, partial='show')
+ task_class = @task.is_completed? ? 'completedTasks' : 'openTasks'
+ if task.errors
+ render :json => {:task_class => task_class, :id => @task.id, :content => render_to_string({:partial => partial, :collection => [@task]})}
+ else
+ render :json => {:task_class => task_class, :id => @task.id, :errors => @task.errors.to_json}, :status => :unprocessable_entity
+ end
+ end
+
def grab_list
begin
@task_list = @active_project.task_lists.find(params[:task_list_id])
@@ -49,6 +49,10 @@ def render_icon(filename, alt, attrs={})
"<img src='/assets/icons/#{filename}.gif' alt='#{alt}' #{attr_values}/>".html_safe
end
+
+ def loading_spinner
+ image_tag 'spinner.gif', {:class => 'loadingSpinner'}
+ end
def action_list(actions)
actions.collect do |action|
View
@@ -35,7 +35,7 @@ class Project < ActiveRecord::Base
has_many :task_lists, :order => "#{self.connection.quote_column_name 'order'} DESC", :dependent => :destroy
- has_many :tasks, :through => :project_task_lists
+ has_many :tasks, :through => :task_lists
has_many :folders, :dependent => :destroy
has_many :project_files, :dependent => :destroy
@@ -85,7 +85,7 @@ def object_url(host = nil)
end
def tasks_by_user(user, completed=false)
- self.tasks.where(["((assigned_to_company_id = ? OR assigned_to_user_id = ?) OR (assigned_to_company_id = 0 OR assigned_to_user_id = 0)) AND project_tasks.completed_on #{completed ? 'IS NOT' : 'IS'} NULL", user.company_id, user.id])
+ self.tasks.where(["((assigned_to_company_id = ? OR assigned_to_user_id = ?) OR (assigned_to_company_id = 0 OR assigned_to_user_id = 0)) AND tasks.completed_on #{completed ? 'IS NOT' : 'IS'} NULL", user.company_id, user.id])
end
def is_active?
@@ -2,7 +2,7 @@
<h2><%= t('calendar_feeds') %></h2>
<div class="blockContent">
<a href="<%= @logged_user.milestone_feed_url(nil, 'ics') %>" class="iCalSubscribe"><%= t('ical') %></a>
- <p><%= t('calendar_feed_milestone_info') %></p>
- <p><%= t('calendar_feeds_password_warning') %></p>
+ <p><%= t('calendar_feed_milestone_info').html_safe %></p>
+ <p><%= t('calendar_feeds_password_warning').html_safe %></p>
</div>
</div>
@@ -22,9 +22,10 @@
<div class="addTask">
<div class="newTask" <% if show_form %>style="display:none;"<% end %>><%= link_to t('add_task'), new_task_path(:task_list_id => task_list.id) %></div>
<div class="inner" <% unless show_form %>style="display: none;"<% end %>>
- <%= form_tag tasks_path(:task_list_id => task_list.id) do %>
+ <%= form_tag tasks_path(:task_list_id => task_list.id), { 'data-remote' => true, 'data-type' => :json } do %>
<%= render :partial => 'tasks/form', :object => Task.new(:task_list => task_list) %>
- <div><button class="submit" type="submit"><%= t('add_task') %></button> <%= t('or') %> <a class="cancel" href="#"><%= t('cancel') %></a></div>
+ <%= loading_spinner %>
+ <div class="buttons"><button class="submit" type="submit"><%= t('add_task') %></button> <%= t('or') %> <a class="cancel" href="#"><%= t('cancel') %></a></div>
<% end %>
</div>
</div>
@@ -1,4 +1,5 @@
-<%= form_tag task_path(:task_list_id => @task.task_list_id, :id => @task.id), :method => :put, :class => 'editTaskItem' %>
+<%= form_tag task_path(:task_list_id => @task.task_list_id, :id => @task.id), :method => :put, 'data-remote' => true, 'data-type' => :json, :class => 'editTaskItem' %>
<%= render :partial => 'form', :object => @task %>
- <div><button class="submit" type="submit"><%=t('edit_task') %></button> <%= t('or') %> <%= link_to t('cancel'), task_path(:task_list_id => @task.task_list_id, :id => @task.id), :class => 'cancel' %></div>
-</form>
+ <%= loading_spinner %>
+ <div class="buttons"><button class="submit" type="submit"><%=t('edit_task') %></button> <%= t('or') %> <%= link_to t('cancel'), task_path(:task_list_id => @task.task_list_id, :id => @task.id), :class => 'cancel', 'data-remote' => true, 'data-type' => :json %></div>
+</form>
@@ -9,7 +9,7 @@
<div class="taskItemContent">
<% if can?(:edit,task_item) %>
<div class="taskControls">
- <%= link_to render_icon('trash', 'Trash'), task_path(:id => task_item.id, :task_list_id => task_item.task_list_id), {:confirm => t('task_delete_confirm'), :method => :delete, :class => 'blank taskDelete'} %><%= link_to 'Edit', edit_task_path(:id => task_item.id, :task_list_id => task_item.task_list_id), {:class => 'blank taskEdit edit'} %>
+ <%= link_to render_icon('trash', 'Trash'), task_path(:id => task_item.id, :task_list_id => task_item.task_list_id), {:confirm => t('task_delete_confirm'), :method => :delete, :class => 'blank taskDelete', 'data-remote' => true, 'data-type' => :json} %><%= link_to 'Edit', edit_task_path(:id => task_item.id, :task_list_id => task_item.task_list_id), {:class => 'blank taskEdit edit', 'data-remote' => true, 'data-type' => :json} %>
</div>
<% end %>
<% if can?(:edit,task_item) %>

0 comments on commit 4ba3eda

Please sign in to comment.