var TracksForm = { toggle: function(toggleLinkId, formContainerId, formId, hideLinkText, hideLinkTitle, showLinkText, showLinkTitle) { form=$('#'+formContainerId) form.toggle(); toggleLink = $('#'+toggleLinkId); if (!form.is(':visible')) { toggleLink.text(showLinkText).attr('title', showLinkTitle); } else { toggleLidefault_ajax_optionsnk.text(hideLinkText).attr('title', hideLinkTitle); $('#'+formId+' input:text:first').focus(); } toggleLink.parent().toggleClass('hide_form'); }, set_project_name: function (name) { $('input#todo_project_name').val(name); }, set_project_name_for_multi_add: function (name) { $('#multi_todo_project_name').val(name); }, set_context_name: function (name) { $('input#todo_context_name').val(name); }, set_context_name_for_multi_add: function (name) { $('#multi_todo_context_name').val(name); }, set_context_name_and_default_context_name: function (name) { TracksForm.set_context_name(name); $('input[name=default_context_name]').val(name); }, set_project_name_and_default_project_name: function (name) { TracksForm.set_project_name(''); $('#default_project_name_id').val(name); $('#project_name').html(name); }, set_tag_list: function (name) { $('input#tag_list').val(name); }, set_tag_list_for_multi_add: function (name) { $('#multi_tag_list').val(name); }, setup_behavior: function() { /* toggle new todo form for single todo */ $('#toggle_action_new').click(function(){ if ($("#todo_multi_add").is(':visible')) { /* hide multi next action form first */ $('#todo_new_action').show(); $('#todo_multi_add').hide(); $('a#toggle_multi').text("Add multiple next actions"); } TracksForm.toggle('toggle_action_new', 'todo_new_action', 'todo-form-new-action', '« Hide form', 'Hide next action form', 'Add a next action »', 'Add a next action'); }); /* toggle new todo form for multi edit */ $('#toggle_multi').click(function(){ if ($("#todo_multi_add").is(':visible')) { $('#todo_new_action').show(); $('#todo_multi_add').hide(); $('a#toggle_multi').text("Add multiple next actions"); } else { $('#todo_new_action').hide(); $('#todo_multi_add').show(); $('a#toggle_multi').text("Add single next action"); $('a#toggle_action_new').text('« Hide form'); } }); /* add behavior to clear the date both buttons for show_from and due */ $(".date_clear").live('click', function() { $(this).prev().val(''); }); /* 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'); }); /* submit todo form after entering new todo */ $("button#todo_new_action_submit").live('click', function (ev) { if (TodoItems.askIfNewContextProvided('', this)) submit_with_ajax_and_block_element('form#todo-form-new-action', $(this)); return false; }); /* submit multi-todo form after entering multiple new todos */ $("button#todo_multi_new_action_submit").live('click', function (ev) { if (TodoItems.askIfNewContextProvided('multi_', this)) submit_with_ajax_and_block_element('form#todo-form-multi-new-action', $(this)); return false; }); } } var TracksPages = { show_errors: function (html) { $('div#error_status').html(html); $('div#error_status').show(); }, show_edit_errors: function(html) { $('div#edit_error_status').html(html); $('div#edit_error_status').show(); }, show_errors_for_multi_add: function(html) { $('div#multiple_error_status').html(html); $('div#multiple_error_status').show(); }, hide_errors: function() { $('div#error_status').hide(); $('div#edit_error_status').hide(); $('div#multiple_error_status').hide(); }, update_sidebar: function(html) { $('#sidebar').html(html); }, setup_nifty_corners: function() { Nifty("div#recurring_new_container","normal"); Nifty("div#context_new_container","normal"); Nifty("div#feedlegend","normal"); Nifty("div#feedicons-project","normal"); Nifty("div#feedicons-context","normal"); Nifty("div#todo_new_action_container","normal"); Nifty("div#project_new_project_container","normal"); }, page_notify: function(type, message, fade_duration_in_sec) { flash = $('h4#flash'); flash.html("

"+message+"

"); flash = $('h4#flash'); flash.show(); flash.fadeOut(fade_duration_in_sec*1000); }, set_page_badge: function(count) { $('#badge_count').html(count); }, setup_behavior: function () { /* main menu */ $('ul.sf-menu').superfish({ delay: 250, animation: { opacity:'show', height:'show' }, autoArrows: false, dropShadows: false, speed: 'fast' }); /* context menu */ $('ul.sf-item-menu').superfish({ delay: 100, animation: { opacity:'show', height:'show' }, autoArrows: false, dropShadows: false, speed: 'fast', onBeforeShow: function() { /* highlight todo */ $(this.parent().parent().parent()).addClass("sf-item-selected"); }, onHide: function() { /* remove hightlight from todo */ $(this.parent().parent().parent()).removeClass("sf-item-selected"); } }); /* for toggle notes link in mininav */ $("#toggle-notes-nav").click(function () { $(".todo_notes").toggle(); }); /* fade flashes and alerts in automatically */ $(".alert").fadeOut(8000); /* for edit project form and edit todo form * TODO: refactor to separate calls from project and todo */ $('.edit-form a.negative').live('click', function(){ $(this).parents('.edit-form').fadeOut(200, function () { $(this).parents('.list').find('.project').fadeIn(500); $(this).parents('.container').find('.item-show').fadeIn(500); }) }); } } var TodoItemsContainer = { // public ensureVisibleWithEffectAppear: function(elemId){ $('#'+elemId).fadeIn(500); }, expandNextActionListing: function(itemsElem, skipAnimation) { itemsElem = $(itemsElem); if(skipAnimation == true) { itemsElem.show(); } else { itemsElem.show('blind', 400); } TodoItems.showContainer(itemsElem.parentNode); }, collapseNextActionListing: function(itemsElem, skipAnimation) { itemsElem = $(itemsElem); if(skipAnimation == true) { itemsElem.hide(); } else { itemsElem.hide('blind', 400); } TodoItems.hideContainer(itemsElem.parentNode); }, ensureContainerHeight: function(itemsElem) { $(itemsElem).css({ height: '', overflow: '' }); }, expandNextActionListingByContext: function(itemsElemId, skipAnimation){ TodoItems.expandNextActionListing($('#'+itemsElemId).get(), skipAnimation); }, setup_container_toggles: function(){ // bind handlers $('.container_toggle').click(function(evt){ toggle_target = $(this.parentNode.parentNode).find('.toggle_target'); if(toggle_target.is(':visible')){ // hide it imgSrc = $(this).find('img').attr('src'); $(this).find('img').attr('src', imgSrc.replace('collapse', 'expand')); $.cookie(TodoItemsContainer.buildCookieName(this.parentNode.parentNode), true); toggle_target.slideUp(500); } else { // show it imgSrc = $(this).find('img').attr('src'); $(this).find('img').attr('src', imgSrc.replace('expand', 'collapse')); $.cookie(TodoItemsContainer.buildCookieName(this.parentNode.parentNode), null); toggle_target.slideDown(500); } return false; }); // set to cookied state $('.container.context').each(function(){ if($.cookie(TodoItemsContainer.buildCookieName(this))=="true"){ imgSrc = $(this).find('.container_toggle img').attr('src'); if (imgSrc) { $(this).find('.container_toggle img').attr('src', imgSrc.replace('collapse', 'expand')); $(this).find('.toggle_target').hide(); } } }); }, // private buildCookieName: function(containerElem) { tracks_login = $.cookie('tracks_login'); return 'tracks_'+tracks_login+'_context_' + containerElem.id + '_collapsed'; }, showContainer: function(containerElem) { imgSrc = $(containerElem).find('.container_toggle img').attr('src'); $(containerElem).find('.container_toggle img').attr('src', imgSrc.replace('expand', 'collapse')); }, hideContainer: function (containerElem) { imgSrc = $(containerElem).find('.container_toggle img').attr('src'); $(containerElem).find('.container_toggle img').attr('src', imgSrc.replace('collapse', 'expand')); } } var TodoItems = { getContextsForAutocomplete: function (term, element_to_block) { var allContexts = null; params = default_ajax_options_for_scripts('GET', relative_to_root('contexts.autocomplete'), element_to_block); params.data = "term="+term; params.dataType = "json"; params.async = false; params.success = function(result){ allContexts = result; } $.ajax(params); return allContexts; }, askIfNewContextProvided: function(source, element_to_block) { var givenContextName = $('#'+source+'todo_context_name').val(); if (givenContextName.length == 0) return true; // do nothing and depend on rails validation error contexts = TodoItems.getContextsForAutocomplete(givenContextName, element_to_block); if (contexts) { for (i=0; i