From 2be4c08b220a68b42c871bf172fded931e7213b7 Mon Sep 17 00:00:00 2001
From: nau
Date: Mon, 5 Sep 2016 20:27:36 +0200
Subject: [PATCH] travel comments system added
---
www/js/controllers.js | 47 ++++++++++++++++++++++++++++++++++++++-
www/templates/travel.html | 25 ++++++++++++++++++++-
2 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/www/js/controllers.js b/www/js/controllers.js
index bd1f4bd..5c15cb8 100644
--- a/www/js/controllers.js
+++ b/www/js/controllers.js
@@ -314,7 +314,7 @@ angular.module('starter.controllers', [])
};
})
-.controller('TravelCtrl', function($scope, $stateParams, $http) {
+.controller('TravelCtrl', function($scope, $stateParams, $http, $ionicModal) {
if(localStorage.getItem('c_token')){// adding token to the headers
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token');
}
@@ -345,6 +345,17 @@ angular.module('starter.controllers', [])
.then(function(result){
joins = result.data;
});
+ $http.get(urlapi + 'travels/comment/'+$stateParams.travelId)
+ .success(function(data, status, headers,config){
+ console.log(data); // for browser console
+ $scope.comments = data; // for UI
+ })
+ .error(function(data, status, headers,config){
+ console.log('data error');
+ })
+ .then(function(result){
+ comments = result.data;
+ });
$scope.deleteTravel = function(){
console.log("delete travel: " + $stateParams.travelId);
@@ -380,6 +391,40 @@ angular.module('starter.controllers', [])
// failed
});
};
+
+ /* adding comment */
+ $scope.doingNewComment=false;
+ $scope.newComment={};
+
+ $scope.showNewComment = function() {
+ $scope.doingNewComment=true;
+ };
+ $scope.closeNewComment = function() {
+ $scope.doingNewComment=false;
+ };
+ $scope.doNewComment = function() {
+ $scope.newComment.commentUserId=localStorage.getItem("c_userid");
+ $scope.newComment.commentUsername=localStorage.getItem("c_username");
+console.log($scope.newComment);
+ $http({
+ url: urlapi + 'travels/comment/' + $stateParams.travelId,
+ method: "POST",
+ data: $scope.newComment
+ })
+ .then(function(response) {
+ // success
+ console.log("newComment added to server: " + response);
+ console.log(response);
+ if(response.data.success==false){
+
+ $ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 });
+ }
+ },
+ function(response) { // optional
+ // failed
+ });
+ $scope.closeNewComment();
+ };
})
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) {
diff --git a/www/templates/travel.html b/www/templates/travel.html
index 56c371d..11b5389 100644
--- a/www/templates/travel.html
+++ b/www/templates/travel.html
@@ -43,11 +43,34 @@
-