prepare for multiactions

This commit is contained in:
Frédéric Péters 2018-07-11 21:38:56 +02:00
parent 605f354a6d
commit 4d9b566aa5
4 changed files with 137 additions and 11 deletions

View File

@ -65,6 +65,12 @@
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/>
<browser:page
name="multiactions"
class=".multiactions.MultiActionsView"
permission="zope2.View"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/>
<!--
<browser:page

View File

@ -0,0 +1,18 @@
from Products.Five.browser import BrowserView
from plone import api
class MultiActionsView(BrowserView):
def __call__(self):
action = self.request.form['action'] # ex: process_without_comment
documents = self.request.form['documents[]']
if isinstance(documents, basestring):
documents = [documents]
for document_id in documents:
document = api.content.get(document_id)
api.content.transition(document, action)
document.reindexObject(idxs=['review_state'])
if action == 'to_process':
from pfwbged.policy.subscribers.mail import incoming_mail_attributed
incoming_mail_attributed(document, u'')
return 'OK'

View File

@ -1,5 +1,5 @@
(function ($) {
$.querywidget.updateSearch = function () {
$.querywidget.updateSearch = function (stay_on_page) {
var context_url = (function() {
var baseUrl, pieces;
baseUrl = $('base').attr('href');
@ -83,6 +83,9 @@
{},
function (data) { results.html(data); });
});
/*if (stay_on_page) {
querylist.push($('a.batch-link.current').data('query'));
}*/
query += querylist.join('&');
query += '&sort_on=' + $('#sort_on').val();
if ($('#sort_order:checked').length > 0) {
@ -116,6 +119,7 @@
$.querywidget.updateExtraColumnsMenu();
$.querywidget.updateTableHeaders();
$.querywidget.updatePreviewLinks();
$.querywidget.updateMultiCheckboxes();
$.pfwbged.prepareLinearNavigation();
});
};
@ -133,6 +137,7 @@
$.querywidget.updateExtraColumnsMenu();
$.querywidget.updateTableHeaders();
$.querywidget.updatePreviewLinks();
$.querywidget.updateMultiCheckboxes();
$.pfwbged.prepareLinearNavigation();
});
return false;
@ -290,6 +295,55 @@
});
};
$.querywidget.updateMultiCheckboxes = function () {
$('th span.colour-column-head').click(function(e) {
var $table = $(this).parents('table');
$table.find('td.colour-column input').click();
});
$('td.colour-column input').change(function(e) {
if ($(this).prop('checked')) {
$(this).parents('tr').addClass('selected');
} else {
$(this).parents('tr').removeClass('selected');
}
$('.multi-actions button').each(function(idx, elem) {
var action_status = $(elem).data('status');
var action_type = $(elem).data('type');
var selector = 'tr.selected.row-state-' + action_status;
if (action_type) {
selector = selector + '.row-type-' + action_type;
}
if ($(this).parents('div.table').find(selector).length) {
$(elem).show();
} else {
$(elem).hide();
}
});
e.stopPropagation();
return true;
});
$('.multi-actions button').on('click', function() {
var $div = $(this).parent();
var url = $(this).parent().data('actions-url');
var action = $(this).data('action');
var action_status = $(this).data('status');
var documents = Array();
$(this).parents('div.table').find('tr.selected.row-state-' + action_status + ' input').each(function(idx, elem) {
documents.push($(elem).data('value'));
});
$div.find('button').prop('disabled', true);
$.post(url, {'action': action, 'documents': documents }
).done(function() {
console.log('success');
console.log('xx:', $.querywidget.updateSearch);
$.querywidget.updateSearch(true);
}).fail(function() {
console.log('fail');
}).always(function() {
$div.find('button').prop('disabled', false);
});
});
}
}(jQuery));
function update_portaltypes()

View File

@ -1,3 +1,5 @@
# -*- coding: utf8 -*-
from collections import OrderedDict
import json
import datetime
@ -182,6 +184,23 @@ class ResultsTable(BaseTable):
'title': _(u'Recipient(s)'),}]
class ResultsDocumentsTable(ResultsTable):
def render(self):
portal_url = api.portal.get().portal_url()
return self.renderTable() + u"""
<div class="multi-actions" data-actions-url="%(portal_url)s/@@multiactions">
<button data-status="assigning" data-action="to_process">À traiter</button>
<button data-status="processing" data-action="to_considered">Pris en compte</button>
<button data-status="processing" data-action="to_noaction">Sans suite</button>
</div>
""" % {'portal_url': portal_url}
class ResultsTasksTable(TasksTable):
def updateBatch(self):
@ -205,6 +224,26 @@ class ResultsTasksTable(TasksTable):
def getPotentialExtraColumns(self):
return []
def render(self):
portal_url = api.portal.get().portal_url()
#abandon ask-for-refusal attribute take-responsibility
return self.renderTable() + """
<div class="multi-actions" data-actions-url="%(portal_url)s/@@multiactions">
<button data-type="task" data-status="todo" data-action="take-responsibility">Prendre en charge</button>
<button data-type="task" data-status="in-progress" data-action="mark-as-done">Marquer comme fait </button>
<button data-type="information" data-status="todo" data-action="mark-as-done">Marquer comme lu</button>
</div>
""" % {'portal_url': portal_url}
class ResultsOpinionsTable(ResultsTasksTable):
def render(self):
# no multiactions for opinions
return self.renderTable()
class ContactsTasksTable(ResultsTable):
@ -379,19 +418,28 @@ def get_appropriate_table_class(context, query):
table_class = ResultsTable
if parsed_query.get('portal_type'):
portal_types = parsed_query.get('portal_type').get('query')
if portal_types is not None and not (set(portal_types) - set(['task', 'opinion',
'validation', 'information'])):
if portal_types is None:
return table_class
if not (set(portal_types) - set(['opinion'])):
# nothing but "opinions", use a more appropriate table
return ResultsOpinionsTable
if not (set(portal_types) - set(['task', 'opinion', 'validation', 'information'])):
# nothing but "tasks", use a more appropriate table
table_class = ResultsTasksTable
if portal_types is not None and not (set(portal_types) - set(['information'])):
# nothing but "tasks", use a more appropriate table
table_class = ResultsInformationsTable
if portal_types is not None and not (set(portal_types) - set(['person', 'organization'])):
return ResultsTasksTable
if not (set(portal_types) - set(['information'])):
# nothing but "informations", use a more appropriate table
return ResultsInformationsTable
if not (set(portal_types) - set(['person', 'organization'])):
# nothing but "contacts", use a more appropriate table
table_class = ContactsTasksTable
if portal_types is not None and not (set(portal_types) - set(['pfwbgedfolder'])):
return ContactsTasksTable
if not (set(portal_types) - set(['pfwbgedfolder'])):
# nothing but "folders", use a more appropriate table
table_class = ResultsFoldersTable
return ResultsFoldersTable
if not set(portal_types).intersection(set(['task', 'opinion',
'validation', 'information', 'person', 'organization',
'pfwbgedfolder'])):
# nothing but documents (hopefully)
return ResultsDocumentsTable
return table_class
BATCH_SIZE = 10