mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Closes #97: Handle write permission in #/tag and #/tag/id
This commit is contained in:
parent
b1e58396d1
commit
79141edf70
@ -3,13 +3,16 @@
|
||||
/**
|
||||
* 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' };
|
||||
|
||||
// Retrieve tags
|
||||
Restangular.one('tag/list').get().then(function(data) {
|
||||
$scope.tags = data.tags;
|
||||
});
|
||||
$scope.loadTags = function() {
|
||||
Restangular.one('tag/list').get().then(function(data) {
|
||||
$scope.tags = data.tags;
|
||||
});
|
||||
};
|
||||
$scope.loadTags();
|
||||
|
||||
/**
|
||||
* Display a tag.
|
||||
@ -27,26 +30,4 @@ angular.module('docs').controller('Tag', function($scope, $dialog, Restangular,
|
||||
$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;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* 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
|
||||
Restangular.one('tag', $stateParams.id).get().then(function(data) {
|
||||
$scope.tag = data;
|
||||
@ -23,4 +23,25 @@ angular.module('docs').controller('TagEdit', function($scope, $stateParams, Rest
|
||||
// Update the server
|
||||
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');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
@ -12,7 +12,7 @@
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<button class="btn btn-default" dropdown-toggle>
|
||||
<span class="glyphicon glyphicon-export"></span>
|
||||
|
@ -1,6 +1,12 @@
|
||||
<h1>{{ tag.name }} </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 }} </h1>
|
||||
</div>
|
||||
|
||||
<div class="well col-lg-8" ng-show="tag.writable">
|
||||
<form class="form-horizontal" name="editTagForm" novalidate>
|
||||
<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>
|
||||
|
@ -29,11 +29,6 @@
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
</a>
|
||||
</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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user