Skip to content

Commit 7c9d276

Browse files
committed
bind delete button
1 parent e5b265e commit 7c9d276

6 files changed

Lines changed: 27 additions & 140 deletions

File tree

src/services/snippet.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ angular.module('codexen.services')
2222
return $http.get(url)
2323
}
2424

25+
var destroy = function (id) {
26+
var url = apiUrl + 'snippets/id/' + id
27+
28+
return $http.delete(url)
29+
}
30+
2531
return {
2632
findByUser: findByUser,
2733
create: create,
28-
show: show
34+
show: show,
35+
delete: destroy
2936
}
3037
})

src/states/snippets/detail.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
/* global angular */
22
angular.module('codexen.states')
3-
.controller('SnippetsDetailController', function (Snippet, $state) {
3+
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope) {
44
var vm = this
55

66
vm.isLoaded = false
77

88
var snippetId = $state.params.id
99

1010
Snippet.show(snippetId)
11-
.success(function (data) {
12-
vm.snippet = data.snippet
13-
vm.isLoaded = true
11+
.success(function (data) {
12+
vm.snippet = data.snippet
13+
vm.isLoaded = true
14+
})
15+
16+
vm.delete = function () {
17+
Snippet.delete(vm.snippet._id)
18+
.success(function () {
19+
$rootScope.$broadcast('snippetDeleted')
20+
$state.go('snippets')
1421
})
22+
}
1523
})

src/states/snippets/detail.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<span class="detail-header-control pull-right">
88
<button type="button" name="button" class="btn btn-default"><i class="fa fa-share"></i></button>
99
<button type="button" name="button" class="btn btn-default"><i class="fa fa-edit"></i></button>
10-
<button type="button" name="button" class="btn btn-danger"><i class="fa fa-trash"></i></button>
10+
<button ng-click="vm.delete()" type="button" name="button" class="btn btn-danger"><i class="fa fa-trash"></i></button>
1111
</span>
1212
</div>
1313

@@ -18,7 +18,7 @@
1818
</div>
1919

2020
<div ng-if="vm.isLoaded" class="">
21-
<p class="tags">
21+
<p class="tags" ng-if="vm.snippet.tags">
2222
<small><i class="fa fa-tags"></i></small> <a ng-repeat="tag in vm.snippet.tags" ng-bind="tag.name" href="#" class="label label-default"></a>
2323
</p>
2424
<label>Description</label>

src/states/snippets/list.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ angular.module('codexen.states')
3737
laodSnippets()
3838
})
3939

40+
$scope.$on('snippetDeleted', function () {
41+
laodSnippets()
42+
})
43+
4044
})

src/states/snippets/list.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h4 ng-bind="snippet.title"></h4>
3434
</div>
3535
</div>
3636
<p ng-bind="snippet.description"></p>
37-
<p class="tags">
37+
<p class="tags" ng-if="snippet.tags.length">
3838
<small><i class="fa fa-tags"></i></small> <a ng-repeat="tag in snippet.tags" ng-bind="tag.name" href="#" class="label label-default"></a>
3939
</p>
4040
</li>

test.js

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)