[IMP] change publish button, fix website_sale product order + push top/bottom
bzr revid: chm@openerp.com-20130926111854-22ikjc2enj0hi0qu
This commit is contained in:
parent
b05cd31b59
commit
c66c5d5b6a
|
@ -258,17 +258,16 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||
pass
|
||||
return request.make_response(image_data, headers)
|
||||
|
||||
@website.route(['/website/publish/'], type='http', auth="public")
|
||||
def publish(self, **post):
|
||||
_id = int(post['id'])
|
||||
_object = request.registry[post['object']]
|
||||
@website.route(['/website/publish'], type='json', auth="public")
|
||||
def publish(self, id, object):
|
||||
_id = int(id)
|
||||
_object = request.registry[object]
|
||||
|
||||
obj = _object.browse(request.cr, request.uid, _id)
|
||||
_object.write(request.cr, request.uid, [_id],
|
||||
{'website_published': not obj.website_published},
|
||||
context=request.context)
|
||||
obj = _object.browse(request.cr, request.uid, _id)
|
||||
|
||||
return obj.website_published and "1" or "0"
|
||||
|
||||
@website.route(['/website/kanban/'], type='http', auth="public")
|
||||
|
|
|
@ -352,27 +352,12 @@ ul.nav-stacked > li > a {
|
|||
}
|
||||
|
||||
/* ---- PUBLISH ---- */
|
||||
a[data-publish] {
|
||||
text-decoration: none !important;
|
||||
z-index: 2;
|
||||
}
|
||||
a[data-publish] .label {
|
||||
padding: 5px 8px;
|
||||
}
|
||||
a[data-publish] .css_unpublish, a[data-publish] .css_publish, a[data-publish] .css_unpublished, a[data-publish] .css_published {
|
||||
.dropdown .css_unpublish, .dropdown .css_publish {
|
||||
display: none;
|
||||
}
|
||||
a[data-publish][data-publish='off'] .css_unpublished, a[data-publish][data-publish='off']:hover .css_publish {
|
||||
display: inline;
|
||||
}
|
||||
a[data-publish][data-publish='off']:hover .css_unpublished {
|
||||
display: none;
|
||||
}
|
||||
a[data-publish][data-publish='on'] .css_published, a[data-publish][data-publish='on']:hover .css_unpublish {
|
||||
display: inline;
|
||||
}
|
||||
a[data-publish][data-publish='on']:hover .css_published {
|
||||
display: none;
|
||||
|
||||
.dropdown.css_publish .css_unpublish, .dropdown.css_unpublish .css_publish {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.unpublish {
|
||||
|
|
|
@ -267,23 +267,11 @@ ul.nav-stacked > li > a
|
|||
text-transform: uppercase
|
||||
|
||||
/* ---- PUBLISH ---- */
|
||||
a[data-publish]
|
||||
text-decoration: none !important
|
||||
z-index: 2
|
||||
.label
|
||||
padding: 5px 8px
|
||||
.css_unpublish, .css_publish, .css_unpublished, .css_published
|
||||
display: none
|
||||
&[data-publish='off']
|
||||
.css_unpublished, &:hover .css_publish
|
||||
display: inline
|
||||
&:hover .css_unpublished
|
||||
display: none
|
||||
&[data-publish='on']
|
||||
.css_published, &:hover .css_unpublish
|
||||
display: inline
|
||||
&:hover .css_published
|
||||
display: none
|
||||
|
||||
.dropdown .css_unpublish, .dropdown .css_publish
|
||||
display: none
|
||||
.dropdown.css_publish .css_unpublish, .dropdown.css_unpublish .css_publish
|
||||
display: block
|
||||
|
||||
.unpublish
|
||||
opacity: 0.5
|
||||
|
|
|
@ -116,19 +116,24 @@
|
|||
|
||||
dom_ready.then(function () {
|
||||
/* ----- PUBLISHING STUFF ---- */
|
||||
$('[data-publish]:has(.js_publish)').each(function () {
|
||||
$(this).attr("data-publish", $(".js_publish li.active", this).size() ? "on" : 'off');
|
||||
$('[data-publish]:has(.js_publish_management)').each(function () {
|
||||
$(this).attr("data-publish", $(".js_publish_management .btn-success", this).size() ? "on" : 'off');
|
||||
});
|
||||
|
||||
$(document).on('click', '.js_publish a.js_publish_btn', function (e) {
|
||||
var $li = $(this).parent("li");
|
||||
var $data = $li.parents(".js_publish:first");
|
||||
var publish = $li.hasClass("active");
|
||||
$li.toggleClass("active");
|
||||
$.post('/website/publish', {'id': $data.data('id'), 'object': $data.data('object')}, function (result) {
|
||||
$li.toggleClass("active", !!+result);
|
||||
$li.parents("[data-publish]").attr("data-publish", +result ? 'on' : 'off');
|
||||
});
|
||||
$(document).on('click', '.js_publish_management .js_publish_btn', function (e) {
|
||||
var $data = $(this).parents(".js_publish_management:first");
|
||||
var $btn = $data.find('.btn:first');
|
||||
var publish = $btn.hasClass("btn-success");
|
||||
|
||||
$data.toggleClass("css_unpublish css_publish");
|
||||
$btn.removeClass("btn-default btn-success");
|
||||
|
||||
openerp.jsonRpc('/website/publish', 'call', {'id': +$data.data('id'), 'object': $data.data('object')})
|
||||
.then(function (result) {
|
||||
$btn.toggleClass("btn-default", !+result).toggleClass("btn-success", !!+result);
|
||||
$data.toggleClass("css_unpublish", !+result).toggleClass("css_publish", !!+result);
|
||||
$data.parents("[data-publish]").attr("data-publish", +result ? 'on' : 'off');
|
||||
});
|
||||
});
|
||||
|
||||
/* ----- KANBAN WEBSITE ---- */
|
||||
|
|
|
@ -335,13 +335,17 @@
|
|||
</ul>
|
||||
</template>
|
||||
|
||||
<template id="publish">
|
||||
<template id="publish_management">
|
||||
<t t-if="editable" t-ignore="true">
|
||||
<div class="dropdown js_publish pull-right" t-att-data-id="object.id" t-att-data-object="object._name">
|
||||
<a class="btn btn-default" id="dopprod" role="button" data-toggle="dropdown"> Manage <span class="caret"></span></a>
|
||||
<div t-attf-class="dropdown js_publish_management pull-right #{object.id and object.website_published and 'css_publish' or 'css_unpublish'}" t-att-data-id="object.id" t-att-data-object="object._name">
|
||||
<a t-attf-class="btn btn-#{object.id and object.website_published and 'success' or 'default'}" id="dopprod" role="button" data-toggle="dropdown"> Publish options <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dopprod">
|
||||
<li t-att-class="object.id and object.website_published and 'active' or ''"><a href="#" class="js_publish_btn">Publish</a></li>
|
||||
<li><a t-att-href="'/admin/#model=%s&id=%s' % (object._name, object.id)">Manage Products</a></li>
|
||||
<t t-raw="0"/>
|
||||
<li>
|
||||
<a href="#" class="js_publish_btn css_unpublish">Unpublish</a>
|
||||
<a href="#" class="js_publish_btn css_publish">Publish</a>
|
||||
</li>
|
||||
<li><a t-att-href="'/admin/#model=%s&id=%s' % (object._name, object.id)">Manage</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</t>
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<template id="view_blog_post" name="Blog Post">
|
||||
<div>
|
||||
<t t-call="website_mail.follow"><t t-set="object" t-value="blog_post"/></t>
|
||||
<t t-call="website.publish"><t t-set="object" t-value="blog_post"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="blog_post"/></t>
|
||||
</div><div class="clearfix"/>
|
||||
|
||||
<h2 class="text-center" t-field="blog_post.name"/>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<ul class="media-list" id="comments">
|
||||
<li t-foreach="blog_post.website_message_ids" t-as="message" class="media">
|
||||
<div class="media-body well well-sm">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="message"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="message"/></t>
|
||||
<t t-raw="message.body"/>
|
||||
<small class="pull-left text-muted text-left">
|
||||
<t t-field="message.author_id"/> on <t t-field="message.date"/>
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
<div>
|
||||
<div t-foreach="partner_ids" t-as="partner" class="media thumbnail" data-publish="">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner"/></t>
|
||||
<a class="pull-left" t-attf-href="/references/#{ partner.id }/">
|
||||
<img class="media-object" t-att-src="partner.img('image_small')"/>
|
||||
</a>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<template id="details" name="Reference Detail">
|
||||
<t t-call="website_contract.layout">
|
||||
<t t-set="ref_content">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner_id"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner_id"/></t>
|
||||
<h1 class="col-md-12 text-center" t-field="partner_id.name"/>
|
||||
<div class="col-md-4">
|
||||
<div class="text-center">
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<h3 class="text-center well"><span t-field="partner.grade_id"/> Partners</h3>
|
||||
</t>
|
||||
<div class="media thumbnail" data-publish="">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner"/></t>
|
||||
<a class="pull-left" t-attf-href="/partners/#{ partner.id }/">
|
||||
<img class="media-object" t-att-src="partner.img('image_small')"/>
|
||||
</a>
|
||||
|
@ -110,7 +110,7 @@
|
|||
<template id="details" name="Partner Detail">
|
||||
<t t-call="website_crm_partner_assign.layout">
|
||||
<t t-set="ref_content">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner_id"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner_id"/></t>
|
||||
<h1 class="col-md-12 text-center" t-field="partner_id.name"/>
|
||||
<div class="col-md-4">
|
||||
<div class="text-center">
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
<ul class="media-list">
|
||||
<li t-foreach="event_ids" t-as="event" class="media" data-publish="">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="event"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="event"/></t>
|
||||
<div class="media-body">
|
||||
<span t-if="not event.event_ticket_ids" class="label label-default pull-right">No tickets needed.</span>
|
||||
<t t-if="event.event_ticket_ids">
|
||||
|
@ -137,7 +137,7 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="event_id"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="event_id"/></t>
|
||||
<t t-call="website_mail.follow"><t t-set="object" t-value="event_id"/></t>
|
||||
<h1 class="text-center" t-field="event_id.name"></h1>
|
||||
<h4 class="text-center">
|
||||
|
@ -199,7 +199,7 @@
|
|||
<ul class="media-list" id="comment">
|
||||
<li t-foreach="event_id.website_message_ids" t-as="comment" class="media">
|
||||
<div class="media-body">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="comment"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="comment"/></t>
|
||||
<t t-raw="comment.body"/>
|
||||
<small class="pull-right muted text-right">
|
||||
<div t-field="comment.author_id"/>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<div class="thumbnails">
|
||||
<div t-foreach="employee_ids" t-as="employee" class="col-md-4 mt16">
|
||||
<div class="media img-thumbnail" data-publish="">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="employee"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="employee"/></t>
|
||||
<a class="pull-left" href="#">
|
||||
<img class="media-object" t-att-src="employee.img('image_small')"/>
|
||||
</a>
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
</t>
|
||||
<t t-set="partner" t-value="membership_line_id.partner"/>
|
||||
<div class="media thumbnail" data-publish="">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner"/></t>
|
||||
<a class="pull-left" t-attf-href="/members/#{ partner.id }/">
|
||||
<img class="media-object" t-att-src="partner.img('image_small')"/>
|
||||
</a>
|
||||
|
@ -101,7 +101,7 @@
|
|||
<template id="details" name="Member Detail">
|
||||
<t t-call="website_membership.layout">
|
||||
<t t-set="ref_content">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="partner_id"/></t>
|
||||
<t t-call="website.publish_management"><t t-set="object" t-value="partner_id"/></t>
|
||||
<h1 class="col-md-12 text-center" t-field="partner_id.name"/>
|
||||
<div class="col-md-4">
|
||||
<div class="text-center">
|
||||
|
|
|
@ -49,6 +49,8 @@ class Website(osv.osv):
|
|||
|
||||
class Ecommerce(http.Controller):
|
||||
|
||||
_order = 'website_sequence desc, website_published'
|
||||
|
||||
def get_categories(self):
|
||||
domain = [('parent_id', '=', False)]
|
||||
|
||||
|
@ -93,7 +95,8 @@ class Ecommerce(http.Controller):
|
|||
product_obj = request.registry.get('product.template')
|
||||
data_obj = request.registry.get('ir.model.data')
|
||||
|
||||
product_ids = product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)
|
||||
# search for checking of access rules and keep order
|
||||
product_ids = [id for id in product_ids if id in product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)]
|
||||
|
||||
size_ids = {}
|
||||
data_domain = [('model', '=', 'website.product.style'), ('name', 'like', 'size%')]
|
||||
|
@ -180,7 +183,8 @@ class Ecommerce(http.Controller):
|
|||
# browse product to fill the holes
|
||||
if fill_hole:
|
||||
fill_hole_products = []
|
||||
fill_hole = product_obj.search(request.cr, request.uid, [("id", 'in', fill_hole)], context=request.context)
|
||||
# search for checking of access rules and keep order
|
||||
fill_hole = [id for id in fill_hole if id in product_obj.search(request.cr, request.uid, [("id", 'in', fill_hole)], context=request.context)]
|
||||
for product in product_obj.browse(request.cr, SUPERUSER_ID, fill_hole, context=request.context):
|
||||
fill_hole_products.append(product)
|
||||
fill_hole_products.reverse()
|
||||
|
@ -202,7 +206,8 @@ class Ecommerce(http.Controller):
|
|||
|
||||
def get_products(self, product_ids):
|
||||
product_obj = request.registry.get('product.template')
|
||||
product_ids = product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)
|
||||
# search for checking of access rules and keep order
|
||||
product_ids = [id for id in product_ids if id in product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)]
|
||||
return product_obj.browse(request.cr, SUPERUSER_ID, product_ids, context=request.context)
|
||||
|
||||
@website.route(['/shop/', '/shop/category/<cat_id>/', '/shop/category/<cat_id>/page/<int:page>/', '/shop/page/<int:page>/'], type='http', auth="public")
|
||||
|
@ -230,9 +235,9 @@ class Ecommerce(http.Controller):
|
|||
pager = request.website.pager(url="/shop/category/%s/" % cat_id, total=product_count, page=page, step=step, scope=7, url_args=post)
|
||||
|
||||
request.context['pricelist'] = self.get_pricelist()
|
||||
|
||||
product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'], context=request.context)
|
||||
fill_hole = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']+step, context=request.context)
|
||||
|
||||
product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'], order=self._order, context=request.context)
|
||||
fill_hole = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']+step, order=self._order, context=request.context)
|
||||
|
||||
values = {
|
||||
'get_categories': self.get_categories,
|
||||
|
@ -578,4 +583,13 @@ class Ecommerce(http.Controller):
|
|||
request.httprequest.session['ecommerce_pricelist'] = False
|
||||
return werkzeug.utils.redirect("/shop/")
|
||||
|
||||
@website.route(['/shop/change_sequence/'], type='json', auth="public")
|
||||
def change_sequence(self, id, top):
|
||||
product_obj = request.registry.get('product.template')
|
||||
if top:
|
||||
product_obj.set_sequence_top(request.cr, request.uid, [id], request.context)
|
||||
else:
|
||||
product_obj.set_sequence_bottom(request.cr, request.uid, [id], request.context)
|
||||
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -38,7 +38,19 @@ class product_template(osv.Model):
|
|||
'suggested_product_id': fields.many2one('product.template', 'Suggested For Product'),
|
||||
'suggested_product_ids': fields.one2many('product.template', 'suggested_product_id', 'Suggested Products'),
|
||||
'website_style_ids' : fields.many2many('website.product.style','product_website_style_rel', 'product_id', 'style_id', 'Styles'),
|
||||
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
|
||||
}
|
||||
_defaults = {
|
||||
'website_sequence': 0,
|
||||
}
|
||||
|
||||
def set_sequence_top(self, cr, uid, ids, context=None):
|
||||
cr.execute('SELECT MAX(website_sequence) FROM product_template')
|
||||
max_sequence = cr.fetchone()[0] or 0
|
||||
return self.write(cr, uid, ids, {'website_sequence': max_sequence + 1}, context=context)
|
||||
|
||||
def set_sequence_bottom(self, cr, uid, ids, context=None):
|
||||
return self.write(cr, uid, ids, {'website_sequence': 0}, context=context)
|
||||
|
||||
def recommended_products(self, cr, uid, ids, context=None):
|
||||
id = ids[0]
|
||||
|
|
|
@ -64,4 +64,9 @@ $(document).ready(function () {
|
|||
return false;
|
||||
});
|
||||
|
||||
$('.js_go_to_top, .js_go_to_bottom').on('click', function () {
|
||||
var $data = $(this).parents(".js_publish_management:first");
|
||||
openerp.jsonRpc('/shop/change_sequence/', 'call', {'id': $data.data('id'), 'top': $(this).hasClass('js_go_to_top')});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<group name="website" string="Website">
|
||||
<field name="website_published"/>
|
||||
<field name="suggested_product_ids" widget="many2many_tags"/>
|
||||
<field name="website_style_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
</group>
|
||||
</field>
|
||||
|
@ -162,6 +163,7 @@
|
|||
<t t-call="website_sale.products_cart"/>
|
||||
</td>
|
||||
</t>
|
||||
<td t-if="td_product == None"/>
|
||||
</t>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -232,7 +234,16 @@
|
|||
<li class="active" t-field="product.name">Product Name</li>
|
||||
</ol>
|
||||
</div><div class="col-sm-3">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="product"/></t>
|
||||
<t t-call="website.publish_management">
|
||||
<t t-set="object" t-value="product"/>
|
||||
<li class='dropdown-submenu'>
|
||||
<a tabindex="-1" href="#">Sequence</a>
|
||||
<ul class="dropdown-menu" name="sequence">
|
||||
<li><a href="#" class="js_go_to_top">Push on top</a></li>
|
||||
<li><a href="#" class="js_go_to_bottom">Push on bottom</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</t>
|
||||
</div><div class="col-sm-3 col-sm-offset-1">
|
||||
<form t-attf-action="/shop/#{ category_id and ('category/%s/' % category_id) or ''}" method="get" class="pull-right">
|
||||
<div class="input-group">
|
||||
|
|
Loading…
Reference in New Issue