2014-02-12 05:23:40 -05:00
|
|
|
define [
|
|
|
|
"ide/ConnectionManager"
|
|
|
|
"history/HistoryManager"
|
|
|
|
"auto-complete/AutoCompleteManager"
|
|
|
|
"project-members/ProjectMembersManager"
|
|
|
|
"settings/SettingsManager"
|
|
|
|
"editor/Editor"
|
|
|
|
"pdf/PdfManager"
|
|
|
|
"ide/MainAreaManager"
|
|
|
|
"ide/SideBarManager"
|
|
|
|
"ide/TabManager"
|
|
|
|
"ide/LayoutManager"
|
|
|
|
"ide/FileUploadManager"
|
|
|
|
"spelling/SpellingManager"
|
|
|
|
"search/SearchManager"
|
|
|
|
"models/Project"
|
|
|
|
"models/User"
|
|
|
|
"utils/Modal"
|
|
|
|
"file-tree/FileTreeManager"
|
|
|
|
"messages/MessageManager"
|
|
|
|
"help/HelpManager"
|
|
|
|
"cursors/CursorManager"
|
|
|
|
"keys/HotkeysManager"
|
|
|
|
"keys/BackspaceHighjack"
|
|
|
|
"file-view/FileViewManager"
|
|
|
|
"tour/IdeTour"
|
|
|
|
"analytics/AnalyticsManager"
|
2014-03-05 12:55:47 -05:00
|
|
|
"track-changes/TrackChangesManager"
|
2014-03-27 13:33:07 -04:00
|
|
|
"debug/DebugManager"
|
2014-02-12 05:23:40 -05:00
|
|
|
"ace/ace"
|
|
|
|
"libs/jquery.color"
|
|
|
|
"libs/jquery-layout"
|
|
|
|
"libs/backbone"
|
|
|
|
"main"
|
|
|
|
], (
|
|
|
|
ConnectionManager,
|
|
|
|
HistoryManager,
|
|
|
|
AutoCompleteManager,
|
|
|
|
ProjectMembers,
|
|
|
|
SettingsManager,
|
|
|
|
Editor,
|
|
|
|
PdfManager,
|
|
|
|
MainAreaManager,
|
|
|
|
SideBarManager,
|
|
|
|
TabManager,
|
|
|
|
LayoutManager,
|
|
|
|
FileUploadManager,
|
|
|
|
SpellingManager,
|
|
|
|
SearchManager,
|
|
|
|
Project,
|
|
|
|
User,
|
2014-03-14 07:14:02 -04:00
|
|
|
Modal,
|
2014-02-12 05:23:40 -05:00
|
|
|
FileTreeManager,
|
|
|
|
MessageManager,
|
|
|
|
HelpManager,
|
|
|
|
CursorManager,
|
|
|
|
HotkeysManager,
|
|
|
|
BackspaceHighjack,
|
|
|
|
FileViewManager,
|
|
|
|
IdeTour,
|
2014-03-05 12:55:47 -05:00
|
|
|
AnalyticsManager,
|
|
|
|
TrackChangesManager
|
2014-03-27 13:33:07 -04:00
|
|
|
DebugManager
|
2014-02-12 05:23:40 -05:00
|
|
|
) ->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProjectMembersManager = ProjectMembers.ProjectMembersManager
|
|
|
|
|
|
|
|
mainAreaManager = undefined
|
|
|
|
socket = undefined
|
|
|
|
currentDoc_id = undefined
|
|
|
|
selectElement = undefined
|
|
|
|
security = undefined
|
|
|
|
_.templateSettings =
|
|
|
|
interpolate : /\{\{(.+?)\}\}/g
|
|
|
|
|
|
|
|
isAllowedToDoIt = (permissionsLevel)->
|
|
|
|
|
|
|
|
if permissionsLevel == "owner" && _.include ["owner"], security.permissionsLevel
|
|
|
|
return true
|
|
|
|
else if permissionsLevel == "readAndWrite" && _.include ["readAndWrite", "owner"], security.permissionsLevel
|
|
|
|
return true
|
|
|
|
else if permissionsLevel == "readOnly" && _.include ["readOnly", "readAndWrite", "owner"], security.permissionsLevel
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
|
|
|
|
Ide = class Ide
|
|
|
|
constructor: () ->
|
|
|
|
@userSettings = window.userSettings
|
|
|
|
@project_id = @userSettings.project_id
|
|
|
|
|
|
|
|
@user = User.findOrBuild window.user.id, window.user
|
|
|
|
|
|
|
|
ide = this
|
|
|
|
@isAllowedToDoIt = isAllowedToDoIt
|
|
|
|
|
|
|
|
ioOptions =
|
|
|
|
reconnect: false
|
|
|
|
"force new connection": true
|
|
|
|
@socket = socket = io.connect null, ioOptions
|
|
|
|
|
|
|
|
@messageManager = new MessageManager(@)
|
|
|
|
@connectionManager = new ConnectionManager(@)
|
|
|
|
@tabManager = new TabManager(@)
|
|
|
|
@layoutManager = new LayoutManager(@)
|
|
|
|
@sideBarView = new SideBarManager(@, $("#sections"))
|
|
|
|
selectElement = @sideBarView.selectElement
|
|
|
|
mainAreaManager = @mainAreaManager = new MainAreaManager(@, $("#content"))
|
2014-03-20 12:30:37 -04:00
|
|
|
@fileTreeManager = new FileTreeManager(@)
|
2014-02-12 05:23:40 -05:00
|
|
|
@editor = new Editor(@)
|
|
|
|
@pdfManager = new PdfManager(@)
|
|
|
|
if @userSettings.autoComplete
|
|
|
|
@autoCompleteManager = new AutoCompleteManager(@)
|
|
|
|
@spellingManager = new SpellingManager(@)
|
|
|
|
@fileUploadManager = new FileUploadManager(@)
|
|
|
|
@searchManager = new SearchManager(@)
|
|
|
|
@cursorManager = new CursorManager(@)
|
|
|
|
@fileViewManager = new FileViewManager(@)
|
|
|
|
@analyticsManager = new AnalyticsManager(@)
|
2014-03-31 04:47:36 -04:00
|
|
|
if @userSettings.oldHistory
|
2014-03-20 12:45:39 -04:00
|
|
|
@historyManager = new HistoryManager(@)
|
2014-03-31 04:47:36 -04:00
|
|
|
else
|
|
|
|
@trackChangesManager = new TrackChangesManager(@)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@setLoadingMessage("Connecting")
|
|
|
|
firstConnect = true
|
|
|
|
socket.on "connect", () =>
|
|
|
|
@setLoadingMessage("Joining project")
|
|
|
|
joinProject = () =>
|
|
|
|
socket.emit 'joinProject', {project_id: @project_id}, (err, project, permissionsLevel, protocolVersion) =>
|
|
|
|
@hideLoadingScreen()
|
|
|
|
if @protocolVersion? and @protocolVersion != protocolVersion
|
|
|
|
location.reload(true)
|
|
|
|
@protocolVersion = protocolVersion
|
|
|
|
Security = {}
|
|
|
|
Security.permissionsLevel = permissionsLevel
|
|
|
|
@security = security = Object.freeze(Security)
|
|
|
|
@project = new Project project, parse: true
|
|
|
|
@project.set("ide", ide)
|
|
|
|
ide.trigger "afterJoinProject", @project
|
|
|
|
|
|
|
|
if firstConnect
|
|
|
|
@pdfManager.refreshPdf(isAutoCompile:true)
|
|
|
|
firstConnect = false
|
|
|
|
|
|
|
|
setTimeout(joinProject, 100)
|
|
|
|
|
|
|
|
showErrorModal: (title, message)->
|
2014-03-14 07:14:02 -04:00
|
|
|
new Modal {
|
2014-02-12 05:23:40 -05:00
|
|
|
title: title
|
2014-03-14 07:14:02 -04:00
|
|
|
message: message
|
|
|
|
buttons: [ text: "OK" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
showGenericServerErrorMessage: ()->
|
|
|
|
new Modal {
|
|
|
|
title: "There was a problem talking to the server"
|
|
|
|
message: "Sorry, we couldn't complete your request right now. Please wait a few moments and try again. If the problem persists, please let us know."
|
|
|
|
buttons: [ text: "OK" ]
|
|
|
|
}
|
|
|
|
|
2014-03-31 08:30:47 -04:00
|
|
|
recentEvents: []
|
|
|
|
|
|
|
|
pushEvent: (type, meta = {}) ->
|
|
|
|
@recentEvents.push type: type, meta: meta, date: new Date()
|
|
|
|
if @recentEvents.length > 10
|
|
|
|
@recentEvents.shift()
|
|
|
|
|
2014-03-14 07:14:02 -04:00
|
|
|
reportError: (error, meta = {}) ->
|
2014-03-14 13:23:50 -04:00
|
|
|
meta.client_id = @socket?.socket?.sessionid
|
|
|
|
meta.transport = @socket?.socket?.transport?.name
|
|
|
|
meta.client_now = new Date()
|
2014-03-31 08:30:47 -04:00
|
|
|
meta.recent_events = @recentEvents
|
2014-03-14 07:14:02 -04:00
|
|
|
errorObj = {}
|
|
|
|
for key in Object.getOwnPropertyNames(error)
|
|
|
|
errorObj[key] = error[key]
|
|
|
|
$.ajax
|
|
|
|
url: "/error/client"
|
|
|
|
type: "POST"
|
|
|
|
data: JSON.stringify
|
|
|
|
error: errorObj
|
|
|
|
meta: meta
|
|
|
|
contentType: "application/json; charset=utf-8"
|
|
|
|
headers:
|
|
|
|
"X-Csrf-Token": window.csrfToken
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
setLoadingMessage: (message) ->
|
|
|
|
$("#loadingMessage").text(message)
|
|
|
|
|
|
|
|
hideLoadingScreen: () ->
|
|
|
|
$("#loadingScreen").remove()
|
|
|
|
|
|
|
|
_.extend(Ide::, Backbone.Events)
|
|
|
|
window.ide = ide = new Ide()
|
|
|
|
ide.projectMembersManager = new ProjectMembersManager ide
|
|
|
|
ide.settingsManager = new SettingsManager ide
|
|
|
|
ide.helpManager = new HelpManager ide
|
|
|
|
ide.hotkeysManager = new HotkeysManager ide
|
|
|
|
ide.layoutManager.resizeAllSplitters()
|
|
|
|
ide.tourManager = new IdeTour ide
|
2014-03-27 13:33:07 -04:00
|
|
|
ide.debugManager = new DebugManager(ide)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
ide.savingAreaManager =
|
|
|
|
$savingArea : $('#saving-area')
|
|
|
|
timeOut: undefined
|
|
|
|
saved:->
|
|
|
|
@clearTimeout()
|
|
|
|
$("#savingProblems").hide()
|
|
|
|
saving:->
|
|
|
|
return if @timeOut?
|
|
|
|
@clearTimeout()
|
|
|
|
@timeOut = setTimeout((=>
|
2014-03-14 07:14:02 -04:00
|
|
|
ga?('send', 'event', 'editor-interaction', 'notification-shown', "saving")
|
2014-02-12 05:23:40 -05:00
|
|
|
$("#savingProblems").show()
|
2014-03-24 06:53:37 -04:00
|
|
|
), 3000)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
clearTimeout:->
|
|
|
|
if @timeOut?
|
|
|
|
clearTimeout @timeOut
|
|
|
|
delete @timeOut
|
|
|
|
|