2014-03-06 09:08:12 -05:00
|
|
|
define [
|
2014-03-07 07:00:31 -05:00
|
|
|
"models/User"
|
2014-03-06 09:08:12 -05:00
|
|
|
"libs/backbone"
|
2014-03-07 07:00:31 -05:00
|
|
|
], (User) ->
|
2014-03-06 09:08:12 -05:00
|
|
|
Diff = Backbone.Model.extend
|
2014-03-21 07:34:16 -04:00
|
|
|
initialize: (attributes, options) ->
|
|
|
|
@ide = options.ide
|
|
|
|
@set "doc", @ide.fileTreeManager.getEntity(@get("doc_id"))
|
|
|
|
|
2014-03-06 09:08:12 -05:00
|
|
|
url: () ->
|
2014-03-21 10:23:07 -04:00
|
|
|
url = "/project/#{@get("project_id")}/doc/#{@get("doc_id")}/diff"
|
|
|
|
if @get("from")? and @get("to")?
|
|
|
|
url += "?from=#{@get("from")}&to=#{@get("to")}"
|
|
|
|
return url
|
2014-03-07 07:00:31 -05:00
|
|
|
|
|
|
|
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()
|
2014-03-07 07:00:31 -05:00
|
|
|
return diff
|
2014-03-21 07:34:16 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|