References dialog cleanup

Objectives:

* Remove the whole toolbar subset thing, it's up to the creator of the
  subsurface to know what is and is now allowed, and the commands were
  still passing through unfiltered
* Correctly separate initialization from opening - fix issue where opening
  the reference dialog multiple times will keep adding more and more
  controls

Changes:

ve.init.Target.js
* Remove getToolbarSubset method

ve.ui.MWReferenceDialog.js
* Add toolbar tools and surface commands configs to reference dialog,
  including the things that are safe to use in references
* Move creation of field sets and reused controls to initialize method
  to prevent re-creation each time the dialog is opened
* Move static initialization stuff to the top near the other static stuff

Change-Id: I1c8577d17c506bac76e61b2b036655c59ef5a218
This commit is contained in:
Trevor Parscal 2013-06-11 14:35:35 -07:00
parent 2bccb3da85
commit 2d044518bd
2 changed files with 48 additions and 54 deletions

View file

@ -39,24 +39,3 @@ ve.init.Target.static.toolbarTools = [
ve.init.Target.static.surfaceCommands = [
'bold', 'italic', 'link', 'undo', 'redo', 'indent', 'outdent'
];
/* Static Methods */
/**
* Get a subset of toolbarTools excluding certain tools.
*
* @param {string[]} exclude List of tools to exclude
* @returns {Object} Toolbar tools object
*/
ve.init.Target.static.getToolbarSubset = function ( exclude ) {
var i, iLen, items, group, toolbarSubset = [];
for ( i = 0, iLen = this.toolbarTools.length; i < iLen; i++ ) {
items = ve.simpleArrayDifference( this.toolbarTools[i].items, exclude );
if ( items.length ) {
group = ve.copyObject( this.toolbarTools[i] );
group.items = items;
toolbarSubset.push( group );
}
}
return toolbarSubset;
};

View file

@ -35,6 +35,27 @@ ve.ui.MWReferenceDialog.static.icon = 'reference';
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
ve.ui.MWReferenceDialog.static.toolbarTools = [
{ 'items': ['undo', 'redo'] },
{ 'items': ['mwFormat'] },
{ 'items': ['bold', 'italic', 'mwLink', 'clear', 'mwMediaInsert'] }
];
ve.ui.MWReferenceDialog.static.surfaceCommands = [
'bold', 'italic', 'mwLink', 'undo', 'redo'
];
/* Static Initialization */
ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
've.ce.Node.css',
've.ce.Surface.css',
've.ui.Surface.css',
've.ui.Context.css',
've.ui.Tool.css',
've.ui.Toolbar.css'
] );
/* Methods */
/**
@ -46,8 +67,27 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
// Call parent method
ve.ui.Dialog.prototype.initialize.call( this );
// Properties
this.contentFieldset = new ve.ui.FieldsetLayout( {
// TODO: use message string
'$$': this.frame.$$, 'label': 'Content', 'icon': 'parameter'
} );
this.nameFieldset = new ve.ui.FieldsetLayout( {
// TODO: use message string
'$$': this.frame.$$, 'label': 'Name', 'icon': 'parameter'
} );
this.nameInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$ } );
this.nameLabel = new ve.ui.InputLabelWidget( {
'$$': this.frame.$$,
'input': this.nameInput,
// TODO: use message string
'label': 'Reuse this reference by this name'
} );
// Initialization
this.$body.addClass( 've-ui-mwReferenceDialog-body' );
this.$body.append( this.contentFieldset.$, this.nameFieldset.$ );
this.nameFieldset.$.append( this.nameLabel.$, this.nameInput.$ );
};
/**
@ -56,32 +96,20 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
* @method
*/
ve.ui.MWReferenceDialog.prototype.onOpen = function () {
var focusedNode, doc, data,
// Remove mwReference tool as you can't have nested references
toolbarSubset = ve.init.mw.ViewPageTarget.static.getToolbarSubset( [
// Can't have nested references
'mwReference',
// Lists not properly supported by PHP parser
'number', 'bullet', 'outdent', 'indent'
] );
var focusedNode, data,
doc = this.surface.getModel().getDocument();
// Parent method
ve.ui.Dialog.prototype.onOpen.call( this );
// Get data from selection
// Get reference content
focusedNode = this.surface.getView().getFocusedNode();
doc = this.surface.getModel().getDocument();
if ( focusedNode instanceof ve.ce.MWReferenceNode ) {
this.internalItem = focusedNode.getModel().getInternalItem();
data = doc.getData( this.internalItem.getRange(), true );
} else {
data = [
{
'type': 'paragraph',
'internal': {
'generated': 'wrapper'
}
},
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
{ 'type': '/paragraph' }
];
}
@ -94,9 +122,9 @@ ve.ui.MWReferenceDialog.prototype.onOpen = function () {
// Initialization
this.referenceToolbar.$.addClass( 've-ui-mwReferenceDialog-toolbar' );
this.$body.append( this.referenceToolbar.$, this.referenceSurface.$ );
this.referenceToolbar.addTools( toolbarSubset );
this.referenceSurface.addCommands( ve.init.mw.ViewPageTarget.static.surfaceCommands );
this.contentFieldset.$.append( this.referenceToolbar.$, this.referenceSurface.$ );
this.referenceToolbar.addTools( this.constructor.static.toolbarTools );
this.referenceSurface.addCommands( this.constructor.static.surfaceCommands );
this.referenceSurface.initialize();
this.referenceSurface.view.documentView.documentNode.$.focus();
};
@ -138,9 +166,7 @@ ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
{
'type': 'mwReference',
'attributes': {
'mw': {
'name': 'ref'
},
'mw': { 'name': 'ref' },
'listIndex': newItem.index,
'listGroup': 'mwReference/' + groupName,
'listKey': key,
@ -158,17 +184,6 @@ ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
this.referenceToolbar.destroy();
};
/* Initialization */
ve.ui.MWReferenceDialog.static.addLocalStylesheets( [
've.ce.Node.css',
've.ce.Surface.css',
've.ui.Surface.css',
've.ui.Context.css',
've.ui.Tool.css',
've.ui.Toolbar.css'
] );
/* Registration */
ve.ui.dialogFactory.register( 'mwReference', ve.ui.MWReferenceDialog );