mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-22 06:01:53 +00:00
Added delete button to the edit page
This commit is contained in:
@@ -25,11 +25,9 @@ var HomebrewAdmin = React.createClass({
|
||||
},
|
||||
|
||||
deleteBrew : function(brewId){
|
||||
console.log('removing');
|
||||
request.get('/homebrew/remove/' + brewId +'?admin_key=' + this.props.admin_key)
|
||||
.send()
|
||||
.end(function(err, res){
|
||||
console.log('DONE');
|
||||
window.location.reload();
|
||||
})
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ var React = require('react');
|
||||
var _ = require('lodash');
|
||||
var cx = require('classnames');
|
||||
var Moment = require('moment');
|
||||
var request = require('superagent')
|
||||
|
||||
var Logo = require('naturalCrit/logo/logo.jsx');
|
||||
|
||||
@@ -13,7 +14,7 @@ var Statusbar = React.createClass({
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
//editId: null,
|
||||
editId: null,
|
||||
sourceText : null,
|
||||
shareId : null,
|
||||
printId : null,
|
||||
@@ -38,14 +39,22 @@ var Statusbar = React.createClass({
|
||||
},
|
||||
|
||||
|
||||
deleteBrew : function(){
|
||||
if(!confirm("are you sure you want to delete this brew?")) return;
|
||||
if(!confirm("are you REALLY sure? You will not be able to recover it")) return;
|
||||
|
||||
request.get('/homebrew/remove/' + this.props.editId)
|
||||
.send()
|
||||
.end(function(err, res){
|
||||
window.location.href = '/homebrew';
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
openSourceWindow : function(){
|
||||
var sourceWindow = window.open();
|
||||
|
||||
var content = replaceAll(this.props.sourceText, '<', '<');
|
||||
content = replaceAll(content, '>', '>');
|
||||
|
||||
console.log(content);
|
||||
|
||||
sourceWindow.document.write('<code><pre>' + content + '</pre></code>');
|
||||
},
|
||||
|
||||
@@ -97,6 +106,15 @@ var Statusbar = React.createClass({
|
||||
</a>
|
||||
},
|
||||
|
||||
renderDeleteButton : function(){
|
||||
if(!this.props.editId) return null;
|
||||
|
||||
|
||||
return <div className='deleteButton' onClick={this.deleteBrew}>
|
||||
Delete <i className='fa fa-trash' />
|
||||
</div>
|
||||
},
|
||||
|
||||
renderStatus : function(){
|
||||
if(!this.props.editId) return null;
|
||||
|
||||
@@ -123,6 +141,7 @@ var Statusbar = React.createClass({
|
||||
{this.renderStatus()}
|
||||
{this.renderInfo()}
|
||||
{this.renderSourceButton()}
|
||||
{this.renderDeleteButton()}
|
||||
{this.renderPrintButton()}
|
||||
{this.renderShare()}
|
||||
{this.renderNewButton()}
|
||||
|
||||
@@ -58,6 +58,15 @@
|
||||
background-color : fade(@green, 70%);
|
||||
}
|
||||
}
|
||||
.deleteButton{
|
||||
.animate(background-color);
|
||||
color : white;
|
||||
text-decoration : none;
|
||||
cursor: pointer;
|
||||
&:hover{
|
||||
background-color : fade(@red, 70%);
|
||||
}
|
||||
}
|
||||
.shareField{
|
||||
.animate(background-color);
|
||||
cursor : pointer;
|
||||
|
||||
@@ -43,7 +43,7 @@ module.exports = function(app){
|
||||
});
|
||||
|
||||
app.get('/homebrew/remove/:id', function(req, res){
|
||||
if(req.query && req.query.admin_key == process.env.ADMIN_KEY){
|
||||
//if(req.query && req.query.admin_key == process.env.ADMIN_KEY){
|
||||
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
||||
console.log(err);
|
||||
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
|
||||
@@ -53,9 +53,9 @@ module.exports = function(app){
|
||||
return res.status(200).send();
|
||||
})
|
||||
});
|
||||
}else{
|
||||
return res.status(401).send('Access denied');
|
||||
}
|
||||
//}else{
|
||||
// return res.status(401).send('Access denied');
|
||||
//}
|
||||
});
|
||||
|
||||
app.get('/homebrew/clear', function(req, res){
|
||||
|
||||
Reference in New Issue
Block a user