c6d88c5cf041e44e6db0e14caedb3b9e1cd35669
[ldapsaisie.git] / public_html / includes / js / LSformElement_mail.js
1 var LSformElement_mail = new Class({
2     initialize: function(){
3       this.initialiseLSformElement_mail();
4       if (typeof(varLSform) != "undefined") {
5         varLSform.addModule("LSformElement_mail",this);
6       }
7       this.LSmail_open = 0;
8     },
9     
10     initialiseLSformElement_mail: function(el) {
11       if (typeof(el) == 'undefined') {
12         el = document;
13       }
14       el.getElements('input.LSformElement_mail').each(function(input) {
15         this.addBtnAfter.bind(this)(input);
16       }, this);
17       el.getElements('a.LSformElement_mail').each(function(a) {
18         this.addBtnAfter.bind(this)(a);
19       }, this);
20     },
21     
22     addBtnAfter: function(el) {
23       var btn = new Element('img');
24       btn.setProperties({
25         src:    varLSdefault.imagePath('mail.png')
26       });
27       btn.addClass('btn');
28       btn.injectAfter(el);
29       btn.addEvent('click',this.onBtnClick.bind(this,btn));
30       varLSdefault.addHelpInfo(btn,'LSformElement_mail','mail');
31     },
32     
33     reinitialize: function(el) {
34       varLSform.initializeModule('LSformElement_text',el);
35       this.initialiseLSformElement_mail(el);
36     },
37     
38     onBtnClick: function(btn) {
39       if (this.LSmail_open==0) {
40         var mail = btn.getParent().getFirst().innerHTML;
41         if ((typeof(mail)!='string')||(mail=='')) {
42            mail = btn.getParent().getFirst().value;
43         }
44         if(!$type(this.LSmail)) {
45           this.LSmail = new LSmail();
46           this.LSmail.addEvent('close',this.onLSmailClose.bind(this));
47           this.LSmail.addEvent('valid',this.onLSmailValid.bind(this));
48         }
49         if ((mail!="")) {
50           this.LSmail_open = 1;
51           this.LSmail.setMails([mail]);
52           this.LSmail.setObject(varLSform.objecttype,varLSform.objectdn);
53           this.LSmail.open(btn);
54         }
55       }
56     },
57     
58     onLSmailClose: function(LSmail) {
59       LSdebug('LSformElement_mail : close LSmail');
60       this.LSmail_open = 0;
61     },
62     
63     onLSmailValid: function(LSmail) {
64       LSdebug('LSformElement_mail : valid LSmail');
65       LSmail.send();
66     }
67 });
68 window.addEvent(window.ie ? 'load' : 'domready', function() {
69   varLSformElement_mail = new LSformElement_mail();
70 });