diff --git a/app/assets/javascripts/controllers/main/mainCreatePostCtrl.js.coffee b/app/assets/javascripts/controllers/main/mainCreatePostCtrl.js.coffee deleted file mode 100644 index 7c9120c..0000000 --- a/app/assets/javascripts/controllers/main/mainCreatePostCtrl.js.coffee +++ /dev/null @@ -1,23 +0,0 @@ -@CreatePostCtrl = ($scope, $location, postData) -> - - $scope.data = postData.data - postData.loadPosts(null) - - $scope.formData = - newPostTitle: '' - newPostContents: '' - - $scope.navNewPost = -> - $location.url('/post/new') - - $scope.navHome = -> - $location.url('/') - - $scope.createPost = -> - postData.createPost($scope.formData) - - $scope.clearPost = -> - $scope.formData.newPostTitle = '' - $scope.formData.newPostContents = '' - -@CreatePostCtrl.$inject = ['$scope', '$location', 'postData'] \ No newline at end of file diff --git a/app/assets/javascripts/controllers/main/mainPostCtrl.js.coffee b/app/assets/javascripts/controllers/main/mainPostCtrl.js.coffee deleted file mode 100644 index ecd03cf..0000000 --- a/app/assets/javascripts/controllers/main/mainPostCtrl.js.coffee +++ /dev/null @@ -1,29 +0,0 @@ -@PostCtrl = ($scope, $routeParams, $location, $q, postData) -> - - $scope.data = - postData: postData.data - currentPost: - title: 'Loading...' - contents: '' - - $scope.data.postId = $routeParams.postId - - $scope.prepPostData = -> - post = _.findWhere(postData.data.posts, { id: parseInt($scope.data.postId) }) - $scope.data.currentPost.title = post.title - $scope.data.currentPost.contents = post.contents - - $scope.navNewPost = -> - $location.url('/post/new') - - $scope.navHome = -> - $location.url('/') - - # Create promise to be resolved after posts load - @deferred = $q.defer() - @deferred.promise.then($scope.prepPostData) - - # Provide deferred promise chain to the loadPosts function - postData.loadPosts(@deferred) - -@PostCtrl.$inject = ['$scope', '$routeParams', '$location', '$q', 'postData'] \ No newline at end of file diff --git a/app/assets/javascripts/services/main/postData.js.coffee b/app/assets/javascripts/services/main/postData.js.coffee deleted file mode 100644 index 9851500..0000000 --- a/app/assets/javascripts/services/main/postData.js.coffee +++ /dev/null @@ -1,52 +0,0 @@ -angular.module('TypingTrainer').factory('postData', ['$http', ($http) -> - - postData = - data: - posts: [{title: 'Loading', contents: ''}] - isLoaded: false - - postData.loadPosts = (deferred) -> - if !postData.isLoaded - $http.get('./posts.json').success( (data) -> - postData.data.posts = data - postData.isLoaded = true - console.log('Successfully loaded posts.') - if deferred - deferred.resolve() - ).error( -> - console.error('Failed to load posts.') - if deferred - deferred.reject('Failed to load posts.') - ) - else - if deferred - deferred.resolve() - - postData.createPost = (newPost) -> - # Client-side data validation - if newPost.newPostTitle == '' or newPost.newPostContents == '' - alert('Neither the Title nor the Body are allowed to be left blank.') - return false - - # Create data object to POST - data = - new_post: - title: newPost.newPostTitle - contents: newPost.newPostContents - - # Do POST request to /posts.json - $http.post('./posts.json', data).success( (data) -> - - # Add new post to array of posts - postData.data.posts.push(data) - console.log('Successfully created post.') - - ).error( -> - console.error('Failed to create new post.') - ) - - return true - - return postData - -]) \ No newline at end of file diff --git a/app/assets/templates/mainCreatePost.html b/app/assets/templates/mainCreatePost.html deleted file mode 100644 index dbdabae..0000000 --- a/app/assets/templates/mainCreatePost.html +++ /dev/null @@ -1,22 +0,0 @@ -
- -{{ data.currentPost.contents }}
-