diff --git a/app/assets/javascripts/habits.js.coffee b/app/assets/javascripts/habits.js.coffee index 761567942f..18d631ca4e 100644 --- a/app/assets/javascripts/habits.js.coffee +++ b/app/assets/javascripts/habits.js.coffee @@ -1,3 +1,30 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + +$(document).ready -> + $("#habits").sortable + axis: "y" + dropOnEmpty: false + cursor: "move" + items: "li" + opacity: 0.4 + scroll: true + update: -> + $.ajax + type: "post" + data: $("#habits").sortable("serialize") + dataType: "script" + complete: (request) -> + $("#habits").effect "highlight" + + url: "/habits/sort" + +(($) -> + $.fn.highlight = -> + $(this).css + color: "red" + background: "yellow" + + $(this).fadeIn() +) jQuery \ No newline at end of file diff --git a/app/assets/stylesheets/habits.css.scss b/app/assets/stylesheets/habits.css.scss index a5480d8db0..0f56e61bd0 100644 --- a/app/assets/stylesheets/habits.css.scss +++ b/app/assets/stylesheets/habits.css.scss @@ -8,6 +8,10 @@ .good { background-color:rgb(147, 196, 125); } .done { background-color:rgb(201, 218, 248); } -#habits ul, #daily ul{ +#habits, #daily { list-style:none; } + +#habits li:hover, #daily li:hover { + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/habits_controller.rb b/app/controllers/habits_controller.rb index fa83c1998a..2906c73101 100644 --- a/app/controllers/habits_controller.rb +++ b/app/controllers/habits_controller.rb @@ -95,4 +95,13 @@ class HabitsController < ApplicationController end end end + + def sort + current_user.habits.each do |habit| + logger.fatal params['habit'].index(habit.id.to_s) + habit.position = params['habit'].index(habit.id.to_s) + habit.save + end + render :nothing => true + end end diff --git a/app/views/habits/_habit.html.erb b/app/views/habits/_habit.html.erb index f228b493b6..ca0725c343 100644 --- a/app/views/habits/_habit.html.erb +++ b/app/views/habits/_habit.html.erb @@ -1,4 +1,5 @@ -
- Habits-
|
- Daily-
|