mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Star toggling and todo checking working
Todo unchecking is still buggy, but needs a bunch more work to make it happen. Also added some useful globals to the standard layout for later access by application.js.
This commit is contained in:
parent
4c68144c93
commit
f9e6540ed2
8 changed files with 67 additions and 51 deletions
|
|
@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
|
|||
helper_method :current_user, :prefs
|
||||
|
||||
layout proc{ |controller| controller.mobile? ? "mobile" : "standard" }
|
||||
exempt_from_layout /\.js\.erb$/
|
||||
|
||||
before_filter :set_session_expiration
|
||||
before_filter :set_time_zone
|
||||
|
|
|
|||
|
|
@ -14,26 +14,12 @@ module TodosHelper
|
|||
:id => dom_id(@todo, 'form'),
|
||||
:class => dom_id(@todo, 'form') + " inline-form edit_todo_form" },
|
||||
&block )
|
||||
apply_behavior 'form.edit_todo_form', make_remote_form(
|
||||
:method => :put,
|
||||
:before => "todoSpinner = this.down('button.positive'); todoSpinner.startWaiting()",
|
||||
:loaded => "todoSpinner.stopWaiting()",
|
||||
:condition => "!(this.down('button.positive').isWaiting())"),
|
||||
:prevent_default => true
|
||||
end
|
||||
|
||||
def set_behavior_for_star_icon
|
||||
apply_behavior '.item-container a.star_item:click',
|
||||
remote_to_href(:method => 'put', :with => "{ _source_view : '#{@source_view}' }"),
|
||||
:prevent_default => true
|
||||
end
|
||||
|
||||
def remote_star_icon
|
||||
str = link_to( image_tag_for_star(@todo),
|
||||
link_to( image_tag_for_star(@todo),
|
||||
toggle_star_todo_path(@todo),
|
||||
:class => "icon star_item", :title => "star the action '#{@todo.description}'")
|
||||
set_behavior_for_star_icon
|
||||
str
|
||||
end
|
||||
|
||||
def remote_edit_menu_item(parameters, todo)
|
||||
|
|
@ -91,18 +77,9 @@ module TodosHelper
|
|||
:class => "recurring_icon", :title => recurrence_pattern_as_text(todo.recurring_todo))
|
||||
end
|
||||
|
||||
def set_behavior_for_toggle_checkbox
|
||||
parameters = "_source_view=#{@source_view}"
|
||||
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
|
||||
apply_behavior '.item-container input.item-checkbox:click',
|
||||
remote_function(:url => javascript_variable('this.value'), :method => 'put',
|
||||
:with => "'#{parameters}'")
|
||||
end
|
||||
|
||||
def remote_toggle_checkbox
|
||||
str = check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox')
|
||||
set_behavior_for_toggle_checkbox
|
||||
str
|
||||
check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox')
|
||||
end
|
||||
|
||||
def date_span
|
||||
|
|
|
|||
|
|
@ -37,11 +37,5 @@
|
|||
<div class="message"><p>Currently there are no incomplete actions in this context</p></div>
|
||||
</div>
|
||||
<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %>
|
||||
<% if @not_done.empty?
|
||||
# fix (hack) for #713
|
||||
set_behavior_for_star_icon
|
||||
set_behavior_for_toggle_checkbox
|
||||
end
|
||||
-%>
|
||||
</div><!-- [end:items] -->
|
||||
</div><!-- [end:c<%= context.id %>] -->
|
||||
|
|
@ -16,10 +16,12 @@
|
|||
<% bundle :name => "tracks_js" do %>
|
||||
<%= javascript_include_tag *%w[
|
||||
hoverIntent superfish application
|
||||
calendar calendar-en calendar-setup
|
||||
accesskey-hints todo-items niftycube
|
||||
protoload flashobject ] %>
|
||||
<% end %>
|
||||
<%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
|
||||
<%= javascript_tag "var SOURCE_VIEW = '#{@source_view}';" %>
|
||||
<%= javascript_tag "var TAG_NAME = '#{@tag_name}';" if @tag_name %>
|
||||
<link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" />
|
||||
<%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %>
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="Tracks" href="<%= search_plugin_path %>" />
|
||||
|
|
|
|||
|
|
@ -17,11 +17,5 @@
|
|||
<div class="message"><p>Currently there are no incomplete actions in this project</p></div>
|
||||
</div>
|
||||
<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "project" } %>
|
||||
<% if @not_done.empty?
|
||||
# fix (hack) for #713
|
||||
set_behavior_for_star_icon
|
||||
set_behavior_for_toggle_checkbox
|
||||
end
|
||||
-%>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
3
app/views/todos/toggle_star.js.erb
Normal file
3
app/views/todos/toggle_star.js.erb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<% if @saved -%>
|
||||
$('div#line_todo_<%= @todo.id %> a.star_item img').toggleClass('starred_todo').toggleClass('unstarred_todo');
|
||||
<% end -%>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
if @saved
|
||||
page[@todo].down('a.star_item').down('img').toggleClassName('starred_todo').toggleClassName('unstarred_todo')
|
||||
end
|
||||
|
|
@ -93,15 +93,63 @@ var TodoBehavior = {
|
|||
});
|
||||
}
|
||||
}
|
||||
// uncomment the next four lines for easier debugging with FireBug
|
||||
// Ajax.Responders.register({
|
||||
// onException: function(source, exception) {
|
||||
// console.error(exception);
|
||||
// }
|
||||
// });
|
||||
|
||||
/* fade flashes automatically */
|
||||
$(document).ready(function() {
|
||||
$(".alert").fadeIn(8000);
|
||||
/****************************************
|
||||
* Unobtrusive jQuery written by Eric Allen
|
||||
****************************************/
|
||||
|
||||
/* Set up authenticity token proplery */
|
||||
$(document).ajaxSend(function(event, request, settings) {
|
||||
if ( settings.type == 'POST' ) {
|
||||
settings.data = (settings.data ? settings.data + "&" : "")
|
||||
+ "authenticity_token=" + encodeURIComponent( AUTH_TOKEN ) + "&"
|
||||
+ "_source_view=" + encodeURIComponent( SOURCE_VIEW );
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
request.setRequestHeader("Accept", "text/javascript");
|
||||
});
|
||||
|
||||
function toggle_star_remote(ev){
|
||||
ev.preventDefault();
|
||||
$.post(this.href, {_method: 'put'}, null, 'script');
|
||||
}
|
||||
|
||||
function toggle_checkbox_remote(ev){
|
||||
params = {_method: 'put'};
|
||||
if(typeof(TAG_NAME) !== 'undefined')
|
||||
params._tag_name = TAG_NAME;
|
||||
$.post(this.value, params, null, 'script');
|
||||
}
|
||||
|
||||
function set_behavior_for_tag_edit_todo(){
|
||||
/*
|
||||
apply_behavior 'form.edit_todo_form', make_remote_form(
|
||||
:method => :put,
|
||||
:before => "todoSpinner = this.down('button.positive'); todoSpinner.startWaiting()",
|
||||
:loaded => "todoSpinner.stopWaiting()",
|
||||
:condition => "!(this.down('button.positive').isWaiting())"),
|
||||
:prevent_default => true
|
||||
*/
|
||||
}
|
||||
|
||||
function setup_container_toggles(){
|
||||
// bind handlers
|
||||
// set to cookied state
|
||||
}
|
||||
|
||||
/* Unobtrusive jQuery behavior */
|
||||
|
||||
$(document).ready(function() {
|
||||
/* fade flashes automatically */
|
||||
$(".alert").fadeIn(8000);
|
||||
|
||||
/* set behavior for star icon */
|
||||
$(".item-container a.star_item").
|
||||
live('click', toggle_star_remote);
|
||||
|
||||
/* set behavior for toggle checkboxes */
|
||||
$(".item-container input.item-checkbox").
|
||||
live('click', toggle_checkbox_remote);
|
||||
|
||||
setup_container_toggles();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue