Repository: cordova-plugin-dialogs Updated Branches: refs/heads/dev 3a17d55bf -> 3d51112bd (forced update)
[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/e8fd5cbf Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/e8fd5cbf Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/e8fd5cbf Branch: refs/heads/dev Commit: e8fd5cbfffc118c849977a2b9d5515ea74d0b45c Parents: 31252a7 Author: sgrebnov <[email protected]> Authored: Wed Aug 7 13:02:37 2013 +0400 Committer: Archana Naik <[email protected]> Committed: Thu Mar 20 16:27:44 2014 -0700 ---------------------------------------------------------------------- src/wp/Notification.cs | 113 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/e8fd5cbf/src/wp/Notification.cs ---------------------------------------------------------------------- diff --git a/src/wp/Notification.cs b/src/wp/Notification.cs index 1c0c63b..84ec4de 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<string[]>(options); @@ -129,6 +145,56 @@ namespace WPCordovaClassLib.Cordova.Commands }); } + public void prompt(string options) + { + string[] args = JSON.JsonHelper.Deserialize<string[]>(options); + string message = args[0]; + string title = args[1]; + string buttonLabelsArray = args[2]; + string[] buttonLabels = JSON.JsonHelper.Deserialize<string[]>(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<string[]>(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;
