Skip to content

Commit

Permalink
fixed sorting answers, added delete answer
Browse files Browse the repository at this point in the history
  • Loading branch information
ilshad committed May 6, 2010
1 parent ec10dbb commit 7c5a2db
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/bbru/answers/browser/answer/actions.zcml
Expand Up @@ -18,7 +18,7 @@
<contextMenuItem
name="thanks"
view=".display.View"
title="Этот ответ решает мою задачу"
title="Этот решает мою задачу"
permission="bbru.answers.EditQuestion"
weight="1"
/>
Expand All @@ -32,10 +32,10 @@
/>

<contextMenuItem
name="delete"
name="delete-answer"
view=".display.View"
title="Удалить"
permission="bbru.answers.Manage"
permission="bbru.answers.EditAnswer"
weight="3"
/>

Expand Down
8 changes: 8 additions & 0 deletions src/bbru/answers/browser/answer/configure.zcml
Expand Up @@ -44,6 +44,14 @@
template="edit.pt"
/>

<!-- удалить ответ -->
<browser:page
for="...interfaces.IQuestionAnswer"
name="delete"
class=".delete.Ajax"
permission="bbru.answers.EditAnswer"
/>

<include file="actions.zcml" />

</configure>
19 changes: 19 additions & 0 deletions src/bbru/answers/browser/answer/delete.py
@@ -0,0 +1,19 @@
# coding: utf-8
# This code was developed for http://bluebream.ru by its community and
# placed under Public Domain.

""" Удалить ответ.
"""

from z3c.form import form, button

class Ajax(form.Form):

@button.buttonAndHandler(u"Удалить", name="delete")
def handleDelete(self, action):
name = self.context.__name__
parent = self.context.__parent__
del parent[name]

@button.buttonAndHandler(u"Отмена", name="cancel")
def handleCancel(*args): pass
16 changes: 9 additions & 7 deletions src/bbru/answers/browser/answer/listing.py
Expand Up @@ -7,14 +7,16 @@
"""

from zope.interface import Interface
from zope.component import getUtility, getMultiAdapter
from zope.component import getMultiAdapter
from zope.dublincore.interfaces import IZopeDublinCore

class Ajax:

def __call__(self):
answers = []
for name, ob in self.context.items():
view = getMultiAdapter((ob, self.request), Interface, "display")
answers.append(view)
answers.sort(key=lambda x:int(x.context.__name__))
return u''.join(x() for x in answers)
answers = [x for x in self.context.values()]
answers.sort(key=lambda x:IZopeDublinCore(x).created)

views = [getMultiAdapter((x, self.request), Interface, "display")
for x in answers]

return u''.join(x() for x in views)
30 changes: 30 additions & 0 deletions src/bbru/answers/browser/javascript/answers.js
Expand Up @@ -119,6 +119,31 @@ function load_edit_answer_form(anchor, params) {

}

function load_delete_answer_form(anchor) {
var place = $(anchor).parents('.answer-wrapper');
var context_url = $('div.context_url', place).text();
var question_url = $('.question .metadata .context_url').text();

$.post(context_url + "/@@delete", {}, function(data) {

var container = $('<div></div>');
container.append(data);
place.after(container);

$('#form-buttons-delete', container).click(function() {
$.post(context_url + "/@@delete", get_form_params(this), function () {
load_answers_listing(question_url);
});
return false;
});

$('#form-buttons-cancel', container).click(function() {
container.remove();
return false;
});
});
}

function question_init (context_url) {
load_answers_listing(context_url);

Expand All @@ -143,4 +168,9 @@ function answer_init () {
load_edit_answer_form(this, {});
return false;
});

$('.delete-answer').click(function() {
load_delete_answer_form(this);
return false;
});
}
6 changes: 1 addition & 5 deletions src/bbru/answers/configure.zcml
Expand Up @@ -46,13 +46,9 @@
interface="zope.container.interfaces.IReadContainer"
/>
<require
attributes="__setitem__"
attributes="__setitem__ __delitem__"
permission="bbru.answers.Answer"
/>
<require
attributes="__delitem__"
permission="bbru.answers.Manage"
/>
</class>

<!-- Ответ -->
Expand Down
4 changes: 4 additions & 0 deletions src/bbru/answers/security.zcml
Expand Up @@ -56,6 +56,10 @@
permission="bbru.answers.EditQuestion"
role="bbru.answers.Moderator"
/>
<grant
permission="bbru.answers.EditAnswer"
role="bbru.answers.Moderator"
/>
<grant
permission="bbru.answers.Manage"
role="bbru.answers.Moderator"
Expand Down

0 comments on commit 7c5a2db

Please sign in to comment.