2014-02-12 05:23:40 -05:00
|
|
|
define [
|
|
|
|
"models/User"
|
|
|
|
"models/ProjectMemberList"
|
|
|
|
"models/Folder"
|
2014-06-05 08:11:39 -04:00
|
|
|
"models/Doc"
|
2014-02-12 05:23:40 -05:00
|
|
|
"libs/backbone"
|
2014-06-05 08:11:39 -04:00
|
|
|
], (User, ProjectMemberList, Folder, Doc) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
Project = Backbone.Model.extend
|
|
|
|
initialize: ->
|
|
|
|
@on "change:ide", (project, ide) =>
|
|
|
|
@bindToRootDocId()
|
|
|
|
@bindToProjectName()
|
|
|
|
@bindToPublicAccessLevel()
|
|
|
|
@bindToCompiler()
|
|
|
|
@bindToSpellingPreference()
|
|
|
|
@bindToProjectDescription()
|
|
|
|
|
|
|
|
parse: (rawAttributes) ->
|
|
|
|
attributes =
|
|
|
|
id : rawAttributes._id
|
|
|
|
name : rawAttributes.name
|
|
|
|
rootFolder : new Folder(rawAttributes.rootFolder[0], parse: true)
|
|
|
|
rootDoc_id : rawAttributes.rootDoc_id
|
|
|
|
publicAccesLevel : rawAttributes.publicAccesLevel
|
|
|
|
features : rawAttributes.features
|
|
|
|
compiler : rawAttributes.compiler
|
|
|
|
spellCheckLanguage: rawAttributes.spellCheckLanguage
|
|
|
|
dropboxEnabled : rawAttributes.dropboxEnabled
|
|
|
|
description : rawAttributes.description
|
|
|
|
deletedByExternalDataSource: rawAttributes.deletedByExternalDataSource
|
|
|
|
useOt : rawAttributes.useOt
|
|
|
|
|
|
|
|
attributes.members = members = new ProjectMemberList()
|
|
|
|
|
|
|
|
attributes.owner = owner = User.findOrBuild rawAttributes.owner._id, rawAttributes.owner
|
|
|
|
owner.set("privileges", "owner")
|
|
|
|
members.add owner
|
|
|
|
|
|
|
|
for rawMember in rawAttributes.members
|
|
|
|
member = User.findOrBuild rawMember._id, rawMember
|
|
|
|
members.add member
|
|
|
|
|
2014-06-05 08:11:39 -04:00
|
|
|
for doc in rawAttributes.deletedDocs
|
|
|
|
doc.deleted = true
|
|
|
|
|
|
|
|
attributes.deletedDocs = new Folder({
|
|
|
|
_id: "deleted-docs-folder"
|
|
|
|
name: "Deleted documents"
|
|
|
|
docs: rawAttributes.deletedDocs
|
|
|
|
}, parse: true)
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
return attributes
|
|
|
|
|
|
|
|
bindToRootDocId: ->
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
@on "change:rootDoc_id", (project, docId) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
if !remoteChange
|
|
|
|
@get("ide").socket.emit "setRootDoc", docId
|
2014-02-12 05:23:40 -05:00
|
|
|
@get("ide").socket.on "rootDocUpdated", (docId) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = true
|
2014-02-12 05:23:40 -05:00
|
|
|
@set("rootDoc_id", docId)
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
bindToProjectName: ->
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
@on "change:name", (project, name) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
if !remoteChange
|
2014-04-07 10:37:40 -04:00
|
|
|
@get("ide").socket.emit "setProjectName", name
|
|
|
|
@get("ide").socket.on "projectNameUpdated", (name) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = true
|
2014-02-12 05:23:40 -05:00
|
|
|
@set("name", name)
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
bindToCompiler: ->
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
@on "change:compiler", (project, name) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
if !remoteChange
|
|
|
|
@get("ide").socket.emit "setCompiler", name
|
2014-02-12 05:23:40 -05:00
|
|
|
@get("ide").socket.on "compilerUpdated", (compiler) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = true
|
|
|
|
@set("compiler", compiler)
|
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
bindToSpellingPreference: ->
|
|
|
|
@on "change:spellCheckLanguage", (project, languageCode) =>
|
|
|
|
@get("ide").socket.emit "setSpellCheckLanguage", languageCode
|
|
|
|
|
|
|
|
bindToPublicAccessLevel: ->
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
@on "change:publicAccesLevel", (project, level) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
if !remoteChange
|
|
|
|
@get("ide").socket.emit "setPublicAccessLevel", level
|
2014-02-12 05:23:40 -05:00
|
|
|
@get("ide").socket.on 'publicAccessLevelUpdated', (level) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = true
|
2014-02-12 05:23:40 -05:00
|
|
|
@set("publicAccesLevel", level)
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
bindToProjectDescription: ->
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
@on "change:description", (project, description) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
if !remoteChange
|
|
|
|
@get("ide").socket.emit "updateProjectDescription", description
|
2014-02-12 05:23:40 -05:00
|
|
|
@get("ide").socket.on 'projectDescriptionUpdated', (description) =>
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = true
|
2014-02-12 05:23:40 -05:00
|
|
|
@set("description", description)
|
2014-02-19 12:16:32 -05:00
|
|
|
remoteChange = false
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
getRootDocumentsList: (callback) ->
|
|
|
|
@get("ide").socket.emit "getRootDocumentsList", (err, listOfDocs) ->
|
|
|
|
callback(listOfDocs)
|
|
|
|
|