cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] git commit: [CB-2682] [CB-2683] add prompt dialog to Notification API for WP
Date Thu, 28 Nov 2013 02:25:57 GMT
Updated Branches:
  refs/heads/master 439fd253c -> 0d508c524


[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/master
Commit: f046a01e227d1279efb5df9204b2fbc6b9153d13
Parents: da54b61
Author: sgrebnov <sergei.grebnov@gmail.com>
Authored: Wed Aug 7 13:02:37 2013 +0400
Committer: sgrebnov <sergei.grebnov@gmail.com>
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<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;


Mime
View raw message