travel comments system added
nau idoctnef@openmailbox.org
Mon, 05 Sep 2016 20:27:36 +0200
2 files changed,
70 insertions(+),
2 deletions(-)
M
www/js/controllers.js
→
www/js/controllers.js
@@ -314,7 +314,7 @@ }, 1000);
}; }) -.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 @@ })
.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);@@ -379,6 +390,40 @@ },
function(response) { // optional // 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(); }; })
M
www/templates/travel.html
→
www/templates/travel.html
@@ -43,11 +43,34 @@ <a href="#" ng-click="deleteTravel()" class="button button-assertive o-pull-right">Delete</a>
</p> </div> </div> - <div class="item item-body"> + <div class="item item-body" ng-show="joins[0]"> Joined users:<br> <a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark"> {{join.joinedUsername}}<br> </a> + </div> + <div class="item item-body"> + <div ng-show="comments[0]"> + Comments:<br> + <a ng-repeat="comment in comments" ng-href="#/app/users/{{comment.commentUsername}}" class="item"> + <h3>{{comment.commentUsername}}</h3> + <p>{{comment.comment}}</p> + </a> + </div> + <a ng-click="showNewComment()" ng-show="!doingNewComment" class="button button-calm right">New comment</a> + <form class="list" ng-show="doingNewComment"> + <label class="item item-input item-floating-label"> + <span class="input-label">Comment</span> + <input ng-model="newComment.comment" type="text" placeholder="Comment"> + </label> + + <button ng-click="closeNewComment()" class="button button-assertive"> + Cancel + </button> + <button ng-click="doNewComment()" class="button button-calm"> + Post comment + </button> + </form> </div> </ion-content> </ion-view>