mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-24 06:35:27 +00:00
Clear completed & add todo at bottom of list
This commit is contained in:
parent
b2308aa706
commit
7e674852bb
2 changed files with 26 additions and 23 deletions
|
|
@ -9,7 +9,9 @@ class HabitTracker.Models.Habit extends Backbone.Model
|
|||
up: true
|
||||
down: true
|
||||
done: false
|
||||
position: 0
|
||||
# TODO this is being calculated instead on habit creation in index_view
|
||||
# because HabitsCollection instance isn't available here. Fix that
|
||||
position: 0
|
||||
|
||||
isHabit: =>
|
||||
@get("habit_type")==1
|
||||
|
|
@ -50,10 +52,21 @@ class HabitTracker.Models.Habit extends Backbone.Model
|
|||
done = false if direction=="down"
|
||||
@set({ score: score, done: done })
|
||||
window.userStats.updateStats(this, delta)
|
||||
|
||||
|
||||
#send all the update information, as well as tack on userStats which will save to Users
|
||||
@save({ user_stats: window.userStats })
|
||||
|
||||
class HabitTracker.Collections.HabitsCollection extends Backbone.Collection
|
||||
model: HabitTracker.Models.Habit
|
||||
url: '/habits'
|
||||
comparator: (habit) ->
|
||||
habit.get("position")
|
||||
|
||||
# Filter down the list of all todo items that are finished.
|
||||
doneTodos: ->
|
||||
@filter (todo) ->
|
||||
todo.get('done') and todo.isTodo()
|
||||
|
||||
nextPosition: ->
|
||||
if (!@length) then return 1
|
||||
return @max() + 1
|
||||
|
|
@ -5,8 +5,8 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
|||
|
||||
events:
|
||||
"keypress .new-habit": "createOnEnter",
|
||||
"keyup .new-habit": "showTooltip",
|
||||
"click .todo-clear a": "clearCompleted"
|
||||
# "keyup .new-habit": "showTooltip", #TODO get this function todo.js
|
||||
"click .clear-completed": "clearCompleted"
|
||||
|
||||
initialize: () ->
|
||||
@options.habits.bind('reset', @addAll)
|
||||
|
|
@ -17,29 +17,19 @@ class HabitTracker.Views.Habits.IndexView extends Backbone.View
|
|||
createOnEnter: (e) ->
|
||||
input = $(e.target)
|
||||
if (!input.val() or e.keyCode != 13) then return
|
||||
@options.habits.create {name: input.val(), habit_type: input.attr('data-type')} #,
|
||||
#TODO
|
||||
# success: (habit) =>
|
||||
# @model = habit
|
||||
# error: (habit, jqXHR) =>
|
||||
# @model.set({errors: $.parseJSON(jqXHR.responseText)}
|
||||
@options.habits.create {name: input.val(), habit_type: input.attr('data-type'), position: @options.habits.nextPosition()},
|
||||
#TODO what's this all about?
|
||||
success: (habit) ->
|
||||
@model = habit
|
||||
error: (habit, jqXHR) ->
|
||||
@model.set({errors: $.parseJSON(jqXHR.responseText)})
|
||||
input.val('')
|
||||
|
||||
#TODO
|
||||
clearCompleted: ->
|
||||
# _.each(Todos.done(), function(todo){ todo.destroy(); });
|
||||
# return false;
|
||||
_.each @options.habits.doneTodos(), (todo) ->
|
||||
todo.destroy()
|
||||
return false
|
||||
|
||||
#TODO
|
||||
showTooltip: (e) ->
|
||||
# var tooltip = this.$(".ui-tooltip-top");
|
||||
# var val = this.input.val();
|
||||
# tooltip.fadeOut();
|
||||
# if (this.tooltipTimeout) clearTimeout(this.tooltipTimeout);
|
||||
# if (val == '' || val == this.input.attr('placeholder')) return;
|
||||
# var show = function(){ tooltip.show().fadeIn(); };
|
||||
# this.tooltipTimeout = _.delay(show, 1000);
|
||||
|
||||
# TODO create a view & template, bind to existing element
|
||||
updateStats: () =>
|
||||
stats = window.userStats
|
||||
|
|
|
|||
Loading…
Reference in a new issue