overleaf/services/web/public/coffee/ide/templates/controllers/TemplatesController.coffee

52 lines
1.6 KiB
CoffeeScript
Raw Normal View History

2014-07-15 12:56:09 -04:00
define [
"base"
"ide/permissions/PermissionsManager"
], (App, PermissionsManager) ->
2014-07-15 12:56:09 -04:00
App.controller "TemplatesController", ($scope, $modal, ide) ->
$scope.openPublishTemplateModal = () ->
$modal.open {
templateUrl: "publishProjectAsTemplateModalTemplate"
controller: "PublishProjectAsTemplateModalController"
resolve:
diff: () -> $scope.trackChanges.diff
}
App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
permissionsManager = new PermissionsManager(ide, $scope)
user_id = ide.$scope.user.id
2014-07-15 12:56:09 -04:00
$scope.template =
description: window.project_description
$scope.publishedDetails =
exists:false
$scope.state =
publishInflight: false
unpublishInflight: false
refreshPublishedStatus = ->
ide.socket.emit "getPublishedDetails", user_id, (err, data)->
$scope.publishedDetails = data
$scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
refreshPublishedStatus()
$scope.updateProjectDescription = ->
description = $scope.template.description
if description?
ide.socket.emit 'updateProjectDescription', description, () =>
$scope.publish = ->
$scope.state.publishInflight = true
ide.socket.emit 'publishProjectAsTemplate', user_id, (error, docLines, version) =>
refreshPublishedStatus()
$scope.state.publishInflight = false
$scope.unpublishTemplate = ->
$scope.state.unpublishInflight = true
ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error, docLines, version) =>
refreshPublishedStatus()
$scope.state.unpublishInflight = false
$scope.cancel = () ->
$modalInstance.dismiss()