overleaf/services/web/public/coffee/track-changes/models/Diff.coffee

33 lines
861 B
CoffeeScript
Raw Normal View History

2014-03-06 09:08:12 -05:00
define [
"models/User"
2014-03-06 09:08:12 -05:00
"libs/backbone"
], (User) ->
2014-03-06 09:08:12 -05:00
Diff = Backbone.Model.extend
initialize: (attributes, options) ->
@ide = options.ide
@set "doc", @ide.fileTreeManager.getEntity(@get("doc_id"))
2014-03-06 09:08:12 -05:00
url: () ->
"/project/#{@get("project_id")}/doc/#{@get("doc_id")}/diff?from=#{@get("from")}&to=#{@get("to")}"
parse: (diff) ->
for entry in diff.diff
2014-03-11 08:13:46 -04:00
if entry.meta?
if entry.meta.user?
entry.meta.user = User.findOrBuild(entry.meta.user.id, entry.meta.user)
else
entry.meta.user = User.getAnonymousUser()
return diff
restore: (callback = (error) ->) ->
$.ajax {
url: "/project/#{@get("project_id")}/doc/#{@get("doc_id")}/version/#{@get("from")}/restore"
type: "POST"
headers:
"X-CSRF-Token": window.csrfToken
success: () ->
callback()
error: (error) ->
callback(error)
}