Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8A3410340 for ; Tue, 10 Dec 2013 00:30:42 +0000 (UTC) Received: (qmail 36445 invoked by uid 500); 10 Dec 2013 00:30:42 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 36420 invoked by uid 500); 10 Dec 2013 00:30:42 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 36385 invoked by uid 99); 10 Dec 2013 00:30:42 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Dec 2013 00:30:42 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 587308B1CE8; Tue, 10 Dec 2013 00:30:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Tue, 10 Dec 2013 00:30:42 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/6] git commit: [CB-2682] [CB-2683] add prompt dialog to Notification API for WP Updated Branches: refs/heads/dev 96c5fa74e -> 6f46067b9 [CB-2682] [CB-2683] add prompt dialog to Notification API for WP Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/f046a01e Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/f046a01e Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/f046a01e Branch: refs/heads/dev Commit: f046a01e227d1279efb5df9204b2fbc6b9153d13 Parents: da54b61 Author: sgrebnov Authored: Wed Aug 7 13:02:37 2013 +0400 Committer: sgrebnov Committed: Wed Aug 7 13:02:37 2013 +0400 ---------------------------------------------------------------------- src/wp/Notification.cs | 113 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/f046a01e/src/wp/Notification.cs ---------------------------------------------------------------------- diff --git a/src/wp/Notification.cs b/src/wp/Notification.cs index 339978a..8ce3668 100644 --- a/src/wp/Notification.cs +++ b/src/wp/Notification.cs @@ -87,6 +87,22 @@ namespace WPCordovaClassLib.Cordova.Commands public string buttonLabel; } + [DataContract] + public class PromptResult + { + [DataMember] + public int buttonIndex; + + [DataMember] + public string input1; + + public PromptResult(int index, string text) + { + this.buttonIndex = index; + this.input1 = text; + } + } + public void alert(string options) { string[] args = JSON.JsonHelper.Deserialize(options); @@ -129,6 +145,56 @@ namespace WPCordovaClassLib.Cordova.Commands }); } + public void prompt(string options) + { + string[] args = JSON.JsonHelper.Deserialize(options); + string message = args[0]; + string title = args[1]; + string buttonLabelsArray = args[2]; + string[] buttonLabels = JSON.JsonHelper.Deserialize(buttonLabelsArray); + string defaultText = args[3]; + string aliasCurrentCommandCallbackId = args[4]; + + Deployment.Current.Dispatcher.BeginInvoke(() => + { + PhoneApplicationPage page = Page; + if (page != null) + { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) + { + var previous = notifyBox; + notifyBox = new NotificationBox(); + notifyBox.Tag = new NotifBoxData { previous = previous, callbackId = aliasCurrentCommandCallbackId }; + notifyBox.PageTitle.Text = title; + notifyBox.SubTitle.Text = message; + TextBox textBox = new TextBox(); + textBox.Text = defaultText; + notifyBox.TitlePanel.Children.Add(textBox); + + for (int i = 0; i < buttonLabels.Length; ++i) + { + Button button = new Button(); + button.Content = buttonLabels[i]; + button.Tag = i + 1; + button.Click += promptBoxbutton_Click; + notifyBox.TitlePanel.Children.Add(button); + } + + grid.Children.Add(notifyBox); + if (previous != null) + { + page.BackKeyPress += page_BackKeyPress; + } + } + } + else + { + DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION)); + } + }); + } + public void confirm(string options) { string[] args = JSON.JsonHelper.Deserialize(options); @@ -182,6 +248,53 @@ namespace WPCordovaClassLib.Cordova.Commands }); } + void promptBoxbutton_Click(object sender, RoutedEventArgs e) + { + Button button = sender as Button; + FrameworkElement promptBox = null; + int buttonIndex = 0; + string callbackId = string.Empty; + string text = string.Empty; + if (button != null) + { + buttonIndex = (int)button.Tag; + promptBox = button.Parent as FrameworkElement; + while ((promptBox = promptBox.Parent as FrameworkElement) != null && + !(promptBox is NotificationBox)) ; + } + + if (promptBox != null) + { + foreach (UIElement element in (promptBox as NotificationBox).TitlePanel.Children) + { + if (element is TextBox) + { + text = (element as TextBox).Text; + break; + } + } + PhoneApplicationPage page = Page; + if (page != null) + { + Grid grid = page.FindName("LayoutRoot") as Grid; + if (grid != null) + { + grid.Children.Remove(promptBox); + } + + NotifBoxData data = promptBox.Tag as NotifBoxData; + promptBox = data.previous as NotificationBox; + callbackId = data.callbackId as string; + + if (promptBox == null) + { + page.BackKeyPress -= page_BackKeyPress; + } + } + } + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, new PromptResult(buttonIndex, text)), callbackId); + } + void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) { PhoneApplicationPage page = sender as PhoneApplicationPage;