Skip to content

Commit

Permalink
add a RAZ button
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jun 4, 2012
1 parent 7ecd2c7 commit 8a40865
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -41,6 +41,7 @@
<section id="public_storage">
<h2 id="publicTitle">Read access for "public" category</h2>
<p>
<input type="submit" id="eraseData" value="RAZ" />
<label for="publicKey">Key:</label>
<!--<input type="text" id="publicKey" value="foo" />-->
<input type="submit" id="fetchText" value="Fetch" />
Expand Down
25 changes: 25 additions & 0 deletions src/app.js
Expand Up @@ -51,6 +51,31 @@
return false;
});

$('#eraseData').on('click', function() {

//helper.showSpinner('fetchPublicSpinner');

storage.getData('unpapered', 'index', function(error, data) {
if(error)
console.log(error)
else {
var index = JSON.parse(data)
for(var i=0; i<index.length; i++) {
storage.deleteData('unpapered', index[i], function(error) {
if(error)
console.log("couldn't delete element for key="+index[i])
})
}
storage.deleteData('unpapered', 'index', function(error) {
if(error)
console.log("couldn't delete the index")
})
}
})

return false;
});

/*$('#publishPublic').on('click', function() {
var key = $('#publicKey').val();
var value = $('#publicValue').val();
Expand Down
19 changes: 19 additions & 0 deletions src/wrapper.js
Expand Up @@ -104,6 +104,24 @@ var wrapper = (function() {
});
}

function deleteData(category, key, callback) {
var storageInfo = JSON.parse(localStorage.getItem('userStorageInfo'));
var token = localStorage.getItem('bearerToken');
var client = remoteStorage.createClient(storageInfo, category, token);

client.delete(key, function(error) {
if (error) {
alert('Could not store "' + key + '" in "' + category + '" category');
console.log(error);
} else {
console.log('Stored "' + value + '" for key "' + key + '" in "' + category + '" category');
}

callback(error);
});
}


// Now all that's left is to bind the events from the UI elements to
// these actions, as can be seen [here](app.html).

Expand All @@ -112,6 +130,7 @@ var wrapper = (function() {
authorize: authorize,
getData: getData,
putData: putData,
deleteData: deleteData,
};

})();

0 comments on commit 8a40865

Please sign in to comment.