ForumConvCtrl.js
2.27 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
angular.module('ForumConvCtrl', ['SessionsServ', 'ApiServ', 'MessEditDrct'])
.controller('ForumConvCtrl', 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], null, function (err, conv) {
if (!err) {
$scope.conv = conv;
ApiServ("récupération des messages", 'get', ['messs', conv._id], null, function (err, messs) {
if (!err) {
$scope.messs = messs;
}
});
}
});
$scope.addMess = function () {
data = {
content: $scope.mess.content,
conv: $scope.conv._id
};
ApiServ("envoi du message", 'post', 'messs', data, function (err, mess) {
if (!err) {
$scope.formData = {};
$scope.messs.push(mess);
}
});
};
$scope.delMess = function (index) {
ApiServ("suppression du message", 'delete', ['messs', $scope.messs[index]._id], null, function (err) {
if (!err)
$scope.messs.splice(index, 1);
});
};
$scope.editButton = function (index) {
mess = $scope.messs[index];
if (mess.editMode) {
ApiServ("édition du message", 'put', ['messs', mess._id], {
content: mess.content
}, function (err, data) {
if (!err) {
mess.content = data.content;
mess.editDate = data.editDate;
mess.editMode = false;
mess.viewSource = false;
}
});
} else {
mess.editMode = true;
mess.viewSource = true;
}
};
$scope.mine = function (mess) {
return $scope.session.bureau || mess.login == $scope.session.login;
};
});