overleaf/services/web/public/coffee/app/ide/settings/SettingsManager.coffee

56 lines
1.8 KiB
CoffeeScript
Raw Normal View History

2014-06-24 15:28:53 -04:00
define [], () ->
class SettingsManager
constructor: (@ide, @$scope) ->
@$scope.settings = window.userSettings
2014-06-24 15:46:00 -04:00
if @$scope.settings.mode not in ["default", "vim", "emacs"]
@$scope.settings.mode = "default"
2014-06-24 15:28:53 -04:00
@$scope.$watch "settings.theme", (theme, oldTheme) =>
if theme != oldTheme
@saveSettings({theme: theme})
2014-06-24 15:46:00 -04:00
@$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
if fontSize != oldFontSize
@saveSettings({fontSize: parseInt(fontSize, 10)})
@$scope.$watch "settings.mode", (mode, oldMode) =>
if mode != oldMode
@saveSettings({mode: mode})
2014-06-24 16:09:20 -04:00
@$scope.$watch "settings.autoComplete", (autoComplete, oldAutoComplete) =>
if autoComplete != oldAutoComplete
@saveSettings({autoComplete: autoComplete})
2014-06-25 08:51:02 -04:00
@$scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
return if @ignoreUpdates
if oldLanguage? and language != oldLanguage
@saveProjectSettings({spellCheckLanguage: language})
# Also set it as the default for the user
@saveSettings({spellCheckLanguage: language})
@$scope.$watch "project.compiler", (compiler, oldCompiler) =>
return if @ignoreUpdates
if oldCompiler? and compiler != oldCompiler
@saveProjectSettings({compiler: compiler})
@ide.socket.on "compilerUpdated", (compiler) =>
@ignoreUpdates = true
@$scope.$apply () =>
@$scope.project.compiler = compiler
delete @ignoreUpdates
@ide.socket.on "spellCheckLanguageUpdated", (languageCode) =>
@ignoreUpdates = true
@$scope.$apply () =>
@$scope.project.spellCheckLanguage = languageCode
delete @ignoreUpdates
2014-06-24 15:28:53 -04:00
saveSettings: (data) ->
data._csrf = window.csrfToken
@ide.$http.post "/user/settings", data
2014-06-25 08:51:02 -04:00
saveProjectSettings: (data) ->
data._csrf = window.csrfToken
@ide.$http.post "/project/#{@ide.project_id}/settings", data