Permalink
Browse files

Implemented an undo for delete and refactored the success functions i…

…n the

controller so that they are all the same.
  • Loading branch information...
1 parent b313725 commit 55b1c176542a09788f963efbbf6e9ab0d5df3d34 @KayEss committed Mar 16, 2012
Showing with 24 additions and 12 deletions.
  1. +3 −0 usr/share/beanbag/wiki/media/page.html
  2. +21 −12 usr/share/beanbag/wiki/media/wiki.js
@@ -23,6 +23,9 @@ <h1 ng:switch-default ng:cloak>{{page.title}}</h1>
<li ng:click="tab='edit'" ng:class="'edit-'+tab">Edit</li>
<li ng:click="tab='delete'" ng:class="'delete-'+tab"
ng:show='meta.version' ng:cloak>Delete</li>
+ <li ng:click="undelete()" ng:class="'undelete='+tab"
+ ng:show='deleted &amp;&amp; !page.content &amp;&amp; !page.title'
+ ng:cloak>Undo delete</li>
</ul>
<hr />
<div class="content">
@@ -10,27 +10,27 @@ RouteWatcher.$inject = ['$route', '$location'];
function WikiController($location, $http) {
var self = this;
- this.meta = {}
- this.page = {}
+ this.meta = {};
+ this.page = {};
+ this.deleted = null;
+ this.success = function(data, status, headers, config) {
+ self.tab = 'show';
+ self.deleted = null;
+ self.page = data;
+ self.meta.version = headers()["etag"];
+ }
this.loadpage = function() {
$http.get($location.path()).
- success(function(data, status, headers, config) {
- self.tab = 'show';
- self.page = data;
- self.meta.version = headers()["etag"];
- }).
+ success(self.success).
error(function(data, status, headers, config) {
console.log("error", data, status, headers, config);
});
}
this.loadpage();
this.savepage = function() {
- $http.put($location.path(), this.page,
+ $http.put($location.path(), self.page,
{headers:{'If-Match': self.meta.version}}).
- success(function(data, status, headers, config) {
- self.tab = 'show';
- self.meta.version = headers()["etag"];
- }).
+ success(self.success).
error(function(data, status, headers, config) {
console.log("error", data, status, headers, config);
});
@@ -40,13 +40,22 @@ function WikiController($location, $http) {
{headers:{'If-Match': self.meta.version}}).
error(function(data, status, headers, config) {
if ( status == 410 ) {
+ self.deleted = self.page;
self.page = {};
self.tab = 'edit';
self.meta.version = null;
} else
console.log("error", data, status, headers, config);
});
}
+ this.undelete = function() {
+ $http.put($location.path(), self.deleted,
+ {headers:{'If-Not-Match': '*'}}).
+ success(self.success).
+ error(function(data, status, headers, config) {
+ console.log("error", data, status, headers, config);
+ });
+ }
self.tab = 'edit';
}
WikiController.$inject = ['$location', '$http'];

0 comments on commit 55b1c17

Please sign in to comment.