ForumDirCtrl.js
2.02 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
angular.module('ForumDirCtrl', ['SessionsServ', 'ApiServ'])
.controller('ForumDirCtrl', function ($scope, $routeParams, SessionServ, ApiServ) {
$scope.convs = [];
$scope.dosss = [];
$scope.formDoss = {};
$scope.formConv = {};
$scope.session = SessionServ.cur;
SessionServ.onChange(function () {
$scope.session = SessionServ.cur;
});
ApiServ("récupération du dossier", 'get', 'dosss', $routeParams.doss_id, function (err, doss) {
if (err) {
console.error(err);
} else {
if (doss) {
$scope.dosss = doss.dosss;
$scope.convs = doss.convs;
}
}
});
// Dossiers
$scope.createDoss = function () {
$scope.formDoss.parent = $routeParams.doss_id;
ApiServ("création du dossier", 'post', 'dosss', $scope.formDoss, function (err, doss) {
if (!err) {
$scope.formDoss = {};
$scope.dosss.push(doss);
}
});
};
$scope.deleteDoss = function (index) {
ApiServ("suppression du dossier", 'delete', 'dosss', $scope.dosss[index]._id, function (err) {
if (!err)
$scope.dosss.splice(index, 1);
});
};
// Conversations
$scope.createConv = function () {
$scope.formConv.parent = $routeParams.doss_id;
ApiServ("création de la conversation", 'post', 'convs', $scope.formConv, function (err, conv) {
if (!err) {
$scope.formConv = {};
$scope.convs.push(conv);
}
});
};
$scope.deleteConv = function (index) {
ApiServ("suppression de la conversation", 'delete', 'convs', $scope.convs[index]._id, function (err) {
if (!err)
$scope.convs.splice(index, 1);
});
};
});