666e746275c63f8fe1bd64a3a2cf9508cc46c97a
[ldapsaisie.git] / public_html / includes / js / LSview.js
1 var LSview = new Class({
2     initialize: function(){
3       this.labels = varLSdefault.LSjsConfig['LSview_labels'];
4       if (!$type(this.labels)) {
5         this.labels = {
6           delete_confirm_text:      "Do you really want to delete",
7           delete_confirm_title:     "Caution",
8           delete_confirm_validate:  "Delete"
9         };
10       }
11       
12       $$('td.LSobject-list-names').each(function(el) {
13         el.addEvent('click',this.onTdLSobjectListNamesClick.bind(this,el));
14       }, this);
15       $$('td.LSobject-list-names').each(function(el) {
16         el.addEvent('mouseenter',this.onTdLSobjectListNamesOver.bind(this,el));
17       }, this);
18       $$('td.LSobject-list-names').each(function(el) {
19         el.addEvent('mouseleave',this.onTdLSobjectListNamesOut.bind(this,el));
20       }, this);
21       $$('a.LSobject-list-actions').each(function(el) {
22         var checkRemove = /remove\.php.*/;
23         if (checkRemove.exec(el.href)) {
24           el.addEvent('click',this.onRemoveListBtnClick.bindWithEvent(this,el));
25         }
26       }, this);
27       $$('a.LSview-actions').each(function(el) {
28         var checkRemove = /remove\.php.*/;
29         if (checkRemove.exec(el.href)) {
30           el.addEvent('click',this.onRemoveViewBtnClick.bindWithEvent(this,el));
31         }
32       }, this);
33       
34       this.LSsearchForm = $('LSsearch_form');
35       this.LSsearchPredefinedFilter = $('LSview_search_predefinedFilter');
36       if($type(this.LSsearchPredefinedFilter) && $type('LSsearch_form')) {
37         this.LSsearchPredefinedFilter.addEvent('change',this.onLSsearchPredefinedFilterChange.bind(this));
38       }
39     },
40     
41     onLSsearchPredefinedFilterChange: function() {
42       if (this.LSsearchForm) {
43         this.LSsearchForm.submit();
44       }
45     },
46
47     onTdLSobjectListNamesClick: function(td) {
48       window.location=td.getFirst().href;
49     },
50
51     onTdLSobjectListNamesOver: function(td){
52       td.imgEdit = new Element('img');
53       td.imgEdit.src = varLSdefault.imagePath('view.png');
54       td.imgEdit.injectInside(td);
55     },
56     
57     onTdLSobjectListNamesOut: function(td) {
58       if(td.imgEdit)
59         td.imgEdit.destroy();
60     },
61     
62     onRemoveListBtnClick: function(event,a) {
63       Event(event).stop();
64       if (!this._confirmBoxOpen) {
65         this._confirmBoxOpen = 1;
66         var name = a.getParent().getParent().getFirst('td').getElement('a').innerHTML;
67         this.confirmBox = new LSconfirmBox({
68           text:         this.labels.delete_confirm_text + ' "'+name+'" ?', 
69           startElement: a,
70           onConfirm:    this.removeFromA.bind(this,a),
71           onClose:      this.onConfirmBoxClose.bind(this)
72         });
73       }
74     },
75     
76     onRemoveViewBtnClick: function(event,a) {
77       Event(event).stop();
78       if (!this._confirmBoxOpen) {
79         this._confirmBoxOpen = 1;
80         var name = $('LSview_title').innerHTML;
81         this.confirmBox = new LSconfirmBox({
82           text:           this.labels.delete_confirm_text + ' "'+name+'" ?',
83           title:          this.labels.delete_confirm_title,
84           validate_label: this.labels.delete_confirm_yes_btn,
85           startElement:   a,
86           onConfirm:      this.removeFromA.bind(this,a),
87           onClose:        this.onConfirmBoxClose.bind(this)
88         });
89       }
90     },
91     
92     onConfirmBoxClose: function() {
93       this._confirmBoxOpen = 0;
94     },
95     
96     removeFromA: function(a) {
97       document.location = a.href+'&valid';
98     },
99
100     onCustomActionBtnClick: function(event,a) {
101       Event(event).stop();
102       if (!this._confirmBoxOpen) {
103         this._confirmBoxOpen = 1;
104         var getName = new RegExp('customAction=([^&]*)');
105         var name = getName.exec(a.href)[1];
106         if (name) {
107           var title = a.innerHTML;
108           if ($type(this.labels['custom_action_'+name+'_confirm_text'])) {
109             var text = this.labels['custom_action_'+name+'_confirm_text']
110           }
111           else {
112             var objectname = $('LSview_title').innerHTML;
113             var text = getFData('Do you really want to execute custom action %{customAction} on %{objectname} ?',{customAction: name, objectname: objectname });
114           }
115           this.confirmBox = new LSconfirmBox({
116             text:           text,
117             title:          title,
118             startElement:   a,
119             onConfirm:      this.executeCustomActionFromA.bind(this,a),
120             onClose:        this.onConfirmBoxClose.bind(this)
121           });
122         }
123       }
124     },
125
126     executeCustomActionFromA: function(a) {
127       document.location = a.href+'&valid';
128     }
129
130 });
131 window.addEvent(window.ie ? 'load' : 'domready', function() {
132   varLSview = new LSview();
133 });