Rename trunk directory to public_html
[ldapsaisie.git] / public_html / includes / js / LSformElement.js
1 var LSformElement = new Class({
2     initialize: function(LSform,name,ul){
3       this.LSform=LSform;
4       this.name=name;
5       this.ul=ul;
6       this.fields=[];
7       this.multiple = this.ul.hasClass('LSformElement_multiple');
8       this.initializeLSformElement();
9     },
10     
11     initializeLSformElement: function(li) {
12       if (typeof(li) == 'undefined') {
13         var elements = this.ul.getElements('li');
14       }
15       else {
16         var elements = [li];
17       }
18       elements.each(function(li) {
19         var id='LSformElement_field_'+this.name+'_'+$random(1,1000);
20         this.fields[id] = new LSformElement_field(this,li,id);
21       }, this);
22     },
23     
24     onAddFieldBtnClick: function(field){
25       var data = {
26         template:   'LSform',
27         action:     'onAddFieldBtnClick',
28         attribute:  this.name,
29         objecttype: this.LSform.objecttype,
30         objectdn:   this.LSform.objectdn,
31         idform:     this.LSform.idform,
32         fieldId:    field.id
33       };
34       LSdebug(data);
35       data.imgload = varLSdefault.loadingImgDisplay(field.li,'inside');
36       new Request({url: 'index_ajax.php', data: data, onSuccess: this.onAddFieldBtnClickComplete.bind(this)}).send();
37     },
38
39     onAddFieldBtnClickComplete: function(responseText, responseXML) {
40       var data = JSON.decode(responseText);
41       LSdebug(data);
42       if ( varLSdefault.checkAjaxReturn(data) ) {
43         var li = new Element('li');
44         var field = this.fields[data.fieldId];
45         li.set('html',data.html);
46         li.injectAfter(field.li);
47         this.initializeLSformElement(li);
48         this.LSform.initializeModule(data.fieldtype,li);
49       }
50     },
51
52     onRemoveFieldBtnClick: function(field) {
53       if (this.ul.getElements('li').length == 1) {
54         field.clearValue.bind(field)();
55       }
56       else {
57         field.remove.bind(field)();
58       }
59     }
60 });