DRY up javascript for form visibility toggling.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@644 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-11-18 08:05:39 +00:00
parent cb648ef141
commit ae95f03c5b
6 changed files with 46 additions and 43 deletions

View file

@ -9,7 +9,17 @@
<div id="input_box">
<div id="context_new_container">
<a id="toggle-new-context-form" href="#" accesskey="n" title="Create a new context">Create new context &#187;</a>
<div id="toggle_context_new" class="hide_form">
<a title="Hide new context form" accesskey="n">&laquo; Hide form</a>
<% apply_behavior '#toggle_context_new a:click', :prevent_default => true do |page|
page << "TracksForm.toggle('toggle_context_new', 'context_new', 'context-form',
'&laquo; Hide form', 'Hide new context form',
'Create a new context &#187;', 'Add a context');"
end
%>
</div>
<div id="context_new" class="context_new" style="display:block">
<% form_remote_tag(
:url => contexts_path,
@ -41,10 +51,4 @@
</div>
<%
sortable_element 'list-contexts', get_listing_sortable_options
apply_behavior '#toggle-new-context-form:click', :prevent_default => true do |page|
page['context_new'].toggle
page['context-form'].down('input').focus
#page << "Form.focusFirstElement('context-form');"
end
-%>

View file

@ -12,10 +12,16 @@
<div id="project_new_project_filler">
<div id="project_new_project_container">
<%= link_to_function("Create a new project &#187;",
"Element.toggle('project_new');Form.focusFirstElement('project-form');",
{:title => "Add a next action", :accesskey => "n"}) %>
<div id="toggle_project_new" class="hide_form">
<a title="Hide new project form" accesskey="n">&laquo; Hide form</a>
<% apply_behavior '#toggle_project_new a:click', :prevent_default => true do |page|
page << "TracksForm.toggle('toggle_project_new', 'project_new', 'project-form',
'&laquo; Hide form', 'Hide new project form',
'Create a new project &#187;', 'Add a project');"
end
%>
</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'},

View file

@ -7,16 +7,15 @@
%>
<div id="todo_new_action_container">
<div id="show_todo_new_action" style="display:none">
<%= link_to_function("Add a next action &#187;",
"todoItems.showNewActionForm();return false;",
{:title => "Add a next action"}) %>
</div>
<div id="hide_todo_new_action" style="display:block">
<%= link_to_function("&laquo; Hide form",
"todoItems.hideNewActionForm();return false;",
{:title => "Hide next action form", :accesskey => "n"}) %>
</div>
<div id="toggle_action_new" class="hide_form">
<a title="Hide new action form" accesskey="n">&laquo; Hide form</a>
<% apply_behavior '#toggle_action_new a:click', :prevent_default => true do |page|
page << "TracksForm.toggle('toggle_action_new', 'todo_new_action', 'todo-form-new-action',
'&laquo; Hide form', 'Hide next action form',
'Add a next action &#187;', 'Add a next action');"
end
%>
</div>
<div id="todo_new_action" style="display:block">

View file

@ -19,7 +19,21 @@ var Login = {
new CookieManager().setCookie('preferred_auth', 'database');
}
}
var TracksForm = {
toggle: function(toggleDivId, formContainerId, formId, hideLinkText, hideLinkTitle, showLinkText, showLinkTitle) {
$(formContainerId).toggle();
toggleDiv = $(toggleDivId);
toggleLink = toggleDiv.down('a');
if (toggleDiv.hasClassName('hide_form')) {
toggleLink.update(showLinkText).setAttribute('title', showLinkTitle);
}
else {
toggleLink.update(hideLinkText).setAttribute('title', hideLinkTitle);
Form.focusFirstElement(formId);
}
toggleDiv.toggleClassName('hide_form');
}
}
Ajax.Responders.register({
onCreate: function() {
if($('busy') && Ajax.activeRequestCount>0)

View file

@ -162,27 +162,7 @@ ToDoItems.prototype = {
parentElem = parentElem.parentNode;
}
return null;
},
showNewActionForm: function()
{
Element.show('todo_new_action');
Element.hide('show_todo_new_action');
$('show_todo_new_action').down('a').accessKey = '';
$('hide_todo_new_action').down('a').accessKey = 'n';
Element.show('hide_todo_new_action');
Form.focusFirstElement('todo-form-new-action');
},
hideNewActionForm: function()
{
Element.hide('todo_new_action');
Element.hide('hide_todo_new_action');
$('hide_todo_new_action').down('a').accessKey = '';
$('show_todo_new_action').down('a').accessKey = 'n';
Element.show('show_todo_new_action');
}
}
todoItems = new ToDoItems();

View file

@ -732,7 +732,7 @@ input#go_to_project, input#context_hide {
.edit_todo_form .submit_box input {
width:120px;
}
#hide_todo_new_action {
#hide_todo_new_action, .hide_form {
text-align:right;
}
#todo-form-new-action label, .edit_todo_form label {