mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-29 04:06:11 +01:00
migrate project creation
This commit is contained in:
parent
36e63a4ad9
commit
4413cabbba
12 changed files with 152 additions and 94 deletions
|
|
@ -10,6 +10,7 @@ class ProjectsController < ApplicationController
|
|||
def index
|
||||
@source_view = params['_source_view'] || 'project_list'
|
||||
@projects = current_user.projects
|
||||
@new_project = current_user.projects.build
|
||||
if params[:projects_and_actions]
|
||||
projects_and_actions
|
||||
else
|
||||
|
|
@ -73,6 +74,7 @@ class ProjectsController < ApplicationController
|
|||
render_failure "Expected post format is valid xml like so: <request><project><name>project name</name></project></request>."
|
||||
return
|
||||
end
|
||||
|
||||
@project = current_user.projects.build
|
||||
params_are_invalid = true
|
||||
if (params['project'] || (params['request'] && params['request']['project']))
|
||||
|
|
@ -81,9 +83,11 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
@go_to_project = params['go_to_project']
|
||||
@saved = @project.save
|
||||
|
||||
@project_not_done_counts = { @project.id => 0 }
|
||||
@active_projects_count = current_user.projects.active.count
|
||||
@contexts = current_user.contexts
|
||||
|
||||
respond_to do |format|
|
||||
format.js { @down_count = current_user.projects.size }
|
||||
format.xml do
|
||||
|
|
@ -95,6 +99,7 @@ class ProjectsController < ApplicationController
|
|||
head :created, :location => project_url(@project), :text => @project.id
|
||||
end
|
||||
end
|
||||
format.html {redirect_to :action => 'index'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
40
app/views/projects/_new_project_form.rhtml
Normal file
40
app/views/projects/_new_project_form.rhtml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<div id="project_new_project_container">
|
||||
|
||||
<div id="toggle_project_link" class="hide_form">
|
||||
<a id="toggle_project_new" href="#" title="<%= t('projects.hide_new_project_form') %>" accesskey="n">« <%= t('projects.hide_form') %></a>
|
||||
</div>
|
||||
|
||||
<div id="project_new" class="project_new" style="display:block">
|
||||
<% form_for(@new_project, :html => {:id => 'project_form',:name=>'project',:class => "inline-form", :method => :post }) do -%>
|
||||
<div id="error_status"><%= error_messages_for("project") %></div>
|
||||
|
||||
<label for="project_name"><%= Project.human_attribute_name(:name) %>:</label><br />
|
||||
<%= text_field 'project', 'name', "tabindex" => 1 %><br />
|
||||
|
||||
<label for="project_description"><%= Project.human_attribute_name(:description) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_area 'project', 'description', "cols" => 30, "rows" => 4, "tabindex" => 2 %><br />
|
||||
|
||||
<% unless @contexts.empty? -%>
|
||||
<label for="default_context_name"><%= Project.human_attribute_name(:default_context_name) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_field_tag("project[default_context_name]", @new_project.default_context.name, :tabindex => 3) %>
|
||||
<br />
|
||||
<% end -%>
|
||||
|
||||
<label for="default_tags"><%= Project.human_attribute_name(:default_tags) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_field_tag("project[default_tags]", @new_project.default_tags, :tabindex => 4) %>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="project_new_project_submit">
|
||||
<%= image_tag("accept.png", :alt => "") + t('projects.add_project') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input id="go_to_project" type="checkbox" tabindex="5" name="go_to_project"/><label for="go_to_project"><%= t('projects.to_new_project_page') %></label><br />
|
||||
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
48
app/views/projects/create.js.erb
Normal file
48
app/views/projects/create.js.erb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<% if @saved -%>
|
||||
<% if @go_to_project %>
|
||||
redirect_to ("<%= project_path(@project) %>")
|
||||
<% end %>
|
||||
hide_errors();
|
||||
hide_empty_msg();
|
||||
set_page_badge(<%= @down_count %>);
|
||||
update_active_projects_container();
|
||||
add_project();
|
||||
clear_form();
|
||||
<% else -%>
|
||||
show_errors();
|
||||
<% end -%>
|
||||
|
||||
function show_errors() {
|
||||
$('div#error_status').html(html_for_error_messages());
|
||||
$('div#error_status').show();
|
||||
}
|
||||
|
||||
function hide_errors() {
|
||||
$('div#error_status').hide();
|
||||
}
|
||||
|
||||
function hide_empty_msg() {
|
||||
$('projects-empty-nd').hide();
|
||||
}
|
||||
|
||||
function add_project() {
|
||||
$('#list-active-projects').append(html_for_project_listing);
|
||||
}
|
||||
|
||||
function clear_form() {
|
||||
$('#project_form').clearForm();
|
||||
$('#project_form input:text:first').focus();
|
||||
}
|
||||
|
||||
function update_active_projects_container() {
|
||||
ProjectListPage.set_state_container_visibility('active', true);
|
||||
ProjectListPage.update_state_count('active', <%=@active_projects_count%>);
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(error_messages_for('project')) %>";
|
||||
}
|
||||
|
||||
function html_for_project_listing() {
|
||||
return "<%= @saved ? escape_javascript(render(:partial => 'project_listing', :locals => { :project_listing => @project })) : "" %>";
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
if @saved and @go_to_project
|
||||
page.redirect_to project_path(@project)
|
||||
elsif @saved
|
||||
page.hide 'status'
|
||||
page['badge_count'].replace_html @down_count
|
||||
page.hide 'projects-empty-nd'
|
||||
page.show 'list-active-projects-container'
|
||||
page.replace_html "active-projects-count", @active_projects_count
|
||||
page.insert_html :bottom, "list-active-projects", :partial => 'project_listing', :locals => { :project_listing => @project }
|
||||
page.sortable "list-active-projects", get_listing_sortable_options('list-active-projects')
|
||||
page << "$('#project-form').clearForm();"
|
||||
page << "$('#project-form input:text:first').focus();"
|
||||
else
|
||||
page.show 'status'
|
||||
page.replace_html 'status', "#{error_messages_for('project')}"
|
||||
end
|
||||
page.hide "busy"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
remove_deleted_project();
|
||||
ProjectListPage.update_state_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>)
|
||||
ProjectListPage.show_or_hide_state_container(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>);
|
||||
page_notify('notice', "Deleted project '#{@project.name}'", 5);
|
||||
ProjectListPage.update_all_states_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>)
|
||||
ProjectListPage.show_or_hide_all_state_containers(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>);
|
||||
page_notify('notice', "Deleted project '<%= @project.name%>'", 5);
|
||||
set_page_badge(<%=@down_count%>);
|
||||
|
||||
function remove_deleted_project() {
|
||||
|
|
|
|||
|
|
@ -7,60 +7,8 @@
|
|||
<%= render :partial => 'project_state_group', :object => @completed_projects, :locals => { :state => 'completed'} %>
|
||||
</div>
|
||||
|
||||
<% @project = @new_project -%>
|
||||
<div id="input_box">
|
||||
<div id="project_new_project_filler">
|
||||
<div id="project_new_project_container">
|
||||
|
||||
<div id="toggle_project_link" class="hide_form">
|
||||
<a id="toggle_project_new" href="#" title="<%= t('projects.hide_new_project_form') %>" accesskey="n">« <%= t('projects.hide_form') %></a>
|
||||
</div>
|
||||
|
||||
<div id="project_new" class="project_new" style="display:block">
|
||||
<% form_remote_tag(:url => projects_path, :method => :post,
|
||||
:html=> { :id=>'project-form', :name=>'project', :class => 'inline-form'},
|
||||
:before => "$('#project_new_project_submit').block({message:null})",
|
||||
:complete => "$('#project_new_project_submit').unblock()") do -%>
|
||||
|
||||
<div id="status"><%= error_messages_for('project') %></div>
|
||||
|
||||
<label for="project_name"><%= Project.human_attribute_name(:name) %>:</label><br />
|
||||
<%= text_field 'project', 'name', "tabindex" => 1 %><br />
|
||||
|
||||
<label for="project_description"><%= Project.human_attribute_name(:description) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_area 'project', 'description', "cols" => 30, "rows" => 4, "tabindex" => 2 %><br />
|
||||
|
||||
<% unless @contexts.empty? -%>
|
||||
<label for="default_context_name"><%= Project.human_attribute_name(:default_context_name) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_field_tag("project[default_context_name]", @project.default_context.name, :tabindex => 3) %>
|
||||
<br />
|
||||
<% end -%>
|
||||
|
||||
<label for="default_tags"><%= Project.human_attribute_name(:default_tags) %> (<%= t('common.optional') %>):</label><br />
|
||||
<%= text_field_tag("project[default_tags]", @project.default_tags, :tabindex => 4) %>
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="project_new_project_submit">
|
||||
<%= image_tag("accept.png", :alt => "") + t('projects.add_project') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br/><br/>
|
||||
<input id="go_to_project" type="checkbox" tabindex="5" name="go_to_project"/><label for="go_to_project"><%= t('projects.to_new_project_page') %></label><br />
|
||||
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
<%= render :partial => 'new_project_form' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.onload=function(){
|
||||
Nifty("div#project_new_project_container","normal");
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@
|
|||
replace_project_form_with_updated_project();
|
||||
<% end -%>
|
||||
|
||||
update_sortable();
|
||||
ProjectListPage.update_state_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>)
|
||||
ProjectListPage.show_or_hide_state_container(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>);
|
||||
ProjectListPage.update_all_states_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>)
|
||||
ProjectListPage.show_or_hide_all_state_containers(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>);
|
||||
|
||||
<% else # assume source_view :project %>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue