LSobject / customAction : Added noConfirmation parameter
[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         else if(el.hasClass('LScustomActions')) {
33           el.addEvent('click',this.onCustomActionBtnClick.bindWithEvent(this,el));
34         }
35       }, this);
36       
37       this.LSsearchForm = $('LSsearch_form');
38       this.LSsearchPredefinedFilter = $('LSview_search_predefinedFilter');
39       if($type(this.LSsearchPredefinedFilter) && $type('LSsearch_form')) {
40         this.LSsearchPredefinedFilter.addEvent('change',this.onLSsearchPredefinedFilterChange.bind(this));
41       }
42     },
43     
44     onLSsearchPredefinedFilterChange: function() {
45       if (this.LSsearchForm) {
46         this.LSsearchForm.submit();
47       }
48     },
49
50     onTdLSobjectListNamesClick: function(td) {
51       window.location=td.getFirst().href;
52     },
53
54     onTdLSobjectListNamesOver: function(td){
55       td.imgEdit = new Element('img');
56       td.imgEdit.src = varLSdefault.imagePath('view.png');
57       td.imgEdit.injectInside(td);
58     },
59     
60     onTdLSobjectListNamesOut: function(td) {
61       if(td.imgEdit)
62         td.imgEdit.destroy();
63     },
64     
65     onRemoveListBtnClick: function(event,a) {
66       Event(event).stop();
67       if (!this._confirmBoxOpen) {
68         this._confirmBoxOpen = 1;
69         var name = a.getParent().getParent().getFirst('td').getElement('a').innerHTML;
70         this.confirmBox = new LSconfirmBox({
71           text:         this.labels.delete_confirm_text + ' "'+name+'" ?', 
72           startElement: a,
73           onConfirm:    this.removeFromA.bind(this,a),
74           onClose:      this.onConfirmBoxClose.bind(this)
75         });
76       }
77     },
78     
79     onRemoveViewBtnClick: function(event,a) {
80       Event(event).stop();
81       if (!this._confirmBoxOpen) {
82         this._confirmBoxOpen = 1;
83         var name = $('LSview_title').innerHTML;
84         this.confirmBox = new LSconfirmBox({
85           text:           this.labels.delete_confirm_text + ' "'+name+'" ?',
86           title:          this.labels.delete_confirm_title,
87           validate_label: this.labels.delete_confirm_yes_btn,
88           startElement:   a,
89           onConfirm:      this.removeFromA.bind(this,a),
90           onClose:        this.onConfirmBoxClose.bind(this)
91         });
92       }
93     },
94     
95     onConfirmBoxClose: function() {
96       this._confirmBoxOpen = 0;
97     },
98     
99     removeFromA: function(a) {
100       document.location = a.href+'&valid';
101     },
102
103     onCustomActionBtnClick: function(event,a) {
104       if (a.hasClass('LScustomActions_noConfirmation')) {
105         return true;
106       }
107       Event(event).stop();
108       if (!this._confirmBoxOpen) {
109         this._confirmBoxOpen = 1;
110         var getName = new RegExp('customAction=([^&]*)');
111         var name = getName.exec(a.href)[1];
112         if (name) {
113           var title = a.innerHTML;
114           if ($type(this.labels['custom_action_'+name+'_confirm_text'])) {
115             var text = this.labels['custom_action_'+name+'_confirm_text']
116           }
117           else {
118             var objectname = $('LSview_title').innerHTML;
119             var text = getFData('Do you really want to execute custom action %{customAction} on %{objectname} ?',{customAction: name, objectname: objectname });
120           }
121           this.confirmBox = new LSconfirmBox({
122             text:           text,
123             title:          title,
124             startElement:   a,
125             onConfirm:      this.executeCustomActionFromA.bind(this,a),
126             onClose:        this.onConfirmBoxClose.bind(this)
127           });
128         }
129       }
130     },
131
132     executeCustomActionFromA: function(a) {
133       document.location = a.href+'&valid';
134     }
135
136 });
137 window.addEvent(window.ie ? 'load' : 'domready', function() {
138   varLSview = new LSview();
139 });