fix for "can't delete todos"

This commit is contained in:
Tyler Renelle 2013-01-29 14:09:04 -05:00
parent bb4fa87f4a
commit 69e577818a

View file

@ -155,7 +155,15 @@ ready (model) ->
exports.del = (e, el) -> exports.del = (e, el) ->
# Derby extends model.at to support creation from DOM nodes # Derby extends model.at to support creation from DOM nodes
task = model.at(e.target) #task = model.at(e.target)
# FIXME normally that would work, and we'd later simply call `user.del task` (instead of that 4-liner down there)
# however, see https://github.com/lefnire/habitrpg/pull/226#discussion_r2810391
id = $(e.target).parents('li.task').attr('data-id')
return unless id?
task = user.at "tasks.#{id}"
type = task.get('type')
history = task.get('history') history = task.get('history')
if history and history.length>2 if history and history.length>2
@ -166,7 +174,7 @@ ready (model) ->
return # Cancel. Don't delete, don't hurt user return # Cancel. Don't delete, don't hurt user
else else
task.set('type','habit') # hack to make sure it hits HP, instead of performing "undo checkbox" task.set('type','habit') # hack to make sure it hits HP, instead of performing "undo checkbox"
scoring.score(task.get('id'), direction:'down') scoring.score(id, direction:'down')
# prevent accidently deleting long-standing tasks # prevent accidently deleting long-standing tasks
else else
@ -176,8 +184,12 @@ ready (model) ->
#TODO bug where I have to delete from _users.tasks AND _{type}List, #TODO bug where I have to delete from _users.tasks AND _{type}List,
# fix when query subscriptions implemented properly # fix when query subscriptions implemented properly
$('[rel=tooltip]').tooltip('hide') $('[rel=tooltip]').tooltip('hide')
user.del('tasks.'+task.get('id'))
task.remove() ids = user.get("#{type}Ids")
ids.splice(ids.indexOf(id),1)
user.del('tasks.'+id)
user.set("#{type}Ids", ids)
exports.clearCompleted = (e, el) -> exports.clearCompleted = (e, el) ->
todoIds = user.get('todoIds') todoIds = user.get('todoIds')