Added image.php to permit fully dynamic image path
[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         if (!input.hasClass('LSformElement_mail_disableMailSending')) {
16           this.addBtnAfter.bind(this)(input);
17         }
18       }, this);
19       el.getElements('a.LSformElement_mail').each(function(a) {
20         if (!a.hasClass('LSformElement_mail_disableMailSending')) {
21           this.addBtnAfter.bind(this)(a);
22         }
23       }, this);
24     },
25     
26     addBtnAfter: function(el) {
27       var btn = new Element('img');
28       btn.setProperties({
29         src:    varLSdefault.imagePath('mail')
30       });
31       btn.addClass('btn');
32       btn.injectAfter(el);
33       btn.addEvent('click',this.onBtnClick.bind(this,btn));
34       varLSdefault.addHelpInfo(btn,'LSformElement_mail','mail');
35     },
36     
37     reinitialize: function(el) {
38       varLSform.initializeModule('LSformElement_text',el);
39       this.initialiseLSformElement_mail(el);
40     },
41     
42     onBtnClick: function(btn) {
43       if (this.LSmail_open==0) {
44         var mail = btn.getParent().getFirst().innerHTML;
45         if ((typeof(mail)!='string')||(mail=='')) {
46            mail = btn.getParent().getFirst().value;
47         }
48         if(!$type(this.LSmail)) {
49           this.LSmail = new LSmail();
50           this.LSmail.addEvent('close',this.onLSmailClose.bind(this));
51           this.LSmail.addEvent('valid',this.onLSmailValid.bind(this));
52         }
53         if ((mail!="")) {
54           this.LSmail_open = 1;
55           this.LSmail.setMails([mail]);
56           this.LSmail.setObject(varLSform.objecttype,varLSform.objectdn);
57           this.LSmail.open(btn);
58         }
59       }
60     },
61     
62     onLSmailClose: function(LSmail) {
63       LSdebug('LSformElement_mail : close LSmail');
64       this.LSmail_open = 0;
65     },
66     
67     onLSmailValid: function(LSmail) {
68       LSdebug('LSformElement_mail : valid LSmail');
69       LSmail.send();
70     }
71 });
72 window.addEvent(window.ie ? 'load' : 'domready', function() {
73   varLSformElement_mail = new LSformElement_mail();
74 });