mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
46 lines
1.1 KiB
CoffeeScript
46 lines
1.1 KiB
CoffeeScript
define [
|
|
], () ->
|
|
class ReferencesSearchManager
|
|
constructor: (@ide, @$scope) ->
|
|
|
|
@$scope.$root._references = @state = keys: []
|
|
|
|
@$scope.$on 'document:closed', (e, doc) =>
|
|
if doc.doc_id
|
|
entity = @ide.fileTreeManager.findEntityById doc.doc_id
|
|
if entity?.name?.match /.*\.bib$/
|
|
@$scope.$emit 'references:changed', entity
|
|
@indexReferences doc.doc_id
|
|
|
|
@$scope.$on 'project:joined', (e) =>
|
|
@getReferenceKeys()
|
|
|
|
indexReferences: (doc_id) ->
|
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
|
return
|
|
$.post(
|
|
"/project/#{@$scope.project_id}/references",
|
|
{
|
|
docId: doc_id,
|
|
_csrf: window.csrfToken
|
|
},
|
|
(data) =>
|
|
setTimeout(
|
|
( () -> @getReferenceKeys() ).bind(this),
|
|
500
|
|
)
|
|
)
|
|
|
|
getReferenceKeys: (callback) ->
|
|
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
|
|
return
|
|
$.get(
|
|
"/project/#{@$scope.project_id}/references/keys",
|
|
{
|
|
_csrf: window.csrfToken
|
|
},
|
|
(data) =>
|
|
@$scope.$root._references.keys = data.keys
|
|
if callback
|
|
callback(data.keys)
|
|
)
|