fix to kb, delete question, ans

This commit is contained in:
Rushabh Mehta
2011-08-30 15:37:46 +05:30
parent 385a3792e1
commit e3393bead9
4 changed files with 37 additions and 10 deletions

View File

@@ -19,12 +19,25 @@ KBItemToolbar = function(args, kb) {
this.line1.innerHTML = repl('By %(name)s | %(when)s', {
name: wn.utils.full_name(this.det.first_name, this.det.last_name),
when: wn.datetime.comment_when(this.det.modified)
})
});
// allow system manager to delete questions / answers
if(has_common(user_roles, ['Administrator', 'System Manager'])) {
this.line1.innerHTML += ' | '
$ln(this.line1, 'delete', me.del);
}
}
this.make_vote = function() {
new KBPoints(this.line2, this.det.points, this.det._users_voted, this.doctype, this.det.name, this.det.owner);
}
this.del = function() {
this.innerHTML = 'deleting...'; this.disabled = 1;
$c_page('knowledge_base', 'questions', 'delete', {dt:me.doctype, dn:me.det.name}, function(r,rt) {
// reload the list
kb.list.run()
});
}
this.make_tags = function() {

View File

@@ -128,7 +128,7 @@ KBAnswerList = function(args) {
as_dict: 1,
no_results_message: 'No answers yet, be the first one to answer!',
render_row: function(body, data) {
new KBAnswer(body, data)
new KBAnswer(body, data, me)
},
get_query: function() {
return repl("SELECT t1.name, t1.owner, t1.answer, t1.points, t1._users_voted, t2.first_name, "
@@ -150,7 +150,7 @@ KBAnswerList = function(args) {
// answer
// by xxx | on xxx
// points yyy
KBAnswer = function(body, data) {
KBAnswer = function(body, data, ans_list) {
body.className = 'qv-answer';
new EditableText({
parent: body,
@@ -169,7 +169,7 @@ KBAnswer = function(body, data) {
det: data,
with_tags: 0,
doctype: 'Answer'
}, null)
}, ans_list)
}

View File

@@ -35,3 +35,11 @@ def vote(arg):
(p, cstr(res[1]) + ',' + webnotes.user.name, args['dn']))
return p
def delete(arg):
"""
delete a question or answer (called from kb toolbar)
"""
args = load_json(arg)
from webnotes.model import delete_doc
delete_doc(args['dt'], args['dn'])