From 598da7b1d1041bc7c4cf0f241f47b39041b1a857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=C3=ADaz?= Date: Fri, 23 Aug 2019 14:18:58 +0200 Subject: [PATCH] [FIX] website_apps_store: Javascript WebsiteSale --- website_apps_store/controllers/main.py | 20 -- website_apps_store/models/product_template.py | 38 +++ website_apps_store/static/src/css/main.scss | 5 + .../static/src/js/website_apps_store_tour.js | 143 +++++------ .../static/src/js/website_sale.js | 236 +++++------------- website_apps_store/views/templates.xml | 60 ++--- 6 files changed, 209 insertions(+), 293 deletions(-) diff --git a/website_apps_store/controllers/main.py b/website_apps_store/controllers/main.py index 5a48f8e..7968d60 100644 --- a/website_apps_store/controllers/main.py +++ b/website_apps_store/controllers/main.py @@ -149,26 +149,6 @@ def shop(self, page=0, category=None, search='', ppg=False, **post): }) return res - @http.route(['/shop/change_attribute_version'], type='json', - auth="public", website=True) - def change_product_attribute_version(self, **kwargs): - product_id = kwargs.get('product_id', False) - product = request.env['product.product'].sudo().browse(product_id) - vals = { - 'name_product': product.name, - 'technical_name': - product.odoo_module_version_id.module_id.technical_name, - 'license': product.app_license_id.name, - 'license_url': product.app_license_id.website, - 'author': ', '.join( - author.name for author in product.app_author_ids), - 'website': product.app_website, - 'repository': product.app_github_url, - 'rst_html': product.app_description_rst_html, - 'app_summary': product.app_summary, - } - return vals - def validate_recaptcha(self, captcha): """ Function for validating Recaptcha """ captcha_obj = request.env['website.form.recaptcha'] diff --git a/website_apps_store/models/product_template.py b/website_apps_store/models/product_template.py index 79caf47..6b997ca 100644 --- a/website_apps_store/models/product_template.py +++ b/website_apps_store/models/product_template.py @@ -24,3 +24,41 @@ def get_version_info(self): products = self.product_variant_ids.sorted( lambda a: a.attribute_value_ids.sequence, reverse=True) return products[0] + + @api.multi + def _get_combination_info(self, combination=False, product_id=False, + add_qty=1, pricelist=False, + parent_combination=False, only_template=False): + vals = super()._get_combination_info( + combination=combination, product_id=product_id, add_qty=add_qty, + pricelist=pricelist, parent_combination=parent_combination, + only_template=only_template) + if not vals['product_id']: + return vals + product = self.env['product.product'].browse(vals['product_id']) + if product.odoo_module_id: + vals.update({ + 'is_odoo_module': True, + 'name_product': product.name, + 'technical_name': + product.odoo_module_version_id.module_id.technical_name, + 'license': product.app_license_id.name, + 'license_url': product.app_license_id.website, + 'author': ', '.join( + author.name for author in product.app_author_ids), + 'website': product.app_website, + 'repository': product.app_github_url, + 'rst_html': product.app_description_rst_html, + 'app_summary': product.app_summary, + }) + return vals + + @api.multi + def _get_first_possible_combination(self, parent_combination=None, + necessary_values=None): + """Override method to load last version first in app store""" + values = list(self._get_possible_combinations( + parent_combination, necessary_values)) + if not any(values): + return self.env['product.template.attribute.value'] + return values[-1] diff --git a/website_apps_store/static/src/css/main.scss b/website_apps_store/static/src/css/main.scss index 0793914..95f95c7 100644 --- a/website_apps_store/static/src/css/main.scss +++ b/website_apps_store/static/src/css/main.scss @@ -12,3 +12,8 @@ max-height: 15rem; overflow-y: auto; } + +#product_details .col-form-label { + padding-top: 0; + padding-bottom: 0; +} diff --git a/website_apps_store/static/src/js/website_apps_store_tour.js b/website_apps_store/static/src/js/website_apps_store_tour.js index b1f66e3..6d6ff5a 100644 --- a/website_apps_store/static/src/js/website_apps_store_tour.js +++ b/website_apps_store/static/src/js/website_apps_store_tour.js @@ -1,106 +1,101 @@ odoo.define('website_apps_store.tour_custom', function (require) { -'use strict'; + 'use strict'; -var Tour = require("web_tour.tour"); -var base = require("web_editor.base"); + var Tour = require("web_tour.tour"); + var base = require("web_editor.base"); Tour.register('download_zip', { name: "Download Zip File", url: '/shop/page/2', test: true, - wait_for: base.ready() - },[ - { - content: "Shop", - trigger: ".oe_product_cart a:contains('Odoo Module 1')" + wait_for: base.ready(), + }, [ + { + content: "Shop", + trigger: ".oe_product_cart a:contains('Odoo Module 1')", + }, + { + content: "Select Version", + trigger: "input[type=radio]", + run: function () { + $('input[type=radio]:last').attr("checked", "checked"); }, - { - content: "Select Version", - trigger: "input[type=radio]", - run: function(){ - $('input[type=radio]:last').attr("checked", "checked"); - } - }, - { - content: "Download", - trigger: "button:contains(Download)" - } - ] - ); + }, + { + content: "Download", + trigger: "button:contains(Download)", + }, + ]); Tour.register('select_version_search', { name: "Select Version", url: '/shop', test: true, - wait_for: base.ready() - },[ - { - content: "Shop", - trigger: ".dropdown_version_by a.dropdown-toggle" - }, - { - content: "Select Version", - trigger: ".dropdown_version_by .dropdown-menu a:contains('10.0')", - }, - ] - ); + wait_for: base.ready(), + }, [ + { + content: "Shop", + trigger: ".dropdown_version_by a.dropdown-toggle", + }, + { + content: "Select Version", + trigger: ".dropdown_version_by .dropdown-menu a:contains('10.0')", + }, + ]); Tour.register('select_category_search', { name: "Select Category", url: '/shop', test: true, - wait_for: base.ready() - },[ - { - content: "Shop", - trigger: ".dropdown_category_by a.dropdown-toggle" - }, - { - content: "Select Category", - trigger: ".dropdown_category_by .dropdown-menu a:contains('Category1')", - }, - ] - ); + wait_for: base.ready(), + }, [ + { + content: "Shop", + trigger: ".dropdown_category_by a.dropdown-toggle", + }, + { + content: "Select Category", + trigger: + ".dropdown_category_by .dropdown-menu a:contains('Category1')", + }, + ]); Tour.register('module_search', { name: "Select Product(Module)", url: '/shop', test: true, - wait_for: base.ready() - },[ - { - content: "Shop", - trigger: ".search-query", - run: function(){ - $('.search-query').attr('value', 'Test'); - } - }, - { - content: "Search Button", - trigger: ".oe_search_button", + wait_for: base.ready(), + }, [ + { + content: "Shop", + trigger: ".search-query", + run: function () { + $('.search-query').attr('value', 'Test'); }, - ] - ); + }, + { + content: "Search Button", + trigger: ".oe_search_button", + }, + ]); Tour.register('technical_name_search', { name: "Select Product(Module) by Technical Name", url: '/shop', test: true, - wait_for: base.ready() - },[ - { - content: "Shop", - trigger: ".search-query", - run: function(){ - $('.search-query').attr('value', 'odoo_module1'); - } + wait_for: base.ready(), + }, [ + { + content: "Shop", + trigger: ".search-query", + run: function () { + $('.search-query').attr('value', 'odoo_module1'); }, - { - content: "Search Button", - trigger: ".oe_search_button", - }, - ] - ); - + }, + { + content: "Search Button", + trigger: ".oe_search_button", + }, + ]); }); diff --git a/website_apps_store/static/src/js/website_sale.js b/website_apps_store/static/src/js/website_sale.js index cd1eebd..90071df 100644 --- a/website_apps_store/static/src/js/website_sale.js +++ b/website_apps_store/static/src/js/website_sale.js @@ -1,3 +1,4 @@ +/* global grecaptcha */ /** * Copyright 2018 BizzAppDev * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -7,182 +8,79 @@ odoo.define('website_apps_store.website_sale', function (require) { 'use strict'; require('web.dom_ready'); - var base = require("web_editor.base"); var ajax = require('web.ajax'); - var utils = require('web.utils'); - var core = require('web.core'); - var config = require('web.config'); - require("website.content.zoomodoo"); - var _t = core._t; - - - $('.oe_website_sale').each(function () { - var oe_website_sale = this; - var $product_global; - - function price_to_str(price) { - var l10n = _t.database.parameters; - var precision = 2; - - if ($(".decimal_precision").length) { - precision = parseInt($(".decimal_precision").last().data('precision')); - } - var formatted = _.str.sprintf('%.' + precision + 'f', price).split('.'); - formatted[0] = utils.insert_thousand_seps(formatted[0]); - return formatted.join(l10n.decimal_point); - } - - - function update_product_image(event_source, product_id) { - var $img; - if ($('#o-carousel-product').length) { - $img = $(event_source).closest('tr.js_product, .oe_website_sale').find('img.js_variant_img'); - $img.attr("src", "/web/image/product.product/" + product_id + "/image"); - $img.parent().attr('data-oe-model', 'product.product').attr('data-oe-id', product_id) - .data('oe-model', 'product.product').data('oe-id', product_id); - - var $thumbnail = $(event_source).closest('tr.js_product, .oe_website_sale').find('img.js_variant_img_small'); - if ($thumbnail.length !== 0) { // if only one, thumbnails are not displayed - $thumbnail.attr("src", "/web/image/product.product/" + product_id + "/image/90x90"); - $('.carousel').carousel(0); + var sAnimations = require('website.content.snippets.animation'); + var WebsiteSale = sAnimations.registry.WebsiteSale; + + WebsiteSale.include({ + read_events: _.extend({}, WebsiteSale.prototype.read_events, { + 'click #download_zip': '_onClickDownload', + }), + + init: function () { + this._super.apply(this, arguments); + var $captchas = $('.o_website_form_recaptcha'); + ajax.post('/website/recaptcha/', {}).then( + function (result) { + var data = JSON.parse(result); + $captchas.append($( + '
' + )); + if ($captchas.length) { + $.getScript('https://www.google.com/recaptcha/api.js'); + } } + ); + }, + + _onChangeCombination: function (ev, $parent, combination) { + this._super.apply(this, arguments); + if ('is_odoo_module' in combination && combination.is_odoo_module) { + var $tech_deatil = this.$(".tech_deatil"); + var $license_detail = this.$(".license_detail"); + var $license_url = this.$(".license_url"); + var $author_detail = this.$(".author_detail"); + var $website_detail = this.$(".website_detail"); + var $repo_detail = this.$(".repo_detail"); + var $rst_html = this.$(".desc_rst"); + var $app_summary = this.$(".app_summary"); + var $name_product = this.$(".name_product"); + + $tech_deatil.text(combination.technical_name); + $license_detail.text(combination.license); + $license_url.attr('href', combination.license_url); + $author_detail.text(combination.author); + $website_detail.text(combination.website); + $repo_detail.text(combination.repository); + $repo_detail.parent()[0].href = combination.repository; + $rst_html.html(combination.rst_html); + $app_summary.text(combination.app_summary); + $name_product.text(combination.name_product); } - else { - $img = $(event_source).closest('tr.js_product, .oe_website_sale').find('span[data-oe-model^="product."][data-oe-type="image"] img:first, img.product_detail_img'); - $img.attr("src", "/web/image/product.product/" + product_id + "/image"); - $img.parent().attr('data-oe-model', 'product.product').attr('data-oe-id', product_id) - .data('oe-model', 'product.product').data('oe-id', product_id); - } - // reset zooming constructs - $img.filter('[data-zoom-image]').attr('data-zoom-image', $img.attr('src')); - if ($img.data('zoomOdoo') !== undefined) { - $img.data('zoomOdoo').isReady = false; + }, + + _onClickDownload: function (ev) { + var $product_template_id = this.$('.product_template_id'); + var product_template_id = $product_template_id.val(); + var $product_id = this.$('.product_id'); + var product_id = $product_id.val(); + ev.preventDefault(); + var google_captcha = $('#g-recaptcha-response').val(); + if (!google_captcha) { + return; } - } - - $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change, ul[data-attribute_value_ids]', function (ev) { - var $ul = $(ev.target).closest('.js_add_cart_variants'); - var $parent = $ul.closest('.js_product'); - var $product_id = $parent.find('.product_id').first(); - var $price = $parent.find(".oe_price:first .oe_currency_value"); - var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); - var $tech_deatil = $(".tech_deatil"); - var $license_detail = $(".license_detail"); - var $license_url = $(".license_url"); - var $author_detail = $(".author_detail"); - var $website_detail = $(".website_detail"); - var $repo_detail = $(".repo_detail"); - var $rst_html = $(".desc_rst"); - var $app_summary = $(".app_summary"); - var $name_product = $(".name_product"); - var $optional_price = $parent.find(".oe_optional:first .oe_currency_value"); - var variant_ids = $ul.data("attribute_value_ids"); - if(_.isString(variant_ids)) { - variant_ids = JSON.parse(variant_ids.replace(/'/g, '"')); - } - var values = []; - var unchanged_values = $parent.find('div.oe_unchanged_value_ids').data('unchanged_value_ids') || []; - - $parent.find('input.js_variant_change:checked, select.js_variant_change').each(function () { - values.push(+$(this).val()); - }); - values = values.concat(unchanged_values); - - $parent.find("label").removeClass("text-muted css_not_available"); - - var product_id = false; - for (var k in variant_ids) { - if (_.isEmpty(_.difference(variant_ids[k][1], values))) { - $.when(base.ready()).then(function() { - $price.html(price_to_str(variant_ids[k][2])); - $default_price.html(price_to_str(variant_ids[k][3])); - }); - if (variant_ids[k][3]-variant_ids[k][2]>0.01) { - $default_price.closest('.oe_website_sale').addClass("discount"); - $optional_price.closest('.oe_optional').show().css('text-decoration', 'line-through'); - $default_price.parent().removeClass('hidden'); - } else { - $optional_price.closest('.oe_optional').hide(); - $default_price.parent().addClass('hidden'); - } - product_id = variant_ids[k][0]; - $product_global = product_id; - update_product_image(this, product_id); - ajax.jsonRpc("/shop/change_attribute_version", 'call', { - 'product_id': product_id, - }).then(function (data) { - if(data){ - $tech_deatil.text(data['technical_name']); - $license_detail.text(data['license']); - $('.license_url').attr('href', data['license_url']); - $author_detail.text(data['author']); - $website_detail.text(data['website']); - $repo_detail.text(data['repository']); - $repo_detail.parent()[0].href = data['repository']; - $rst_html.html(data['rst_html']); - $app_summary.text(data['app_summary']); - $name_product.text(data['name_product']); - } - }); - break; - } + if (typeof grecaptcha !== 'undefined') { + grecaptcha.reset(); } - - $parent.find("input.js_variant_change:radio, select.js_variant_change").each(function () { - var $input = $(this); - var id = +$input.val(); - var values = [id]; - - $parent.find("ul:not(:has(input.js_variant_change[value='" + id + "'])) input.js_variant_change:checked, select.js_variant_change").each(function () { - values.push(+$(this).val()); - }); - - for (var k in variant_ids) { - if (!_.difference(values, variant_ids[k][1]).length) { - return; - } - } - $input.closest("label").addClass("css_not_available"); - $input.find("option[value='" + id + "']").addClass("css_not_available"); - }); - if (product_id) { - $parent.removeClass("css_not_available"); - $product_id.val(product_id); - $parent.find("#add_to_cart").removeClass("disabled"); + window.location.href = "/shop/download_product_zip/" + + product_template_id + '/' + product_id + '/' + + google_captcha; } else { - $parent.addClass("css_not_available"); - $product_id.val(0); - $parent.find("#add_to_cart").addClass("disabled"); - } - }); - - $('#download_zip').on('click', function(ev){ - var product_template_id = $(this).data('tmpl-id'); - ev.preventDefault(); - var google_captcha = $('#g-recaptcha-response').val(); - if (!google_captcha) - return ; - if (grecaptcha !== 'undefined'){ - grecaptcha.reset(); - } - if ($product_global){ - window.location.href = "/shop/download_product_zip/" + product_template_id + '/' + $product_global + '/' + google_captcha; - }else{ - window.location.href = "/shop/download_product_zip/" + product_template_id + '/' + google_captcha; - } - }); - var $captchas = $('.o_website_form_recaptcha'); - ajax.post('/website/recaptcha/', {}).then( - function (result) { - var data = JSON.parse(result); - $captchas.append($( - '
' - )); - if ($captchas.length) { - $.getScript('https://www.google.com/recaptcha/api.js'); - } + window.location.href = "/shop/download_product_zip/" + + product_template_id + '/' + google_captcha; } - ); + }, }); }); diff --git a/website_apps_store/views/templates.xml b/website_apps_store/views/templates.xml index 8b91cf6..0fcc33f 100644 --- a/website_apps_store/views/templates.xml +++ b/website_apps_store/views/templates.xml @@ -194,79 +194,79 @@ -
-
-
-
+
+
+
+
Technical Name:
-
+
-
-
-
+
+
+
Version:
-
+
-
-
-
+
+
+
License:
-
+
-
-
-
+
+
+
Author:
-
+
-
-
-
+
+ -
-
-
+
+
+
Website:
-
+
-
-
-
+
+
+
Repository:
-
+
@@ -294,7 +294,7 @@ - +