Skip to content
Permalink
Browse files

tmp

  • Loading branch information...
kea14 committed Sep 30, 2019
1 parent 27be427 commit 22edb839325b90fdc861520d6a5cb06517bb71c5
@@ -71,7 +71,7 @@ def process(self, products, ppg=20, ppr=4):
self.table[(pos // ppr) + y2][(pos % ppr) + x2] = False
self.table[pos // ppr][pos % ppr] = {
'product': p, 'x': x, 'y': y,
'class': " ".join(x.html_class for x in p.website_style_ids if x.html_class)
'class': " ".join(x.html_class for x in p.website_style_id if x.html_class)
}
if index <= ppg:
maxy = max(maxy, y + (pos // ppr))
@@ -1054,25 +1054,40 @@ def add_product(self, name=None, category=None, **post):
})
return "%s?enable_editor=1" % product.product_tmpl_id.website_url

@http.route(['/shop/add_edit_style'], type='json', auth='user', methods=['POST'], website=True)
def add_edit_style(self, name, id=None, edit=False):
product_style = request.env['product.style']
if edit:
product_style.browse(id).write({
'name': name,
# 'color': color
})
else:
product_style.create({
'name': name,
'html_class': 'oe_ribbon_promo',
# 'color': color
})

@http.route(['/shop/change_styles'], type='json', auth='user')
def change_styles(self, id, style_id):
product = request.env['product.template'].browse(id)

remove = []
active = False
style_id = int(style_id)
for style in product.website_style_ids:
if style.id == style_id:
remove.append(style.id)
active = True
break
if product.website_style_id.id == style_id:
# remove.append(style.id)
product.write({'website_style_id': False})
active = True

style = request.env['product.style'].browse(style_id)

if remove:
product.write({'website_style_ids': [(3, rid) for rid in remove]})
# if remove:
# product.write({'website_style_id': [(3, rid) for rid in remove]})
if not active:
product.write({'website_style_ids': [(4, style.id)]})
# product.write({'website_style_id': [(4, product.website_style.id)]})
product.write({'website_style_id': style.id})

return not active

@@ -19,8 +19,9 @@
</record>

<record id="website_sale.image_promo" model="product.style">
<field name="name">Sale Ribbon</field>
<field name="name">Sale</field>
<field name="html_class">oe_ribbon_promo</field>
<field name="color">btn-danger</field>
</record>

<record id="sales_team.salesteam_website_sales" model="crm.team">
@@ -15,6 +15,7 @@ class ProductStyle(models.Model):

name = fields.Char(string='Style Name', required=True)
html_class = fields.Char(string='HTML Classes')
color = fields.Char(string='Color Tag')


class ProductPricelist(models.Model):
@@ -185,7 +186,7 @@ class ProductTemplate(models.Model):
'reviews the cart before payment (cross-sell strategy).')
website_size_x = fields.Integer('Size X', default=1)
website_size_y = fields.Integer('Size Y', default=1)
website_style_ids = fields.Many2many('product.style', string='Styles')
website_style_id = fields.Many2one('product.style', string='Style')
website_sequence = fields.Integer('Website Sequence', help="Determine the display order in the Website E-commerce",
default=lambda self: self._default_website_sequence())
public_categ_ids = fields.Many2many('product.public.category', relation='product_public_category_product_template_rel', string='Website Product Category',
@@ -6,7 +6,7 @@ access_product_category_pos_manager,product.public.category manager,model_produc
access_product_public_category_public,product.category.public,model_product_public_category,,1,0,0,0
access_product_pricelist_public,product.pricelist.public,product.model_product_pricelist,,1,0,0,0
access_product_pricelist_item_public,product.pricelist.item.public,product.model_product_pricelist_item,,1,0,0,0
access_product_style,product.style.public,website_sale.model_product_style,,1,0,0,0
access_product_style,product.style.public,website_sale.model_product_style,,1,1,1,1
access_product_supplierinfo,product.supplierinfo.public,product.model_product_supplierinfo,,1,0,0,0
access_product_attribute_public,product.attribute public,product.model_product_attribute,,1,0,0,0
access_product_attribute_value_public,product.attribute value public,product.model_product_attribute_value,,1,0,0,0
@@ -183,11 +183,14 @@ options.registry.WebsiteSaleGridLayout = options.Class.extend({
});

options.registry.WebsiteSaleProductsItem = options.Class.extend({
xmlDependencies: ['/website_sale/static/src/xml/website_sale.editor.xml'],
events: _.extend({}, options.Class.prototype.events || {}, {
'mouseenter .o_wsale_soptions_menu_sizes table': '_onTableMouseEnter',
'mouseleave .o_wsale_soptions_menu_sizes table': '_onTableMouseLeave',
'mouseover .o_wsale_soptions_menu_sizes td': '_onTableItemMouseEnter',
'click .o_wsale_soptions_menu_sizes td': '_onTableItemClick',
'click .o_wsale_soptions_add_edit_ribbon': '_onAddNewOrEditRibbonClick',
'click .o_wsale_soptions_remove_ribbon': '_onRemoveRibbonClick',
}),

/**
@@ -201,19 +204,7 @@ options.registry.WebsiteSaleProductsItem = options.Class.extend({

var defs = [this._super.apply(this, arguments)];

defs.push(this._rpc({
model: 'product.style',
method: 'search_read',
}).then(function (data) {
var $ul = self.$el.find('[name="style"]');
for (var k in data) {
$ul.append(
$('<we-button data-style="' + data[k]['id'] + '" data-toggle-class="' + data[k]['html_class'] + '"/>')
.append(data[k]['name'])
);
}
self._setActive();
}));
defs.push(this._loadData());

return $.when.apply($, defs);
},
@@ -275,6 +266,27 @@ options.registry.WebsiteSaleProductsItem = options.Class.extend({

return this._super.apply(this, arguments);
},
/**
* @private
*/
_loadData: function () {
var self = this;
this._rpc({
model: 'product.style',
method: 'search_read',
}).then(function (data) {
var $ul = self.$el.find('[name="style"]');
for (var k in data) {
$ul.append(
$('<we-button data-style="' + data[k]['id'] + '" data-toggle-class="' + data[k]['html_class'] + '" data-color="' + data[k]['color'] + '"/>')
.append(data[k]['name'])
.append('<a href="#" class="o_wsale_soptions_add_edit_ribbon ml-2" data-edit="true"><i class="fa fa-edit"/></a>')
.append('<a href="#" class="o_wsale_soptions_remove_ribbon ml-2"><i class="fa fa-remove"/></a>')
);
}
self._setActive();
});
},

//--------------------------------------------------------------------------
// Handlers
@@ -331,6 +343,98 @@ options.registry.WebsiteSaleProductsItem = options.Class.extend({
},
}).then(reload);
},
/**
* @private
* @param {Event} ev
*/
_onAddNewOrEditRibbonClick: function (ev) {
var self = this;
var $currentTarget = $(ev.currentTarget);
var $weButton = $currentTarget.closest('we-button');
var editing = $currentTarget.data('edit');
ev.stopPropagation();
new Dialog(this, {
title: editing ? _t('Edit Ribbon Name') : _t('Add New Ribbon'),
$content: $(qweb.render('website_sale.dialog.addNewOrEditRibbon', {
currentName: $weButton.text(),
})),
buttons: [
{
text: _t('Save'),
classes: 'btn-primary',
click: function () {
var ribbonName = $('#ribbon_name').val();
if (ribbonName.length) {
$currentTarget.closest('we-collapse-area').find('we-button').remove();
this._rpc({
route: '/shop/add_edit_style',
params: {
'name': ribbonName,
'id': $weButton.data('style'),
'edit': editing,
// 'color':
},
}).then(function () {
self._loadData();
});
}
},
close: true,
},
{
text: _t('Discard'),
close: true,
},
],
}).open();
},
/**
* @private
* @param {Event} ev
*/
_onRemoveRibbonClick: function (ev) {
var self = this;
new Dialog(this, {
title: _t('Remove This Ribbon'),
$content: $(qweb.render('website_sale.dialog.removeRibbon')),
buttons: [
{
text: _t('Remove'),
classes: 'btn-danger',
click: function () {
var $weButton = $(ev.target).closest('we-button');
$weButton.remove();
this._rpc({
model: 'product.style',
method: 'unlink',
args: [$weButton.data('style')],
}).then(function () {
self._loadData();
});
},
close: true,
},
{
text: _t('Discard'),
close: true,
},
],
}).open();
},
/**
* @override
* @param {Event} ev
*/
_onLinkClick: function (ev) {
var $target = $(ev.target);
if ($target[0].nodeName === 'WE-BUTTON') {
this.$target.find('.ribbon-wrapper > a')
.text($target.text())
.removeClass('btn-danger') // to-do
.addClass($target.data('color'));
this._super.apply(this, arguments);
}
},
});

