limitless.directive('commentsList', ['Zupit.Core.AppService', 'config', 'Zupit.Core.HttpClient', 'Zupit.Core.NotificationService', function (app,config, $http, $notifier) { return { scope: { get: '=', create: '=', remove: '=', item: '=', admin:'=' }, replace: true, templateUrl: config.baseUrl + 'app/components/commentsList.html', controller: function ($scope) { function load() { $scope.message = ''; $http.get($scope.get + $scope.item).then(function(ret) { if (ret.succeded) $scope.comments = ret.data; }); } $scope.userid = app.user.name; load(); $scope.add = function () { if ($scope.message.length === 0) { $notifier.warning('YOU_NEED_TO_INSERT_COMMENT_MESSAGE'); return; } app.Loading.show(); $http.post($scope.create + $scope.item, { message:$scope.message }).then(function (ret) { app.Loading.hide(); if (ret.succeded) { $notifier.success('COMMENT_ADD_SUCCEDED', 'COMMENT_ADD_SUCCEDEDS_TITLE'); load(); } else $notifier.error('COMMENT_ADD_FAIL', 'COMMENT_ADD_FAIL_TITLE'); }); } $scope.delete = function (commentId) { $notifier.confirm('DELETE_COMMENT_MESSAGE', 'DELETE_COMMENT_TITLE').then(function (ok) { app.Loading.show(); $http.delete($scope.remove + commentId).then(function (ret) { if (ret.succeded) { app.Loading.hide(); $notifier.success('COMMENT_DELETE_SUCCEDED', 'COMMENT_DELETE_SUCCEDEDS_TITLE'); load(); } else $notifier.error('COMMENT_DELETE_FAIL', 'COMMENT_DELETE_FAIL_TITLE'); }); }); } } } } ]);