supannCompositeAttribute: fix clearing value

This commit is contained in:
Benjamin Renard 2021-07-07 16:26:55 +02:00
parent 6e98cfef20
commit 3c02b94085
4 changed files with 231 additions and 219 deletions

View file

@ -1,17 +1,17 @@
var LSformElement_supannCompositeAttribute = new Class({ var LSformElement_supannCompositeAttribute = new Class({
initialize: function(){ initialize: function(){
this.fields = []; this.fields = [];
this.initialiseLSformElement_supannCompositeAttribute(); this.initialiseLSformElement_supannCompositeAttribute();
}, },
initialiseLSformElement_supannCompositeAttribute: function(el) { initialiseLSformElement_supannCompositeAttribute: function(el) {
if (!$type(el)) { if (!$type(el)) {
el = document; el = document;
}
el.getElements('ul.LSformElement_supannCompositeAttribute').each(function(ul) {
this.fields[ul.id] = new LSformElement_supannCompositeAttribute_field(ul);
}, this);
} }
el.getElements('ul.LSformElement_supannCompositeAttribute').each(function(ul) {
this.fields[ul.id] = new LSformElement_supannCompositeAttribute_field(ul);
}, this);
}
}); });
window.addEvent(window.ie ? 'load' : 'domready', function() { window.addEvent(window.ie ? 'load' : 'domready', function() {
varLSformElement_supannCompositeAttribute = new LSformElement_supannCompositeAttribute(); varLSformElement_supannCompositeAttribute = new LSformElement_supannCompositeAttribute();

View file

@ -1,34 +1,33 @@
var LSformElement_supannCompositeAttribute_field = new Class({ var LSformElement_supannCompositeAttribute_field = new Class({
initialize: function(ul){ initialize: function(ul){
this.ul=ul; this.ul=ul;
this.dd=ul.getParent(); this.dd=ul.getParent();
this.name = ul.id; this.name = ul.id;
this.values = []; this.values = [];
this.field_type = ul.get('data-fieldType'); this.field_type = ul.get('data-fieldType');
this.initializeLSformElement_supannCompositeAttribute_field(); this.initializeLSformElement_supannCompositeAttribute_field();
varLSform.addField(this.name,this); varLSform.addField(this.name,this);
}, },
initializeLSformElement_supannCompositeAttribute_field: function(el) { initializeLSformElement_supannCompositeAttribute_field: function(el) {
if (!$type(el)) { if (!$type(el)) {
el = this.ul; el = this.ul;
} }
el.getElements('li').each(function(li) { el.getElements('li').each(function(li) {
this.values.push(new LSformElement_supannCompositeAttribute_field_value(li,this.name,this.field_type)); this.values.push(new LSformElement_supannCompositeAttribute_field_value(li,this.name,this.field_type));
}, this); }, this);
}, },
clearValue: function() { clearValue: function() {
console.log('clear'); if (this.values.length>1) {
console.log(this.values); for(var i=1; i<=this.values.length; i++) {
if (this.values.length>1) { $(this.values[i].li).dispose();
for(var i=1; i<=this.values.length; i++) { delete this.values[i];
$(this.values[i].li).dispose(); }
} this.values[0].clear();
this.values[0].clear(); }
} else if (this.values.length==1) {
else if (this.values.length==1) { this.values[0].clear();
this.values[0].clear(); }
} }
}
}); });

View file

@ -1,29 +1,29 @@
var LSformElement_supannCompositeAttribute_field_value = new Class({ var LSformElement_supannCompositeAttribute_field_value = new Class({
initialize: function(li,name,field_type){ initialize: function(li,name,field_type){
this.li=li; this.li=li;
this.name = name; this.name = name;
this.components = {}; this.components = {};
this.field_type = field_type; this.field_type = field_type;
this.initializeLSformElement_supannCompositeAttribute_field_value(); this.initializeLSformElement_supannCompositeAttribute_field_value();
varLSform.addModule(field_type,this); varLSform.addModule(field_type,this);
}, },
initializeLSformElement_supannCompositeAttribute_field_value: function(el) { initializeLSformElement_supannCompositeAttribute_field_value: function(el) {
if (!$type(el)) { if (!$type(el)) {
el = this.li; el = this.li;
} }
el.getElements('p').each(function(p) { el.getElements('p').each(function(p) {
this.components[p.get('data-component')]=new LSformElement_supannCompositeAttribute_field_value_component(p,p.get('data-component'),this.name); this.components[p.get('data-component')]=new LSformElement_supannCompositeAttribute_field_value_component(p,p.get('data-component'),this.name);
}, this); }, this);
}, },
reinitialize: function(el) { reinitialize: function(el) {
this.initializeLSformElement_supannCompositeAttribute_field_value(el); this.initializeLSformElement_supannCompositeAttribute_field_value(el);
}, },
clear: function() { clear: function() {
for (c in this.components) { for (c in this.components) {
this.components[c].clear(); this.components[c].clear();
} }
} }
}); });

View file

@ -1,173 +1,186 @@
var LSformElement_supannCompositeAttribute_field_value_component = new Class({ var LSformElement_supannCompositeAttribute_field_value_component = new Class({
initialize: function(p,name,field_name){ initialize: function(p,name,field_name){
this.p = p; this.p = p;
this.field_name = field_name; this.field_name = field_name;
this.name = name; this.name = name;
this.params = varLSdefault.LSjsConfig[this.field_name]; this.params = varLSdefault.LSjsConfig[this.field_name];
this.cconf = this.params.components[this.name];
if (this.cconf.type == 'select') {
this.select = p.getElement('select');
}
else if (['date', 'text'].includes(this.cconf.type)) {
this.input = p.getElement('input');
}
else if (['table', 'codeEntite', 'parrainDN'].includes(this.cconf.type)) {
this.input = p.getElement('input'); this.input = p.getElement('input');
this.img = p.getElement('img'); this.img = p.getElement('img');
this.span = p.getElement('span'); this.span = p.getElement('span');
if (['table', 'codeEntite', 'parrainDN'].includes(this.params.components[this.name].type)) { this.inputSearch=new Element(
this.inputSearch=new Element( 'input',
'input', {
{ 'class': 'LSformElement_supannCompositeAttribute_search',
'class': 'LSformElement_supannCompositeAttribute_search', 'styles': {
'styles': { 'display': 'none'
'display': 'none' }
}
}
);
this.inputSearch.addEvent('keydown',this.onKeyUpInputSearch.bindWithEvent(this));
this.inputSearch.injectInside(this.p);
this.searchBtn=new Element(
'img',
{
'src': varLSdefault.imagePath('modify'),
'alt': this.params.searchBtn,
'title': this.params.searchBtn,
}
);
this.searchBtn.addEvent('click',this.toggleInputSearch.bind(this));
this.searchBtn.injectBefore(this.inputSearch);
this._lastSearch=null;
this._possibleValues=null;
}
},
toggleInputSearch: function() {
if (this.inputSearch.getStyle('display')=='none') {
this.inputSearch.setStyle('display','block');
this.inputSearch.focus();
}
else {
this.hidePossibleValues();
this.inputSearch.setStyle('display','none');
this.inputSearch.set('value','');
}
},
onKeyUpInputSearch: function(event) {
event = new Event(event);
if ((event.key=='enter')||(event.key=='tab')) {
event.stop();
if (this.inputSearch.value!="") {
this.launchSearch();
} }
);
this.inputSearch.addEvent('keydown',this.onKeyUpInputSearch.bindWithEvent(this));
this.inputSearch.injectInside(this.p);
this.searchBtn=new Element(
'img',
{
'src': varLSdefault.imagePath('modify'),
'alt': this.params.searchBtn,
'title': this.params.searchBtn,
} }
);
this.searchBtn.addEvent('click',this.toggleInputSearch.bind(this));
this.searchBtn.injectBefore(this.inputSearch);
if (event.key=='esc') { this._lastSearch=null;
this.toggleInputSearch(); this._possibleValues=null;
}
},
toggleInputSearch: function() {
if (this.inputSearch.getStyle('display')=='none') {
this.inputSearch.setStyle('display','block');
this.inputSearch.focus();
}
else {
this.hidePossibleValues();
this.inputSearch.setStyle('display','none');
this.inputSearch.set('value','');
}
},
onKeyUpInputSearch: function(event) {
event = new Event(event);
if ((event.key=='enter')||(event.key=='tab')) {
event.stop();
if (this.inputSearch.value!="") {
this.launchSearch();
} }
}, }
launchSearch: function() { if (event.key=='esc') {
this.hidePossibleValues(); this.toggleInputSearch();
this._lastSearch=this.inputSearch.value; }
var data = { },
attribute: this.field_name,
objecttype: varLSform.objecttype,
idform: varLSform.idform,
component: this.name,
pattern: this.inputSearch.value
};
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch);
new Request({url: 'ajax/class/LSformElement_supannCompositeAttribute/searchComponentPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send();
},
onSearchComplete: function(responseText, responseXML) { launchSearch: function() {
var data = JSON.decode(responseText); this.hidePossibleValues();
if ( varLSdefault.checkAjaxReturn(data) ) { this._lastSearch=this.inputSearch.value;
this.displayPossibleValues(data.possibleValues); var data = {
} attribute: this.field_name,
}, objecttype: varLSform.objecttype,
idform: varLSform.idform,
component: this.name,
pattern: this.inputSearch.value
};
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch);
new Request({url: 'ajax/class/LSformElement_supannCompositeAttribute/searchComponentPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send();
},
displayPossibleValues: function(possibleValues) { onSearchComplete: function(responseText, responseXML) {
if (this._possibleValues==null) { var data = JSON.decode(responseText);
this._possibleValues=new Element( if ( varLSdefault.checkAjaxReturn(data) ) {
'div', this.displayPossibleValues(data.possibleValues);
{ }
'class': 'supannCompositeAttribute_possibleValues', },
}
);
this._possibleValues.injectInside(this.p);
}
displayPossibleValues: function(possibleValues) {
if (this._possibleValues==null) {
this._possibleValues=new Element(
'div',
{
'class': 'supannCompositeAttribute_possibleValues',
}
);
this._possibleValues.injectInside(this.p);
}
var ul=new Element('ul'); var ul=new Element('ul');
possibleValues.each(function(v) { possibleValues.each(function(v) {
var li=new Element( var li=new Element(
'li', 'li',
{ {
'data-value': v.value, 'data-value': v.value,
'data-label': v.label, 'data-label': v.label,
'data-translated': v.translated, 'data-translated': v.translated,
} }
); );
if (v.label!='no') { if (v.label!='no') {
li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated); li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated);
} }
else { else {
li.set('html',v.translated); li.set('html',v.translated);
} }
li.injectInside(this); li.injectInside(this);
}, ul); }, ul);
if (ul.getElements('li').length==0) { if (ul.getElements('li').length==0) {
new Element( new Element(
'li', 'li',
{ {
'html': this.params.noResultLabel 'html': this.params.noResultLabel
} }
).injectInside(ul); ).injectInside(ul);
} }
else { else {
ul.getElements('li').each(function(li) { ul.getElements('li').each(function(li) {
li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this)); li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this));
}, this); }, this);
} }
ul.injectInside(this._possibleValues); ul.injectInside(this._possibleValues);
this._possibleValues.setStyle('display', 'block'); this._possibleValues.setStyle('display', 'block');
}, },
hidePossibleValues: function() { hidePossibleValues: function() {
if (this._possibleValues!=null) { if (this._possibleValues!=null) {
this._possibleValues.setStyle('display', 'none'); this._possibleValues.setStyle('display', 'none');
this._possibleValues.empty(); this._possibleValues.empty();
} }
}, },
onClickPossibleValue: function(event) { onClickPossibleValue: function(event) {
this.hidePossibleValues(); this.hidePossibleValues();
event = new Event(event); event = new Event(event);
var li=$(event.target); var li=$(event.target);
if (event.target.tagName=='IMG') { if (event.target.tagName=='IMG') {
li=li.getParent(); li=li.getParent();
} }
this.input.set('value',li.get('data-value')); this.input.set('value',li.get('data-value'));
if (li.get('data-label')!='no') { if (li.get('data-label')!='no') {
if (this.img==null) { if (this.img==null) {
this.img=new Element('img'); this.img=new Element('img');
this.img.injectBefore(this.span); this.img.injectBefore(this.span);
} }
this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label'))); this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label')));
} }
this.span.set('html',li.get('data-translated')); this.span.set('html',li.get('data-translated'));
this.span.set('title',li.get('data-value')); this.span.set('title',li.get('data-value'));
this.toggleInputSearch(); this.toggleInputSearch();
}, },
clear: function() { clear: function() {
if (this.img) { if (this.cconf.type == 'select') {
this.img.dispose(); this.select.set('value', '');
this.img=null; }
} else if (['date', 'text'].includes(this.cconf.type)) {
this.input.set('value',''); this.input.set('value', '');
if (this.span) { }
this.span.set('html',this.params.noValueLabel); else if (['table', 'codeEntite', 'parrainDN'].includes(this.cconf.type)) {
} this.input.set('value', '');
} if (this.img) {
this.img.dispose();
this.img=null;
}
this.span.set('html', this.params.noValueLabel);
this.span.set('title', '');
}
}
}); });