Explorar o código

Use angular `$http` service for spellcheck

Shane Kilkelly %!s(int64=9) %!d(string=hai) anos
pai
achega
a66cb15f48

+ 2 - 2
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -35,7 +35,7 @@ define [
 			url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}"
 			url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}"
 			return url
 			return url
 
 
-	App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, graphics, preamble) ->
+	App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, graphics, preamble, $http) ->
 		monkeyPatchSearch($rootScope, $compile)
 		monkeyPatchSearch($rootScope, $compile)
 
 
 		return  {
 		return  {
@@ -97,7 +97,7 @@ define [
 
 
 				if scope.spellCheck # only enable spellcheck when explicitly required
 				if scope.spellCheck # only enable spellcheck when explicitly required
 					spellCheckCache =  $cacheFactory("spellCheck-#{scope.name}", {capacity: 1000})
 					spellCheckCache =  $cacheFactory("spellCheck-#{scope.name}", {capacity: 1000})
-					spellCheckManager = new SpellCheckManager(scope, editor, element, spellCheckCache)
+					spellCheckManager = new SpellCheckManager(scope, editor, element, spellCheckCache, $http)
 				undoManager           = new UndoManager(scope, editor, element)
 				undoManager           = new UndoManager(scope, editor, element)
 				highlightsManager     = new HighlightsManager(scope, editor, element)
 				highlightsManager     = new HighlightsManager(scope, editor, element)
 				cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)
 				cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)

+ 6 - 13
services/web/public/coffee/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.coffee

@@ -5,7 +5,7 @@ define [
 	Range = ace.require("ace/range").Range
 	Range = ace.require("ace/range").Range
 
 
 	class SpellCheckManager
 	class SpellCheckManager
-		constructor: (@$scope, @editor, @element, @cache) ->
+		constructor: (@$scope, @editor, @element, @cache, @$http) ->
 			$(document.body).append @element.find(".spell-check-menu")
 			$(document.body).append @element.find(".spell-check-menu")
 			
 			
 			@updatedLines = []
 			@updatedLines = []
@@ -235,18 +235,11 @@ define [
 		apiRequest: (endpoint, data, callback = (error, result) ->)->
 		apiRequest: (endpoint, data, callback = (error, result) ->)->
 			data.token = window.user.id
 			data.token = window.user.id
 			data._csrf = window.csrfToken
 			data._csrf = window.csrfToken
-			options =
-				url: "/spelling" + endpoint
-				type: "POST"
-				dataType: "json"
-				headers:
-					"Content-Type": "application/json"
-				data: JSON.stringify data
-				success: (data, status, xhr) ->
-					callback null, data
-				error: (xhr, status, error) ->
-					callback error
-			return $.ajax options
+			@$http.post("/spelling" + endpoint, data)
+			.then (response) =>
+				callback(null, response.data)
+			.catch (response) =>
+				callback(new Error('api failure'))
 
 
 		blacklistedCommandRegex: ///
 		blacklistedCommandRegex: ///
 			\\                    # initial backslash
 			\\                    # initial backslash