Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/132113

Change subject: Add confirmation dialog
......................................................................

Add confirmation dialog

After some discussion on IRC, we think the confirmation dialog in
I98f9a03d is more appropriate for OOUI.

Bug: 50955
Change-Id: I292fb34d15495429e5a9134f0f5ceab3c0a3a819
---
M build/modules.json
M i18n/en.json
M i18n/qqq.json
A src/ConfirmationDialog.js
M src/core.js
5 files changed, 95 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/13/132113/1

diff --git a/build/modules.json b/build/modules.json
index 96739a8..2e5f907 100644
--- a/build/modules.json
+++ b/build/modules.json
@@ -8,6 +8,7 @@
                        "src/Window.js",
                        "src/WindowSet.js",
                        "src/Dialog.js",
+                       "src/ConfirmationDialog.js",
                        "src/Layout.js",
                        "src/Widget.js",
                        "src/elements/ButtonedElement.js",
diff --git a/i18n/en.json b/i18n/en.json
index 5ff9915..e0dae18 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -20,5 +20,6 @@
     "ooui-outline-control-move-down": "Move item down",
     "ooui-outline-control-move-up": "Move item up",
     "ooui-outline-control-remove": "Remove item",
-    "ooui-toolbar-more": "More"
+    "ooui-toolbar-more": "More",
+    "ooui-dialog-confirm-title": "Confirm"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index d433fe1..fe1f20d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -23,5 +23,6 @@
        "ooui-outline-control-move-down": "Tool tip for a button that moves 
items in a list down one place",
        "ooui-outline-control-move-up": "Tool tip for a button that moves items 
in a list up one place",
        "ooui-outline-control-remove": "Tool tip for a button that removes 
items from a list.\n{{Identical|Remove item}}",
-       "ooui-toolbar-more": "Label for the toolbar group that contains a list 
of all other available tools.\n{{Identical|More}}"
+       "ooui-toolbar-more": "Label for the toolbar group that contains a list 
of all other available tools.\n{{Identical|More}}",
+       "ooui-dialog-confirm-title": "Title of the generic dialog used to 
confirm things"
 }
diff --git a/src/ConfirmationDialog.js b/src/ConfirmationDialog.js
new file mode 100644
index 0000000..0aaf09e
--- /dev/null
+++ b/src/ConfirmationDialog.js
@@ -0,0 +1,87 @@
+/**
+ * Dialog for showing a confirmation/warning message.
+ *
+ * @class
+ * @extends OO.ui.Dialog
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ */
+OO.ui.ConfirmationDialog = function OoUiConfirmationDialog( config ) {
+       // Configuration initialization
+       config = $.extend( { 'size': 'small' }, config );
+
+       // Parent constructor
+       OO.ui.Dialog.call( this, config );
+};
+
+/* Inheritance */
+
+OO.inheritClass( OO.ui.ConfirmationDialog, OO.ui.Dialog );
+
+/* Static Properties */
+
+OO.ui.ConfirmationDialog.static.name = 'confirm';
+
+OO.ui.ConfirmationDialog.static.title = OO.ui.deferMsg( 
'ooui-dialog-confirm-title' );
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.ConfirmationDialog.prototype.initialize = function () {
+       // Parent method
+       OO.ui.Dialog.prototype.initialize.call( this );
+
+       // Set up the layout
+       var contentLayout = new OO.ui.PanelLayout( {
+               '$': this.$,
+               'padded': true
+       } );
+
+       this.$container = this.$( '<div>' ).addClass( 
'oo-ui-dialog-confirmation-container' );
+
+       // Make the buttons
+       contentLayout.$element.append( this.$container );
+       this.$body.append( contentLayout.$element );
+
+       this.noButton = new OO.ui.ButtonWidget( {
+               'flags': [ 'destructive' ]
+       } );
+
+       this.yesButton = new OO.ui.ButtonWidget( {
+               'flags': [ 'constructive' ]
+       } );
+
+       this.$foot.append(
+               this.noButton.$element,
+               this.yesButton.$element
+       );
+};
+
+/*
+ * Open a confirmation dialog.
+ *
+ * @param {OO.ui.Surface} surface
+ * @param {object} data
+ * @param {string} data.prompt
+ * @param {string} data.yesText
+ * @param {string} data.noText
+ * @chainable
+ */
+OO.ui.ConfirmationDialog.prototype.open = function ( fragment, options ) {
+       this.connect( this, { 'yes': 'close', 'no': 'close' } );
+
+       this.$container.text( options.prompt );
+       this.yesButton
+               .setLabel( options.yesText )
+               .connect( this, { 'click': [ 'emit', 'yes' ] } );
+       this.noButton
+               .setLabel( options.noText )
+               .connect( this, { 'click': [ 'emit', 'no' ] } );
+
+       OO.ui.Dialog.prototype.open.call( this, fragment, options );
+
+       return this;
+};
diff --git a/src/core.js b/src/core.js
index 0dec3f9..42e3224 100644
--- a/src/core.js
+++ b/src/core.js
@@ -99,7 +99,9 @@
        // Tool tip for a button that removes items from a list
        'ooui-outline-control-remove': 'Remove item',
        // Label for the toolbar group that contains a list of all other 
available tools
-       'ooui-toolbar-more': 'More'
+       'ooui-toolbar-more': 'More',
+       // Label for the generic dialog used to confirm things
+       'ooui-dialog-confirm-title': 'Confirm'
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I292fb34d15495429e5a9134f0f5ceab3c0a3a819
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <kren...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to