assigned user autocomplete own
This commit is contained in:
@@ -26,27 +26,39 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/assigned-user', 'views/fields/user-with-avatar', function (Dep) {
|
||||
define('views/fields/assigned-user', 'views/fields/user-with-avatar', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
init: function () {
|
||||
this.assignmentPermission = this.getAcl().get('assignmentPermission');
|
||||
if (this.assignmentPermission == 'no') {
|
||||
|
||||
if (this.assignmentPermission === 'no') {
|
||||
this.setReadOnly(true);
|
||||
}
|
||||
|
||||
Dep.prototype.init.call(this);
|
||||
},
|
||||
|
||||
getSelectBoolFilterList: function () {
|
||||
if (this.assignmentPermission == 'team') {
|
||||
if (this.assignmentPermission === 'team') {
|
||||
return ['onlyMyTeam'];
|
||||
}
|
||||
},
|
||||
|
||||
getSelectPrimaryFilterName: function () {
|
||||
return 'active';
|
||||
}
|
||||
},
|
||||
|
||||
getEmptyAutocompleteResult: function () {
|
||||
return {
|
||||
list: [
|
||||
{
|
||||
id: this.getUser().id,
|
||||
name: this.getUser().get('name'),
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,29 +26,28 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/assigned-users', 'views/fields/link-multiple', function (Dep) {
|
||||
define('views/fields/assigned-users', 'views/fields/link-multiple', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
init: function () {
|
||||
this.assignmentPermission = this.getAcl().get('assignmentPermission');
|
||||
if (this.assignmentPermission == 'no') {
|
||||
|
||||
if (this.assignmentPermission === 'no') {
|
||||
this.readOnly = true;
|
||||
}
|
||||
|
||||
Dep.prototype.init.call(this);
|
||||
},
|
||||
|
||||
getSelectBoolFilterList: function () {
|
||||
if (this.assignmentPermission == 'team') {
|
||||
if (this.assignmentPermission === 'team') {
|
||||
return ['onlyMyTeam'];
|
||||
}
|
||||
},
|
||||
|
||||
getSelectPrimaryFilterName: function () {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
}, Dep.prototype.data.call(this));
|
||||
},
|
||||
|
||||
getEmptyAutocompleteResult: null,
|
||||
|
||||
getSelectFilters: function () {},
|
||||
|
||||
getSelectBoolFilterList: function () {
|
||||
@@ -320,30 +322,31 @@ define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
serviceUrl: q => {
|
||||
return this.getAutocompleteUrl(q);
|
||||
},
|
||||
paramName: 'q',
|
||||
minChars: 1,
|
||||
lookup: (q, callback) => {
|
||||
if (q.length === 0) {
|
||||
|
||||
if (this.getEmptyAutocompleteResult) {
|
||||
callback(
|
||||
this._transformAutocompleteResult(this.getEmptyAutocompleteResult())
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Espo.Ajax
|
||||
.getRequest(this.getAutocompleteUrl(q), {q: q})
|
||||
.then(response => {
|
||||
callback(this._transformAutocompleteResult(response));
|
||||
});
|
||||
},
|
||||
minChars: 0,
|
||||
triggerSelectOnValidInput: false,
|
||||
autoSelectFirst: true,
|
||||
noCache: true,
|
||||
formatResult: suggestion => {
|
||||
return this.getHelper().escapeString(suggestion.name);
|
||||
},
|
||||
transformResult: response => {
|
||||
var response = JSON.parse(response);
|
||||
var list = [];
|
||||
|
||||
response.list.forEach(item => {
|
||||
list.push({
|
||||
id: item.id,
|
||||
name: item.name || item.id,
|
||||
data: item.id,
|
||||
value: item.name || item.id,
|
||||
attributes: item,
|
||||
});
|
||||
});
|
||||
|
||||
return {suggestions: list};
|
||||
},
|
||||
onSelect: (s) => {
|
||||
this.getModelFactory().create(this.foreignScope, (model) => {
|
||||
model.set(s.attributes);
|
||||
@@ -355,7 +358,15 @@ define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
|
||||
this.$elementName.off('focus.autocomplete');
|
||||
|
||||
this.$elementName.on('focus', () => this.$elementName.get(0).select());
|
||||
this.$elementName.on('focus', () => {
|
||||
if (this.$elementName.val()) {
|
||||
this.$elementName.get(0).select();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.$elementName.autocomplete('onFocus');
|
||||
});
|
||||
|
||||
this.$elementName.attr('autocomplete', 'espo-' + this.name);
|
||||
|
||||
@@ -382,18 +393,8 @@ define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
},
|
||||
transformResult: response => {
|
||||
var response = JSON.parse(response);
|
||||
var list = [];
|
||||
|
||||
response.list.forEach(item => {
|
||||
list.push({
|
||||
id: item.id,
|
||||
name: item.name || item.id,
|
||||
data: item.id,
|
||||
value: item.name || item.id,
|
||||
});
|
||||
});
|
||||
|
||||
return {suggestions: list};
|
||||
return this._transformAutocompleteResult(response);
|
||||
},
|
||||
onSelect: s => {
|
||||
this.addLinkOneOf(s.id, s.name);
|
||||
@@ -438,6 +439,22 @@ define('views/fields/link', 'views/fields/base', function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
_transformAutocompleteResult: function (response) {
|
||||
let list = [];
|
||||
|
||||
response.list.forEach(item => {
|
||||
list.push({
|
||||
id: item.id,
|
||||
name: item.name || item.id,
|
||||
data: item.id,
|
||||
value: item.name || item.id,
|
||||
attributes: item,
|
||||
});
|
||||
});
|
||||
|
||||
return {suggestions: list};
|
||||
},
|
||||
|
||||
getValueForDisplay: function () {
|
||||
return this.model.get(this.nameName);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user