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-05-30 16:40:38 -04:00
|
|
|
PatchModal = require 'views/editor/patch_modal'
|
2014-06-24 16:41:55 -04:00
|
|
|
nameLoader = require 'lib/NameLoader'
|
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
2014-01-15 18:35:17 -05:00
|
|
|
|
2014-06-24 16:41:55 -04:00
|
|
|
class VersionsViewCollection extends CocoCollection
|
2014-01-15 18:35:17 -05:00
|
|
|
url: ""
|
|
|
|
model: null
|
|
|
|
|
|
|
|
initialize: (@url, @levelID, @model) ->
|
2014-06-24 16:41:55 -04:00
|
|
|
super()
|
2014-01-15 18:35:17 -05:00
|
|
|
@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
|
2014-06-24 16:41:55 -04:00
|
|
|
@original = new model(_id: @ID)
|
|
|
|
@original = @supermodel.loadModel(@original, 'document').model
|
|
|
|
@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-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())
|
2014-05-30 16:40:38 -04:00
|
|
|
@deltaView = new DeltaView({model:earlierVersion, comparisonModel:laterVersion, skipPaths:PatchModal.DOC_SKIP_PATHS})
|
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
|