...
  View open merge request
Commits (3)
......@@ -79,18 +79,18 @@ VidjilAutoComplete.prototype = {
return true;
},
setupTags: function(input) {
this.setupAtWho(input, this.atWhoTags);
setupTags: function(input, override_callbacks) {
this.setupAtWho(input, this.atWhoTags, override_callbacks);
},
setupSamples: function(input) {
this.setupAtWho(input, this.atWhoSamples);
setupSamples: function(input, override_callbacks) {
this.setupAtWho(input, this.atWhoSamples, override_callbacks);
},
setupAtWho: function(input, callback) {
setupAtWho: function(input, callback, override_callbacks) {
var $input = $(input);
if ($input.data('needs-atwho')) {
$input.off('focus.setupAtWho').on('focus.setupAtWho', callback.bind(this, $input));
$input.off('focus.setupAtWho').on('focus.setupAtWho', callback.bind(this, $input, override_callbacks));
$input.on('change.atwho', function() { input.dispatchEvent(new Event('input'))});
// This triggers at.js again
// Needed for quick actions with suffixes (ex: /label ~)
......@@ -103,7 +103,7 @@ VidjilAutoComplete.prototype = {
}
},
atWhoTags : function($input) {
atWhoTags : function($input, override_callbacks) {
var self = this;
var at = '#';
this.initCache(at);
......@@ -118,7 +118,7 @@ VidjilAutoComplete.prototype = {
});
},
atWhoSamples : function($input) {
atWhoSamples : function($input, override_callbacks) {
var self = this;
var at = '';
this.initCache(at);
......@@ -209,6 +209,12 @@ VidjilAutoComplete.prototype = {
return $.fn.atwho.default.callbacks.filter(query, data, searchKey);
};
if (typeof override_callbacks !== 'undefined') {
for (var key in override_callbacks) {
callbacks[key] = override_callbacks[key];
}
}
$input.atwho({
at: at,
alias: 'samples',
......
......@@ -5,11 +5,28 @@
<h3></h3>
<script type="text/javascript">
function callback_sample_click(value, li) {
var match_sample_set_id = /\(([0-9]+)\)\s*$/;
var matches = value.match(match_sample_set_id);
db.call('sample_set/index', {'id': matches[1], 'config_id': -1});
}
</script>
<div class="db_block">
<div class="db_block_left">
search
<input id="db_filter_input" type="text" value="{{=request.vars["filter"]}}" onchange="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter' : this.value} )"
onfocus="new VidjilAutoComplete().setupTags(this);"
onfocus="vat = new VidjilAutoComplete();
var callbacks = {'beforeInsert': function (value, li) {
var match_sample_set_id = /\(([0-9]+)\)\s*$/;
var matches = value.match(match_sample_set_id);
db.call('sample_set/index', {'id': matches[1], 'config_id': -1});
}};
vat.setupSamples(this, callbacks);
$(this).data('needs-atwho', true);
vat.setupTags(this);
"
data-needs-atwho="true" data-keys="{{=group_ids}}">
</div>
</div>
......