Skip to content

Instantly share code, notes, and snippets.

@Znow
Created April 30, 2012 08:46
Show Gist options
  • Save Znow/2556663 to your computer and use it in GitHub Desktop.
Save Znow/2556663 to your computer and use it in GitHub Desktop.
<div id="createTask" class="modal hide fade custom_modal" style="display: none;">
<%= form_for [:admin, task], :url => admin_tasks_path, :remote => true, :html => { :id => 'new-task-form' } do |f| %>
<div class="modal-header">
<h3>
Add New Task
<span class="pull-right">
<%= submit_tag "Save", :class => 'btn btn-primary custom_button' %>
<a href="#" data-dismiss="modal" class="btn btn-small custom_button_dark">Cancel</a>
</span>
</h3>
</div>
<div class="modal-body">
<%= render :partial => "admin/shared/ajax_loader" %>
<div class="modal-errors"></div>
<%= render :partial => "admin/tasks/task_form", :locals => { :f => f } %>
</div>
<div class="modal-footer">
</div>
<% end %>
</div>
<% if current_user && current_user.authorized? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Create (+)<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a data-toggle="modal" href="#createClient">Add Client</a>
</li>
<li>
<a data-toggle="modal" href="#createContractor">Add Contractor</a>
</li>
<li>
<a data-toggle="modal" href="#createTimesheet">Add Timesheet</a>
</li>
<li>
<a data-toggle="modal" href="#createTask">Add Task</a>
</li>
<% if yield(:context_menu_items).present? %>
<%= yield(:context_menu_items) %>
<% end %>
</ul>
</li>
<% content_for :modal_partials do %>
<%= render :partial => "admin/shared/create_client_modal", :locals => {:client => Client.new} %>
<%= render :partial => "admin/shared/create_contractor_modal", :locals => {:contractor => Contractor.new} %>
<%= render :partial => "admin/shared/create_task_modal", :locals => {:task => Task.new} %>
<% end %>
<% end %>
<%
task_types = @task_types
responsible = @responsible
client = @client
%>
<%= debug task_types %>
<p>
<%= f.label :task_type, "Type <span class='required'>*</span>".html_safe %>
<%= f.select :task_type, options_for_select(@task_types), :class => "span4" %>
</p>
<p>
<%= f.label :subject, "Subject <span class='required'>*</span>".html_safe %>
<%= f.text_area :subject, :class => "input-xlarge span4" %>
</p>
<p>
<%= f.label :responsible, "Responsible <span class='required'>*</span>".html_safe %>
<%= f.select :responsible, options_for_select(@responsible), :class => "span4" %>
</p>
<p>
<%= f.label :client, "Client" %>
<%= f.select :client, options_for_select(@client), :class => "span4" %>
</p>
<p>
<%= f.label :deadline, "Deadline <span class='required'>*</span>".html_safe %>
<%= f.text_field :deadline, :id => "task-deadline" %>
</p>
def create
@task = Task.new(params[:task])
@task.merge!(params[:author] => current_user)
@client_tasks = @task.client_tasks.create(@client.id)
@client = Client.all.map(&:name)
@task_types = ['Follow-up', 'Meeting', 'Email', 'Contract', 'Conference call', 'Note']
@responsible = User.all.map(&:name)
respond_to do |format|
if @task.save
flash[:success] = "<strong>Success!</strong> #{@task.subject} was successfully added.".html_safe
end
format.js { render :template => "admin/tasks/create.js.erb",
:locals => {
:task => @task,
:redirect_path => admin_tasks_path,
}
} # create.js.erb
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment