- Passage à Mootools v1.2templates/LSrelations.tpl
[ldapsaisie.git] / trunk / includes / js / LSformElement_select_object.js
1 var LSformElement_select_object = new Class({
2     initialize: function(){
3       this.initialiseLSformElement_select_object();
4     },
5     
6     initialiseLSformElement_select_object: function() {
7       $$('a.LSformElement_select_object_addBtn').each(function(el) {
8         el.addEvent('click',this.onLSformElement_select_object_addBtnClick.bindWithEvent(this,el));
9       }, this);
10       
11       $$('img.LSformElement_select_object_deleteBtn').each(function(el) {
12         el.addEvent('click',this.LSformElement_select_object_deleteBtn.bind(this,el));
13       }, this);
14     },
15     
16     onLSformElement_select_object_addBtnClick: function(event,a) {
17       new Event(event).stop();
18       var getFieldId = /a_(.*)/
19       var fieldId = getFieldId.exec(a.id)[1];
20       var getId = /a_LSformElement_select_object_.*_([0-9]*)$/
21       var Id = getId.exec(a.id)[1];
22       
23       values = new Array();
24       $$('input.LSformElement_select_object').each(function(el) {
25         values.push(el.getProperty('value'));
26       }, this);
27       
28       var data = {
29         template:   'LSselect',
30         action:     'refreshSession',
31         objecttype: $('LSformElement_select_object_objecttype_'+Id).value,
32         values:     JSON.encode(values),
33         href:       a.href
34       };
35       
36       data.imgload=varLSdefault.loadingImgDisplay(a,'inside');
37       this.refreshFields=fieldId;
38       new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSformElement_select_object_addBtnClickComplete.bind(this)}).send();
39     },
40     
41     onLSformElement_select_object_addBtnClickComplete: function(responseText, responseXML) {
42       var data = JSON.decode(responseText);
43       if ( varLSdefault.checkAjaxReturn(data) ) {
44         varLSsmoothbox.setRefreshElement(this);
45         varLSsmoothbox.displayValidBtn();
46         varLSsmoothbox.openURL(data.href,{width: 615});
47       }
48     },
49     
50     refresh: function() {
51       var getAttrName = /LSformElement_select_object_(.*)_[0-9]*/
52       var attrName = getAttrName.exec(this.refreshFields)[1];
53       var data = {
54         template:   'LSform',
55         action:     'refreshField',
56         attribute:  attrName,
57         objecttype: $('LSform_objecttype').value,
58         objectdn:   $('LSform_objectdn').value,
59         idform:     $('LSform_idform').value,
60         ul:         this.refreshFields
61       };
62       data.imgload=varLSdefault.loadingImgDisplay($('a_' + this.refreshFields));
63       new Request({url: 'index_ajax.php', data: data, onSuccess: this.onRefreshComplete.bind(this)}).send();
64     },
65     
66     onRefreshComplete: function(responseText, responseXML) {
67       var data = JSON.decode(responseText);
68       if ( varLSdefault.checkAjaxReturn(data) ) {
69         $(this.refreshFields).getParent().set('html',data.html);
70         this.initialiseLSformElement_select_object();
71       }
72     },
73     
74     LSformElement_select_object_deleteBtn: function(img) {
75       img.getParent().destroy();
76     }
77 });
78 window.addEvent(window.ie ? 'load' : 'domready', function() {
79   varLSformElement_select_object = new LSformElement_select_object();
80 });