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({
initialize: function(){
this.fields = [];
this.initialiseLSformElement_supannCompositeAttribute();
},
initialize: function(){
this.fields = [];
this.initialiseLSformElement_supannCompositeAttribute();
},
initialiseLSformElement_supannCompositeAttribute: function(el) {
if (!$type(el)) {
el = document;
}
el.getElements('ul.LSformElement_supannCompositeAttribute').each(function(ul) {
this.fields[ul.id] = new LSformElement_supannCompositeAttribute_field(ul);
}, this);
initialiseLSformElement_supannCompositeAttribute: function(el) {
if (!$type(el)) {
el = document;
}
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() {
varLSformElement_supannCompositeAttribute = new LSformElement_supannCompositeAttribute();

View file

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

View file

@ -1,29 +1,29 @@
var LSformElement_supannCompositeAttribute_field_value = new Class({
initialize: function(li,name,field_type){
this.li=li;
this.name = name;
this.components = {};
this.field_type = field_type;
this.initializeLSformElement_supannCompositeAttribute_field_value();
varLSform.addModule(field_type,this);
},
initialize: function(li,name,field_type){
this.li=li;
this.name = name;
this.components = {};
this.field_type = field_type;
this.initializeLSformElement_supannCompositeAttribute_field_value();
varLSform.addModule(field_type,this);
},
initializeLSformElement_supannCompositeAttribute_field_value: function(el) {
if (!$type(el)) {
el = this.li;
}
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);
},
initializeLSformElement_supannCompositeAttribute_field_value: function(el) {
if (!$type(el)) {
el = this.li;
}
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);
},
reinitialize: function(el) {
this.initializeLSformElement_supannCompositeAttribute_field_value(el);
},
reinitialize: function(el) {
this.initializeLSformElement_supannCompositeAttribute_field_value(el);
},
clear: function() {
for (c in this.components) {
this.components[c].clear();
}
}
clear: function() {
for (c in this.components) {
this.components[c].clear();
}
}
});

View file

@ -1,173 +1,186 @@
var LSformElement_supannCompositeAttribute_field_value_component = new Class({
initialize: function(p,name,field_name){
this.p = p;
this.field_name = field_name;
this.name = name;
this.params = varLSdefault.LSjsConfig[this.field_name];
initialize: function(p,name,field_name){
this.p = p;
this.field_name = field_name;
this.name = 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.img = p.getElement('img');
this.span = p.getElement('span');
if (['table', 'codeEntite', 'parrainDN'].includes(this.params.components[this.name].type)) {
this.inputSearch=new Element(
'input',
{
'class': 'LSformElement_supannCompositeAttribute_search',
'styles': {
'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=new Element(
'input',
{
'class': 'LSformElement_supannCompositeAttribute_search',
'styles': {
'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);
if (event.key=='esc') {
this.toggleInputSearch();
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();
}
},
}
launchSearch: function() {
this.hidePossibleValues();
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();
},
if (event.key=='esc') {
this.toggleInputSearch();
}
},
onSearchComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
this.displayPossibleValues(data.possibleValues);
}
},
launchSearch: function() {
this.hidePossibleValues();
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();
},
displayPossibleValues: function(possibleValues) {
if (this._possibleValues==null) {
this._possibleValues=new Element(
'div',
{
'class': 'supannCompositeAttribute_possibleValues',
}
);
this._possibleValues.injectInside(this.p);
}
onSearchComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
this.displayPossibleValues(data.possibleValues);
}
},
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');
possibleValues.each(function(v) {
var li=new Element(
'li',
{
'data-value': v.value,
'data-label': v.label,
'data-translated': v.translated,
}
);
if (v.label!='no') {
li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated);
}
else {
li.set('html',v.translated);
}
li.injectInside(this);
}, ul);
if (ul.getElements('li').length==0) {
new Element(
'li',
{
'html': this.params.noResultLabel
}
).injectInside(ul);
}
else {
ul.getElements('li').each(function(li) {
li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this));
}, this);
}
ul.injectInside(this._possibleValues);
this._possibleValues.setStyle('display', 'block');
},
var ul=new Element('ul');
possibleValues.each(function(v) {
var li=new Element(
'li',
{
'data-value': v.value,
'data-label': v.label,
'data-translated': v.translated,
}
);
if (v.label!='no') {
li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated);
}
else {
li.set('html',v.translated);
}
li.injectInside(this);
}, ul);
if (ul.getElements('li').length==0) {
new Element(
'li',
{
'html': this.params.noResultLabel
}
).injectInside(ul);
}
else {
ul.getElements('li').each(function(li) {
li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this));
}, this);
}
ul.injectInside(this._possibleValues);
this._possibleValues.setStyle('display', 'block');
},
hidePossibleValues: function() {
if (this._possibleValues!=null) {
this._possibleValues.setStyle('display', 'none');
this._possibleValues.empty();
}
},
hidePossibleValues: function() {
if (this._possibleValues!=null) {
this._possibleValues.setStyle('display', 'none');
this._possibleValues.empty();
}
},
onClickPossibleValue: function(event) {
this.hidePossibleValues();
event = new Event(event);
var li=$(event.target);
if (event.target.tagName=='IMG') {
li=li.getParent();
}
this.input.set('value',li.get('data-value'));
if (li.get('data-label')!='no') {
if (this.img==null) {
this.img=new Element('img');
this.img.injectBefore(this.span);
}
this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label')));
}
this.span.set('html',li.get('data-translated'));
this.span.set('title',li.get('data-value'));
this.toggleInputSearch();
},
onClickPossibleValue: function(event) {
this.hidePossibleValues();
event = new Event(event);
var li=$(event.target);
if (event.target.tagName=='IMG') {
li=li.getParent();
}
this.input.set('value',li.get('data-value'));
if (li.get('data-label')!='no') {
if (this.img==null) {
this.img=new Element('img');
this.img.injectBefore(this.span);
}
this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label')));
}
this.span.set('html',li.get('data-translated'));
this.span.set('title',li.get('data-value'));
this.toggleInputSearch();
},
clear: function() {
if (this.img) {
this.img.dispose();
this.img=null;
}
this.input.set('value','');
if (this.span) {
this.span.set('html',this.params.noValueLabel);
}
}
clear: function() {
if (this.cconf.type == 'select') {
this.select.set('value', '');
}
else if (['date', 'text'].includes(this.cconf.type)) {
this.input.set('value', '');
}
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', '');
}
}
});