2014-03-10 18:17:19 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/modal/versions'
|
2014-01-15 18:35:17 -05:00
|
|
|
tableTemplate = require 'templates/kinds/table'
|
2014-05-08 13:54:39 -04:00
|
|
|
DeltaView = require 'views/editor/delta'
|
2014-01-15 18:35:17 -05:00
|
|
|
|
|
|
|
class VersionsViewCollection extends Backbone.Collection
|
|
|
|
url: ""
|
|
|
|
model: null
|
|
|
|
|
|
|
|
initialize: (@url, @levelID, @model) ->
|
|
|
|
@url = url + levelID + '/versions'
|
|
|
|
@model = model
|
|
|
|
|
2014-03-10 18:17:19 -04:00
|
|
|
module.exports = class VersionsModalView extends ModalView
|
2014-01-15 18:35:17 -05:00
|
|
|
template: template
|
|
|
|
startsLoading: true
|
2014-04-17 14:22:33 -04:00
|
|
|
plain: true
|
|
|
|
modalWidthPercent: 80
|
2014-01-15 18:35:17 -05:00
|
|
|
|
|
|
|
# needs to be overwritten by child
|
|
|
|
id: ""
|
2014-03-10 18:17:19 -04:00
|
|
|
url: ""
|
|
|
|
page: ""
|
2014-05-08 13:54:39 -04:00
|
|
|
|
|
|
|
events:
|
|
|
|
'change input.select': 'onSelectionChanged'
|
2014-01-15 18:35:17 -05:00
|
|
|
|
|
|
|
constructor: (options, @ID, @model) ->
|
|
|
|
super options
|
|
|
|
@view = new model(_id: @ID)
|
|
|
|
@view.fetch()
|
2014-03-24 02:53:41 -04:00
|
|
|
@listenToOnce(@view, 'sync', @onViewSync)
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-03-24 02:53:41 -04:00
|
|
|
onViewSync: ->
|
2014-01-15 18:35:17 -05:00
|
|
|
@collection = new VersionsViewCollection(@url, @view.attributes.original, @model)
|
|
|
|
@collection.fetch()
|
2014-03-24 02:53:41 -04:00
|
|
|
@listenTo(@collection, 'sync', @onVersionFetched)
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-03-24 02:53:41 -04:00
|
|
|
onVersionFetched: ->
|
2014-01-15 18:35:17 -05:00
|
|
|
@startsLoading = false
|
|
|
|
@render()
|
|
|
|
|
2014-05-08 13:54:39 -04:00
|
|
|
onSelectionChanged: ->
|
|
|
|
rows = @$el.find 'input.select:checked'
|
|
|
|
deltaEl = @$el.find '.delta-view'
|
2014-05-08 14:10:22 -04:00
|
|
|
@removeSubView(@deltaView) if @deltaView
|
|
|
|
@deltaView = null
|
2014-05-08 13:54:39 -04:00
|
|
|
if rows.length isnt 2 then return
|
|
|
|
|
|
|
|
laterVersion = new @model(_id:$(rows[0]).val())
|
|
|
|
earlierVersion = new @model(_id:$(rows[1]).val())
|
|
|
|
@deltaView = new DeltaView({model:earlierVersion, comparisonModel:laterVersion, skipPaths:['_id','version', 'commitMessage', 'parent', 'created', 'slug', 'index']})
|
|
|
|
@insertSubView(@deltaView, deltaEl)
|
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-15 18:35:17 -05:00
|
|
|
context = super(context)
|
|
|
|
context.page = @page
|
|
|
|
context.dataList = (m.attributes for m in @collection.models) if @collection
|
|
|
|
context
|