From dd028bec3822d1d9c28c35d599d687e038c7705f Mon Sep 17 00:00:00 2001
From: wei <>
Date: Thu, 4 Jan 2007 11:23:26 +0000
Subject: Add chat demo and tutorial.
---
demos/chat/protected/pages/Home.page | 51 +++++++++++++++++++++
demos/chat/protected/pages/Home.php | 56 +++++++++++++++++++++++
demos/chat/protected/pages/Login.page | 35 +++++++++++++++
demos/chat/protected/pages/Login.php | 40 +++++++++++++++++
demos/chat/protected/pages/config.xml | 15 +++++++
demos/chat/protected/pages/send.gif | Bin 0 -> 993 bytes
demos/chat/protected/pages/send.png | Bin 0 -> 32586 bytes
demos/chat/protected/pages/style.css | 82 ++++++++++++++++++++++++++++++++++
8 files changed, 279 insertions(+)
create mode 100644 demos/chat/protected/pages/Home.page
create mode 100644 demos/chat/protected/pages/Home.php
create mode 100644 demos/chat/protected/pages/Login.page
create mode 100644 demos/chat/protected/pages/Login.php
create mode 100644 demos/chat/protected/pages/config.xml
create mode 100644 demos/chat/protected/pages/send.gif
create mode 100644 demos/chat/protected/pages/send.png
create mode 100644 demos/chat/protected/pages/style.css
(limited to 'demos/chat/protected/pages')
diff --git a/demos/chat/protected/pages/Home.page b/demos/chat/protected/pages/Home.page
new file mode 100644
index 00000000..b896cd28
--- /dev/null
+++ b/demos/chat/protected/pages/Home.page
@@ -0,0 +1,51 @@
+
+
+
+
+ Prado Chat Demo
+
+
+
+
+
+Prado Chat Demo
+
+
+
+
+
+
+
+
+
+
+ OnClick="processMessage"/>
+
+
+
+
+
+ Event.observe($("<%= $this->userinput->ClientID %>"), "keypress", function(ev)
+ {
+ if(Event.keyCode(ev) == Event.KEY_RETURN)
+ {
+ if(Event.element(ev).value.length > 0)
+ new Prado.Callback("<%= $this->sendButton->UniqueID %>");
+ Event.stop(ev);
+ }
+ });
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/chat/protected/pages/Home.php b/demos/chat/protected/pages/Home.php
new file mode 100644
index 00000000..65cb22dc
--- /dev/null
+++ b/demos/chat/protected/pages/Home.php
@@ -0,0 +1,56 @@
+Application->User->Name;
+ if(!$this->Application->Modules['users']->usernameExists($username))
+ {
+ $auth = $this->Application->Modules['auth'];
+ $auth->logout();
+
+ //redirect to login page.
+ $this->Response->Redirect($this->Service->ConstructUrl($auth->LoginPage));
+ }
+ }
+
+ function processMessage($sender, $param)
+ {
+ if(strlen($this->userinput->Text) > 0)
+ {
+ $record = new ChatBufferRecord();
+ $record->message = $this->userinput->Text;
+ $record->from_user = $this->Application->User->Name;
+ $record->saveMessage();
+ $this->userinput->Text = '';
+ $this->refresh($sender, $param);
+ $this->CallbackClient->focus($this->userinput);
+ }
+ }
+
+ function refresh($sender, $param)
+ {
+ //refresh the message list
+ $content = ChatBufferRecord::finder()->getUserMessages($this->Application->User->Name);
+ if(strlen($content) > 0)
+ {
+ $client = $this->Page->CallbackClient;
+ $anchor = (string)time();
+ $content .= " ";
+ $client->appendContent("messages", $content);
+ $client->focus($anchor);
+ }
+
+ //refresh the user list
+ $lastUpdate = $this->getViewState('userList','');
+ $users = ChatUserRecord::finder()->getUserList();
+ if($lastUpdate != $users)
+ {
+ $this->Page->CallbackClient->update('users', $users);
+ $this->setViewstate('userList', $users);
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/demos/chat/protected/pages/Login.page b/demos/chat/protected/pages/Login.page
new file mode 100644
index 00000000..0d0a3fa8
--- /dev/null
+++ b/demos/chat/protected/pages/Login.page
@@ -0,0 +1,35 @@
+
+
+
+
+ Prado Chat Demo Login
+
+
+
+
+
+
+ Prado Chat Demo Login
+
+
+
+
\ No newline at end of file
diff --git a/demos/chat/protected/pages/Login.php b/demos/chat/protected/pages/Login.php
new file mode 100644
index 00000000..831ab925
--- /dev/null
+++ b/demos/chat/protected/pages/Login.php
@@ -0,0 +1,40 @@
+Application->Modules['users'];
+ if($manager->usernameExists($this->username->Text))
+ $param->IsValid = false;
+ }
+
+ /**
+ * Create and login a new user, then redirect to the requested page.
+ * @param TControl button control that created the event.
+ * @param TEventParameter event parameters.
+ */
+ function createNewUser($sender, $param)
+ {
+ if($this->Page->IsValid)
+ {
+ $manager = $this->Application->Modules['users'];
+ $manager->addNewUser($this->username->Text);
+
+ //do manual login
+ $user = $manager->getUser($this->username->Text);
+ $auth = $this->Application->Modules['auth'];
+ $auth->updateSessionUser($user);
+ $this->Application->User = $user;
+
+ $this->Response->redirect($auth->ReturnUrl);
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/demos/chat/protected/pages/config.xml b/demos/chat/protected/pages/config.xml
new file mode 100644
index 00000000..c9fbdaae
--- /dev/null
+++ b/demos/chat/protected/pages/config.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/chat/protected/pages/send.gif b/demos/chat/protected/pages/send.gif
new file mode 100644
index 00000000..b3c5219d
Binary files /dev/null and b/demos/chat/protected/pages/send.gif differ
diff --git a/demos/chat/protected/pages/send.png b/demos/chat/protected/pages/send.png
new file mode 100644
index 00000000..3025b77d
Binary files /dev/null and b/demos/chat/protected/pages/send.png differ
diff --git a/demos/chat/protected/pages/style.css b/demos/chat/protected/pages/style.css
new file mode 100644
index 00000000..884aff7c
--- /dev/null
+++ b/demos/chat/protected/pages/style.css
@@ -0,0 +1,82 @@
+body
+{
+ width: 700px;
+ margin: 2em auto;
+ font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
+}
+
+h1
+{
+ font-size: 1.5em;
+ color: #444;
+}
+
+.login
+{
+ width: 500px;
+ margin: 1em auto;
+}
+
+.login .username
+{
+ margin: 1em;
+}
+
+.login .login-button
+{
+ padding-left: 7em;
+}
+
+.messages
+{
+ width: 500px;
+ height: 300px;
+ float: left;
+ border: 1px solid ButtonFace;
+ overflow: auto;
+}
+
+.messages .message
+{
+ margin: 0.4em 1em;
+ font-size: 0.85em;
+}
+
+.user-list
+{
+ margin-left: 2px;
+ float: left;
+ width: 180px;
+ height: 300px;
+ border: 1px solid ButtonFace;
+ overflow: auto;
+ font-size: 0.85em;
+}
+
+.message-input
+{
+ float: left;
+}
+
+.message-input textarea
+{
+ margin-top: 3px;
+ padding: 0.4em 0.2em;
+ width: 493px;
+ font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
+ font-size: 0.85em;
+ height: 40px;
+}
+
+.send-button
+{
+ margin: 0.5em;
+}
+
+#footer
+{
+ clear: both;
+ font-size: 0.7em;
+ text-align: center;
+ padding-top: 50px;
+}
\ No newline at end of file
--
cgit v1.2.3