Bug 432368 - Create a reusable Orion prompt dialog
diff --git a/bundles/org.eclipse.orion.client.ui/web/css/controls.css b/bundles/org.eclipse.orion.client.ui/web/css/controls.css
index e4f8c10..6579a6a 100644
--- a/bundles/org.eclipse.orion.client.ui/web/css/controls.css
+++ b/bundles/org.eclipse.orion.client.ui/web/css/controls.css
@@ -101,7 +101,7 @@
 	color: whitesmoke;

 	vertical-align: middle;

 	font-weight: normal;

-	padding: 3px;

+	padding: 3px 0 0 3px;

 	padding-bottom: 0;

 }

 

@@ -119,6 +119,12 @@
 	min-width: 16px;

 }

 

+.parametersDismiss .core-sprite-close {

+	margin-right: 0;

+	padding-right: 0;

+	padding-top: 0;

+}

+

 .cancelButton {

 	border: 1px solid transparent;

 	background: #D3D3D3 !important;

@@ -1240,3 +1246,19 @@
 	from{margin-left: -100%;}

 	to{margin-left: 100%;}

 }

+

+.promptDialogMessage {

+	color: #222;

+	margin: 0 2px 4px 2px;

+}

+

+.promptDialogInput {

+	min-width: 200px;

+	padding: 4px;

+	margin: 2px 2px 0 2px;

+	background-color: white;

+	border: 1px solid #CCC;

+	border-radius: 3px;

+	font-size: 12px;

+	color: #222;

+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.ui/web/css/theme.css b/bundles/org.eclipse.orion.client.ui/web/css/theme.css
index 51ec242..5090f18 100644
--- a/bundles/org.eclipse.orion.client.ui/web/css/theme.css
+++ b/bundles/org.eclipse.orion.client.ui/web/css/theme.css
@@ -274,6 +274,11 @@
 	color: #cdcdcd;

 }

 

+.commandButton.disabled:hover {

+	background-color: #ddd;

+	box-shadow: none;

+}

+

 .commandImage {

 	border: 1px solid transparent;

     border-radius: 1px;

@@ -653,7 +658,6 @@
 	border-top-right-radius: 1px;

 }

 

-

 .dialogTitleText {

 	margin: 2px 2px 0;

 	color: whitesmoke;

@@ -663,6 +667,18 @@
 	font-weight: bold;

 }

 

+.dialogTitle .dismissButton {

+	margin-right: 0;	

+}

+

+.parameterPopup .dismissButton, .dialogTitle .dismissButton {

+	color: rgb(221, 221, 221);

+	cursor: pointer;

+}

+

