[REM] website: kanban helper
website_project has been removed and this helper is now useless.
This commit is contained in:
@@ -329,13 +329,6 @@ class Website(openerp.addons.web.controllers.main.Home):
|
||||
res[id_or_xml_id] = request.registry["ir.ui.view"].render(request.cr, request.uid, id_or_xml_id, values=values, engine='ir.qweb', context=request.context)
|
||||
return res
|
||||
|
||||
#------------------------------------------------------
|
||||
# Helpers
|
||||
#------------------------------------------------------
|
||||
@http.route(['/website/kanban'], type='http', auth="public", methods=['POST'], website=True)
|
||||
def kanban(self, **post):
|
||||
return request.website.kanban_col(**post)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Server actions
|
||||
#------------------------------------------------------
|
||||
|
||||
@@ -549,80 +549,6 @@ class website(osv.osv):
|
||||
break
|
||||
return res
|
||||
|
||||
def kanban(self, cr, uid, ids, model, domain, column, template, step=None, scope=None, orderby=None, context=None):
|
||||
step = step and int(step) or 10
|
||||
scope = scope and int(scope) or 5
|
||||
orderby = orderby or "name"
|
||||
|
||||
get_args = dict(request.httprequest.args or {})
|
||||
model_obj = self.pool[model]
|
||||
relation = model_obj._columns.get(column)._obj
|
||||
relation_obj = self.pool[relation]
|
||||
|
||||
get_args.setdefault('kanban', "")
|
||||
kanban = get_args.pop('kanban')
|
||||
kanban_url = "?%s&kanban=" % werkzeug.url_encode(get_args)
|
||||
|
||||
pages = {}
|
||||
for col in kanban.split(","):
|
||||
if col:
|
||||
col = col.split("-")
|
||||
pages[int(col[0])] = int(col[1])
|
||||
|
||||
objects = []
|
||||
for group in model_obj.read_group(cr, uid, domain, ["id", column], groupby=column):
|
||||
obj = {}
|
||||
|
||||
# browse column
|
||||
relation_id = group[column][0]
|
||||
obj['column_id'] = relation_obj.browse(cr, uid, relation_id)
|
||||
|
||||
obj['kanban_url'] = kanban_url
|
||||
for k, v in pages.items():
|
||||
if k != relation_id:
|
||||
obj['kanban_url'] += "%s-%s" % (k, v)
|
||||
|
||||
# pager
|
||||
number = model_obj.search(cr, uid, group['__domain'], count=True)
|
||||
obj['page_count'] = int(math.ceil(float(number) / step))
|
||||
obj['page'] = pages.get(relation_id) or 1
|
||||
if obj['page'] > obj['page_count']:
|
||||
obj['page'] = obj['page_count']
|
||||
offset = (obj['page']-1) * step
|
||||
obj['page_start'] = max(obj['page'] - int(math.floor((scope-1)/2)), 1)
|
||||
obj['page_end'] = min(obj['page_start'] + (scope-1), obj['page_count'])
|
||||
|
||||
# view data
|
||||
obj['domain'] = group['__domain']
|
||||
obj['model'] = model
|
||||
obj['step'] = step
|
||||
obj['orderby'] = orderby
|
||||
|
||||
# browse objects
|
||||
object_ids = model_obj.search(cr, uid, group['__domain'], limit=step, offset=offset, order=orderby)
|
||||
obj['object_ids'] = model_obj.browse(cr, uid, object_ids)
|
||||
|
||||
objects.append(obj)
|
||||
|
||||
values = {
|
||||
'objects': objects,
|
||||
'range': range,
|
||||
'template': template,
|
||||
}
|
||||
return request.website._render("website.kanban_contain", values)
|
||||
|
||||
def kanban_col(self, cr, uid, ids, model, domain, page, template, step, orderby, context=None):
|
||||
html = ""
|
||||
model_obj = self.pool[model]
|
||||
domain = safe_eval(domain)
|
||||
step = int(step)
|
||||
offset = (int(page)-1) * step
|
||||
object_ids = model_obj.search(cr, uid, domain, limit=step, offset=offset, order=orderby)
|
||||
object_ids = model_obj.browse(cr, uid, object_ids)
|
||||
for object_id in object_ids:
|
||||
html += request.website._render(template, {'object_id': object_id})
|
||||
return html
|
||||
|
||||
def _image_placeholder(self, response):
|
||||
logger.warning("Deprecated _image_placeholder method, please use this method on ir.attachment")
|
||||
return self.pool['ir.attachment']._image_placeholder(response)
|
||||
|
||||
@@ -158,62 +158,6 @@ var form = function (url, method, params) {
|
||||
form.submit();
|
||||
};
|
||||
|
||||
var init_kanban = function ($kanban) {
|
||||
$('.js_kanban_col', $kanban).each(function () {
|
||||
var $col = $(this);
|
||||
var $pagination = $('.pagination', $col);
|
||||
if(!$pagination.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var page_count = $col.data('page_count');
|
||||
var scope = $pagination.last().find("li").size()-2;
|
||||
var kanban_url_col = $pagination.find("li a:first").attr("href").replace(/[0-9]+$/, '');
|
||||
|
||||
var data = {
|
||||
'domain': $col.data('domain'),
|
||||
'model': $col.data('model'),
|
||||
'template': $col.data('template'),
|
||||
'step': $col.data('step'),
|
||||
'orderby': $col.data('orderby')
|
||||
};
|
||||
|
||||
$pagination.on('click', 'a', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $a = $(ev.target);
|
||||
if($a.parent().hasClass('active')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var page = +$a.attr("href").split(",").pop().split('-')[1];
|
||||
data['page'] = page;
|
||||
|
||||
$.post('/website/kanban', data, function (col) {
|
||||
$col.find("> .thumbnail").remove();
|
||||
$pagination.last().before(col);
|
||||
});
|
||||
|
||||
var page_start = page - parseInt(Math.floor((scope-1)/2), 10);
|
||||
if (page_start < 1 ) page_start = 1;
|
||||
var page_end = page_start + (scope-1);
|
||||
if (page_end > page_count ) page_end = page_count;
|
||||
|
||||
if (page_end - page_start < scope) {
|
||||
page_start = page_end - scope > 0 ? page_end - scope : 1;
|
||||
}
|
||||
|
||||
$pagination.find('li.prev a').attr("href", kanban_url_col+(page-1 > 0 ? page-1 : 1));
|
||||
$pagination.find('li.next a').attr("href", kanban_url_col+(page < page_end ? page+1 : page_end));
|
||||
for(var i=0; i < scope; i++) {
|
||||
$pagination.find('li:not(.prev):not(.next):eq('+i+') a').attr("href", kanban_url_col+(page_start+i)).html(page_start+i);
|
||||
}
|
||||
$pagination.find('li.active').removeClass('active');
|
||||
$pagination.find('li:has(a[href="'+kanban_url_col+page+'"])').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
ajax.loadXML('/website/static/src/xml/website.xml', qweb);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user