diff --git a/addons/website_sale/static/src/js/website_sale.editor.js b/addons/website_sale/static/src/js/website_sale.editor.js index 7fe3b3789c6..e5992e9664c 100644 --- a/addons/website_sale/static/src/js/website_sale.editor.js +++ b/addons/website_sale/static/src/js/website_sale.editor.js @@ -1,101 +1,107 @@ -(function() { - "use strict"; +odoo.define('website_sale.editor', ['web.ajax', 'web.core', 'web.Model', 'website.contentMenu', 'website.snippets.editor', 'website.website'], function (require) { +"use strict"; - var website = openerp.website; - var _t = openerp._t; +var ajax = require('web.ajax'); +var core = require('web.core'); +var Model = require('web.Model'); +var contentMenu = require('website.contentMenu'); +var snippet_editor = require('website.snippets.editor'); +var website = require('website.website'); - website.EditorBarContent.include({ - new_product: function() { - website.prompt({ - id: "editor_new_product", - window_title: _t("New Product"), - input: "Product Name", - }).then(function (name) { - website.form('/shop/add_product', 'POST', { - name: name +var _t = core._t; + + +contentMenu.EditorBarContent.include({ + new_product: function() { + website.prompt({ + id: "editor_new_product", + window_title: _t("New Product"), + input: "Product Name", + }).then(function (name) { + website.form('/shop/add_product', 'POST', { + name: name + }); + }); + }, +}); + +snippet_editor.options.website_sale = snippet_editor.Option.extend({ + start: function () { + var self = this; + this.product_tmpl_id = parseInt(this.$target.find('[data-oe-model="product.template"]').data('oe-id')); + + var size_x = parseInt(this.$target.attr("colspan") || 1); + var size_y = parseInt(this.$target.attr("rowspan") || 1); + + var $size = this.$el.find('ul[name="size"]'); + var $select = $size.find('tr:eq(0) td:lt('+size_x+')'); + if (size_y >= 2) $select = $select.add($size.find('tr:eq(1) td:lt('+size_x+')')); + if (size_y >= 3) $select = $select.add($size.find('tr:eq(2) td:lt('+size_x+')')); + if (size_y >= 4) $select = $select.add($size.find('tr:eq(3) td:lt('+size_x+')')); + $select.addClass("selected"); + + new Model('product.style') + .call('search_read', [[]]) + .then(function (data) { + var $ul = self.$el.find('ul[name="style"]'); + for (var k in data) { + $ul.append( + $('
  • ') + .append( $('').text(data[k]['name']) )); + } + self.set_active(); }); - }); - }, - }); - website.snippet.options.website_sale = website.snippet.Option.extend({ - start: function () { - var self = this; - this.product_tmpl_id = parseInt(this.$target.find('[data-oe-model="product.template"]').data('oe-id')); - - var size_x = parseInt(this.$target.attr("colspan") || 1); - var size_y = parseInt(this.$target.attr("rowspan") || 1); - - var $size = this.$el.find('ul[name="size"]'); - var $select = $size.find('tr:eq(0) td:lt('+size_x+')'); - if (size_y >= 2) $select = $select.add($size.find('tr:eq(1) td:lt('+size_x+')')); - if (size_y >= 3) $select = $select.add($size.find('tr:eq(2) td:lt('+size_x+')')); - if (size_y >= 4) $select = $select.add($size.find('tr:eq(3) td:lt('+size_x+')')); - $select.addClass("selected"); - - website.session.model('product.style') - .call('search_read', [[]]) - .then(function (data) { - var $ul = self.$el.find('ul[name="style"]'); - for (var k in data) { - $ul.append( - $('
  • ') - .append( $('').text(data[k]['name']) )); - } - self.set_active(); - }); - - this.bind_resize(); - }, - reload: function () { - if (location.href.match(/\?enable_editor/)) { - location.reload(); - } else { - location.href = location.href.replace(/\?(enable_editor=1&)?|#.*|$/, '?enable_editor=1&'); - } - }, - bind_resize: function () { - var self = this; - this.$el.on('mouseenter', 'ul[name="size"] table', function (event) { - $(event.currentTarget).addClass("oe_hover"); - }); - this.$el.on('mouseleave', 'ul[name="size"] table', function (event) { - $(event.currentTarget).removeClass("oe_hover"); - }); - this.$el.on('mouseover', 'ul[name="size"] td', function (event) { - var $td = $(event.currentTarget); - var $table = $td.closest("table"); - var x = $td.index()+1; - var y = $td.parent().index()+1; - - var tr = []; - for (var yi=0; yi'+ ' ' + data.warning + ''); } @@ -81,7 +86,7 @@ $('.oe_website_sale').each(function () { }); // change price when they are variants - $('form.js_add_cart_json label', oe_website_sale).on('mouseup touchend', function (ev) { + $('form.js_add_cart_json label', oe_website_sale).on('mouseup touchend', function () { var $label = $(this); var $price = $label.parents("form:first").find(".oe_price .oe_currency_value"); if (!$price.data("price")) { @@ -92,7 +97,7 @@ $('.oe_website_sale').each(function () { $price.html(value + (dec < 0.01 ? ".00" : (dec < 1 ? "0" : "") )); }); // hightlight selected color - $('.css_attribute_color input', oe_website_sale).on('change', function (ev) { + $('.css_attribute_color input', oe_website_sale).on('change', function () { $('.css_attribute_color').removeClass("active"); $('.css_attribute_color:has(input:checked)').addClass("active"); }); @@ -103,7 +108,7 @@ $('.oe_website_sale').each(function () { return price + (dec ? '' : '.0') + (dec%10 ? '' : '0'); } - $(oe_website_sale).on('change', 'input.js_product_change', function (ev) { + $(oe_website_sale).on('change', 'input.js_product_change', function () { var $parent = $(this).closest('.js_product'); $parent.find(".oe_default_price:first .oe_currency_value").html( price_to_str(+$(this).data('lst_price')) ); $parent.find(".oe_price:first .oe_currency_value").html(price_to_str(+$(this).data('price')) ); @@ -112,7 +117,7 @@ $('.oe_website_sale').each(function () { $img.attr("src", "/website/image/product.product/" + $(this).val() + "/image"); }); - $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change', function (ev) { + $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change', function () { var $ul = $(this).parents('ul.js_add_cart_variants:first'); var $parent = $ul.closest('.js_product'); var $product_id = $parent.find('input.product_id').first(); @@ -197,3 +202,5 @@ $('.oe_website_sale').each(function () { $(oe_website_sale).find("select[name='shipping_country_id']").change(); }); }); + +}); diff --git a/addons/website_sale/static/src/js/website_sale_payment.js b/addons/website_sale/static/src/js/website_sale_payment.js index 8ca1b85f907..6cbf0048c52 100644 --- a/addons/website_sale/static/src/js/website_sale_payment.js +++ b/addons/website_sale/static/src/js/website_sale_payment.js @@ -1,3 +1,8 @@ +odoo.define('website_sale.payment', ['web.ajax'], function (require) { +"use strict"; + +var ajax = require('web.ajax'); + $(document).ready(function () { // When choosing an acquirer, display its Pay Now button @@ -18,9 +23,11 @@ $(document).ready(function () { if (! acquirer_id) { return false; } - openerp.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}).then(function (data) { + ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {}).then(function () { $form.submit(); }); }); }); + +}); diff --git a/addons/website_sale/static/src/js/website_sale_tour_buy.js b/addons/website_sale/static/src/js/website_sale_tour_buy.js index 1235861ec15..74e0f653005 100644 --- a/addons/website_sale/static/src/js/website_sale_tour_buy.js +++ b/addons/website_sale/static/src/js/website_sale_tour_buy.js @@ -1,95 +1,98 @@ -(function () { - 'use strict'; - openerp.Tour.register({ - id: 'shop_buy_product', - name: "Try to buy products", - path: '/shop', - mode: 'test', - steps: [ - { - title: "search ipod", - element: 'form:has(input[name="search"]) a.a-submit', - onload: function() { - $('input[name="search"]').val("ipod"); - } - }, - { - title: "select ipod", - element: '.oe_product_cart a:contains("iPod")', - }, - { - title: "select ipod 32GB", - waitFor: '#product_detail', - element: 'label:contains(32 GB) input', - }, - { - title: "click on add to cart", - waitFor: 'label:contains(32 GB) input:propChecked', - element: '#product_detail form[action^="/shop/cart/update"] .btn', - }, - { - title: "add suggested", - waitNot: '#cart_products:contains("[A8767] Apple In-Ear Headphones")', - element: '.oe_cart a:contains("Add to Cart")', - }, - { - title: "add one more iPod", - waitFor: '.my_cart_quantity:contains(2)', - element: '#cart_products tr:contains("32 GB") a.js_add_cart_json:eq(1)', - }, - { - title: "remove Headphones", - waitFor: '#cart_products tr:contains("32 GB") input.js_quantity:propValue(2)', - element: '#cart_products tr:contains("Apple In-Ear Headphones") a.js_add_cart_json:first', - }, - { - title: "set one iPod", - waitNot: '#cart_products tr:contains("Apple In-Ear Headphones")', - element: '#cart_products input.js_quantity', - sampleText: '1', - }, - { - title: "go to checkout", - waitFor: '#cart_products input.js_quantity:propValue(1)', - element: 'a[href="/shop/checkout"]', - }, - { - title: "test with input error", - element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")', - onload: function (tour) { - $("input[name='phone']").val(""); - }, - }, - { - title: "test without input error", - waitFor: 'form[action="/shop/confirm_order"] .has-error', - element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")', - onload: function (tour) { - if ($("input[name='name']").val() === "") - $("input[name='name']").val("website_sale-test-shoptest"); - if ($("input[name='email']").val() === "") - $("input[name='email']").val("website_sale_test_shoptest@websitesaletest.odoo.com"); - $("input[name='phone']").val("123"); - $("input[name='street2']").val("123"); - $("input[name='city']").val("123"); - $("input[name='zip']").val("123"); - $("select[name='country_id']").val("21"); - }, - }, - { - title: "select payment", - element: '#payment_method label:has(img[title="Wire Transfer"]) input', - }, - { - title: "Pay Now", - waitFor: '#payment_method label:has(input:checked):has(img[title="Wire Transfer"])', - element: '.oe_sale_acquirer_button .btn[type="submit"]:visible', - }, - { - title: "finish", - waitFor: '.oe_website_sale:contains("Thank you for your order")', - } - ] - }); +odoo.define('website_sale.tour', ['web.Tour'], function (require) { +'use strict'; -}()); +var Tour = require('web.Tour'); + +Tour.register({ + id: 'shop_buy_product', + name: "Try to buy products", + path: '/shop', + mode: 'test', + steps: [ + { + title: "search ipod", + element: 'form:has(input[name="search"]) a.a-submit', + onload: function() { + $('input[name="search"]').val("ipod"); + } + }, + { + title: "select ipod", + element: '.oe_product_cart a:contains("iPod")', + }, + { + title: "select ipod 32GB", + waitFor: '#product_detail', + element: 'label:contains(32 GB) input', + }, + { + title: "click on add to cart", + waitFor: 'label:contains(32 GB) input:propChecked', + element: '#product_detail form[action^="/shop/cart/update"] .btn', + }, + { + title: "add suggested", + waitNot: '#cart_products:contains("[A8767] Apple In-Ear Headphones")', + element: '.oe_cart a:contains("Add to Cart")', + }, + { + title: "add one more iPod", + waitFor: '.my_cart_quantity:contains(2)', + element: '#cart_products tr:contains("32 GB") a.js_add_cart_json:eq(1)', + }, + { + title: "remove Headphones", + waitFor: '#cart_products tr:contains("32 GB") input.js_quantity:propValue(2)', + element: '#cart_products tr:contains("Apple In-Ear Headphones") a.js_add_cart_json:first', + }, + { + title: "set one iPod", + waitNot: '#cart_products tr:contains("Apple In-Ear Headphones")', + element: '#cart_products input.js_quantity', + sampleText: '1', + }, + { + title: "go to checkout", + waitFor: '#cart_products input.js_quantity:propValue(1)', + element: 'a[href="/shop/checkout"]', + }, + { + title: "test with input error", + element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")', + onload: function (tour) { + $("input[name='phone']").val(""); + }, + }, + { + title: "test without input error", + waitFor: 'form[action="/shop/confirm_order"] .has-error', + element: 'form[action="/shop/confirm_order"] .btn:contains("Confirm")', + onload: function (tour) { + if ($("input[name='name']").val() === "") + $("input[name='name']").val("website_sale-test-shoptest"); + if ($("input[name='email']").val() === "") + $("input[name='email']").val("website_sale_test_shoptest@websitesaletest.odoo.com"); + $("input[name='phone']").val("123"); + $("input[name='street2']").val("123"); + $("input[name='city']").val("123"); + $("input[name='zip']").val("123"); + $("select[name='country_id']").val("21"); + }, + }, + { + title: "select payment", + element: '#payment_method label:has(img[title="Wire Transfer"]) input', + }, + { + title: "Pay Now", + waitFor: '#payment_method label:has(input:checked):has(img[title="Wire Transfer"])', + element: '.oe_sale_acquirer_button .btn[type="submit"]:visible', + }, + { + title: "finish", + waitFor: '.oe_website_sale:contains("Thank you for your order")', + } + ] +}); + +}); diff --git a/addons/website_sale/static/src/js/website_sale_tour_shop.js b/addons/website_sale/static/src/js/website_sale_tour_shop.js index 7c613ed25d3..0af26b69b37 100644 --- a/addons/website_sale/static/src/js/website_sale_tour_shop.js +++ b/addons/website_sale/static/src/js/website_sale_tour_shop.js @@ -1,10 +1,14 @@ -(function () { - 'use strict'; +odoo.define('website_sale.tour_shop', ['web.core', 'web.Tour', 'website.website'], function (require) { +'use strict'; - var _t = openerp._t; - var website = openerp.website; - website.ready().done(function() { - openerp.Tour.register({ +var core = require('web.core'); +var Tour = require('web.Tour'); +var website = require('website.website'); + +var _t = core._t; + +website.ready().done(function () { + Tour.register({ id: 'shop', name: _t("Create a product"), steps: [ @@ -108,6 +112,6 @@ }, ] }); - }); +}); -}()); +}); diff --git a/addons/website_sale/static/src/js/website_sale_tracking.js b/addons/website_sale/static/src/js/website_sale_tracking.js index 8ff5a5ac789..9de9edbd302 100644 --- a/addons/website_sale/static/src/js/website_sale_tracking.js +++ b/addons/website_sale/static/src/js/website_sale_tracking.js @@ -1,14 +1,18 @@ +odoo.define('website_sale.tracking', function(require) { + +var ajax = require('web.ajax'); + $(document).ready(function () { // Watching a product if ($("#product_detail.oe_website_sale").length) { - prod_id = $("input[name='product_id']").attr('value'); + var prod_id = $("input[name='product_id']").attr('value'); vpv("/stats/ecom/product_view/" + prod_id); } // Add a product into the cart $(".oe_website_sale form[action='/shop/cart/update'] a.a-submit").on('click', function(o) { - prod_id = $("input[name='product_id']").attr('value'); + var prod_id = $("input[name='product_id']").attr('value'); vpv("/stats/ecom/product_add_to_cart/" + prod_id); }); @@ -36,10 +40,10 @@ $(document).ready(function () { if ($(".oe_website_sale div.oe_cart div.oe_website_sale_tx_status").length) { track_ga('require', 'ecommerce'); - order_id = $(".oe_website_sale div.oe_cart div.oe_website_sale_tx_status").data("order-id"); + var order_id = $(".oe_website_sale div.oe_cart div.oe_website_sale_tx_status").data("order-id"); vpv("/stats/ecom/order_confirmed/" + order_id); - openerp.jsonRpc("/shop/tracking_last_order/").then(function(o) { + ajax.jsonRpc("/shop/tracking_last_order/").then(function(o) { track_ga('ecommerce:clear'); if (o.transaction && o.lines) { @@ -65,3 +69,5 @@ $(document).ready(function () { } }); + +}); diff --git a/addons/website_sale/static/src/js/website_sale_validate.js b/addons/website_sale/static/src/js/website_sale_validate.js index 25974a1936e..17b9f45a3f7 100644 --- a/addons/website_sale/static/src/js/website_sale_validate.js +++ b/addons/website_sale/static/src/js/website_sale_validate.js @@ -1,3 +1,8 @@ +odoo.define('website_sale.validate', ['web.ajax'], function(require) { +"use strict"; + +var ajax = require('web.ajax'); + $(document).ready(function () { var _poll_nbr = 0; @@ -8,7 +13,7 @@ $(document).ready(function () { return; } var order_id = order_node.data('order-id'); - return openerp.jsonRpc('/shop/payment/get_status/' + order_id, 'call', { + return ajax.jsonRpc('/shop/payment/get_status/' + order_id, 'call', { }).then(function (result) { _poll_nbr += 1; if(result.recall && _poll_nbr <= 5){ @@ -20,3 +25,5 @@ $(document).ready(function () { payment_transaction_poll_status(); }); + +}); diff --git a/addons/website_sale_options/static/src/js/website_sale.js b/addons/website_sale_options/static/src/js/website_sale.js index 871babd6550..20d2231c004 100644 --- a/addons/website_sale_options/static/src/js/website_sale.js +++ b/addons/website_sale_options/static/src/js/website_sale.js @@ -1,78 +1,86 @@ +odoo.define('website_sale.website_sale', ['web.ajax', 'website.website'], function(require) { +"use strict"; + +var ajax = require('web.ajax'); +var website = require('website.website'); + $(document).ready(function () { - $('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit') - .off('click') - .removeClass('a-submit') - .click(function (event) { - var $form = $(this).closest('form'); - var quantity = parseFloat($form.find('input[name="add_qty"]').val() || 1); - var product_id = parseInt($form.find('input[type="hidden"][name="product_id"], input[type="radio"][name="product_id"]:checked').first().val(),10); - event.preventDefault(); - openerp.jsonRpc("/shop/modal", 'call', { - 'product_id': product_id, - kwargs: { - context: openerp.website.get_context() - }, - }).then(function (modal) { - var $modal = $(modal); +$('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit') + .off('click') + .removeClass('a-submit') + .click(function (event) { + var $form = $(this).closest('form'); + var quantity = parseFloat($form.find('input[name="add_qty"]').val() || 1); + var product_id = parseInt($form.find('input[type="hidden"][name="product_id"], input[type="radio"][name="product_id"]:checked').first().val(),10); + event.preventDefault(); + ajax.jsonRpc("/shop/modal", 'call', { + 'product_id': product_id, + kwargs: { + context: website.get_context() + }, + }).then(function (modal) { + var $modal = $(modal); - $modal.find('img:first').attr("src", "/website/image/product.product/" + product_id + "/image_medium"); + $modal.find('img:first').attr("src", "/website/image/product.product/" + product_id + "/image_medium"); - $modal.appendTo($form) - .modal() - .on('hidden.bs.modal', function () { - $(this).remove(); - }); + $modal.appendTo($form) + .modal() + .on('hidden.bs.modal', function () { + $(this).remove(); + }); - $modal.on('click', '.a-submit', function () { - var $a = $(this); - $form.ajaxSubmit({ - url: '/shop/cart/update_option', - success: function (quantity) { - if (!$a.hasClass('js_goto_shop')) { - window.location.href = window.location.href.replace(/shop([\/?].*)?$/, "shop/cart"); - } - var $q = $(".my_cart_quantity"); - $q.parent().parent().removeClass("hidden", !quantity); - $q.html(quantity).hide().fadeIn(600); + $modal.on('click', '.a-submit', function () { + var $a = $(this); + $form.ajaxSubmit({ + url: '/shop/cart/update_option', + success: function (quantity) { + if (!$a.hasClass('js_goto_shop')) { + window.location.href = window.location.href.replace(/shop([\/?].*)?$/, "shop/cart"); } - }); - $modal.modal('hide'); - }); - - $modal.on("click", "a.js_add, a.js_remove", function (event) { - event.preventDefault(); - var $parent = $(this).parents('.js_product:first'); - $parent.find("a.js_add, span.js_remove").toggleClass("hidden"); - $parent.find("input.js_optional_same_quantity").val( $(this).hasClass("js_add") ? 1 : 0 ); - var $remove = $parent.find(".js_remove"); - }); - - $modal.on("change", "input.js_quantity", function (event) { - var qty = parseFloat($(this).val()); - if (qty === 1) { - $(".js_remove .js_items").addClass("hidden"); - $(".js_remove .js_item").removeClass("hidden"); - } else { - $(".js_remove .js_items").removeClass("hidden").text($(".js_remove .js_items:first").text().replace(/[0-9.,]+/, qty)); - $(".js_remove .js_item").addClass("hidden"); + var $q = $(".my_cart_quantity"); + $q.parent().parent().removeClass("hidden", !quantity); + $q.html(quantity).hide().fadeIn(600); } }); - - $modal.find('input[name="add_qty"]').val(quantity).change(); - $('ul.js_add_cart_variants').each(function () { - $('input.js_variant_change, select.js_variant_change', this).first().trigger('change'); - }); + $modal.modal('hide'); }); - return false; - }); - - - $('#cart_products input.js_quantity').change(function () { - var value = $(this).val(); - var $next = $(this).closest('tr').next('.optional_product'); - while($next.length) { - $next.find('.js_quantity').text(value); - $next = $next.next('.optional_product'); - } + + $modal.on("click", "a.js_add, a.js_remove", function (event) { + event.preventDefault(); + var $parent = $(this).parents('.js_product:first'); + $parent.find("a.js_add, span.js_remove").toggleClass("hidden"); + $parent.find("input.js_optional_same_quantity").val( $(this).hasClass("js_add") ? 1 : 0 ); + var $remove = $parent.find(".js_remove"); + }); + + $modal.on("change", "input.js_quantity", function () { + var qty = parseFloat($(this).val()); + if (qty === 1) { + $(".js_remove .js_items").addClass("hidden"); + $(".js_remove .js_item").removeClass("hidden"); + } else { + $(".js_remove .js_items").removeClass("hidden").text($(".js_remove .js_items:first").text().replace(/[0-9.,]+/, qty)); + $(".js_remove .js_item").addClass("hidden"); + } + }); + + $modal.find('input[name="add_qty"]').val(quantity).change(); + $('ul.js_add_cart_variants').each(function () { + $('input.js_variant_change, select.js_variant_change', this).first().trigger('change'); + }); + }); + return false; }); + + +$('#cart_products input.js_quantity').change(function () { + var value = $(this).val(); + var $next = $(this).closest('tr').next('.optional_product'); + while($next.length) { + $next.find('.js_quantity').text(value); + $next = $next.next('.optional_product'); + } +}); +}); + }); diff --git a/addons/website_sale_options/static/src/js/website_sale.test.js b/addons/website_sale_options/static/src/js/website_sale.test.js index 976af2fa304..e7d63e23401 100644 --- a/addons/website_sale_options/static/src/js/website_sale.test.js +++ b/addons/website_sale_options/static/src/js/website_sale.test.js @@ -1,94 +1,99 @@ -(function () { - 'use strict'; - var _t = openerp._t; - var steps = openerp.Tour.tours.shop_buy_product.steps; - for (var k=0; k