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-16 09:18:28 -04:00
|
|
|
|
2014-07-15 12:56:09 -04:00
|
|
|
App.controller "TemplatesController", ($scope, $modal, ide) ->
|
|
|
|
$scope.openPublishTemplateModal = () ->
|
2014-07-16 09:18:28 -04:00
|
|
|
resetState = ->
|
|
|
|
$scope.problemTalkingToTemplateApi = false
|
|
|
|
|
|
|
|
resetState()
|
|
|
|
|
|
|
|
modal = $modal.open {
|
2014-07-15 12:56:09 -04:00
|
|
|
templateUrl: "publishProjectAsTemplateModalTemplate"
|
|
|
|
controller: "PublishProjectAsTemplateModalController"
|
2014-07-16 09:18:28 -04:00
|
|
|
scope:$scope
|
2014-07-15 12:56:09 -04:00
|
|
|
}
|
2014-07-16 09:18:28 -04:00
|
|
|
modal.result.then(resetState, resetState)
|
2014-07-15 12:56:09 -04:00
|
|
|
|
2014-07-16 06:02:45 -04:00
|
|
|
App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
|
|
|
|
user_id = ide.$scope.user.id
|
2014-07-16 09:18:28 -04:00
|
|
|
$scope.templateDetails = {exists:false}
|
2014-07-15 12:56:09 -04:00
|
|
|
|
|
|
|
$scope.state =
|
|
|
|
publishInflight: false
|
|
|
|
unpublishInflight: false
|
|
|
|
|
2014-07-16 09:18:28 -04:00
|
|
|
problemTalkingToTemplateApi = ->
|
|
|
|
$scope.problemTalkingToTemplateApi = true
|
2014-07-16 08:36:02 -04:00
|
|
|
|
2014-07-16 09:18:28 -04:00
|
|
|
refreshPublishedStatus = ->
|
2014-07-15 12:56:09 -04:00
|
|
|
ide.socket.emit "getPublishedDetails", user_id, (err, data)->
|
2014-07-16 09:18:28 -04:00
|
|
|
if !data? or err? then return problemTalkingToTemplateApi()
|
|
|
|
$scope.templateDetails = data
|
|
|
|
$scope.templateDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
|
|
|
|
$scope.templateDetails.description = data.description
|
2014-07-15 12:56:09 -04:00
|
|
|
|
|
|
|
refreshPublishedStatus()
|
2014-07-16 09:18:28 -04:00
|
|
|
$scope.$watch $scope.problemTalkingToTemplateApi, refreshPublishedStatus
|
2014-07-15 12:56:09 -04:00
|
|
|
|
|
|
|
$scope.updateProjectDescription = ->
|
|
|
|
description = $scope.template.description
|
|
|
|
if description?
|
2014-07-16 08:36:02 -04:00
|
|
|
ide.socket.emit 'updateProjectDescription', description, (err) =>
|
2014-07-16 09:18:28 -04:00
|
|
|
if err? then return problemTalkingToTemplateApi()
|
2014-07-15 12:56:09 -04:00
|
|
|
|
2014-07-16 07:04:33 -04:00
|
|
|
$scope.publishTemplate = ->
|
2014-07-15 12:56:09 -04:00
|
|
|
$scope.state.publishInflight = true
|
2014-07-16 08:36:02 -04:00
|
|
|
ide.socket.emit 'publishProjectAsTemplate', user_id, (error) =>
|
2014-07-16 09:18:28 -04:00
|
|
|
if err? then return problemTalkingToTemplateApi()
|
2014-07-15 12:56:09 -04:00
|
|
|
refreshPublishedStatus()
|
|
|
|
$scope.state.publishInflight = false
|
|
|
|
|
|
|
|
$scope.unpublishTemplate = ->
|
|
|
|
$scope.state.unpublishInflight = true
|
2014-07-16 08:36:02 -04:00
|
|
|
ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error) =>
|
2014-07-16 09:18:28 -04:00
|
|
|
if err? then return problemTalkingToTemplateApi()
|
2014-07-15 12:56:09 -04:00
|
|
|
refreshPublishedStatus()
|
|
|
|
$scope.state.unpublishInflight = false
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss()
|