mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
Merge pull request #4662 from artoscinote/ma_SCI_7534
Make deferred SmartAnnotation loading optional [SCI-7534]
This commit is contained in:
commit
c4ba723998
3 changed files with 87 additions and 81 deletions
|
@ -40,7 +40,7 @@ $.fn.dataTable.render.editRepositoryTextValue = function(formId, columnId, cell)
|
|||
data-type="RepositoryTextValue">
|
||||
</div>`);
|
||||
$cell.find('input').val(text);
|
||||
SmartAnnotation.init($cell.find('input'));
|
||||
SmartAnnotation.init($cell.find('input'), true);
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.editRepositoryListValue = function(formId, columnId, cell) {
|
||||
|
|
|
@ -16,7 +16,7 @@ var RepositoryDatatableRowEditor = (function() {
|
|||
function initSmartAnnotation($row) {
|
||||
$row.find('[data-object="repository_cell"]').each(function(el) {
|
||||
if (el.data('atwho')) {
|
||||
SmartAnnotation.init(el);
|
||||
SmartAnnotation.init(el, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ var SmartAnnotation = (function() {
|
|||
});
|
||||
}
|
||||
|
||||
function SetAtWho(field) {
|
||||
function SetAtWho(field, deferred) {
|
||||
var FilterTypeEnum = Object.freeze({
|
||||
USER: { tag: 'users', dataUrl: $(document.body).attr('data-atwho-users-url') },
|
||||
TASK: { tag: 'sa-tasks', dataUrl: $(document.body).attr('data-atwho-task-url') },
|
||||
|
@ -121,90 +121,96 @@ var SmartAnnotation = (function() {
|
|||
};
|
||||
}
|
||||
|
||||
function init() {
|
||||
$(field).on('focus', function() {
|
||||
if ($(this).data('atwho-initialized')) return;
|
||||
function initAtwho() {
|
||||
if ($(this).data('atwho-initialized')) return;
|
||||
|
||||
$(field).on('shown.atwho', function() {
|
||||
var $currentAtWho = $('.atwho-view[style]:not(.old)');
|
||||
var atWhoId = $currentAtWho.find('.atwho-header-res').data('at-who-key');
|
||||
$currentAtWho.addClass('old').attr('data-at-who-id', atWhoId);
|
||||
$(field).attr('data-smart-annotation', atWhoId);
|
||||
$(field).on('shown.atwho', function() {
|
||||
var $currentAtWho = $('.atwho-view[style]:not(.old)');
|
||||
var atWhoId = $currentAtWho.find('.atwho-header-res').data('at-who-key');
|
||||
$currentAtWho.addClass('old').attr('data-at-who-id', atWhoId);
|
||||
$(field).attr('data-smart-annotation', atWhoId);
|
||||
|
||||
$currentAtWho.find('.tab-button').off().on('shown.bs.tab', function() {
|
||||
$(field).click().focus();
|
||||
$(this).closest('.nav-tabs').find('.tab-button').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
});
|
||||
$currentAtWho.find('.repository-object').off().on('click', function() {
|
||||
$(this).parent().find('.repository-object').removeClass('btn-primary')
|
||||
.addClass('btn-light');
|
||||
$(this).addClass('btn-primary').removeClass('btn-light');
|
||||
$(field).click().focus();
|
||||
});
|
||||
$currentAtWho.find('.tab-button').off().on('shown.bs.tab', function() {
|
||||
$(field).click().focus();
|
||||
$(this).closest('.nav-tabs').find('.tab-button').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
});
|
||||
$currentAtWho.find('.repository-object').off().on('click', function() {
|
||||
$(this).parent().find('.repository-object').removeClass('btn-primary')
|
||||
.addClass('btn-light');
|
||||
$(this).addClass('btn-primary').removeClass('btn-light');
|
||||
$(field).click().focus();
|
||||
});
|
||||
|
||||
if ($currentAtWho.find('.tab-pane.active').length === 0) {
|
||||
let filterType = DEFAULT_SEARCH_FILTER.tag;
|
||||
let teamId = $currentAtWho.find('.atwho-header-res').data('team-id');
|
||||
let remeberedState = localStorage.getItem('smart_annotation_states/teams/' + teamId);
|
||||
if (remeberedState) {
|
||||
try {
|
||||
remeberedState = JSON.parse(remeberedState);
|
||||
filterType = remeberedState.tag;
|
||||
$currentAtWho.find(`.repository-object[data-object-id=${remeberedState.repository}]`)
|
||||
.addClass('btn-primary');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
if ($currentAtWho.find('.tab-pane.active').length === 0) {
|
||||
let filterType = DEFAULT_SEARCH_FILTER.tag;
|
||||
let teamId = $currentAtWho.find('.atwho-header-res').data('team-id');
|
||||
let remeberedState = localStorage.getItem('smart_annotation_states/teams/' + teamId);
|
||||
if (remeberedState) {
|
||||
try {
|
||||
remeberedState = JSON.parse(remeberedState);
|
||||
filterType = remeberedState.tag;
|
||||
$currentAtWho.find(`.repository-object[data-object-id=${remeberedState.repository}]`)
|
||||
.addClass('btn-primary');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
$currentAtWho.find(`.${filterType}`).click();
|
||||
}
|
||||
}).on('reposition.atwho', function(event, flag, query) {
|
||||
let inputFieldLeft = query.$inputor.offset().left;
|
||||
if (inputFieldLeft > $(window).width()) {
|
||||
let leftPosition;
|
||||
if (inputFieldLeft < flag.left + $(window).scrollLeft()) {
|
||||
leftPosition = inputFieldLeft;
|
||||
} else {
|
||||
leftPosition = flag.left + $(window).scrollLeft();
|
||||
}
|
||||
query.$el.find('.atwho-view').css('left', leftPosition + 'px');
|
||||
$currentAtWho.find(`.${filterType}`).click();
|
||||
}
|
||||
}).on('reposition.atwho', function(event, flag, query) {
|
||||
let inputFieldLeft = query.$inputor.offset().left;
|
||||
if (inputFieldLeft > $(window).width()) {
|
||||
let leftPosition;
|
||||
if (inputFieldLeft < flag.left + $(window).scrollLeft()) {
|
||||
leftPosition = inputFieldLeft;
|
||||
} else {
|
||||
leftPosition = flag.left + $(window).scrollLeft();
|
||||
}
|
||||
if ($('.repository-show').length) {
|
||||
query.$el.find('.atwho-view').css('top', flag.top + 'px');
|
||||
}
|
||||
}).atwho({
|
||||
at: '@',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(FilterTypeEnum.USER.dataUrl, { query: query }, function(data) {
|
||||
callback(data.users);
|
||||
});
|
||||
},
|
||||
tplEval: function(_tpl, items) {
|
||||
var $items = $(items.name);
|
||||
$items.find('li').data('item-data', { 'atwho-at': '@' }); // Emulate at.js insertContentFor method
|
||||
return $items;
|
||||
},
|
||||
highlighter: function(li, query) {
|
||||
return matchHighlighter(li, query);
|
||||
},
|
||||
beforeInsert: function(value, li) {
|
||||
return `[@${li.attr('data-full-name')}~${li.attr('data-id')}]`;
|
||||
}
|
||||
query.$el.find('.atwho-view').css('left', leftPosition + 'px');
|
||||
}
|
||||
if ($('.repository-show').length) {
|
||||
query.$el.find('.atwho-view').css('top', flag.top + 'px');
|
||||
}
|
||||
}).atwho({
|
||||
at: '@',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(FilterTypeEnum.USER.dataUrl, { query: query }, function(data) {
|
||||
callback(data.users);
|
||||
});
|
||||
},
|
||||
startsWithSpace: true,
|
||||
acceptSpaceBar: true,
|
||||
displayTimeout: 120000
|
||||
})
|
||||
.atwho(atWhoSettings('#'));
|
||||
// .atwho(atWhoSettings('task#', FilterTypeEnum.TASK)) Waiting for better times
|
||||
// .atwho(atWhoSettings('project#', FilterTypeEnum.PROJECT))
|
||||
// .atwho(atWhoSettings('experiment#', FilterTypeEnum.EXPERIMENT))
|
||||
// .atwho(atWhoSettings('sample#', FilterTypeEnum.REPOSITORY));
|
||||
tplEval: function(_tpl, items) {
|
||||
var $items = $(items.name);
|
||||
$items.find('li').data('item-data', { 'atwho-at': '@' }); // Emulate at.js insertContentFor method
|
||||
return $items;
|
||||
},
|
||||
highlighter: function(li, query) {
|
||||
return matchHighlighter(li, query);
|
||||
},
|
||||
beforeInsert: function(value, li) {
|
||||
return `[@${li.attr('data-full-name')}~${li.attr('data-id')}]`;
|
||||
}
|
||||
},
|
||||
startsWithSpace: true,
|
||||
acceptSpaceBar: true,
|
||||
displayTimeout: 120000
|
||||
})
|
||||
.atwho(atWhoSettings('#'));
|
||||
// .atwho(atWhoSettings('task#', FilterTypeEnum.TASK)) Waiting for better times
|
||||
// .atwho(atWhoSettings('project#', FilterTypeEnum.PROJECT))
|
||||
// .atwho(atWhoSettings('experiment#', FilterTypeEnum.EXPERIMENT))
|
||||
// .atwho(atWhoSettings('sample#', FilterTypeEnum.REPOSITORY));
|
||||
|
||||
$(this).data('atwho-initialized', true);
|
||||
});
|
||||
$(this).data('atwho-initialized', true);
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (deferred) {
|
||||
$(field).on('focus', initAtwho);
|
||||
} else {
|
||||
initAtwho();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -217,8 +223,8 @@ var SmartAnnotation = (function() {
|
|||
$('.atwho-header-res').find('.fa-times').click();
|
||||
}
|
||||
|
||||
function initialize(field) {
|
||||
var atWho = new SetAtWho(field);
|
||||
function initialize(field, deferred) {
|
||||
var atWho = new SetAtWho(field, deferred);
|
||||
atWho.init();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue