|
|
var GitError = require('../util/errors').GitError; |
|
|
var _ = require('underscore'); |
|
|
var Q = require('q'); |
|
|
var Backbone = require('backbone'); |
|
|
|
|
|
var ModalTerminal = require('../views').ModalTerminal; |
|
|
var ContainedBase = require('../views').ContainedBase; |
|
|
var ConfirmCancelView = require('../views').ConfirmCancelView; |
|
|
|
|
|
var intl = require('../intl'); |
|
|
|
|
|
require('jquery-ui/ui/widget'); |
|
|
require('jquery-ui/ui/scroll-parent'); |
|
|
require('jquery-ui/ui/data'); |
|
|
require('jquery-ui/ui/widgets/mouse'); |
|
|
require('jquery-ui/ui/ie'); |
|
|
require('jquery-ui/ui/widgets/sortable'); |
|
|
require('jquery-ui/ui/plugin'); |
|
|
require('jquery-ui/ui/safe-active-element'); |
|
|
require('jquery-ui/ui/safe-blur'); |
|
|
require('jquery-ui/ui/widgets/draggable'); |
|
|
|
|
|
var InteractiveRebaseView = ContainedBase.extend({ |
|
|
tagName: 'div', |
|
|
template: _.template($('#interactive-rebase-template').html()), |
|
|
|
|
|
initialize: function(options) { |
|
|
this.deferred = options.deferred; |
|
|
this.rebaseMap = {}; |
|
|
this.entryObjMap = {}; |
|
|
this.options = options; |
|
|
|
|
|
this.rebaseEntries = new RebaseEntryCollection(); |
|
|
options.toRebase.reverse(); |
|
|
options.toRebase.forEach(function(commit) { |
|
|
var id = commit.get('id'); |
|
|
this.rebaseMap[id] = commit; |
|
|
|
|
|
|
|
|
this.entryObjMap[id] = new RebaseEntry({ |
|
|
id: id |
|
|
}); |
|
|
this.rebaseEntries.add(this.entryObjMap[id]); |
|
|
}, this); |
|
|
|
|
|
this.container = new ModalTerminal({ |
|
|
title: intl.str('interactive-rebase-title') |
|
|
}); |
|
|
this.render(); |
|
|
|
|
|
|
|
|
this.show(); |
|
|
|
|
|
if (options.aboveAll) { |
|
|
|
|
|
$('#canvasHolder').css('display', 'none'); |
|
|
} |
|
|
}, |
|
|
|
|
|
restoreVis: function() { |
|
|
|
|
|
$('#canvasHolder').css('display', 'inherit'); |
|
|
}, |
|
|
|
|
|
confirm: function() { |
|
|
this.die(); |
|
|
if (this.options.aboveAll) { |
|
|
this.restoreVis(); |
|
|
} |
|
|
|
|
|
|
|
|
var uiOrder = []; |
|
|
this.$('ul.rebaseEntries li').each(function(i, obj) { |
|
|
uiOrder.push(obj.id); |
|
|
}); |
|
|
|
|
|
|
|
|
var toRebase = []; |
|
|
uiOrder.forEach(function(id) { |
|
|
|
|
|
if (this.entryObjMap[id].get('pick')) { |
|
|
toRebase.unshift(this.rebaseMap[id]); |
|
|
} |
|
|
}, this); |
|
|
toRebase.reverse(); |
|
|
|
|
|
this.deferred.resolve(toRebase); |
|
|
|
|
|
this.$el.html(''); |
|
|
}, |
|
|
|
|
|
render: function() { |
|
|
var json = { |
|
|
num: Object.keys(this.rebaseMap).length, |
|
|
solutionOrder: this.options.initialCommitOrdering |
|
|
}; |
|
|
|
|
|
var destination = this.container.getInsideElement(); |
|
|
this.$el.html(this.template(json)); |
|
|
$(destination).append(this.el); |
|
|
|
|
|
|
|
|
var listHolder = this.$('ul.rebaseEntries'); |
|
|
this.rebaseEntries.each(function(entry) { |
|
|
new RebaseEntryView({ |
|
|
el: listHolder, |
|
|
model: entry |
|
|
}); |
|
|
}, this); |
|
|
|
|
|
|
|
|
listHolder.sortable({ |
|
|
axis: 'y', |
|
|
placeholder: 'rebaseEntry transitionOpacity ui-state-highlight', |
|
|
appendTo: 'parent' |
|
|
}); |
|
|
|
|
|
this.makeButtons(); |
|
|
}, |
|
|
|
|
|
cancel: function() { |
|
|
|
|
|
this.hide(); |
|
|
if (this.options.aboveAll) { |
|
|
this.restoreVis(); |
|
|
} |
|
|
this.deferred.resolve([]); |
|
|
}, |
|
|
|
|
|
makeButtons: function() { |
|
|
|
|
|
var deferred = Q.defer(); |
|
|
deferred.promise |
|
|
.then(function() { |
|
|
this.confirm(); |
|
|
}.bind(this)) |
|
|
.fail(function() { |
|
|
this.cancel(); |
|
|
}.bind(this)) |
|
|
.done(); |
|
|
|
|
|
|
|
|
new ConfirmCancelView({ |
|
|
destination: this.$('.confirmCancel'), |
|
|
deferred: deferred |
|
|
}); |
|
|
} |
|
|
}); |
|
|
|
|
|
var RebaseEntry = Backbone.Model.extend({ |
|
|
defaults: { |
|
|
pick: true |
|
|
}, |
|
|
|
|
|
toggle: function() { |
|
|
this.set('pick', !this.get('pick')); |
|
|
} |
|
|
}); |
|
|
|
|
|
var RebaseEntryCollection = Backbone.Collection.extend({ |
|
|
model: RebaseEntry |
|
|
}); |
|
|
|
|
|
var RebaseEntryView = Backbone.View.extend({ |
|
|
tagName: 'li', |
|
|
template: _.template($('#interactive-rebase-entry-template').html()), |
|
|
|
|
|
toggle: function() { |
|
|
this.model.toggle(); |
|
|
|
|
|
|
|
|
this.listEntry.toggleClass('notPicked', !this.model.get('pick')); |
|
|
}, |
|
|
|
|
|
initialize: function(options) { |
|
|
this.render(); |
|
|
}, |
|
|
|
|
|
render: function() { |
|
|
this.$el.append(this.template(this.model.toJSON())); |
|
|
|
|
|
|
|
|
this.listEntry = this.$el.children(':last'); |
|
|
|
|
|
this.listEntry.delegate('#toggleButton', 'click', function() { |
|
|
this.toggle(); |
|
|
}.bind(this)); |
|
|
} |
|
|
}); |
|
|
|
|
|
exports.InteractiveRebaseView = InteractiveRebaseView; |
|
|
|