Allow creation of projects

This commit is contained in:
James Allen 2014-06-13 16:05:44 +01:00
parent ab5d6f82c0
commit 8b57224267
2 changed files with 92 additions and 3 deletions

View file

@ -18,9 +18,15 @@ block content
a.btn.btn-primary.dropdown-toggle(data-toggle="dropdown", href="#") New Project
ul.dropdown-menu(role="menu")
li
a#blankNewProject(href="#", data-csrf=csrfToken) Blank Project
a(
href="#",
ng-click="openCreateProjectModal()"
) Blank Project
li
a#newProjectExample(href="#", data-csrf=csrfToken) Example Project
a(
href="#",
ng-click="openCreateProjectModal('example')"
) Example Project
li
a#uploadNewProject(href="#", data-csrf=csrfToken) Upload Project
li.divider
@ -218,3 +224,26 @@ block content
.modal-footer
button.btn.btn-default(ng-click="cancel()") Cancel
button.btn.btn-primary(ng-click="rename()") Rename
script(type='text/ng-template', id='newProjectModalTemplate')
.modal-header
h3 New Project
.modal-body
input.form-control(
type="text",
placeholder="Project Name",
ng-model="inputs.projectName",
ng-enter="create()",
ng-focus-on="open"
)
.modal-footer
button.btn.btn-default(
ng-disabled="state.inflight"
ng-click="cancel()"
) Cancel
button.btn.btn-primary(
ng-disabled="state.inflight"
ng-click="create()"
)
span(ng-hide="state.inflight") Create
span(ng-show="state.inflight") Creating...

View file

@ -24,7 +24,7 @@ ProjectPageApp.filter "formatDate", () ->
(date, format = "Do MMM YYYY, h:mm a") ->
moment(date).format(format)
ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) ->
ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http, $q) ->
$scope.projects = window.data.projects
$scope.visibleProjects = $scope.projects
$scope.tags = window.data.tags
@ -177,6 +177,44 @@ ProjectPageApp.controller "ProjectPageController", ($scope, $modal, $http) ->
$scope.createTag(newTagName)
)
$scope.createProject = (name, template = "none") ->
deferred = $q.defer()
$http
.post("/project/new", {
_csrf: window.csrfToken
projectName: name
template: template
})
.success((data, status, headers, config) ->
$scope.projects.push {
name: name
_id: data.project_id
accessLevel: "owner"
# TODO: Check access level if correct after adding it in
# to the rest of the app
}
$scope.updateVisibleProjects()
deferred.resolve(data.project_id)
)
.error((data, status, headers, config) ->
deferred.reject()
)
return deferred.promise
$scope.openCreateProjectModal = (template = "none") ->
modalInstance = $modal.open(
templateUrl: "newProjectModalTemplate"
controller: "NewProjectModalController"
resolve:
template: () -> template
scope: $scope
)
modalInstance.result.then (project_id) ->
window.location = "/project/#{project_id}"
$scope.renameProject = (project, newName) ->
project.name = newName
$http.post "/project/#{project._id}/rename", {
@ -297,3 +335,25 @@ ProjectPageApp.controller 'RenameProjectModalController', ($scope, $modalInstanc
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
ProjectPageApp.controller 'NewProjectModalController', ($scope, $modalInstance, $timeout, template) ->
$scope.inputs =
projectName: ""
$scope.state =
inflight: false
$modalInstance.opened.then () ->
$timeout () ->
$scope.$broadcast "open"
, 700
$scope.create = () ->
$scope.state.inflight = true
$scope
.createProject($scope.inputs.projectName, template)
.then (project_id) ->
$scope.state.inflight = false
$modalInstance.close(project_id)
$scope.cancel = () ->
$modalInstance.dismiss('cancel')