jenkins-bot has submitted this change and it was merged.

Change subject: Make outline controls abilities configurable
......................................................................


Make outline controls abilities configurable

This will allow us to disable removing the last item under certain
conditions.

See the OutlinedBookletDialog for a demo of this in action - despite
the items being removable, removing is disabled generally so it's not
allowed.

Change-Id: If84a5db19a6bc41642b2e161e09986b8d335ccc8
---
M demos/pages/dialogs.js
M src/widgets/OutlineControlsWidget.js
2 files changed, 31 insertions(+), 2 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/demos/pages/dialogs.js b/demos/pages/dialogs.js
index eceb8fc..12cf9f0 100644
--- a/demos/pages/dialogs.js
+++ b/demos/pages/dialogs.js
@@ -162,6 +162,8 @@
        SamplePage.prototype.setupOutlineItem = function ( outlineItem ) {
                SamplePage.super.prototype.setupOutlineItem.call( this, 
outlineItem );
                this.outlineItem
+                       .setMovable( true )
+                       .setRemovable( true )
                        .setIcon( this.icon )
                        .setLabel( this.label );
        };
@@ -252,6 +254,7 @@
                OutlinedBookletDialog.super.prototype.initialize.apply( this, 
arguments );
                this.bookletLayout = new OO.ui.BookletLayout( {
                        outlined: true,
+                       editable: true,
                        menuSize: '15em'
                } );
                this.pages = [
@@ -261,6 +264,8 @@
                        new SamplePage( 'larger', { label: 'Larger', icon: 
'window' } ),
                        new SamplePage( 'full', { label: 'Full', icon: 'window' 
} )
                ];
+
+               this.bookletLayout.getOutlineControls().setAbilities( { remove: 
false } );
                this.bookletLayout.addPages( this.pages );
                this.bookletLayout.connect( this, { set: 'onBookletLayoutSet' } 
);
                this.$body.append( this.bookletLayout.$element );
diff --git a/src/widgets/OutlineControlsWidget.js 
b/src/widgets/OutlineControlsWidget.js
index 9830149..f92cf66 100644
--- a/src/widgets/OutlineControlsWidget.js
+++ b/src/widgets/OutlineControlsWidget.js
@@ -11,6 +11,9 @@
  * @constructor
  * @param {OO.ui.OutlineSelectWidget} outline Outline to control
  * @param {Object} [config] Configuration options
+ * @cfg {Object} [abilities] List of abilties
+ * @cfg {boolean} [abilities.move=true] Allow moving movable items
+ * @cfg {boolean} [abilities.remove=true] Allow removing removable items
  */
 OO.ui.OutlineControlsWidget = function OoUiOutlineControlsWidget( outline, 
config ) {
        // Allow passing positional parameters inside the config object
@@ -47,6 +50,7 @@
                icon: 'remove',
                title: OO.ui.msg( 'ooui-outline-control-remove' )
        } );
+       this.abilities = { move: true, remove: true };
 
        // Events
        outline.connect( this, {
@@ -65,6 +69,7 @@
                .addClass( 'oo-ui-outlineControlsWidget-movers' )
                .append( this.removeButton.$element, this.upButton.$element, 
this.downButton.$element );
        this.$element.append( this.$icon, this.$group, this.$movers );
+       this.setAbilities( config.abilities || {} );
 };
 
 /* Setup */
@@ -87,6 +92,25 @@
 /* Methods */
 
 /**
+ * Set abilities.
+ *
+ * @param {Object} abilities List of abilties
+ * @param {boolean} [abilities.move] Allow moving movable items
+ * @param {boolean} [abilities.remove] Allow removing removable items
+ */
+OO.ui.OutlineControlsWidget.prototype.setAbilities = function ( abilities ) {
+       var ability;
+
+       for ( ability in this.abilities ) {
+               if ( abilities[ability] !== undefined ) {
+                       this.abilities[ability] = !!abilities[ability];
+               }
+       }
+
+       this.onOutlineChange();
+};
+
+/**
  *
  * @private
  * Handle outline change events.
@@ -95,8 +119,8 @@
        var i, len, firstMovable, lastMovable,
                items = this.outline.getItems(),
                selectedItem = this.outline.getSelectedItem(),
-               movable = selectedItem && selectedItem.isMovable(),
-               removable = selectedItem && selectedItem.isRemovable();
+               movable = this.abilities.move && selectedItem && 
selectedItem.isMovable(),
+               removable = this.abilities.remove && selectedItem && 
selectedItem.isRemovable();
 
        if ( movable ) {
                i = -1;

-- 
To view, visit https://gerrit.wikimedia.org/r/198151
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If84a5db19a6bc41642b2e161e09986b8d335ccc8
Gerrit-PatchSet: 2
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to