From 65586f8ef35aa6d7899b23c0b5f041f352caad1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 10 Mar 2015 08:51:40 +0100 Subject: [PATCH] [REF] website_slides: update to the new module system --- addons/website_slides/static/src/js/slides.js | 47 ++++++++++++------- .../static/src/js/slides_embed.js | 18 ++++--- .../static/src/js/slides_upload.js | 38 +++++++++------ 3 files changed, 63 insertions(+), 40 deletions(-) diff --git a/addons/website_slides/static/src/js/slides.js b/addons/website_slides/static/src/js/slides.js index 855b7296ca0..00b89aaa940 100644 --- a/addons/website_slides/static/src/js/slides.js +++ b/addons/website_slides/static/src/js/slides.js @@ -1,18 +1,23 @@ -/*global $, openerp, _, PDFJS */ +/*global $, _, PDFJS */ +odoo.define('website_slides.slides', ['web.ajax', 'web.core', 'web.time', 'web.Widget'], function (require) { +"use strict"; + +var ajax = require('web.ajax'); +var core = require('web.core'); +var time = require('web.time'); +var Widget = require('web.Widget'); + +var _t = core._t; +var page_widgets = {}; + $(document).ready(function () { - "use strict"; - - var website = openerp.website; - var _t = openerp._t; var widget_parent = $('body'); - website.slide = {}; - website.slide.page_widgets = {}; $("timeago.timeago").each(function (index, el) { var datetime = $(el).attr('datetime'), - datetime_obj = openerp.str_to_datetime(datetime), + datetime_obj = time.str_to_datetime(datetime), // if presentation 7 days, 24 hours, 60 min, 60 second, 1000 millis old(one week) // then return fix formate string else timeago display_str = ""; @@ -27,7 +32,7 @@ $(document).ready(function () { /* * Like/Dislike Buttons Widget */ - website.slide.LikeButton = openerp.Widget.extend({ + var LikeButton = Widget.extend({ setElement: function($el){ this._super.apply(this, arguments); this.$el.on('click', this, _.bind(this.apply_action, this)); @@ -43,7 +48,7 @@ $(document).ready(function () { }else{ var target = button.find('.fa'); if (localStorage['slide_vote_' + slide_id] !== user_id.toString()) { - openerp.jsonRpc(href, 'call', {slide_id: slide_id}).then(function (data) { + ajax.jsonRpc(href, 'call', {slide_id: slide_id}).then(function (data) { target.text(data); localStorage['slide_vote_' + slide_id] = user_id; }); @@ -65,13 +70,13 @@ $(document).ready(function () { }, }); - website.slide.page_widgets['likeButton'] = new website.slide.LikeButton(widget_parent).setElement($('.oe_slide_js_like')); - website.slide.page_widgets['dislikeButton'] = new website.slide.LikeButton(widget_parent).setElement($('.oe_slide_js_unlike')); + page_widgets['likeButton'] = new LikeButton(widget_parent).setElement($('.oe_slide_js_like')); + page_widgets['dislikeButton'] = new LikeButton(widget_parent).setElement($('.oe_slide_js_unlike')); /* * Embedded Code Widget */ - website.slide.SlideSocialEmbed = openerp.Widget.extend({ + var SlideSocialEmbed = Widget.extend({ events: { 'change input' : 'change_page', }, @@ -99,24 +104,24 @@ $(document).ready(function () { // TODO : make it work. For now, once the iframe is loaded, the value of #page_count is // still now set (the pdf is still loading) var max_page = $('iframe').contents().find('#page_count').val(); - var slide_social_embed = new website.slide.SlideSocialEmbed($(this), max_page).setElement($('.oe_slide_js_embed_code_widget')); + new SlideSocialEmbed($(this), max_page).setElement($('.oe_slide_js_embed_code_widget')); }); /* * Send by email Widget */ - website.slide.ShareMail = openerp.Widget.extend({ + var ShareMail = Widget.extend({ events: { 'click button' : 'send_mail', }, - send_mail: function(ev){ + send_mail: function(){ var self = this; var input = this.$('input'); var slide_id = this.$('button').data('slide-id'); if(input.val() && input[0].checkValidity()){ this.$el.removeClass('has-error'); - openerp.jsonRpc('/slides/slide/send_share_email', 'call', { + ajax.jsonRpc('/slides/slide/send_share_email', 'call', { slide_id: slide_id, email: input.val(), }).then(function () { @@ -129,7 +134,7 @@ $(document).ready(function () { }, }); - website.slide.page_widgets['share_mail'] = new website.slide.ShareMail(widget_parent).setElement($('.oe_slide_js_share_email')); + page_widgets['share_mail'] = new ShareMail(widget_parent).setElement($('.oe_slide_js_share_email')); /* * Social Sharing Statistics Widget @@ -182,3 +187,9 @@ $(document).ready(function () { }); } }); + +return { + page_widgets: page_widgets, +}; + +}); diff --git a/addons/website_slides/static/src/js/slides_embed.js b/addons/website_slides/static/src/js/slides_embed.js index 69c94f7e94c..3184780e691 100644 --- a/addons/website_slides/static/src/js/slides_embed.js +++ b/addons/website_slides/static/src/js/slides_embed.js @@ -1,4 +1,6 @@ -/*global $, _, PDFJS, PDFSlidesViewer, Bootstrap */ +/*global $, _, PDFSlidesViewer*/ +odoo.define('website_slides.slides_embed', [], function (require) { + /** This file is a minimal version of the PDFViewer widget. @@ -25,7 +27,7 @@ $(document).ready(function () { this.pdf_viewer.loadDocument().then(function(file_content){ self.on_loaded_file(); }); - } + }; EmbeddedViewer.prototype.__proto__ = { // jquery inside the object (like openerp.Widget) $: function(selector){ @@ -50,7 +52,7 @@ $(document).ready(function () { render_page: function (page_number) { this.pdf_viewer.renderPage(page_number).then(this.on_rendered_page); }, - change_page: function (ev) { + change_page: function () { var page_asked = parseInt(this.$('#page_number').val(), 10); if(1 <= page_asked && page_asked <= this.pdf_viewer.pdf_page_total){ this.pdf_viewer.changePage(page_asked).then(this.on_rendered_page); @@ -59,7 +61,7 @@ $(document).ready(function () { this.$('#page_number').val(this.pdf_viewer.pdf_page_current); } }, - next: function (ev) { + next: function () { var self = this; this.pdf_viewer.nextPage().then(function(page_num){ if(page_num){ @@ -105,7 +107,7 @@ $(document).ready(function () { }; // embedded pdf viewer - embedded_viewer = new EmbeddedViewer($('#PDFViewer')); + var embedded_viewer = new EmbeddedViewer($('#PDFViewer')); // bind the actions $('#previous').on('click', function(){ @@ -181,7 +183,7 @@ $(document).ready(function () { url: '/slides/slide/send_share_email', contentType: "application/json; charset=utf-8", data: JSON.stringify({'jsonrpc': "2.0", 'method': "call", "params": {'slide_id': slide_id, 'email': input.val()}}), - success: function (data) { + success: function () { widget.html($('')); }, error: function(data){ @@ -194,4 +196,6 @@ $(document).ready(function () { } }); } -}); \ No newline at end of file +}); + +}); diff --git a/addons/website_slides/static/src/js/slides_upload.js b/addons/website_slides/static/src/js/slides_upload.js index 0ffed1ccb0e..90c962c2cba 100644 --- a/addons/website_slides/static/src/js/slides_upload.js +++ b/addons/website_slides/static/src/js/slides_upload.js @@ -1,14 +1,20 @@ -/*global $, openerp, _, PDFJS */ +/*global $, _, PDFJS */ +odoo.define('website_slides.upload', ['web.ajax', 'web.core', 'web.Widget', 'website.website', 'website_slides.slides'], function (require) { +"use strict"; + +var ajax = require('web.ajax'); +var core = require('web.core'); +var Widget = require('web.Widget'); +var website = require('website.website'); +var slides = require('website_slides.slides'); + +var _t = core._t; + $(document).ready(function () { - "use strict"; + website.add_template_file('/website_slides/static/src/xml/website_slides.xml'); - var website = openerp.website; - var _t = openerp._t; - - website.slide.template = website.add_template_file('/website_slides/static/src/xml/website_slides.xml'); - - website.slide.Dialog = openerp.Widget.extend({ + var SlideDialog = Widget.extend({ template: 'website.slide.upload', events: { 'hidden.bs.modal': 'destroy', @@ -43,7 +49,7 @@ $(document).ready(function () { this.$('.alert-warning').remove(); this.is_valid_url = false; this.$('.save').button('loading'); - openerp.jsonRpc('/slides/dialog_preview/', 'call', value).then(function (data) { + ajax.jsonRpc('/slides/dialog_preview/', 'call', value).then(function (data) { self.$('.save').button('reset'); if (data.error) { self.display_alert(data.error); @@ -57,7 +63,7 @@ $(document).ready(function () { }, check_unique_slide: function (file_name) { var self = this; - return openerp.jsonRpc('/web/dataset/call_kw', 'call', { + return ajax.jsonRpc('/web/dataset/call_kw', 'call', { model: 'slide.slide', method: 'search_count', args: [[['channel_id', '=', self.channel_id], ['name', '=', file_name]]], @@ -235,7 +241,7 @@ $(document).ready(function () { var self = this; $('#category_id').select2(this.select2_wrapper(_t('Category'), false, function () { - return openerp.jsonRpc("/web/dataset/call_kw", 'call', { + return ajax.jsonRpc("/web/dataset/call_kw", 'call', { model: 'slide.category', method: 'search_read', args: [], @@ -257,7 +263,7 @@ $(document).ready(function () { // Tags management from select2 set_tag_ids: function () { $('#tag_ids').select2(this.select2_wrapper(_t('Tags'), true, function () { - return openerp.jsonRpc("/web/dataset/call_kw", 'call', { + return ajax.jsonRpc("/web/dataset/call_kw", 'call', { model: 'slide.tag', method: 'search_read', args: [], @@ -331,7 +337,7 @@ $(document).ready(function () { } this.$('.oe_slides_upload_loading').show(); this.$('.modal-footer, .modal-body').hide(); - openerp.jsonRpc("/slides/add_slide", 'call', values).then(function (data) { + ajax.jsonRpc("/slides/add_slide", 'call', values).then(function (data) { if (data.error) { self.display_alert(data.error); self.$('.oe_slides_upload_loading').hide(); @@ -351,7 +357,9 @@ $(document).ready(function () { // bind the event to the button $('.oe_slide_js_upload').on('click', function () { var channel_id = $(this).attr('channel_id'); - website.slide.page_widgets['upload_dialog'] = new website.slide.Dialog(this, channel_id).appendTo(document.body); + slides.page_widgets['upload_dialog'] = new SlideDialog(this, channel_id).appendTo(document.body); }); -}); \ No newline at end of file +}); + +});