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) ->
|
2014-07-16 06:02:45 -04:00
|
|
|
$scope.showPublishTemplateLinkInSideBar = ide.$scope.hasPermission("admin")
|
2014-07-15 12:56:09 -04:00
|
|
|
|
|
|
|
$scope.openPublishTemplateModal = () ->
|
|
|
|
console.log "open"
|
|
|
|
$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-16 06:56:22 -04:00
|
|
|
$scope.template = {}
|
2014-07-15 12:56:09 -04:00
|
|
|
$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")
|
2014-07-16 06:56:22 -04:00
|
|
|
console.log data
|
|
|
|
$scope.template.description = data.description
|
2014-07-15 12:56:09 -04:00
|
|
|
|
|
|
|
refreshPublishedStatus()
|
|
|
|
|
|
|
|
$scope.updateProjectDescription = ->
|
|
|
|
description = $scope.template.description
|
|
|
|
if description?
|
|
|
|
ide.socket.emit 'updateProjectDescription', description, () =>
|
|
|
|
|
2014-07-16 07:04:33 -04:00
|
|
|
$scope.publishTemplate = ->
|
2014-07-15 12:56:09 -04:00
|
|
|
$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()
|