mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-12 07:32:37 +01:00
move js genreated for ajax calls into their own object to prevent name clashes
I only modified the js that is most likely to be used in cocurrent calls. This because we start the development of Tracks 3 that will change all js.
This commit is contained in:
parent
f0871738e9
commit
4cdbd9a451
14 changed files with 436 additions and 410 deletions
|
|
@ -1,4 +1,10 @@
|
|||
<% if @saved -%>
|
||||
<% unless @saved -%>
|
||||
TracksPages.show_errors(html_for_error_messages());
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>";
|
||||
}
|
||||
<% else -%>
|
||||
<% if @go_to_project -%>
|
||||
redirect_to("<%= project_path(@project) -%>")
|
||||
<% else -%>
|
||||
|
|
@ -10,9 +16,6 @@
|
|||
clear_form();
|
||||
TracksPages.page_notify('notice', "Created new project '<%= @project.name%>'", 5);
|
||||
<% end -%>
|
||||
<% else -%>
|
||||
TracksPages.show_errors(html_for_error_messages());
|
||||
<% end -%>
|
||||
|
||||
/* TODO: make this generic for all pages with lists */
|
||||
function hide_empty_message() {
|
||||
|
|
@ -36,10 +39,8 @@ function update_active_projects_container() {
|
|||
ProjectListPage.update_state_count('active', <%=@active_projects_count%>);
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>";
|
||||
}
|
||||
|
||||
function html_for_project_listing() {
|
||||
return "<%= @saved ? escape_javascript(render(:partial => 'project_listing', :object => @project)) : "" %>";
|
||||
}
|
||||
}
|
||||
|
||||
<% end -%>
|
||||
|
|
@ -3,27 +3,29 @@
|
|||
selector_edit = "div.project-edit-current " + selector_edit unless @source_view=="project"
|
||||
selector_project = "div##{dom_id(@project)}"
|
||||
selector_project = "div.project-edit-current " + selector_project unless @source_view=="project"
|
||||
-%>
|
||||
|
||||
function html_for_edit_form() {
|
||||
return "<%= escape_javascript(render(:partial => 'project_form', :object => @project)) %>";
|
||||
object_name = unique_object_name_for("edit_project_#{@project.id}")
|
||||
-%>
|
||||
var <%=object_name%> = {
|
||||
html_for_edit_form: function() {
|
||||
return "<%= escape_javascript(render(:partial => 'project_form', :object => @project)) %>";
|
||||
},
|
||||
show_edit_form: function() {
|
||||
$('<%= selector_edit %>').html(<%=object_name%>.html_for_edit_form());
|
||||
$('<%= selector_edit %>').fadeIn(500);
|
||||
$('span#project_name').editable('disable');
|
||||
},
|
||||
set_focus: function() {
|
||||
$('input.project-name').focus();
|
||||
},
|
||||
replace_project_with_edit_form: function() {
|
||||
$('<%= selector_project %>').fadeOut(250, function() {
|
||||
<%=object_name%>.show_edit_form();
|
||||
<%=object_name%>.set_focus();
|
||||
});
|
||||
},
|
||||
animate: function() {
|
||||
<%=object_name%>.replace_project_with_edit_form();
|
||||
}
|
||||
}
|
||||
|
||||
function show_edit_form() {
|
||||
$('<%= selector_edit %>').html(html_for_edit_form());
|
||||
$('<%= selector_edit %>').fadeIn(500);
|
||||
$('span#project_name').editable('disable');
|
||||
}
|
||||
|
||||
function set_focus() {
|
||||
$('input.project-name').focus();
|
||||
}
|
||||
|
||||
function replace_project_with_edit_form() {
|
||||
$('<%= selector_project %>').fadeOut(250, function() {
|
||||
show_edit_form();
|
||||
set_focus();
|
||||
});
|
||||
}
|
||||
|
||||
replace_project_with_edit_form();
|
||||
<%=object_name%>.animate();
|
||||
|
|
@ -1,102 +1,98 @@
|
|||
<% if @saved -%>
|
||||
TracksPages.page_notify('notice', '<%=t('projects.project_saved_status')%>', 5);
|
||||
<% if source_view_is_one_of(:project_list, :review) -%>
|
||||
update_project_list_page();
|
||||
<% else # assume source_view :project
|
||||
<%-
|
||||
object_name = unique_object_name_for("update_project_#{@project.id}")
|
||||
-%>
|
||||
var <%=object_name%> = {
|
||||
<% unless @saved -%>
|
||||
animate: function(){
|
||||
TracksPages.show_edit_errors(<%=object_name%>.html_for_error_messages());
|
||||
},
|
||||
html_for_error_messages: function() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>";
|
||||
}
|
||||
<%-
|
||||
else
|
||||
-%>
|
||||
update_project_page();
|
||||
<% end %>
|
||||
<% else -%>
|
||||
TracksPages.show_edit_errors(html_for_error_messages());
|
||||
<% end %>
|
||||
|
||||
<% if @saved
|
||||
# only add these js functions if the project is saved
|
||||
-%>
|
||||
|
||||
function update_project_list_page() {
|
||||
<% if @state_changed -%>
|
||||
remove_and_re_add_project();
|
||||
<% else -%>
|
||||
replace_project_form_with_updated_project();
|
||||
<% end -%>
|
||||
|
||||
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 %>);
|
||||
TracksForm.set_project_name_and_default_project_name("<%= escape_javascript(@project.name)%>");
|
||||
$('div.project-edit-current').removeClass('project-edit-current');
|
||||
animate: function() {
|
||||
TracksPages.page_notify('notice', '<%=t('projects.project_saved_status')%>', 5);
|
||||
<% if source_view_is_one_of(:project_list, :review) -%>
|
||||
<%=object_name%>.update_project_list_page();
|
||||
<% else # assume source_view :project -%>
|
||||
<%=object_name%>.update_project_page();
|
||||
<% end %>
|
||||
},
|
||||
update_project_list_page: function() {
|
||||
<% if @state_changed -%>
|
||||
<%=object_name%>.remove_and_re_add_project();
|
||||
<% else -%>
|
||||
<%=object_name%>.replace_project_form_with_updated_project();
|
||||
<% end -%>
|
||||
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 %>);
|
||||
TracksForm.set_project_name_and_default_project_name("<%= escape_javascript(@project.name)%>");
|
||||
$('div.project-edit-current').removeClass('project-edit-current');
|
||||
},
|
||||
update_project_page: function() {
|
||||
<%=object_name%>.remove_project_edit_form();
|
||||
<%=object_name%>.update_and_show_project_settings();
|
||||
TracksForm.set_project_name("<%= escape_javascript(@project.name)%>");
|
||||
$("h2 span#project_name").html("<%= 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_and_default_tag_list("<%= escape_javascript(@project.default_tags)%>");
|
||||
<% end %>
|
||||
TracksPages.update_sidebar(<%=object_name%>.html_for_sidebar());
|
||||
},
|
||||
remove_project_edit_form: function() {
|
||||
<%-
|
||||
# do not remove() edit form as this will remove the DIV
|
||||
# that is needed to replace with the new form, so only empty the DIV
|
||||
-%>
|
||||
$('#<%=dom_id(@project, 'edit')%>').hide(500, function() {
|
||||
$('#<%=dom_id(@project, 'edit')%>').html("<!- empty ->");
|
||||
});
|
||||
},
|
||||
update_and_show_project_settings: function() {
|
||||
$('#<%=dom_id(@project, 'container')%>').html(<%=object_name%>.html_for_project_settings());
|
||||
$('#<%=dom_id(@project)%>').show();
|
||||
},
|
||||
replace_project_form_with_updated_project: function() {
|
||||
$('div#<%=dom_id(@project, 'container')%>').each(function(index, elem) {
|
||||
$(this).fadeOut(250, function() {
|
||||
<%
|
||||
# first add the updated project after the old one, then remove old one.
|
||||
# Using html() does not work, because it will replace the _content_ of
|
||||
# the container instead of the container itself, i.e. you will get
|
||||
# a container within a container which will break drag-and-drop sorting
|
||||
-%>
|
||||
$(this).after(<%=object_name%>.html_for_project_listing());
|
||||
$(this).remove();
|
||||
$('#<%=dom_id(@project, 'container')%>').fadeIn(500);
|
||||
})
|
||||
});
|
||||
},
|
||||
remove_and_re_add_project: function() {
|
||||
$('#<%=dom_id(@project, 'container')%>').slideUp(500, function() {
|
||||
$('#<%=dom_id(@project, 'container')%>').remove();
|
||||
$('#list-<%=@project.state%>-projects').append(<%=object_name%>.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.
|
||||
-%>
|
||||
html_for_project_listing: function() {
|
||||
return "<%= source_view_is_one_of(:project_list, :review) ? escape_javascript(render(:partial => 'project_listing', :object => @project, :locals=>{:suppress_drag_handle => source_view_is(:review)} )) : "" %>";
|
||||
},
|
||||
html_for_sidebar: function() {
|
||||
return "<%= source_view_is(:project) ? escape_javascript(render(:file => 'sidebar/sidebar')) : "" %>";
|
||||
},
|
||||
html_for_project_settings: function() {
|
||||
return "<%= source_view_is(:project) ? escape_javascript(render(:partial => 'project_settings', :object => @project )) : "" %>";
|
||||
}
|
||||
<% end # if @saved -%>
|
||||
}
|
||||
|
||||
function update_project_page() {
|
||||
remove_project_edit_form();
|
||||
update_and_show_project_settings();
|
||||
TracksForm.set_project_name("<%= escape_javascript(@project.name)%>");
|
||||
$("h2 span#project_name").html("<%= 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_and_default_tag_list("<%= escape_javascript(@project.default_tags)%>");
|
||||
<% end %>
|
||||
TracksPages.update_sidebar(html_for_sidebar());
|
||||
}
|
||||
|
||||
function remove_project_edit_form() {
|
||||
<%-
|
||||
# do not remove() edit form as this will remove the DIV that is needed to replace with the new form, so only empty the DIV
|
||||
-%>
|
||||
$('#<%=dom_id(@project, 'edit')%>').hide(500, function() {
|
||||
$('#<%=dom_id(@project, 'edit')%>').html("<!- empty ->");
|
||||
});
|
||||
}
|
||||
|
||||
function update_and_show_project_settings() {
|
||||
$('#<%=dom_id(@project, 'container')%>').html(html_for_project_settings());
|
||||
$('#<%=dom_id(@project)%>').show();
|
||||
}
|
||||
|
||||
function replace_project_form_with_updated_project() {
|
||||
$('div#<%=dom_id(@project, 'container')%>').each(function(index, elem) {
|
||||
$(this).fadeOut(250, function() {
|
||||
<%
|
||||
# first add the updated project after the old one, then remove old one.
|
||||
# Using html() does not work, because it will replace the _content_ of
|
||||
# the container instead of the container itself, i.e. you will get
|
||||
# a container within a container which will break drag-and-drop sorting
|
||||
-%>
|
||||
$(this).after(html_for_project_listing());
|
||||
$(this).remove();
|
||||
$('#<%=dom_id(@project, 'container')%>').fadeIn(500);
|
||||
})});
|
||||
}
|
||||
|
||||
function remove_and_re_add_project() {
|
||||
$('#<%=dom_id(@project, 'container')%>').slideUp(500, function() {
|
||||
$('#<%=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_one_of(:project_list, :review) ? escape_javascript(render(:partial => 'project_listing', :object => @project, :locals=>{:suppress_drag_handle => source_view_is(:review)} )) : "" %>";
|
||||
}
|
||||
|
||||
function html_for_sidebar() {
|
||||
return "<%= source_view_is(:project) ? escape_javascript(render(:file => 'sidebar/sidebar')) : "" %>";
|
||||
}
|
||||
|
||||
function html_for_project_settings() {
|
||||
return "<%= source_view_is(:project) ? escape_javascript(render(:partial => 'project_settings', :object => @project )) : "" %>";
|
||||
}
|
||||
|
||||
<% end # if @saved
|
||||
-%>
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>";
|
||||
}
|
||||
<%=object_name%>.animate();
|
||||
Loading…
Add table
Add a link
Reference in a new issue