Commit ba3a9e899209b2e2b9ad8693a0fce045376be27d

Authored by Geoffrey PREUD'HOMME
1 parent 66e43291

Ajout de l'édition des messages

app/routes/ApiRtes.js
... ... @@ -96,7 +96,7 @@ sessionData = function (session, cb) {
96 96 session.canAddConv = true;
97 97 session.canDelConv = session.bureau;
98 98 session.canAddMess = true;
99   - session.canEditMess = false;
  99 + session.canEditMess = session.bureau;
100 100 session.canDelMess = session.bureau;
101 101 cb(session);
102 102 });
... ... @@ -301,6 +301,21 @@ api.post('/messs', reqPerm('canAddMess'), function (req, res) { // Ajout d'un me
301 301 });
302 302 });
303 303  
  304 +api.put('/messs', reqPerm('canEditMess'), function (req, res) { // Édition d'un message
  305 + MessServ.edit(req.body, function (err, mess) {
  306 + console.log('CALLED', err, mess);
  307 + if (err) {
  308 + if (err == 'notfound') {
  309 + res.status(404).end();
  310 + } else {
  311 + res.status(500).json(err);
  312 + }
  313 + } else {
  314 + res.status(201).json(mess);
  315 + }
  316 + });
  317 +});
  318 +
304 319 api.delete('/messs/:mess_id', reqPerm('canDelMess'), function (req, res) { // Supression d'un mess
305 320 MessServ.remove(req.params.mess_id, function (err, mess) {
306 321 if (err)
... ...
app/services/MessServ.js
... ... @@ -56,6 +56,22 @@ MesssServ.add = function (data, cb) {
56 56 });
57 57 };
58 58  
  59 +MesssServ.edit = function (data, cb) {
  60 + MessModl.findById(data._id, function (err, mess) {
  61 + if (err) {
  62 + cb(err);
  63 + } else {
  64 + if (mess) {
  65 + mess.content = data.content;
  66 + // TODO Edit date
  67 + mess.save(cb);
  68 + } else {
  69 + cb('notfound');
  70 + }
  71 + }
  72 + });
  73 +};
  74 +
59 75 MesssServ.remove = function (id, cb) {
60 76 // TODO Trash
61 77 MessModl.remove({
... ...
public/js/controllers/ForumConvCtrl.js
... ... @@ -42,12 +42,19 @@ angular.module('ForumConvCtrl', ['SessionsServ', 'ApiServ', 'MessEditDrct'])
42 42 $scope.editButton = function (index) {
43 43 mess = $scope.messs[index];
44 44 if (mess.editMode) {
45   - mess.viewSource = false;
46   - console.log('Submit edition');
  45 + ApiServ("édition du message", 'put', 'messs', mess, function (err, data) {
  46 + if (!err) {
  47 + console.log(data);
  48 + mess.content = data.content;
  49 + mess.editDate = data.editDate;
  50 + mess.editMode = false;
  51 + mess.viewSource = false;
  52 + }
  53 + });
47 54 } else {
  55 + mess.editMode = true;
48 56 mess.viewSource = true;
49 57 }
50   - mess.editMode = !mess.editMode;
51 58 };
52 59  
53 60 });
... ...
public/views/messEdit.html
1 1 <div btf-markdown="mess.content" ng-show="!mess.viewSource"></div>
2   -<code ng-show="mess.viewSource && !mess.editMode">{{ mess.content }}</code>
  2 +<pre ng-show="mess.viewSource && !mess.editMode">{{ mess.content }}</pre>
3 3 <textarea class="form-control" id="nvMessTitre" rows="7" placeholder="Contenu du message" ng-model="mess.content" ng-show="mess.viewSource && mess.editMode"></textarea>
4 4 \ No newline at end of file
... ...