From 855bcc8564459bfaff6f8c71b9f405d69497c849 Mon Sep 17 00:00:00 2001 From: Emmanuel Saracco Date: Thu, 16 Jun 2022 12:59:14 +0200 Subject: [PATCH] LSselect : code cleaning --- src/includes/js/LSselect.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/includes/js/LSselect.js b/src/includes/js/LSselect.js index e181ea48..abc9dd98 100644 --- a/src/includes/js/LSselect.js +++ b/src/includes/js/LSselect.js @@ -7,11 +7,7 @@ var LSselect = new Class({ this.multiple = this.LSselect_search_form.getElement('input[name=multiple]').value; // Add ajax hidden input - var input = new Element('input'); - input.setProperty('name','ajax'); - input.setProperty('type','hidden'); - input.setProperty('value',1); - input.injectInside(this.LSselect_search_form); + this.injectHiddenInput('ajax', 1); this.tempInput = []; this.lastCheckboxChanged = null; @@ -35,11 +31,19 @@ var LSselect = new Class({ } }, + injectHiddenInput: function(name, value) { + var input = new Element('input'); + input.setProperty('type', 'hidden'); + input.setProperty('name', name); + input.setProperty('value', value); + input.injectInside(this.LSselect_search_form); + return input; + }, + initializeTabs: function(ul) { this.tabs_ul.getElements('li').addEvent('click', function (event) { - console.log(event.target); this.LSselect_search_form.getElement('input[name=LSobject]').value = event.target.getProperty('data-object-type'); - this.tabs_ul.getElements('li.current').each(function(li){ console.log(li); li.removeClass('current'); }); + this.tabs_ul.getElements('li.current').each(function(li){ li.removeClass('current'); }); event.target.addClass('current'); this.submitSearchForm(); }.bind(this)); @@ -112,7 +116,7 @@ var LSselect = new Class({ }, onChangePageClick: function(event, a) { - new Event(event).stop(); + event.preventDefault(); var data = { ajax: true }; @@ -131,7 +135,7 @@ var LSselect = new Class({ }, onSubmitSearchForm: function(event) { - new Event(event).stop(); + event.preventDefault(); this.submitSearchForm(); }, @@ -162,20 +166,12 @@ var LSselect = new Class({ }, onClickLSselect_refresh_btn: function() { - this.tempInput['refresh'] = new Element('input'); - this.tempInput['refresh'].setProperty('name','refresh'); - this.tempInput['refresh'].setProperty('type','hidden'); - this.tempInput['refresh'].setProperty('value',1); - this.tempInput['refresh'].injectInside(this.LSselect_search_form); + this.tempInput['refresh'] = this.injectHiddenInput('refresh', 1); this.submitSearchForm(); }, sortBy: function(value) { - this.tempInput['sortBy'] = new Element('input'); - this.tempInput['sortBy'].setProperty('name','sortBy'); - this.tempInput['sortBy'].setProperty('type','hidden'); - this.tempInput['sortBy'].setProperty('value',value); - this.tempInput['sortBy'].injectInside(this.LSselect_search_form); + this.tempInput['sortBy'] = this.injectHiddenInput('sortBy', value); this.submitSearchForm(); },