Closes #97: Handle write permission in #/tag and #/tag/id

This commit is contained in:
jendib 2016-05-09 22:09:29 +02:00
parent b1e58396d1
commit 79141edf70
No known key found for this signature in database
GPG Key ID: 06EE7F699579166F
5 changed files with 38 additions and 35 deletions

View File

@ -3,13 +3,16 @@
/** /**
* Tag controller. * Tag controller.
*/ */
angular.module('docs').controller('Tag', function($scope, $dialog, Restangular, $state) { angular.module('docs').controller('Tag', function($scope, Restangular, $state) {
$scope.tag = { name: '', color: '#3a87ad' }; $scope.tag = { name: '', color: '#3a87ad' };
// Retrieve tags // Retrieve tags
Restangular.one('tag/list').get().then(function(data) { $scope.loadTags = function() {
$scope.tags = data.tags; Restangular.one('tag/list').get().then(function(data) {
}); $scope.tags = data.tags;
});
};
$scope.loadTags();
/** /**
* Display a tag. * Display a tag.
@ -27,26 +30,4 @@ angular.module('docs').controller('Tag', function($scope, $dialog, Restangular,
$scope.tag = { name: '', color: '#3a87ad' }; $scope.tag = { name: '', color: '#3a87ad' };
}); });
}; };
/**
* Delete a tag.
*/
$scope.deleteTag = function(tag) {
var title = 'Delete tag';
var msg = 'Do you really want to delete this tag?';
var btns = [
{result: 'cancel', label: 'Cancel'},
{result: 'ok', label: 'OK', cssClass: 'btn-primary'}
];
$dialog.messageBox(title, msg, btns, function(result) {
if (result == 'ok') {
Restangular.one('tag', tag.id).remove().then(function() {
$scope.tags = _.reject($scope.tags, function(t) {
return tag.id == t.id;
});
});
}
});
};
}); });

View File

@ -3,7 +3,7 @@
/** /**
* Tag edit controller. * Tag edit controller.
*/ */
angular.module('docs').controller('TagEdit', function($scope, $stateParams, Restangular) { angular.module('docs').controller('TagEdit', function($scope, $stateParams, Restangular, $dialog, $state) {
// Retrieve the tag // Retrieve the tag
Restangular.one('tag', $stateParams.id).get().then(function(data) { Restangular.one('tag', $stateParams.id).get().then(function(data) {
$scope.tag = data; $scope.tag = data;
@ -23,4 +23,25 @@ angular.module('docs').controller('TagEdit', function($scope, $stateParams, Rest
// Update the server // Update the server
Restangular.one('tag', $scope.tag.id).post('', $scope.tag); Restangular.one('tag', $scope.tag.id).post('', $scope.tag);
}; };
/**
* Delete a tag.
*/
$scope.deleteTag = function(tag) {
var title = 'Delete tag';
var msg = 'Do you really want to delete this tag?';
var btns = [
{result: 'cancel', label: 'Cancel'},
{result: 'ok', label: 'OK', cssClass: 'btn-primary'}
];
$dialog.messageBox(title, msg, btns, function(result) {
if (result == 'ok') {
Restangular.one('tag', tag.id).remove().then(function() {
$scope.loadTags();
$state.go('tag.default');
});
}
});
};
}); });

View File

@ -12,7 +12,7 @@
</div> </div>
<div ng-show="document"> <div ng-show="document">
<div class="text-right" ng-show="document.writable"> <div class="pull-right" ng-show="document.writable">
<div class="btn-group dropdown" dropdown> <div class="btn-group dropdown" dropdown>
<button class="btn btn-default" dropdown-toggle> <button class="btn btn-default" dropdown-toggle>
<span class="glyphicon glyphicon-export"></span> <span class="glyphicon glyphicon-export"></span>

View File

@ -1,6 +1,12 @@
<h1>{{ tag.name }}&nbsp;</h1> <div class="pull-right" ng-show="tag.writable">
<button class="btn btn-danger" ng-click="deleteTag(tag)"><span class="glyphicon glyphicon-trash"></span> Delete</button>
</div>
<div class="well col-lg-8"> <div class="page-header">
<h1>{{ tag.name }}&nbsp;</h1>
</div>
<div class="well col-lg-8" ng-show="tag.writable">
<form class="form-horizontal" name="editTagForm" novalidate> <form class="form-horizontal" name="editTagForm" novalidate>
<div class="form-group" ng-class="{ 'has-error': !editTagForm.name.$valid, success: editTagForm.name.$valid }"> <div class="form-group" ng-class="{ 'has-error': !editTagForm.name.$valid, success: editTagForm.name.$valid }">
<label class="col-sm-2 control-label" for="inputName">Name</label> <label class="col-sm-2 control-label" for="inputName">Name</label>

View File

@ -29,11 +29,6 @@
<span class="glyphicon glyphicon-pencil"></span> <span class="glyphicon glyphicon-pencil"></span>
</a> </a>
</td> </td>
<td class="col-xs-1">
<button class="btn btn-danger pull-right" ng-click="deleteTag(tag)" title="Delete this tag">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>