text changes to registration mail content
[namibia] / public / js / vendor / ape.sys-message.js
1 function sysMessage(ape, debug){
2         // we call this function once APE has finished loading
3         this.initialize = function(){
4                 // once a new user joins (pipe created), call setup()
5                 ape.addEvent('pipeCreate', this.setup);
6
7                 // when a user joins, update the user list
8                 ape.addEvent('userJoin', this.createUser);
9
10                 // when a user leaves, destroy them with mighty thunder!
11                 ape.addEvent('userLeft', this.deleteUser);
12
13                 // when we want to send data
14                 ape.onCmd('send', this.cmdSend);
15
16                 // and when we recieve data
17                 ape.onRaw('data', this.rawData);
18
19                 // start the session with a random name!
20                 // note: you'll need the chat plugin loaded
21                 ape.start(String((new Date()).getTime()).replace(/D/gi,''));
22         }
23
24         this.setup = function(type, pipe, options){
25                 // add an event listener on our selectbox
26                 $("#button").click(function(){
27                         // get the select box value
28                         if ($("#chat").val())
29                         {
30                                 // send the message to the APE server
31                                 pipe.send($("#chat").val());
32                         }
33                 });
34         }
35
36         this.cmdSend = function(pipe, sessid, pubid, message){
37                 if(debug)
38                         $("<span>    " + ape.user.properties.name + " sent new message: " + message + "</span><br />").prependTo("#debug");
39         }
40
41         this.rawData = function(raw, pipe){
42                 // data has been received by the APE server so do the following...
43                 if(debug)
44                         $("<span>   Received message from  " + raw.datas.sender.properties.name + " saying: " + raw.datas.msg + "</span><br />").prependTo("#debug");
45
46                 // set the selectboxes value to match other clients
47                 $('<span>' + raw.datas.msg + '</span>').prependTo("#wrapper");
48         }
49
50         this.createUser = function(user, pipe){
51                 // a user has joined so prepend them to the debug window
52                 user.element = $("<span>" + user.properties.name + " has joined</span><br />").prependTo("#debug");
53         }
54
55         this.deleteUser = function(user, pipe){
56                 // a user has left so update the debug window
57                 $(user.element).text(user.properties.name + " has left").css("color", "#666666").prependTo("#debug");
58         }
59 }