2015-12-17 10:13:02 -05:00
|
|
|
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
|
|
|
|
2015-12-17 10:13:02 -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
|
|
|
|
|
2015-12-29 08:30:57 -05:00
|
|
|
@$scope.$on 'project:joined', (e) =>
|
|
|
|
@getReferenceKeys()
|
|
|
|
|
2015-12-17 10:13:02 -05:00
|
|
|
indexReferences: (doc_id) ->
|
2015-12-18 11:00:24 -05:00
|
|
|
$.post(
|
|
|
|
"/project/#{@$scope.project_id}/references",
|
|
|
|
{
|
|
|
|
docId: doc_id,
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
},
|
|
|
|
(data) =>
|
|
|
|
console.log(data)
|
|
|
|
setTimeout(
|
|
|
|
( () -> @getReferenceKeys() ).bind(this),
|
|
|
|
100
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
getReferenceKeys: () ->
|
|
|
|
$.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
|
2015-12-18 11:00:24 -05:00
|
|
|
)
|