Templates state resets on modal close so if the api comes back it will work

This commit is contained in:
Henry Oswald 2014-07-16 14:18:28 +01:00
parent 735bc9e53d
commit f3f53a99d0
2 changed files with 28 additions and 27 deletions

View file

@ -14,14 +14,14 @@ script(type="text/ng-template", id="publishProjectAsTemplateModalTemplate")
textarea.form-control(
rows=5,
name='Description',
ng-model="template.description",
ng-model="templateDetails.description",
ng-blur="updateProjectDescription()",
value=""
)
div(ng-show="publishedDetails.exists").text-center.publishedDetails
div(ng-show="templateDetails.exists").text-center.templateDetails
| Your project was last published at
strong {{publishedDetails.publishedDate}}.
a(ng-href="{{publishedDetails.canonicalUrl}}") View it in template gallery.
strong {{templateDetails.publishedDate}}.
a(ng-href="{{templateDetails.canonicalUrl}}") View it in template gallery.
span(ng-show="problemTalkingToTemplateApi") There is a problem with our publishing service, please try again in a few minutes.
@ -38,7 +38,7 @@ script(type="text/ng-template", id="publishProjectAsTemplateModalTemplate")
button.btn.btn-info(
ng-click="unpublishTemplate()",
ng-disabled="state.publishInflight || state.unpublishInflight"
ng-show="publishedDetails.exists"
ng-show="templateDetails.exists"
)
span(ng-show="!state.unpublishInflight") Unpublish
span(ng-show="state.unpublishInflight") Unpublishing...
@ -47,6 +47,6 @@ script(type="text/ng-template", id="publishProjectAsTemplateModalTemplate")
ng-click="publishTemplate()",
ng-disabled="state.publishInflight || state.unpublishInflight"
)
span(ng-show="!state.publishInflight && !publishedDetails.exists") Publish
span(ng-show="!state.publishInflight && publishedDetails.exists") Republish
span(ng-show="!state.publishInflight && !templateDetails.exists") Publish
span(ng-show="!state.publishInflight && templateDetails.exists") Republish
span(ng-show="state.publishInflight") Publishing...

View file

@ -2,58 +2,59 @@ define [
"base"
"ide/permissions/PermissionsManager"
], (App, PermissionsManager) ->
App.controller "TemplatesController", ($scope, $modal, ide) ->
$scope.openPublishTemplateModal = () ->
$modal.open {
templateUrl: "publishProjectAsTemplateModalTemplate"
controller: "PublishProjectAsTemplateModalController"
}
App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
user_id = ide.$scope.user.id
$scope.template = {}
$scope.publishedDetails =
exists:false
resetState = ->
$scope.problemTalkingToTemplateApi = false
problemTalkingToTemplateApi = ->
$scope.problemTalkingToTemplateApi = true
resetState()
successTalkingToTemplateApi = ->
$scope.problemTalkingToTemplateApi = true
modal = $modal.open {
templateUrl: "publishProjectAsTemplateModalTemplate"
controller: "PublishProjectAsTemplateModalController"
scope:$scope
}
modal.result.then(resetState, resetState)
App.controller "PublishProjectAsTemplateModalController", ($scope, $modalInstance, ide) ->
user_id = ide.$scope.user.id
$scope.templateDetails = {exists:false}
$scope.state =
publishInflight: false
unpublishInflight: false
refreshPublishedStatus = ->
problemTalkingToTemplateApi = ->
$scope.problemTalkingToTemplateApi = true
refreshPublishedStatus = ->
ide.socket.emit "getPublishedDetails", user_id, (err, data)->
if !data? or err? then return problemTalkingToTemplateApi() else successTalkingToTemplateApi()
$scope.publishedDetails = data
$scope.publishedDetails.publishedDate = moment(data.publishedDate).format("Do MMM YYYY, h:mm a")
$scope.template.description = data.description
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
refreshPublishedStatus()
$scope.$watch $scope.problemTalkingToTemplateApi, refreshPublishedStatus
$scope.updateProjectDescription = ->
description = $scope.template.description
if description?
ide.socket.emit 'updateProjectDescription', description, (err) =>
if err? then return problemTalkingToTemplateApi() else successTalkingToTemplateApi()
if err? then return problemTalkingToTemplateApi()
$scope.publishTemplate = ->
$scope.state.publishInflight = true
ide.socket.emit 'publishProjectAsTemplate', user_id, (error) =>
if err? then return problemTalkingToTemplateApi() else successTalkingToTemplateApi()
if err? then return problemTalkingToTemplateApi()
refreshPublishedStatus()
$scope.state.publishInflight = false
$scope.unpublishTemplate = ->
$scope.state.unpublishInflight = true
ide.socket.emit 'unPublishProjectAsTemplate', user_id, (error) =>
if err? then return problemTalkingToTemplateApi() else successTalkingToTemplateApi()
if err? then return problemTalkingToTemplateApi()
refreshPublishedStatus()
$scope.state.unpublishInflight = false