2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller "FileTreeController", ["$scope", "$modal", "ide", ($scope, $modal, ide) ->
|
|
|
|
$scope.openNewDocModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "newDocModalTemplate"
|
|
|
|
controller: "NewDocModalController"
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openNewFolderModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "newFolderModalTemplate"
|
|
|
|
controller: "NewFolderModalController"
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.openUploadFileModal = () ->
|
|
|
|
$modal.open(
|
|
|
|
templateUrl: "uploadFileModalTemplate"
|
|
|
|
controller: "UploadFileModalController"
|
|
|
|
scope: $scope
|
|
|
|
resolve: {
|
|
|
|
parent_folder: () -> ide.fileTreeManager.getCurrentFolder()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.orderByFoldersFirst = (entity) ->
|
2015-04-14 12:05:13 -04:00
|
|
|
return '0' if entity?.type == "folder"
|
2014-07-08 07:02:26 -04:00
|
|
|
return '1'
|
|
|
|
|
|
|
|
$scope.startRenamingSelected = () ->
|
|
|
|
$scope.$broadcast "rename:selected"
|
|
|
|
|
|
|
|
$scope.openDeleteModalForSelected = () ->
|
|
|
|
$scope.$broadcast "delete:selected"
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "NewDocModalController", [
|
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
|
|
|
$scope.inputs =
|
|
|
|
name: "name.tex"
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
$scope.create = () ->
|
2015-03-02 07:46:02 -05:00
|
|
|
name = $scope.inputs.name
|
|
|
|
if !name? or name.length == 0
|
|
|
|
return
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = true
|
|
|
|
ide.fileTreeManager
|
2015-03-02 07:46:02 -05:00
|
|
|
.createDoc(name, parent_folder)
|
2014-07-08 07:02:26 -04:00
|
|
|
.success () ->
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "NewFolderModalController", [
|
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
|
|
|
$scope.inputs =
|
|
|
|
name: "name"
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
$scope.create = () ->
|
2015-03-02 07:46:02 -05:00
|
|
|
name = $scope.inputs.name
|
|
|
|
if !name? or name.length == 0
|
|
|
|
return
|
|
|
|
$scope.state.inflight = true
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state.inflight = true
|
|
|
|
ide.fileTreeManager
|
2015-03-02 07:46:02 -05:00
|
|
|
.createFolder(name, parent_folder)
|
2014-07-08 07:02:26 -04:00
|
|
|
.success () ->
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "UploadFileModalController", [
|
|
|
|
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
|
|
|
|
($scope, ide, $modalInstance, $timeout, parent_folder) ->
|
|
|
|
$scope.parent_folder_id = parent_folder?.id
|
2015-12-01 07:55:35 -05:00
|
|
|
$scope.tooManyFiles = false
|
2015-12-01 08:08:49 -05:00
|
|
|
$scope.rateLimitHit = false
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
uploadCount = 0
|
|
|
|
$scope.onUpload = () ->
|
|
|
|
uploadCount++
|
|
|
|
|
2015-12-01 07:55:35 -05:00
|
|
|
$scope.max_files = 20
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.onComplete = (error, name, response) ->
|
|
|
|
$timeout (() ->
|
|
|
|
uploadCount--
|
|
|
|
if uploadCount == 0 and response? and response.success
|
|
|
|
$modalInstance.close("done")
|
|
|
|
), 250
|
|
|
|
|
2015-12-01 07:55:35 -05:00
|
|
|
$scope.onValidateBatch = (files)->
|
|
|
|
if files.length > $scope.max_files
|
|
|
|
$timeout (() ->
|
|
|
|
$scope.tooManyFiles = true
|
|
|
|
), 1
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
|
2015-12-01 08:08:49 -05:00
|
|
|
$scope.onError = (id, name, reason)->
|
|
|
|
if reason.indexOf("429") != -1
|
|
|
|
$scope.rateLimitHit = true
|
2015-12-01 07:55:35 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|