/**
@@ -60,4 +60,23 @@
</div>
</div>

<div t-name="website_sale.dialog.addNewOrEditRibbon">
<div class="form-group row">
<label for="ribbon_name" class="col-lg-auto col-form-label">
Choose a name for the ribbon
</label>
<div class="col">
<input type="text" id="ribbon_name" class="form-control" t-att-value="currentName"/>
</div>
</div>
</div>

<div t-name="website_sale.dialog.removeRibbon">
<div class="form-group row">
<label for="ppg_input" class="col-lg-auto col-form-label">
Are you sure to delete this ribbon ?
</label>
</div>
</div>

</templates>
@@ -100,7 +100,7 @@
<field name="public_categ_ids" widget="many2many_tags" string="Categories"/>
<field name="alternative_product_ids" widget="many2many_tags"/>
<field name="accessory_product_ids" widget="many2many_tags"/>
<field name="website_style_ids" widget="many2many_tags" groups="base.group_no_one"/>
<!-- <field name="website_style_ids" widget="many2many_tags" groups="base.group_no_one"/> -->
</group>
</group>
<group name="product_template_images" string="Extra Product Media">
@@ -81,6 +81,15 @@
<div data-js="WebsiteSaleProductsItem"
data-selector="#products_grid .oe_product"
data-no-check="true">
<we-collapse-area>
<we-toggler>Promote</we-toggler>
<we-collapse data-no-preview="true">
<we-button data-change-sequence="top">Push to top</we-button>
<we-button data-change-sequence="up">Push up</we-button>
<we-button data-change-sequence="down">Push down</we-button>
<we-button data-change-sequence="bottom">Push to bottom</we-button>
</we-collapse>
</we-collapse-area>
<we-collapse-area>
<we-toggler>Size</we-toggler>
<we-collapse class="o_wsale_soptions_menu_sizes">
@@ -101,18 +110,9 @@
</we-collapse>
</we-collapse-area>
<we-collapse-area>
<we-toggler>Styles</we-toggler>
<we-toggler>Ribbon <a href="#" class="o_wsale_soptions_add_edit_ribbon ml-2" data-edit="false"><i class="fa fa-plus-square"/></a></we-toggler>
<we-collapse data-no-preview="true" name="style"/>
</we-collapse-area>
<we-collapse-area>
<we-toggler>Promote</we-toggler>
<we-collapse data-no-preview="true">
<we-button data-change-sequence="top">Push to top</we-button>
<we-button data-change-sequence="up">Push up</we-button>
<we-button data-change-sequence="down">Push down</we-button>
<we-button data-change-sequence="bottom">Push to bottom</we-button>
</we-collapse>
</we-collapse-area>
</div>

<div data-js="ProductsSearchBar"
@@ -146,7 +146,7 @@
<div class="card-body p-1 oe_product_image">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()" />
<div class="ribbon-wrapper">
<a href="#" role="button" class="ribbon btn btn-danger">Sale</a>
<a href="#" role="button" t-attf-class="ribbon btn #{product.website_style_id.color}"><t t-esc="product.website_style_id.name"/></a>
</div>
<a t-att-href="product_href" class="d-block h-100" itemprop="url">
<span t-field="product.image_1920"

0 comments on commit 22edb83

Please sign in to comment.
You can’t perform that action at this time.