Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
Show All 15 Lines | members: { | ||||
_row: null, | _row: null, | ||||
_number: null, | _number: null, | ||||
_length: null, | _length: null, | ||||
_displaySide: null, | _displaySide: null, | ||||
_isNewFile: null, | _isNewFile: null, | ||||
_replyToCommentPHID: null, | _replyToCommentPHID: null, | ||||
_originalText: null, | _originalText: null, | ||||
_snippet: null, | _snippet: null, | ||||
_menuItems: null, | |||||
_documentEngineKey: null, | _documentEngineKey: null, | ||||
_isDeleted: false, | _isDeleted: false, | ||||
_isInvisible: false, | _isInvisible: false, | ||||
_isLoading: false, | _isLoading: false, | ||||
_changeset: null, | _changeset: null, | ||||
_isCollapsed: false, | _isCollapsed: false, | ||||
_isDraft: null, | _isDraft: null, | ||||
_isDraftDone: null, | _isDraftDone: null, | ||||
_isFixed: null, | _isFixed: null, | ||||
_isEditing: false, | _isEditing: false, | ||||
_isNew: false, | _isNew: false, | ||||
_isSynthetic: false, | _isSynthetic: false, | ||||
_isHidden: false, | _isHidden: false, | ||||
_editRow: null, | _editRow: null, | ||||
_undoRow: null, | _undoRow: null, | ||||
_undoType: null, | _undoType: null, | ||||
_undoText: null, | _undoText: null, | ||||
_draftRequest: null, | _draftRequest: null, | ||||
_skipFocus: false, | _skipFocus: false, | ||||
_menu: null, | |||||
bindToRow: function(row) { | bindToRow: function(row) { | ||||
this._row = row; | this._row = row; | ||||
var row_data = JX.Stratcom.getData(row); | var row_data = JX.Stratcom.getData(row); | ||||
row_data.inline = this; | row_data.inline = this; | ||||
this._isCollapsed = row_data.hidden || false; | this._isCollapsed = row_data.hidden || false; | ||||
Show All 28 Lines | bindToRow: function(row) { | ||||
this._isFixed = data.isFixed; | this._isFixed = data.isFixed; | ||||
this._isGhost = data.isGhost; | this._isGhost = data.isGhost; | ||||
this._isSynthetic = data.isSynthetic; | this._isSynthetic = data.isSynthetic; | ||||
this._isDraftDone = data.isDraftDone; | this._isDraftDone = data.isDraftDone; | ||||
this._changesetID = data.changesetID; | this._changesetID = data.changesetID; | ||||
this._isNew = false; | this._isNew = false; | ||||
this._snippet = data.snippet; | this._snippet = data.snippet; | ||||
this._menuItems = data.menuItems; | |||||
this._documentEngineKey = data.documentEngineKey; | this._documentEngineKey = data.documentEngineKey; | ||||
this._isEditing = data.isEditing; | this._isEditing = data.isEditing; | ||||
if (this._isEditing) { | if (this._isEditing) { | ||||
// NOTE: The "original" shipped down in the DOM may reflect a draft | // NOTE: The "original" shipped down in the DOM may reflect a draft | ||||
// which we're currently editing. This flow is a little clumsy, but | // which we're currently editing. This flow is a little clumsy, but | ||||
// reasonable until some future change moves away from "send down | // reasonable until some future change moves away from "send down | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | members: { | ||||
setHidden: function(hidden) { | setHidden: function(hidden) { | ||||
this._isHidden = hidden; | this._isHidden = hidden; | ||||
this._redraw(); | this._redraw(); | ||||
return this; | return this; | ||||
}, | }, | ||||
canReply: function() { | canReply: function() { | ||||
if (!this._hasAction('reply')) { | return this._hasMenuAction('reply'); | ||||
return false; | |||||
} | |||||
return true; | |||||
}, | }, | ||||
canEdit: function() { | canEdit: function() { | ||||
if (!this._hasAction('edit')) { | return this._hasMenuAction('edit'); | ||||
return false; | |||||
} | |||||
return true; | |||||
}, | }, | ||||
canDone: function() { | canDone: function() { | ||||
if (!JX.DOM.scry(this._row, 'input', 'differential-inline-done').length) { | if (!JX.DOM.scry(this._row, 'input', 'differential-inline-done').length) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
}, | }, | ||||
canCollapse: function() { | canCollapse: function() { | ||||
if (!JX.DOM.scry(this._row, 'a', 'hide-inline').length) { | return this._hasMenuAction('collapse'); | ||||
return false; | |||||
} | |||||
return true; | |||||
}, | }, | ||||
getRawText: function() { | getRawText: function() { | ||||
return this._originalText; | return this._originalText; | ||||
}, | }, | ||||
_hasAction: function(action) { | |||||
var nodes = JX.DOM.scry(this._row, 'a', 'differential-inline-' + action); | |||||
return (nodes.length > 0); | |||||
}, | |||||
_newRow: function() { | _newRow: function() { | ||||
var attributes = { | var attributes = { | ||||
sigil: 'inline-row' | sigil: 'inline-row' | ||||
}; | }; | ||||
var row = JX.$N('tr', attributes); | var row = JX.$N('tr', attributes); | ||||
JX.Stratcom.getData(row).inline = this; | JX.Stratcom.getData(row).inline = this; | ||||
this._row = row; | this._row = row; | ||||
this._id = null; | this._id = null; | ||||
this._phid = null; | this._phid = null; | ||||
this._isCollapsed = false; | this._isCollapsed = false; | ||||
this._originalText = null; | this._originalText = null; | ||||
return row; | return row; | ||||
}, | }, | ||||
setCollapsed: function(collapsed) { | setCollapsed: function(collapsed) { | ||||
this._closeMenu(); | |||||
this._isCollapsed = collapsed; | this._isCollapsed = collapsed; | ||||
var op; | var op; | ||||
if (collapsed) { | if (collapsed) { | ||||
op = 'hide'; | op = 'hide'; | ||||
} else { | } else { | ||||
op = 'show'; | op = 'show'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | create: function(text) { | ||||
this.setLoading(true); | this.setLoading(true); | ||||
new JX.Request(uri, handler) | new JX.Request(uri, handler) | ||||
.setData(data) | .setData(data) | ||||
.send(); | .send(); | ||||
}, | }, | ||||
reply: function(text) { | reply: function(with_quote) { | ||||
this._closeMenu(); | |||||
var text; | |||||
if (with_quote) { | |||||
text = this.getRawText(); | |||||
text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n'; | |||||
} else { | |||||
text = ''; | |||||
} | |||||
var changeset = this.getChangeset(); | var changeset = this.getChangeset(); | ||||
return changeset.newInlineReply(this, text); | return changeset.newInlineReply(this, text); | ||||
}, | }, | ||||
edit: function(text, skip_focus) { | edit: function(text, skip_focus) { | ||||
this._closeMenu(); | |||||
this._skipFocus = !!skip_focus; | this._skipFocus = !!skip_focus; | ||||
// If you edit an inline ("A"), modify the text ("AB"), cancel, and then | // If you edit an inline ("A"), modify the text ("AB"), cancel, and then | ||||
// edit it again: discard the undo state ("AB"). Otherwise we end up | // edit it again: discard the undo state ("AB"). Otherwise we end up | ||||
// with an open editor and an active "Undo" link, which is weird. | // with an open editor and an active "Undo" link, which is weird. | ||||
if (this._undoRow) { | if (this._undoRow) { | ||||
JX.DOM.remove(this._undoRow); | JX.DOM.remove(this._undoRow); | ||||
▲ Show 20 Lines • Show All 466 Lines • ▼ Show 20 Lines | _getDraftState: function() { | ||||
text: text | text: text | ||||
}; | }; | ||||
}, | }, | ||||
triggerDraft: function() { | triggerDraft: function() { | ||||
if (this._draftRequest) { | if (this._draftRequest) { | ||||
this._draftRequest.trigger(); | this._draftRequest.trigger(); | ||||
} | } | ||||
}, | |||||
activateMenu: function(button, e) { | |||||
// If we already have a menu for this button, let the menu handle the | |||||
// event. | |||||
var data = JX.Stratcom.getData(button); | |||||
if (data.menu) { | |||||
return; | |||||
} | |||||
e.prevent(); | |||||
var menu = new JX.PHUIXDropdownMenu(button) | |||||
.setWidth(240); | |||||
var list = new JX.PHUIXActionListView(); | |||||
var items = this._newMenuItems(menu); | |||||
for (var ii = 0; ii < items.length; ii++) { | |||||
list.addItem(items[ii]); | |||||
} | |||||
menu.setContent(list.getNode()); | |||||
data.menu = menu; | |||||
this._menu = menu; | |||||
menu.listen('open', JX.bind(this, function() { | |||||
var changeset_list = this.getChangeset().getChangesetList(); | |||||
changeset_list.selectInline(this, true); | |||||
})); | |||||
menu.open(); | |||||
}, | |||||
_newMenuItems: function(menu) { | |||||
var items = []; | |||||
for (var ii = 0; ii < this._menuItems.length; ii++) { | |||||
var spec = this._menuItems[ii]; | |||||
var onmenu = JX.bind(this, this._onMenuItem, menu, spec.action); | |||||
var item = new JX.PHUIXActionView() | |||||
.setIcon(spec.icon) | |||||
.setName(spec.label) | |||||
.setHandler(onmenu); | |||||
if (spec.key) { | |||||
item.setKeyCommand(spec.key); | |||||
} | |||||
items.push(item); | |||||
} | |||||
return items; | |||||
}, | |||||
_onMenuItem: function(menu, action, e) { | |||||
e.prevent(); | |||||
menu.close(); | |||||
switch (action) { | |||||
case 'reply': | |||||
this.reply(); | |||||
break; | |||||
case 'quote': | |||||
this.reply(true); | |||||
break; | |||||
case 'collapse': | |||||
this.setCollapsed(true); | |||||
break; | |||||
case 'delete': | |||||
this.delete(); | |||||
break; | |||||
case 'edit': | |||||
this.edit(); | |||||
break; | |||||
} | |||||
}, | |||||
_hasMenuAction: function(action) { | |||||
for (var ii = 0; ii < this._menuItems.length; ii++) { | |||||
var spec = this._menuItems[ii]; | |||||
if (spec.action === action) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
}, | |||||
_closeMenu: function() { | |||||
if (this._menu) { | |||||
this._menu.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
}); | }); |