Created
May 31, 2017 15:20
-
-
Save Matheo13/a4a09fd51462097b9d5642b0fc6a0223 to your computer and use it in GitHub Desktop.
fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render: function () { | |
var _this = this; | |
var $el = $(this.template); | |
this.setElement($el); | |
if(this.formGrid){ | |
$el.find('.input-group-addon').addClass('hide'); | |
} | |
_(function () { | |
if (_this.editable) { | |
_this.$el.find('#' + _this.id).autocompTree({ | |
wsUrl: _this.wsUrl, | |
webservices: 'fastInitForCompleteTree', | |
language: { hasLanguage: true, lng: _this.lng }, | |
display: { | |
isDisplayDifferent: true, | |
suffixeId: '_value', | |
displayValueName: _this.displayValueName, | |
storedValueName: _this.storedValueName | |
}, | |
inputValue: _this.value, | |
startId: _this.startId, | |
timeout: _this.timeout, // can raise an error | |
onItemClick: function (options) { | |
//for global | |
_this.$el.find('input').trigger('thesaurusChange'); | |
var value = _this.$el.find('#' + _this.id).val(); | |
_this.validateValue(value); | |
}, | |
onInputInitialize: function(options){ | |
if(_this.value){ | |
_this.validateValue(_this.value.displayValue); | |
} | |
} | |
}); | |
// tree navigation arrow | |
$('#treeView' + _this.id).on('keyup',function(e){ | |
var $this = $(this); | |
if (e.keyCode == 38 || e.keyCode == 40){ | |
var itemFocus = $('#treeView' + _this.id).find('.fancytree-focused'); | |
var calcul =$this.scrollTop()+ $this.outerHeight()-itemFocus.height(); | |
if(itemFocus.position().top >= calcul){ | |
$('#treeView' + _this.id).scrollTop(itemFocus.position().top); | |
} | |
if(itemFocus.position().top < $this.scrollTop()){ | |
$('#treeView' + _this.id).scrollTop(itemFocus.position().top); | |
} | |
} | |
if (e.keyCode == 27 || e.keyCode == 9){ | |
$this.css('display', 'none'); | |
} | |
}); | |
} | |
if((typeof _this.value === "string") && _this.value != null && _this.value != 'null' && _this.value != ''){ | |
var tmp = _this.value; | |
_this.value = {}; | |
_this.value.value = tmp; | |
_this.value.displayValue = _this.findDisplayedValue(tmp); | |
} | |
//set inital values | |
if (_this.value) { | |
_this.$el.find('#' + _this.id).val(_this.value.displayValue); | |
_this.$el.find('#' + _this.id + '_value').val(_this.value.value); | |
} | |
}).defer(); | |
return this; | |
}, | |
findDisplayedValue: function(value){ | |
var _this = this; | |
var node = this.$el.find('#treeView' + this.id).fancytree('getTree').findFirst(function(node){ | |
return (node.data.fullpath == value) | |
}); | |
if(node){ | |
return node.data.valueTranslated; | |
} else { | |
return ''; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment