ForumConvCtrl.js
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
angular.module('ForumConvCtrl', ['SessionsServ', 'ApiServ']).controller('ForumConvCtrl', ['$scope', '$routeParams', 'SessionServ', 'ApiServ',
function ($scope, $routeParams, SessionServ, ApiServ) {
$scope.messs = [];
$scope.conv = {};
$scope.formData = {};
$scope.session = SessionServ.cur;
SessionServ.onChange(function () {
$scope.session = SessionServ.cur;
});
ApiServ("récupération de la conversation", 'get', 'convs', $routeParams.conv_id, function (err, conv) {
if (!err) {
$scope.conv = conv;
ApiServ("récupération des messages", 'get', 'messs', conv._id, function (err, messs) {
if (!err)
$scope.messs = messs;
});
}
});
$scope.createMess = function () {
data = $scope.formData;
data.conv = $scope.conv._id;
ApiServ("envoi du message", 'post', 'messs', data, function (err, mess) {
if (!err)
$scope.formData = {};
$scope.messs.push(mess);
});
};
$scope.deleteMess = function (index) {
ApiServ("suppression du message", 'delete', 'messs', $scope.messs[index]._id, function (err) {
if (!err)
$scope.messs.splice(index, 1);
});
};
}
]);