Skip to content

Commit

Permalink
quick and dirty, added delete feature
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHippo committed Jun 23, 2011
1 parent 45e614a commit dd2cd83
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/controllers/translate.js
Expand Up @@ -139,5 +139,20 @@ module.exports = function (DIALECT_HTTP) {
res.end('you are not authorized to perform that operation');
}
});

app.post("/:locale/delete", authenticate, function (req, res) {
if (app.dynamicViewHelpers.can_approve(req, res)) {
dialect.store.collection.remove(
{_id: ObjectID.createFromHexString(req.param('id'))},
function () {
res.writeHead(200);
res.end('ok');
}
);
} else {
res.writeHead(403);
res.end('you are not authorized to perform that operation');
}
});

};
2 changes: 1 addition & 1 deletion lib/public/css/global.css
Expand Up @@ -152,7 +152,7 @@ form {
float:left;
border: 1px solid #bbb;
width: 938px;
height: 94px;
height: 110px;
-moz-box-shadow: inset 1px 1px 0px #fff;
-webkit-box-shadow:inset 1px 1px 0px #fff;
box-shadow: inset 1px 1px 0px #fff;
Expand Down
54 changes: 54 additions & 0 deletions lib/public/js/global.js
Expand Up @@ -105,6 +105,53 @@ $(function () {
updateBars($text_bar, total, ok, pending, missing);
updateLastStatus($textarea);
};

deleteTranslation = function ($textarea, approve) {
var $form = $textarea.parent(),
$text_bar = $('h1.bars'),
parts = $text_bar.text().match(/[0-9]+/g),
ok, pending, missing, total;

total = parts[0];
ok = parts[1];
pending = parts[2];
missing = parts[3];

$.ajax({
type: 'POST',
url: '/' + current_locale + '/delete/',
data: {
id: $textarea.prevAll('input').val()
},
success: function () {
$textarea.busy('hide');
$form.remove();
},
dataType: 'text'
});

$textarea.busy({title: 'saving...'});

total--;
classes = $form.attr('class').split(' ');
for (var i = 0; i<classes.length; i++) {
if (classes[i] == "ok") {
ok--;
break;
}
if (classes[i] == "pending") {
pending--;
break;
}
if (classes[i] == "missing") {
missing--;
break;
}
}

updateBars($text_bar, total, ok, pending, missing);
updateLastStatus($textarea);
};

$('textarea.translation')
.each(function () {
Expand Down Expand Up @@ -177,4 +224,11 @@ $(function () {
approve($textarea, false);
return false;
});

$("a.delete").click(function() {
var $textarea = getTextarea($(this));
deleteTranslation($textarea, false);
return false;

});
});
2 changes: 2 additions & 0 deletions lib/views/locale.jade
Expand Up @@ -47,6 +47,8 @@ input(type= 'hidden', name= 'base_locale', value= dialect.config('base_locale'),
span reject
a.approve(href= '#')
span approve
a.delete(href="#")
span delete
.meta
-if (translation.context)
span.context
Expand Down

0 comments on commit dd2cd83

Please sign in to comment.