2013-08-20 21:34:50 +00:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
2013-08-19 14:11:08 +00:00
|
|
|
|
2013-08-20 21:34:50 +00:00
|
|
|
var website = {};
|
|
|
|
// The following line can be removed in 2017
|
|
|
|
openerp.website = website;
|
2013-08-05 08:26:38 +00:00
|
|
|
|
2013-08-29 15:34:41 +00:00
|
|
|
var templates = website.templates = [
|
2013-08-20 21:34:50 +00:00
|
|
|
'/website/static/src/xml/website.xml'
|
|
|
|
];
|
2013-08-19 14:11:08 +00:00
|
|
|
|
|
|
|
/* ----- TEMPLATE LOADING ---- */
|
2013-08-20 21:34:50 +00:00
|
|
|
website.add_template = function(template) {
|
|
|
|
templates.push(template);
|
|
|
|
};
|
|
|
|
website.load_templates = function(templates) {
|
2013-08-19 14:11:08 +00:00
|
|
|
var def = $.Deferred();
|
|
|
|
var count = templates.length;
|
|
|
|
templates.forEach(function(t) {
|
|
|
|
openerp.qweb.add_template(t, function(err) {
|
|
|
|
if (err) {
|
|
|
|
def.reject();
|
|
|
|
} else {
|
|
|
|
count--;
|
|
|
|
if (count < 1) {
|
|
|
|
def.resolve();
|
|
|
|
}
|
2013-08-11 14:06:19 +00:00
|
|
|
}
|
2013-07-31 14:06:31 +00:00
|
|
|
});
|
|
|
|
});
|
2013-08-19 14:11:08 +00:00
|
|
|
return def;
|
2013-08-20 21:34:50 +00:00
|
|
|
};
|
2013-07-30 15:09:55 +00:00
|
|
|
|
2013-08-23 08:27:12 +00:00
|
|
|
|
2013-08-20 21:34:50 +00:00
|
|
|
var all_ready = null;
|
2013-08-29 10:29:56 +00:00
|
|
|
var dom_ready = website.dom_ready = $.Deferred();
|
2013-08-20 21:34:50 +00:00
|
|
|
$(dom_ready.resolve);
|
|
|
|
|
2013-08-22 09:18:12 +00:00
|
|
|
website.init_kanban = function ($kanban) {
|
|
|
|
$('.js_kanban_col', $kanban).each(function () {
|
|
|
|
var $col = $(this);
|
|
|
|
var $pagination = $('.pagination', $col);
|
|
|
|
if(!$pagination.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-22 12:40:13 +00:00
|
|
|
|
2013-08-22 09:18:12 +00:00
|
|
|
var page_count = $col.data('page_count');
|
2013-08-22 09:25:36 +00:00
|
|
|
var scope = $pagination.last().find("li").size()-2;
|
2013-08-22 09:18:12 +00:00
|
|
|
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);
|
2013-08-22 09:24:16 +00:00
|
|
|
if($a.parent().hasClass('active')) {
|
2013-08-22 09:18:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var page = +$a.attr("href").split(",").pop().split('-')[1];
|
|
|
|
data['page'] = page;
|
|
|
|
|
|
|
|
$.post('/website/kanban/', data, function (col) {
|
2013-08-22 09:24:16 +00:00
|
|
|
$col.find("> .thumbnail").remove();
|
2013-08-22 09:30:49 +00:00
|
|
|
$pagination.last().before(col);
|
2013-08-22 09:18:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var page_start = page - parseInt(Math.floor((scope-1)/2));
|
2013-08-22 09:24:16 +00:00
|
|
|
if (page_start < 1 ) page_start = 1;
|
2013-08-22 09:18:12 +00:00
|
|
|
var page_end = page_start + (scope-1);
|
2013-08-22 09:24:16 +00:00
|
|
|
if (page_end > page_count ) page_end = page_count;
|
2013-08-22 09:18:12 +00:00
|
|
|
|
2013-08-22 09:24:16 +00:00
|
|
|
if (page_end - page_start < scope) {
|
|
|
|
page_start = page_end - scope > 0 ? page_end - scope : 1;
|
2013-08-22 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$pagination.find('li.prev a').attr("href", kanban_url_col+(page-1 > 0 ? page-1 : 1));
|
2013-08-22 09:24:16 +00:00
|
|
|
$pagination.find('li.next a').attr("href", kanban_url_col+(page < page_end ? page+1 : page_end));
|
|
|
|
for(var i=0; i < scope; i++) {
|
2013-08-22 09:18:12 +00:00
|
|
|
$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');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-08-20 21:34:50 +00:00
|
|
|
/**
|
|
|
|
* Returns a deferred resolved when the templates are loaded
|
|
|
|
* and the Widgets can be instanciated.
|
|
|
|
*/
|
|
|
|
website.ready = function() {
|
|
|
|
if (!all_ready) {
|
|
|
|
all_ready = dom_ready.then(function () {
|
|
|
|
// TODO: load translations
|
|
|
|
return website.load_templates(templates);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return all_ready;
|
|
|
|
};
|
|
|
|
|
|
|
|
dom_ready.then(function () {
|
|
|
|
/* ----- PUBLISHING STUFF ---- */
|
2013-09-03 10:41:15 +00:00
|
|
|
$('[data-publish]:has([data-publish])').each(function () {
|
|
|
|
var $pub = $("[data-publish]", this);
|
2013-09-03 11:04:10 +00:00
|
|
|
if($pub.size())
|
|
|
|
$(this).attr("data-publish", $pub.attr("data-publish"));
|
|
|
|
else
|
|
|
|
$(this).removeAttr("data-publish");
|
2013-09-03 10:41:15 +00:00
|
|
|
});
|
|
|
|
|
2013-09-02 14:14:54 +00:00
|
|
|
$(document).on('click', '.js_publish', function (e) {
|
2013-08-20 21:34:50 +00:00
|
|
|
e.preventDefault();
|
2013-09-03 10:41:15 +00:00
|
|
|
var $data = $(":first", this).parents("[data-publish]");
|
|
|
|
$data.attr("data-publish", $data.first().attr("data-publish") == 'off' ? 'on' : 'off');
|
|
|
|
$.post('/website/publish', {'id': $(this).data('id'), 'object': $(this).data('object')}, function (result) {
|
|
|
|
$data.attr("data-publish", +result ? 'on' : 'off');
|
2013-08-20 21:34:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-22 09:18:12 +00:00
|
|
|
/* ----- KANBAN WEBSITE ---- */
|
2013-08-22 09:24:16 +00:00
|
|
|
$('.js_kanban').each(function () {
|
2013-08-22 09:18:12 +00:00
|
|
|
website.init_kanban(this);
|
|
|
|
});
|
|
|
|
|
2013-08-20 21:34:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return website;
|
|
|
|
})();
|
2013-08-14 08:34:39 +00:00
|
|
|
|