tracks/app/views/projects/update.js.erb

99 lines
3.3 KiB
Text
Raw Normal View History

<% if @saved -%>
pageNotify('notice', '<%=t('projects.project_saved_status')%>', 5);
<% if source_view_is :project_list -%>
<% if @state_changed -%>
2010-10-15 11:49:34 +02:00
remove_and_re_add_project();
<% else -%>
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 %>);
<% else # assume source_view :project %>
remove_project_edit_form();
update_and_show_project_settings();
TracksForm.set_project_name("<%= escape_javascript(@project.name)%>");
<% if @project.default_context %>
TracksForm.set_context_name_and_default_context_name("<%= escape_javascript(@project.default_context.name)%>");
<% end %>
<% if @project.default_tags %>
TracksForm.set_tag_list("<%= escape_javascript(@project.default_tags)%>");
<% end %>
update_sidebar();
<% end %>
TracksForm.set_project_name_and_default_project_name("<%= escape_javascript(@project.name)%>");
<% else -%>
show_errors();
<% end %>
enable_rich_interaction();
function show_errors() {
$('div#error_status').html(html_for_error_messages());
$('div#error_status').show();
}
function remove_project_edit_form() {
2010-10-15 11:49:34 +02:00
$('#<%=dom_id(@project, 'edit')%>').hide(500, function() {$('#<%=dom_id(@project, 'edit')%>').remove();} );
}
function update_and_show_project_settings() {
$('#<%=dom_id(@project, 'container')%>').html(html_for_project_settings());
$('#<%=dom_id(@project)%>').show();
}
function update_sidebar() {
$('#sidebar').html();
}
function update_sortable() {
<%#* page.sortable "list-#{@project.state}-projects", get_listing_sortable_options("list-#{@project.state}-projects")-%>
2010-10-15 11:49:34 +02:00
/*console.log("Pending: update_sortable() on update project");*/
}
function replace_project_form_with_updated_project() {
$('#<%=dom_id(@project, 'container')%>').fadeOut(250, function() {
$('#<%=dom_id(@project, 'container')%>').html(html_for_project_listing());
$('#<%=dom_id(@project, 'container')%>').fadeIn(500);
});
}
2010-10-15 11:49:34 +02:00
function remove_and_re_add_project() {
$('#<%=dom_id(@project, 'container')%>').slideUp(500, function() {
2010-10-15 11:49:34 +02:00
$('#<%=dom_id(@project, 'container')%>').remove();
$('#list-<%=@project.state%>-projects').append(html_for_project_listing);
});
}
<%
# the following functions return empty string if rendering the partial is not
# necessary, for example the sidebar is not on the project list page, so do not
# render it into the function.
-%>
function html_for_project_listing() {
return "<%= source_view_is(:project_list) ? escape_javascript(render(:partial => 'project_listing', :locals => { :project_listing => @project })) : "" %>";
}
function html_for_sidebar() {
return "<%= source_view_is(:project) ? escape_javascript(render(:file => 'sidebar/sidebar.html.erb')) : "" %>";
}
function html_for_project_settings() {
return "<%= source_view_is(:project) ? escape_javascript(render(:partial => 'project_settings', :locals => { :project => @project })) : "" %>";
}
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('project')) %>";
}