LSmail : fix input size and the smoothbox
[ldapsaisie.git] / public_html / includes / js / LSmail.js
1 var LSmail = new Class({
2     initialize: function(mails,subject,msg){
3       this.href = "LSmail.php";
4       this.setMails(mails);
5       this.setMsg(msg);
6       this.setSubject(subject);
7       this.object = {};
8       this.opened = 0;
9       this.listeners = {
10         close:    new Array(),
11         valid:  new Array()
12       };
13     },
14     
15     setMails: function(mails) {
16       if ($type(mails)) {
17         this.mails = mails;
18       }
19       else {
20         this.mails = new Array();
21       }      
22     },
23     
24     setMsg: function(msg) {
25       if ($type(msg)) {
26         this.msg = msg;
27       }
28       else {
29         this.msg = "";
30       }      
31     },
32     
33     setSubject: function(subject) {
34       if ($type(subject)) {
35         this.subject = subject;
36       }
37       else {
38         this.subject = "";
39       }      
40     },
41     
42     setObject: function(type,dn) {
43       this.object = {
44         type:   type,
45         dn:     dn
46       };
47     },
48     
49     open: function(startElement) {
50       if (this.opened==0) {
51         var data = {
52           template:   'LSmail',
53           action:     'display',
54           object:     this.object,
55           mails:      this.mails,
56           msg:        this.msg,
57           subject:    this.subject
58         };
59         
60         if ($type(startElement)) {
61           this.startElement = startElement;
62           data.imgload=varLSdefault.loadingImgDisplay(startElement);
63         }
64
65         new Request({url: 'index_ajax.php', data: data, onSuccess: this.onOpenGetHtmlComplete.bind(this)}).send();
66       }
67     },
68     
69     onOpenGetHtmlComplete: function(responseText, responseXML) {
70       var data = JSON.decode(responseText);
71       if ( varLSdefault.checkAjaxReturn(data) ) {
72         varLSsmoothbox.asNew();
73         varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
74         varLSsmoothbox.addEvent('close',this.onLSsmoothboxClose.bind(this));
75         varLSsmoothbox.openHTML(data.html,{startElement: this.startElement, width: 800, height: 400});
76       }
77     },
78     
79     onLSsmoothboxValid: function(LSsmoothbox) {
80       if($type(LSsmoothbox.frame)) {
81         this.sendInfos = {
82           mail:     LSsmoothbox.frame.getElementById('LSmail_mail').value,
83           subject:  LSsmoothbox.frame.getElementById('LSmail_subject').value,
84           msg:      LSsmoothbox.frame.getElementById('LSmail_msg').value
85         };
86       }
87       this.fireEvent.bind(this)('valid');
88     },
89     
90     onLSsmoothboxClose: function(LSsmoothbox) {
91       this.opened=0;
92       this.fireEvent.bind(this)('close');
93     },
94     
95     send: function() {
96       if ($type(this.sendInfos)) {
97         var data = {
98           template:   'LSmail',
99           action:     'send',
100           infos:      this.sendInfos
101         };
102         data.imgload=varLSdefault.loadingImgDisplay(this.startElement);
103         new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSendComplete.bind(this)}).send();
104       }
105     },
106     
107     getMail: function() {
108       return this.sendInfos;
109     },
110     
111     onSendComplete: function(responseText, responseXML) {
112       var data = JSON.decode(responseText);
113       if ( varLSdefault.checkAjaxReturn(data) ) {
114         if ($type(data.msgok)) {
115           varLSdefault.LSinfos.display(data.msgok);
116         }
117       }
118     },
119     
120     addEvent: function(event,fnct) {
121       if ($type(this.listeners[event])) {
122         if ($type(fnct)=="function") {
123           this.listeners[event].include(fnct);
124         }
125       }
126     },
127     
128     fireEvent: function(event) {
129       LSdebug('LSmail :: fireEvent('+event+')');
130       if ($type(this.listeners[event])) {
131         this.listeners[event].each(function(fnct) {
132           try {
133             fnct(this);
134           }
135           catch(e) {
136             LSdebug('LSmail :: '+event+'() -> rater');
137           }
138         },this);
139       }
140     }
141 });