2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2014-11-29 16:36:41 -05:00
|
|
|
template = require 'templates/editor/modal/versions-modal'
|
2014-07-23 10:02:45 -04:00
|
|
|
DeltaView = require 'views/editor/DeltaView'
|
|
|
|
PatchModal = require 'views/editor/PatchModal'
|
2014-11-29 09:50:50 -05:00
|
|
|
nameLoader = require 'core/NameLoader'
|
2014-06-24 16:41:55 -04:00
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
2014-11-28 20:49:41 -05:00
|
|
|
deltasLib = require 'core/deltas'
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-06-24 16:41:55 -04:00
|
|
|
class VersionsViewCollection extends CocoCollection
|
2014-06-30 22:16:26 -04:00
|
|
|
url: ''
|
2014-01-15 18:35:17 -05:00
|
|
|
model: null
|
|
|
|
|
|
|
|
initialize: (@url, @levelID, @model) ->
|
2014-06-24 16:41:55 -04:00
|
|
|
super()
|
2015-01-30 15:27:19 -05:00
|
|
|
@url = @url + @levelID + '/versions'
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class VersionsModal extends ModalView
|
2014-01-15 18:35:17 -05:00
|
|
|
template: template
|
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
|
2014-06-30 22:16:26 -04:00
|
|
|
id: ''
|
|
|
|
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
|
2015-01-30 14:24:27 -05:00
|
|
|
@original = new @model(_id: @ID)
|
2016-02-18 11:44:40 -05:00
|
|
|
@original = @supermodel.loadModel(@original).model
|
2014-06-24 16:41:55 -04:00
|
|
|
@listenToOnce(@original, 'sync', @onViewSync)
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-03-24 02:53:41 -04:00
|
|
|
onViewSync: ->
|
2014-06-24 16:41:55 -04:00
|
|
|
@versions = new VersionsViewCollection(@url, @original.attributes.original, @model)
|
|
|
|
@versions = @supermodel.loadCollection(@versions, 'versions').model
|
|
|
|
@listenTo(@versions, 'sync', @onVersionsFetched)
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-06-24 16:41:55 -04:00
|
|
|
onVersionsFetched: ->
|
|
|
|
ids = (p.get('creator') for p in @versions.models)
|
|
|
|
jqxhrOptions = nameLoader.loadNames ids
|
|
|
|
@supermodel.addRequestResource('user_names', jqxhrOptions).load() if jqxhrOptions
|
2014-01-15 18:35:17 -05:00
|
|
|
|
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-06-30 22:16:26 -04:00
|
|
|
if rows.length isnt 2 then return
|
|
|
|
|
|
|
|
laterVersion = new @model(_id: $(rows[0]).val())
|
|
|
|
earlierVersion = new @model(_id: $(rows[1]).val())
|
2014-07-15 14:23:00 -04:00
|
|
|
@deltaView = new DeltaView({
|
|
|
|
model: earlierVersion
|
|
|
|
comparisonModel: laterVersion
|
2014-10-27 20:11:48 -04:00
|
|
|
skipPaths: deltasLib.DOC_SKIP_PATHS
|
2014-07-15 14:23:00 -04:00
|
|
|
loadModels: true
|
|
|
|
})
|
2014-05-08 13:54:39 -04:00
|
|
|
@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
|
2014-06-24 16:41:55 -04:00
|
|
|
if @versions
|
|
|
|
context.dataList = (m.attributes for m in @versions.models)
|
|
|
|
for version in context.dataList
|
|
|
|
version.creator = nameLoader.getName(version.creator)
|
2014-01-15 18:35:17 -05:00
|
|
|
context
|