+.parameterPopup .dismissButton:hover, .dialogTitle .dismissButton:hover {

+	color: white;

+}

 

 .dialogDismiss {

 	display: block;

diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialog.js b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialog.js
index 9ef00d8..06d1e21 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialog.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialog.js
@@ -108,9 +108,6 @@
 			if (typeof this._bindToDom === "function") { //$NON-NLS-0$
 				this._bindToDom(this.$parent);
 			}
-			if (this.modal) {
-				this._makeModal();
-			}
 		},
 		
 		/*
@@ -259,6 +256,7 @@
 		 */
 		show: function(near) {
 			if(this.modal){//Modal dialog should only appear once unless they are chain dialog
+				this._makeModal();
 				if(modalDialogManager.dialog) {//There is already modal dialog opened
 					if(!modalDialogManager.dialog._inModalExclusion(this)) {//The dialog is NOT a child dialog of the exisitng dialog
 						this.hide(true);
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/PromptDialog.js b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/PromptDialog.js
new file mode 100644
index 0000000..14c5ec1
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/PromptDialog.js
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * @license
+ * Copyright (c) 2014 IBM Corporation and others. 
+ * All rights reserved. This program and the accompanying materials are made 
+ * available under the terms of the Eclipse Public License v1.0 
+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
+ * 
+ * Contributors: IBM Corporation - initial API and implementation
+ ******************************************************************************/
+/*global define*/
+/*jslint browser:true */
+
+define(['i18n!orion/widgets/nls/messages', 'orion/webui/littlelib', 'orion/webui/dialog', 'text!orion/webui/dialogs/promptdialog.html', 'orion/EventTarget'], 
+function(messages, lib, dialog, PromptDialogFragment, EventTarget) {
+
+	/**
+	 * @class orion.webui.dialogs.PromptDialog
+	 * @extends orion.webui.Dialog
+	 * 
+	 * Creates a modal prompt dialog.
+	 * @param {Object} options 	An object containing the options for this dialog.
+	 * 						   	Below is a list of the options that are specific to PromptDialog.
+	 * 							See orion.webui.Dialog for a list of other usable options.
+	 * 		{String} options.title The title to be displayed in the prompt dialog's title bar.
+	 * 		{String} options.promptMessage The message to be displayed in the prompt dialog. Optional.
+	 *
+	 * @name orion.webui.dialogs.PromptDialog
+	 *
+	 */
+	function PromptDialog(options) {
+		EventTarget.attach(this);
+		this._init(options);
+	}
+	
+	PromptDialog.prototype = Object.create(dialog.Dialog.prototype);
+	PromptDialog.prototype.constructor = PromptDialog;
+	
+	PromptDialog.prototype.TEMPLATE = PromptDialogFragment;
+	
+	PromptDialog.prototype._init = function(options) {
+		this.title = options.title;
+		
+		if (options.promptMessage) {
+			this.messages = {
+				PromptMessage: options.promptMessage
+			};	
+		}
+		
+		this.modal = true;
+		
+		this._boundOkPressed = this._okPressed.bind(this);
+		
+		this.buttons = [
+			{id: "okButton", text: messages["OK"], callback: this._boundOkPressed},
+			{id: "cancelButton", text: messages["Cancel"], callback: this._cancelPressed.bind(this)}
+		];
+		
+		this._initialize(); //superclass function
+		
+		if (!options.promptMessage) {
+			//hide prompt message div
+			this.$promptDialogMessage.style.display = "none"; //$NON-NLS-0$
+		}
+	};
+
+	/**
+	 * See orion.webui.Dialog
+	 */
+	PromptDialog.prototype._bindToDom = function(parent) {
+		this.$promptDialogInput.addEventListener("keydown", function(event){
+			if (event.keyCode === lib.KEY.ENTER) {
+				// mirror behavior of clicking the ok button
+				this._boundOkPressed();
+				lib.stop(event);
+			} else if (event.keyCode === lib.KEY.ESCAPE) {
+				this.$cancelButton.focus();
+				lib.stop(event);
+			}
+		}.bind(this), false);
+	};
+	
+	/**
+	 * Dispatches an "ok" event letting listeners know that the 
+	 * OK button was pressed and hides the dialog. 
+	 * 
+	 * @note The dispatched event's "value" property contains 
+	 * 		 the value of this dialog's text input element.
+	 */
+	PromptDialog.prototype._okPressed = function() {
+		this.dispatchEvent({type: "ok", value: this.$promptDialogInput.value});
+		this.hide();
+	};
+	
+	/**
+	 * Dispatches a "cancel" event letting listeners know that the
+	 * cancel button was pressed and hides the dialog.
+	 */
+	PromptDialog.prototype._cancelPressed = function() {
+		this.dispatchEvent({type: "cancel"});
+		this.hide();
+	};
+	
+	//return the module exports
+	return {PromptDialog: PromptDialog};
+});
\ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/promptdialog.html b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/promptdialog.html
new file mode 100644
index 0000000..a407002
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/promptdialog.html
@@ -0,0 +1,4 @@
+<div>

+	<div class="promptDialogMessage" id="promptDialogMessage">${PromptMessage}</div>

+	<input type="text" id="promptDialogInput" class="promptDialogInput" />

+</div>
\ No newline at end of file