2013-05-19 22:48:51 +00:00
|
|
|
algos = require 'habitrpg-shared/script/algos'
|
2013-05-19 17:53:13 +00:00
|
|
|
helpers = require 'habitrpg-shared/script/helpers'
|
2013-05-19 22:48:51 +00:00
|
|
|
_ = require 'lodash'
|
2013-02-08 22:44:06 +00:00
|
|
|
moment = require 'moment'
|
2013-05-21 23:40:46 +00:00
|
|
|
misc = require './misc'
|
2013-02-08 22:44:06 +00:00
|
|
|
|
|
|
|
|
appExports.clearCompleted = (e, el) ->
|
2013-04-10 23:24:33 +00:00
|
|
|
completedIds = _.pluck( _.where(model.get('_todoList'), {completed:true}), 'id')
|
2013-02-09 01:48:31 +00:00
|
|
|
todoIds = user.get('todoIds')
|
2013-05-22 10:29:24 +00:00
|
|
|
_.each completedIds, (id) -> user.del "tasks.#{id}"; true
|
2013-04-10 23:24:33 +00:00
|
|
|
user.set 'todoIds', _.difference(todoIds, completedIds)
|
2013-02-08 22:44:06 +00:00
|
|
|
|
2013-03-18 00:30:54 +00:00
|
|
|
|
|
|
|
|
###
|
|
|
|
|
Undo
|
|
|
|
|
###
|
|
|
|
|
appExports.undo = () ->
|
|
|
|
|
undo = model.get '_undo'
|
2013-03-18 03:15:19 +00:00
|
|
|
clearTimeout(undo.timeoutId) if undo?.timeoutId
|
|
|
|
|
model.del '_undo'
|
2013-05-29 09:23:23 +00:00
|
|
|
_.each undo.stats, (val, key) -> user.set "stats.#{key}", val; true
|
2013-03-18 00:30:54 +00:00
|
|
|
taskPath = "tasks.#{undo.task.id}"
|
2013-03-18 01:43:03 +00:00
|
|
|
_.each undo.task, (val, key) ->
|
2013-05-22 10:29:24 +00:00
|
|
|
return true if key in ['id', 'type'] # strange bugs in this world: https://workflowy.com/shared/a53582ea-43d6-bcce-c719-e134f9bf71fd/
|
2013-03-18 01:43:03 +00:00
|
|
|
if key is 'completed'
|
|
|
|
|
user.pass({cron:true}).set("#{taskPath}.completed",val)
|
|
|
|
|
else
|
2013-05-29 09:23:23 +00:00
|
|
|
user.set "#{taskPath}.#{key}", val
|
2013-05-22 10:29:24 +00:00
|
|
|
true
|