overleaf/services/web/public/coffee/ide/services/ide.coffee
2014-07-24 16:07:43 +01:00

51 lines
1.4 KiB
CoffeeScript

define [
"base"
], (App) ->
# We create and provide this as service so that we can access the global ide
# from within other parts of the angular app.
App.factory "ide", ["$http", "$modal", ($http, $modal) ->
ide = {}
ide.$http = $http
@recentEvents = []
ide.pushEvent = (type, meta = {}) =>
@recentEvents.push type: type, meta: meta, date: new Date()
if @recentEvents.length > 40
@recentEvents.shift()
ide.reportError = (error, meta = {}) =>
meta.client_id = @socket?.socket?.sessionid
meta.transport = @socket?.socket?.transport?.name
meta.client_now = new Date()
meta.recent_events = @recentEvents
errorObj = {}
if typeof error == "object"
for key in Object.getOwnPropertyNames(error)
errorObj[key] = error[key]
else if typeof error == "string"
errorObj.message = error
$http.post "/error/client", {
error: errorObj
meta: meta
_csrf: window.csrfToken
}
ide.showGenericMessageModal = (title, message) ->
$modal.open {
templateUrl: "genericMessageModalTemplate"
controller: "GenericMessageModalController"
resolve:
title: -> title
message: -> message
}
return ide
]
App.controller "GenericMessageModalController", ["$scope", "$modalInstance", "title", "message", ($scope, $modalInstance, title, message) ->
$scope.title = title
$scope.message = message
$scope.done = () ->
$modalInstance.close()
]