LSldapObject : fix foreach error in getObjectKeyValueInRelation() if attribute is...
[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.options = {
10         display_mail_field:     1,
11         display_subject_field:  1
12       };
13       this.listeners = {
14         close:    new Array(),
15         valid:  new Array()
16       };
17     },
18     
19     setMails: function(mails) {
20       if ($type(mails)) {
21         this.mails = mails;
22       }
23       else {
24         this.mails = new Array();
25       }      
26     },
27     
28     setMsg: function(msg) {
29       if ($type(msg)) {
30         this.msg = msg;
31       }
32       else {
33         this.msg = "";
34       }      
35     },
36     
37     setSubject: function(subject) {
38       if ($type(subject)) {
39         this.subject = subject;
40       }
41       else {
42         this.subject = "";
43       }      
44     },
45     
46     setObject: function(type,dn) {
47       this.object = {
48         type:   type,
49         dn:     dn
50       };
51     },
52
53     setOption: function(option,value) {
54       this.options[option]=value;
55     },
56
57     hideMailField: function() {
58       this.setOption('display_mail_field',0);
59     },
60
61     hideSubjectField: function() {
62       this.setOption('display_subject_field',0);
63     },
64
65     setClass: function(c) {
66       this.setOption('class',c);
67     },
68
69     open: function(startElement) {
70       if (this.opened==0) {
71         var data = {
72           template:   'LSmail',
73           action:     'display',
74           object:     this.object,
75           mails:      this.mails,
76           msg:        this.msg,
77           subject:    this.subject,
78           options:    this.options
79         };
80         
81         if ($type(startElement)) {
82           this.startElement = startElement;
83           data.imgload=varLSdefault.loadingImgDisplay(startElement);
84         }
85
86         new Request({url: 'index_ajax.php', data: data, onSuccess: this.onOpenGetHtmlComplete.bind(this)}).send();
87       }
88     },
89     
90     onOpenGetHtmlComplete: function(responseText, responseXML) {
91       var data = JSON.decode(responseText);
92       if ( varLSdefault.checkAjaxReturn(data) ) {
93         varLSsmoothbox.asNew();
94         varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
95         varLSsmoothbox.addEvent('close',this.onLSsmoothboxClose.bind(this));
96         varLSsmoothbox.openHTML(data.html,{startElement: this.startElement, width: 800, height: 400});
97       }
98     },
99     
100     onLSsmoothboxValid: function(LSsmoothbox) {
101       if($type(LSsmoothbox.frame)) {
102         this.sendInfos = {
103           mail:     LSsmoothbox.frame.getElementById('LSmail_mail').value,
104           subject:  LSsmoothbox.frame.getElementById('LSmail_subject').value,
105           msg:      LSsmoothbox.frame.getElementById('LSmail_msg').value
106         };
107       }
108       this.fireEvent.bind(this)('valid');
109     },
110     
111     onLSsmoothboxClose: function(LSsmoothbox) {
112       this.opened=0;
113       this.fireEvent.bind(this)('close');
114     },
115     
116     send: function() {
117       if ($type(this.sendInfos)) {
118         var data = {
119           template:   'LSmail',
120           action:     'send',
121           infos:      this.sendInfos
122         };
123         data.imgload=varLSdefault.loadingImgDisplay(this.startElement);
124         new Request({url: 'index_ajax.php', data: data, onSuccess: this.onSendComplete.bind(this)}).send();
125       }
126     },
127     
128     getMail: function() {
129       return this.sendInfos;
130     },
131     
132     onSendComplete: function(responseText, responseXML) {
133       var data = JSON.decode(responseText);
134       if ( varLSdefault.checkAjaxReturn(data) ) {
135         if ($type(data.msgok)) {
136           varLSdefault.LSinfos.display(data.msgok);
137         }
138       }
139     },
140     
141     addEvent: function(event,fnct) {
142       if ($type(this.listeners[event])) {
143         if ($type(fnct)=="function") {
144           this.listeners[event].include(fnct);
145         }
146       }
147     },
148     
149     fireEvent: function(event) {
150       LSdebug('LSmail :: fireEvent('+event+')');
151       if ($type(this.listeners[event])) {
152         this.listeners[event].each(function(fnct) {
153           try {
154             fnct(this);
155           }
156           catch(e) {
157             LSdebug('LSmail :: '+event+'() -> rater');
158           }
159         },this);
160       }
161     }
162 });