[REF] website_slides: update to the new module system

This commit is contained in:
Géry Debongnie
2015-03-18 09:23:36 +01:00
parent 4289319f62
commit 65586f8ef3
3 changed files with 63 additions and 40 deletions
+29 -18
View File
@@ -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,
};
});
@@ -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($('<div class="alert alert-info" role="alert"><strong>Thank you!</strong> Mail has been sent.</div>'));
},
error: function(data){
@@ -194,4 +196,6 @@ $(document).ready(function () {
}
});
}
});
});
});
@@ -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);
});
});
});
});