overleaf/services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee

48 lines
1.2 KiB
CoffeeScript
Raw Normal View History

define [
], () ->
class ReferencesSearchManager
constructor: (@ide, @$scope) ->
2015-12-29 06:02:59 -05:00
@$scope.$root._references = @state = keys: []
2015-12-18 11:20:58 -05:00
@$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], true)
2015-12-29 08:30:57 -05:00
@$scope.$on 'project:joined', (e) =>
@indexReferences("ALL", false)
# docIds: List[String]|String('ALL'), shouldBroadcast: Bool
indexReferences: (docIds, shouldBroadcast) ->
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
return
opts =
docIds: docIds
shouldBroadcast: shouldBroadcast
_csrf: window.csrfToken
console.log ">>", opts
$.post(
"/project/#{@$scope.project_id}/references/index",
opts,
(data) =>
console.log ">> done ", data
@$scope.$root._references.keys = data.keys
)
getReferenceKeys: (callback=(keys)->) ->
if window._ENABLE_REFERENCES_AUTOCOMPLETE != true
return
$.get(
"/project/#{@$scope.project_id}/references/keys",
{
_csrf: window.csrfToken
},
(data) =>
2015-12-29 06:02:59 -05:00
@$scope.$root._references.keys = data.keys
if callback
callback(data.keys)
)