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

Change subject: Paged dialog upgrades
......................................................................


Paged dialog upgrades

Objective:

* Add functionality to paged dialogs to work with the pages and select
  them programmatically

Changes:

ve.ui.PagedDialog.js
* Keep track of the current page name
* Add setPage method, which is can be used publicly and is also used
  internally when items in the outline are selected
* Add a page content config option which auto-appends to the inside of
  the page
* Add removePage method for removing pages by name
* Add getPageName method which gets the current page name

Change-Id: I2a2f0c329d274796b8c9e7572ecff8294f472f7f
---
M modules/ve/ui/dialogs/ve.ui.PagedDialog.js
1 file changed, 54 insertions(+), 1 deletion(-)

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



diff --git a/modules/ve/ui/dialogs/ve.ui.PagedDialog.js 
b/modules/ve/ui/dialogs/ve.ui.PagedDialog.js
index 6c2bcf5..735cc72 100644
--- a/modules/ve/ui/dialogs/ve.ui.PagedDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.PagedDialog.js
@@ -26,6 +26,7 @@
 
        // Properties
        this.pages = {};
+       this.currentPageName = null;
 };
 
 /* Inheritance */
@@ -68,7 +69,7 @@
  */
 ve.ui.PagedDialog.prototype.onOutlineSelect = function ( item ) {
        if ( item ) {
-               this.pagesPanel.showItem( this.pages[item.getData()] );
+               this.setPage( item.getData() );
        }
 };
 
@@ -82,11 +83,15 @@
  * @param {string} [config.icon] Symbolic name of icon
  * @param {number} [config.level=0] Indentation level
  * @param {number} [config.index] Specific index to insert page at
+ * @param {jQuery} [config.$content] Page content
  * @chainable
  */
 ve.ui.PagedDialog.prototype.addPage = function ( name, config ) {
        // Create and add page panel and outline item
        this.pages[name] = new ve.ui.PanelLayout( { '$$': this.frame.$$, 
'scroll': true } );
+       if ( config.$content ) {
+               this.pages[name].$.append( config.$content );
+       }
        this.pagesPanel.addItems( [this.pages[name]], config.index );
        this.outlineWidget.addItems(
                [
@@ -109,6 +114,29 @@
 };
 
 /**
+ * Remove a page.
+ *
+ * @method
+ * @chainable
+ */
+ve.ui.PagedDialog.prototype.removePage = function ( name ) {
+       var page = this.pages[name];
+
+       if ( page ) {
+               delete this.pages[name];
+               this.pagesPanel.removeItems( [ page ] );
+               this.outlineWidget.removeItems( [ 
this.outlineWidget.getItemFromData( name ) ] );
+       }
+
+       // Auto-select first item when nothing is selected anymore
+       if ( !this.outlineWidget.getSelectedItem() ) {
+               this.outlineWidget.selectItem( 
this.outlineWidget.getClosestSelectableItem( 0 ) );
+       }
+
+       return this;
+};
+
+/**
  * Clear all pages.
  *
  * @method
@@ -118,6 +146,7 @@
        this.pages = [];
        this.pagesPanel.clearItems();
        this.outlineWidget.clearItems();
+       this.currentPageName = null;
 
        return this;
 };
@@ -132,3 +161,27 @@
 ve.ui.PagedDialog.prototype.getPage = function ( name ) {
        return this.pages[name];
 };
+
+/**
+ * Set the page by name.
+ *
+ * @method
+ * @param {string} name Symbolic name of page
+ */
+ve.ui.PagedDialog.prototype.setPage = function ( name ) {
+       if ( name in this.pages ) {
+               this.currentPageName = name;
+               this.pagesPanel.showItem( this.pages[name] );
+               this.pages[name].$.find( ':input:first' ).focus();
+       }
+};
+
+/**
+ * Get current page name.
+ *
+ * @method
+ * @returns {string|null} Current page name
+ */
+ve.ui.PagedDialog.prototype.getPageName = function () {
+       return this.currentPageName;
+};

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2a2f0c329d274796b8c9e7572ecff8294f472f7f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[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