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