点赞功能

chenlw_dev
txz 9 years ago
parent f1783c06a2
commit eb996280a6

@ -10,7 +10,7 @@ app.factory('auth', function($http,$routeParams, $cookies, $q){
var _openid = ''; var _openid = '';
if(debug===true){ if(debug===true){
_openid = "1"; _openid = "2";
} }
var getOpenId = function() { var getOpenId = function() {
@ -61,7 +61,7 @@ app.factory('rms', function(){
return {save: save, get: get}; return {save: save, get: get};
}); });
app.controller('ActivityController',function($scope, $http, auth, rms){ app.controller('ActivityController',function($scope, $http, auth, rms, common){
$scope.replaceUrl = function(url){ $scope.replaceUrl = function(url){
return "http://www.trustie.net/" + url; return "http://www.trustie.net/" + url;
}; };
@ -90,23 +90,22 @@ app.controller('ActivityController',function($scope, $http, auth, rms){
} }
); );
$scope.addPraise = function(act){
act.activity_praise_count += 1;
act.has_praise = true;
//$http $scope.loadActData = loadActData;
}; $scope.addPraise = function(act){
$scope.decreasePraise = function(act){ console.log(act);
act.activity_praise_count -= 1; common.addCommonPraise(act,'activities');
act.has_praise = false; }
};
$scope.loadActData = loadActData; $scope.decreasePraise = function(act){
console.log(act);
common.decreaseCommonPraise(act,'activities');
}
}); });
app.factory('common', function($http, auth){ app.factory('common', function($http, auth, $routeParams){
var addCommonReply = function(id, type, data, cb){ var addCommonReply = function(id, type, data, cb){
console.log(data.comment); console.log(data.comment);
@ -140,7 +139,36 @@ app.factory('common', function($http, auth){
}) })
}; };
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData}; var addCommonPraise = function(act, type){
act.activity_praise_count += 1;
act.has_praise = true;
$http({
method: 'POST',
url: apiUrl,
data:{openid:auth.openid(),type:type,id:$routeParams.id}
}).then(function successCallback(response) {
console.log("点赞成功");
}, function errorCallback(response) {
});
};
var decreaseCommonPraise = function(act, type){
act.activity_praise_count -= 1;
act.has_praise = false;
$http({
method: 'POST',
url: apiUrl ,
data:{openid:auth.openid(),type:type,id:$routeParams.id}
}).then(function successCallback(response) {
console.log("取消赞成功");
}, function errorCallback(response) {
});
};
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
}); });
app.controller('IssueController', function($scope, $http, $routeParams, auth, common){ app.controller('IssueController', function($scope, $http, $routeParams, auth, common){

Loading…
Cancel
Save