mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Recurring todos mostly working now
This commit is contained in:
parent
77a088acdd
commit
e43a7945d5
8 changed files with 90 additions and 160 deletions
|
|
@ -11,19 +11,15 @@ module RecurringTodosHelper
|
|||
end
|
||||
|
||||
def recurring_todo_remote_delete_icon
|
||||
str = link_to( image_tag_for_delete,
|
||||
link_to( image_tag_for_delete,
|
||||
recurring_todo_path(@recurring_todo), :id => "delete_icon_"+@recurring_todo.id.to_s,
|
||||
:class => "icon delete_icon", :title => "delete the recurring action '#{@recurring_todo.description}'")
|
||||
set_behavior_for_delete_icon
|
||||
str
|
||||
end
|
||||
|
||||
def recurring_todo_remote_star_icon
|
||||
str = link_to( image_tag_for_star(@recurring_todo),
|
||||
link_to( image_tag_for_star(@recurring_todo),
|
||||
toggle_star_recurring_todo_path(@recurring_todo),
|
||||
:class => "icon star_item", :title => "star the action '#{@recurring_todo.description}'")
|
||||
set_behavior_for_star_icon
|
||||
str
|
||||
end
|
||||
|
||||
def recurring_todo_remote_edit_icon
|
||||
|
|
@ -31,7 +27,6 @@ module RecurringTodosHelper
|
|||
str = link_to( image_tag_for_edit(@recurring_todo),
|
||||
edit_recurring_todo_path(@recurring_todo),
|
||||
:class => "icon edit_icon")
|
||||
set_behavior_for_edit_icon
|
||||
else
|
||||
str = '<a class="icon">' + image_tag("blank.png") + "</a> "
|
||||
end
|
||||
|
|
@ -40,7 +35,6 @@ module RecurringTodosHelper
|
|||
|
||||
def recurring_todo_remote_toggle_checkbox
|
||||
str = check_box_tag('item_id', toggle_check_recurring_todo_path(@recurring_todo), @recurring_todo.completed?, :class => 'item-checkbox')
|
||||
set_behavior_for_toggle_checkbox
|
||||
str
|
||||
end
|
||||
|
||||
|
|
@ -53,26 +47,4 @@ module RecurringTodosHelper
|
|||
def image_tag_for_edit(todo)
|
||||
image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(todo, 'edit_icon'))
|
||||
end
|
||||
|
||||
def set_behavior_for_delete_icon
|
||||
parameters = "_source_view=#{@source_view}"
|
||||
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
|
||||
apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page|
|
||||
page.confirming "'Are you sure that you want to ' + this.title + '?'" do
|
||||
page << "itemContainer = this.up('.item-container'); itemContainer.startWaiting();"
|
||||
page << remote_to_href(:method => 'delete', :with => "'#{parameters}'", :complete => "itemContainer.stopWaiting();")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_behavior_for_edit_icon
|
||||
parameters = "_source_view=#{@source_view}"
|
||||
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
|
||||
apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page|
|
||||
page << "Effect.Pulsate(this);"
|
||||
page << remote_to_href(:method => 'get', :with => "'#{parameters}'")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
<% form_remote_tag(
|
||||
:url => recurring_todo_path(@recurring_todo), :method => :put,
|
||||
:html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' },
|
||||
:before => "$('recurring_todo_edit_action_submit').startWaiting()",
|
||||
:complete => "$('recurring_todo_edit_action_submit').stopWaiting();",
|
||||
:condition => "!$('recurring_todo_edit_action_submit').isWaiting()") do
|
||||
:before => "$('#recurring_todo_edit_action_submit').block({message: null})",
|
||||
:complete => "$('#recurring_todo_edit_action_submit').unblock();$('#recurring-todo-form-edit-action').clearForm();") do
|
||||
|
||||
-%>
|
||||
<div id="edit_status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
|
|
@ -20,59 +20,13 @@
|
|||
<label for="edit_recurring_todo_project_name">Project</label>
|
||||
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @recurring_todo.project.nil? ? 'None' : @recurring_todo.project.name.gsub(/"/,""") %>" />
|
||||
<div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div>
|
||||
<script type="text/javascript">
|
||||
projectAutoCompleter = new Autocompleter.Local('edit_recurring_todo_project_name', 'edit_project_list', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:false});
|
||||
function selectDefaultContext() {
|
||||
todoContextNameElement = $('edit_recurring_todo_context_name');
|
||||
defaultContextName = todoContextNameElement.projectDefaultContextsMap[this.value];
|
||||
if (defaultContextName && !todoContextNameElement.editedByTracksUser) {
|
||||
todoContextNameElement.value = defaultContextName;
|
||||
}
|
||||
}
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('edit_recurring_todo_tag_list');
|
||||
defaultTagList = todoTagListElement.projectDefaultTagsMap[this.value];
|
||||
if (defaultTagList && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTagList;
|
||||
}
|
||||
}
|
||||
Event.observe($('edit_recurring_todo_project_name'), "focus", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "click", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "blur", selectDefaultContext.bind($('edit_recurring_todo_project_name')));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "blur", selectDefaultTags.bind($('edit_recurring_todo_project_name')));
|
||||
</script>
|
||||
|
||||
|
||||
<label for="edit_recurring_todo_context_name">Context</label>
|
||||
<input id="edit_recurring_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @recurring_todo.context.name %>" />
|
||||
<div class="page_name_auto_complete" id="edit_context_list" style="display:none"></div>
|
||||
<script type="text/javascript">
|
||||
var contextAutoCompleter;
|
||||
function initializeNamesForAutoComplete(contextNamesForAutoComplete) {
|
||||
if (contextNamesForAutoComplete.length == 0 || contextNamesForAutoComplete[0].length == 0) {
|
||||
return;
|
||||
}
|
||||
contextAutoCompleter = new Autocompleter.Local('edit_recurring_todo_context_name', 'edit_context_list', contextNamesForAutoComplete, {choices:100,autoSelect:false});
|
||||
Event.observe($('edit_recurring_todo_context_name'), "focus", function(){ $('edit_recurring_todo_context_name').editedByTracksUser = true; });
|
||||
Event.observe($('edit_recurring_todo_context_name'), "focus", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
Event.observe($('edit_recurring_todo_context_name'), "click", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
}
|
||||
function updateContextNamesForAutoComplete(contextNamesForAutoComplete) {
|
||||
if (contextAutoCompleter) { // i.e. if we're already initialized
|
||||
contextAutoCompleter.options.array = contextNamesForAutoComplete
|
||||
} else {
|
||||
initializeNamesForAutoComplete(contextNamesForAutoComplete)
|
||||
}
|
||||
}
|
||||
initializeNamesForAutoComplete(<%= context_names_for_autocomplete %>);
|
||||
$('edit_recurring_todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')');
|
||||
</script>
|
||||
|
||||
<label for="edit_recurring_todo_tag_list">Tags (separate with commas)</label>
|
||||
<%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%>
|
||||
<script type="text/javascript">
|
||||
$('edit_recurring_todo_tag_list').projectDefaultTagsMap = eval('(' + <%= @default_project_tags_map %> + ')');
|
||||
Event.observe($('edit_recurring_todo_tag_list'), "focus", function(){ $('edit_recurring_todo_tag_list').editedByTracksUser = true; });
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recurring_edit_period_id">
|
||||
|
|
@ -149,13 +103,11 @@
|
|||
<%=image_tag("accept.png", :alt => "") %>
|
||||
Update
|
||||
</button>
|
||||
<button type="button" class="positive" id="recurring_todo_edit_action_cancel" tabindex="15" onclick="TracksForm.toggle_overlay();">
|
||||
<button type="button" class="positive" id="recurring_todo_edit_action_cancel" tabindex="15">
|
||||
<%=image_tag("cancel.png", :alt => "") %>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= calendar_setup( "recurring_todo_edit_start_from" ) %>
|
||||
<%= calendar_setup( "recurring_todo_edit_end_date" ) %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
<% form_remote_tag(
|
||||
:url => recurring_todos_path, :method => :post,
|
||||
:html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' },
|
||||
:before => "$('recurring_todo_new_action_submit').startWaiting()",
|
||||
:complete => "$('recurring_todo_new_action_submit').stopWaiting();",
|
||||
:condition => "!$('recurring_todo_new_action_submit').isWaiting()") do
|
||||
:before => "$('#recurring_todo_new_action_submit').block({message: null})",
|
||||
:complete => "$('#recurring_todo_new_action_submit').unblock();$('#recurring-todo-form-new-action').clearForm();") do
|
||||
-%>
|
||||
<div id="new_status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
|
|
@ -17,59 +16,12 @@
|
|||
<label for="recurring_todo_project_name">Project</label>
|
||||
<input id="recurring_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="" />
|
||||
<div class="page_name_auto_complete" id="project_list" style="display:none"></div>
|
||||
<script type="text/javascript">
|
||||
projectAutoCompleter = new Autocompleter.Local('recurring_todo_project_name', 'project_list', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:false});
|
||||
function selectDefaultContext() {
|
||||
todoContextNameElement = $('recurring_todo_context_name');
|
||||
defaultContextName = todoContextNameElement.projectDefaultContextsMap[this.value];
|
||||
if (defaultContextName && !todoContextNameElement.editedByTracksUser) {
|
||||
todoContextNameElement.value = defaultContextName;
|
||||
}
|
||||
}
|
||||
Event.observe($('recurring_todo_project_name'), "focus", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('recurring_todo_project_name'), "click", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('recurring_todo_project_name'), "blur", selectDefaultContext.bind($('recurring_todo_project_name')));
|
||||
</script>
|
||||
|
||||
<label for="recurring_todo_context_name">Context</label>
|
||||
<input id="recurring_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="" />
|
||||
<div class="page_name_auto_complete" id="context_list" style="display:none"></div>
|
||||
<script type="text/javascript">
|
||||
var contextAutoCompleter;
|
||||
function initializeNamesForAutoComplete(contextNamesForAutoComplete) {
|
||||
if (contextNamesForAutoComplete.length == 0 || contextNamesForAutoComplete[0].length == 0) {
|
||||
return;
|
||||
}
|
||||
contextAutoCompleter = new Autocompleter.Local('recurring_todo_context_name', 'context_list', contextNamesForAutoComplete, {choices:100,autoSelect:false});
|
||||
Event.observe($('recurring_todo_context_name'), "focus", function(){ $('recurring_todo_context_name').editedByTracksUser = true; });
|
||||
Event.observe($('recurring_todo_context_name'), "focus", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
Event.observe($('recurring_todo_context_name'), "click", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
}
|
||||
function updateContextNamesForAutoComplete(contextNamesForAutoComplete) {
|
||||
if (contextAutoCompleter) { // i.e. if we're already initialized
|
||||
contextAutoCompleter.options.array = contextNamesForAutoComplete
|
||||
} else {
|
||||
initializeNamesForAutoComplete(contextNamesForAutoComplete)
|
||||
}
|
||||
}
|
||||
initializeNamesForAutoComplete(<%= context_names_for_autocomplete %>);
|
||||
$('recurring_todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')');
|
||||
</script>
|
||||
|
||||
<label for="tag_list">Tags (separate with commas)</label>
|
||||
<%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 -%>
|
||||
<script type="text/javascript">
|
||||
$('tag_list').projectDefaultTagsMap = eval('(' + <%= @default_project_tags_map %> + ')');
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('tag_list');
|
||||
defaultTagList = todoTagListElement.projectDefaultTagsMap[this.value];
|
||||
if (defaultTagList && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTagList;
|
||||
}
|
||||
}
|
||||
Event.observe($('recurring_todo_project_name'), "blur", selectDefaultTags.bind($('recurring_todo_project_name')));
|
||||
Event.observe($('tag_list'), "focus", function(){ $('tag_list').editedByTracksUser = true; });
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recurring_period_id">
|
||||
|
|
@ -79,8 +31,6 @@
|
|||
<%= radio_button_tag('recurring_todo[recurring_period]', 'weekly')%> Weekly<br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_period]', 'monthly')%> Monthly<br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_period]', 'yearly')%> Yearly<br/>
|
||||
<% apply_behaviour "#recurring_period:click",
|
||||
"TracksForm.hide_all_recurring(); $('recurring_'+TracksForm.get_period()).show();" %>
|
||||
</div>
|
||||
<div id="recurring_timespan">
|
||||
<br/>
|
||||
|
|
@ -147,13 +97,11 @@
|
|||
<%=image_tag("accept.png", :alt => "") %>
|
||||
Create
|
||||
</button>
|
||||
<button type="button" class="positive" id="recurring_todo_new_action_cancel" tabindex="15" onclick="Form.reset('recurring-todo-form-new-action');Form.focusFirstElement('recurring-todo-form-new-action');TracksForm.hide_all_recurring(); $('recurring_daily').show();TracksForm.toggle_overlay();">
|
||||
<button type="button" class="positive" id="recurring_todo_new_action_cancel" tabindex="15">
|
||||
<%=image_tag("cancel.png", :alt => "") %>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= calendar_setup( "recurring_todo_start_from" ) %>
|
||||
<%= calendar_setup( "recurring_todo_end_date" ) %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ page.replace_html 'new_status', "#{error_messages_for('recurring_todo')}"
|
|||
page.notify :notice, @message, 5.0
|
||||
if @recurring_saved
|
||||
# reset form
|
||||
page << "TracksForm.hide_all_recurring(); $('recurring_daily').show();"
|
||||
page << "Form.reset('recurring-todo-form-new-action');"
|
||||
page << "Form.focusFirstElement('recurring-todo-form-new-action');"
|
||||
page << "TracksForm.hide_all_recurring(); $('#recurring_daily').show();"
|
||||
page << "$('#recurring_todo_new_action_submit').unblock();$('#recurring-todo-form-new-action').clearForm();"
|
||||
# hide overlayed edit form
|
||||
page << "TracksForm.toggle_overlay();"
|
||||
# insert new recurring todo
|
||||
|
|
|
|||
|
|
@ -33,16 +33,4 @@
|
|||
<div id="edit-recurring-todo" class="edit-form" style="display:none">
|
||||
<div class='placeholder'>This should not be visible</div>
|
||||
</div>
|
||||
</div><%
|
||||
|
||||
# need to add behaviour for edit form here. Behaviour defined in partials are
|
||||
# not generated for
|
||||
apply_behaviour "#recurring_edit_period:click",
|
||||
"TracksForm.hide_all_edit_recurring(); $('recurring_edit_'+TracksForm.get_edit_period()).show();"
|
||||
-%>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.onload=function(){
|
||||
Nifty("div#recurring_new_container","normal");
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
3
app/views/recurring_todos/toggle_star.js.erb
Normal file
3
app/views/recurring_todos/toggle_star.js.erb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<% if @saved -%>
|
||||
$('div#recurring_todo_<%= @recurring_todo.id %> a.star_item img').toggleClass('starred_todo').toggleClass('unstarred_todo');
|
||||
<% end -%>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
if @saved
|
||||
page[@recurring_todo].down('a.star_item').down('img').toggleClassName('starred_todo').toggleClassName('unstarred_todo')
|
||||
end
|
||||
|
|
@ -94,6 +94,20 @@ var TodoBehavior = {
|
|||
}
|
||||
}
|
||||
|
||||
$.fn.clearForm = function() {
|
||||
return this.each(function() {
|
||||
var type = this.type, tag = this.tagName.toLowerCase();
|
||||
if (tag == 'form')
|
||||
return $(':input',this).clearForm();
|
||||
if (type == 'text' || type == 'password' || tag == 'textarea')
|
||||
this.value = '';
|
||||
else if (type == 'checkbox' || type == 'radio')
|
||||
this.checked = false;
|
||||
else if (tag == 'select')
|
||||
this.selectedIndex = -1;
|
||||
});
|
||||
};
|
||||
|
||||
/****************************************
|
||||
* Unobtrusive jQuery written by Eric Allen
|
||||
****************************************/
|
||||
|
|
@ -209,8 +223,11 @@ function setup_container_toggles(){
|
|||
/* Unobtrusive jQuery behavior */
|
||||
|
||||
$(document).ready(function() {
|
||||
/* Nifty corners */
|
||||
Nifty("div#recurring_new_container","normal");
|
||||
|
||||
/* fade flashes and alerts in automatically */
|
||||
$(".alert").fadeOut(5000);
|
||||
$(".alert").fadeOut(8000);
|
||||
|
||||
/* set behavior for star icon */
|
||||
$(".item-container a.star_item").
|
||||
|
|
@ -238,5 +255,59 @@ $(document).ready(function() {
|
|||
$(".date_clear").live('click', function() {
|
||||
/* add behavior to clear the date both buttons for show_from and due */
|
||||
$(this).prev().val('');
|
||||
})
|
||||
});
|
||||
|
||||
/* recurring todo behavior */
|
||||
|
||||
/* behavior for delete icon */
|
||||
$('.item-container a.delete_icon').live('click', function(evt){
|
||||
evt.preventDefault();
|
||||
params = {};
|
||||
if(typeof(TAG_NAME) !== 'undefined'){
|
||||
params._tag_name = TAG_NAME;
|
||||
}
|
||||
if(confirm("Are you sure that you want to "+this.title+"?")){
|
||||
itemContainer = $(this).parents(".item-container");
|
||||
itemContainer.block({message: null});
|
||||
params._method = 'delete';
|
||||
$.post(this.href, params, function(){
|
||||
itemContainer.unblock();
|
||||
}, 'script');
|
||||
}
|
||||
});
|
||||
|
||||
/* behavior for edit icon */
|
||||
$('.item-container a.edit_icon').live('click', function(evt){
|
||||
evt.preventDefault();
|
||||
params = {};
|
||||
if(typeof(TAG_NAME) !== 'undefined'){
|
||||
params._tag_name = TAG_NAME;
|
||||
}
|
||||
itemContainer = $(this).parents(".item-container");
|
||||
$(this).effect('pulsate', {times: 1}, 800);
|
||||
$.get(this.href, params, function(){
|
||||
}, 'script');
|
||||
});
|
||||
|
||||
$("#recurring_todo_new_action_cancel").click(function(){
|
||||
$('#recurring-todo-form-new-action').clearForm();
|
||||
$('#recurring-todo-form-new-action input:first').focus();
|
||||
TracksForm.hide_all_recurring();
|
||||
$('#recurring_daily').show();
|
||||
TracksForm.toggle_overlay();
|
||||
});
|
||||
|
||||
$("#recurring_todo_edit_action_cancel").live('click', function(){
|
||||
$('#recurring-todo-form-edit-action').clearForm();
|
||||
$('#recurring-todo-form-edit-action input:first').focus();
|
||||
TracksForm.hide_all_recurring();
|
||||
$('#recurring_daily').show();
|
||||
TracksForm.toggle_overlay();
|
||||
});
|
||||
$("#recurring_edit_period input").live('click', function(){
|
||||
$.each(['daily', 'weekly', 'monthly', 'yearly'], function(){
|
||||
$('#recurring_edit_'+this).hide();
|
||||
});
|
||||
$('#recurring_edit_'+this.id.split('_')[5]).show();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue