2014-07-15 12:56:09 -04:00
|
|
|
define [
|
|
|
|
"base"
|
2014-07-16 06:02:45 -04:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2014-07-16 06:02:45 -04:00
|
|
|
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()
|