[REF] website_*: review reorganization and enforce conventions
Review the JS reorganization made by direct parent commits and do more to use our defined JS conventions. Also simplify JS which can be obviously improved.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
odoo.define('website_blog.website_blog', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
@@ -7,26 +7,39 @@ sAnimations.registry.websiteBlog = sAnimations.Class.extend({
|
||||
selector: '.website_blog',
|
||||
read_events: {
|
||||
'click .cover_footer': '_onNextBlogClick',
|
||||
'click a[href^="#blog_content"]': '_onAnimate',
|
||||
'click a[href^="#blog_content"]': '_onContentAnchorClick',
|
||||
'click .o_twitter, .o_facebook, .o_linkedin, .o_google, .o_twitter_complete, .o_facebook_complete, .o_linkedin_complete, .o_google_complete': '_onShareArticle',
|
||||
'click .blog_post_year_collapse': '_onToggleChevron',
|
||||
'mouseenter div.o_blog_post_complete a': '_onHoverBlogPost',
|
||||
'mouseleave div.o_blog_post_complete a': '_onUnhoverBlogPost'
|
||||
'click .blog_post_year_collapse': '_onYearCollapseClick',
|
||||
'mouseenter div.o_blog_post_complete a': '_onBlogPostMouseEnter',
|
||||
'mouseleave div.o_blog_post_complete a': '_onBlogPostMouseLeave',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
$(".js_tweet, .js_comment").share({});
|
||||
|
||||
/* Collapse in active year */
|
||||
start: function () {
|
||||
$('.js_tweet, .js_comment').share({});
|
||||
|
||||
// Active year collapse
|
||||
var $activeYear = $('.blog_post_year li.active');
|
||||
if ($activeYear.length) {
|
||||
var id = $activeYear.closest('ul').attr('id');
|
||||
$("li.blog_post_year_collapse[data-target='#"+ id +"']").click();
|
||||
this._toggleYearCollapse($('.blog_post_year_collapse[data-target="#' + id + '"]'));
|
||||
}
|
||||
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {jQuery} $el
|
||||
*/
|
||||
_toggleYearCollapse: function ($el) {
|
||||
$el.find('i.fa').toggleClass('fa-chevron-down fa-chevron-right');
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -35,96 +48,91 @@ sAnimations.registry.websiteBlog = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onNextBlogClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $el = $(ev.currentTarget);
|
||||
var newLocation = $('.js_next')[0].href;
|
||||
var top = $('.cover_footer').offset().top;
|
||||
$('.cover_footer').animate({
|
||||
height: $(window).height()+'px'
|
||||
var top = $el.offset().top;
|
||||
$el.animate({
|
||||
height: $(window).height() + 'px',
|
||||
}, 300);
|
||||
$('html, body').animate({
|
||||
scrollTop: top
|
||||
scrollTop: top,
|
||||
}, 300, 'swing', function () {
|
||||
window.location.href = newLocation;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onAnimate: function (ev) {
|
||||
_onContentAnchorClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopImmediatePropagation();
|
||||
var element = ev.currentTarget;
|
||||
var target = $(element.hash);
|
||||
$('html, body').stop().animate({
|
||||
'scrollTop': target.offset().top - 32
|
||||
scrollTop: target.offset().top - 32,
|
||||
}, 500, 'swing', function () {
|
||||
window.location.hash = 'blog_content';
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Sharing links hover in blogpost
|
||||
*
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onShareArticle: function (ev) {
|
||||
var url = '';
|
||||
var $element = $(ev.currentTarget);
|
||||
if ($element.is('*[class*="_complete"]')) {
|
||||
var blog_title_complete = $('#blog_post_name').html() || '';
|
||||
if ($element.hasClass('o_twitter_complete')){
|
||||
url = 'https://twitter.com/intent/tweet?tw_p=tweetbutton&text=Amazing blog article : '+blog_title_complete+"! Check it live: "+window.location.href;
|
||||
} else if ($element.hasClass('o_facebook_complete')){
|
||||
url = 'https://www.facebook.com/sharer/sharer.php?u='+window.location.href;
|
||||
} else if ($element.hasClass('o_linkedin_complete')){
|
||||
url = 'https://www.linkedin.com/shareArticle?mini=true&url='+window.location.href+'&title='+blog_title_complete;
|
||||
var blogTitleComplete = $('#blog_post_name').html() || '';
|
||||
if ($element.hasClass('o_twitter_complete')) {
|
||||
url = 'https://twitter.com/intent/tweet?tw_p=tweetbutton&text=Amazing blog article : ' + blogTitleComplete + "! Check it live: " + window.location.href;
|
||||
} else if ($element.hasClass('o_facebook_complete')) {
|
||||
url = 'https://www.facebook.com/sharer/sharer.php?u=' + window.location.href;
|
||||
} else if ($element.hasClass('o_linkedin_complete')) {
|
||||
url = 'https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.href + '&title=' + blogTitleComplete;
|
||||
} else {
|
||||
url = 'https://plus.google.com/share?url='+window.location.href;
|
||||
url = 'https://plus.google.com/share?url=' + window.location.href;
|
||||
}
|
||||
} else {
|
||||
var blog_post = $element.parents("[name='blog_post']");
|
||||
var blog_post_title = blog_post.find('.o_blog_post_title').html() || '';
|
||||
var blog_article_link = blog_post.find('.o_blog_post_title').parent('a').attr('href');
|
||||
var blogPost = $element.parents('[name="blogPost"]');
|
||||
var blogPostTitle = blogPost.find('.o_blog_post_title').html() || '';
|
||||
var blogArticleLink = blogPost.find('.o_blog_post_title').parent('a').attr('href');
|
||||
if ($element.hasClass('o_twitter')) {
|
||||
url = 'https://twitter.com/intent/tweet?tw_p=tweetbutton&text=Amazing blog article : '+blog_post_title+"! "+window.location.host+blog_article_link;
|
||||
} else if ($element.hasClass('o_facebook')){
|
||||
url = 'https://www.facebook.com/sharer/sharer.php?u='+window.location.host+blog_article_link;
|
||||
} else if ($element.hasClass('o_linkedin')){
|
||||
url = 'https://www.linkedin.com/shareArticle?mini=true&url='+window.location.host+blog_article_link+'&title='+blog_post_title;
|
||||
} else if ($element.hasClass('o_google')){
|
||||
url = 'https://plus.google.com/share?url='+window.location.host+blog_article_link;
|
||||
url = 'https://twitter.com/intent/tweet?tw_p=tweetbutton&text=Amazing blog article : ' + blogPostTitle + "! " + window.location.host + blogArticleLink;
|
||||
} else if ($element.hasClass('o_facebook')) {
|
||||
url = 'https://www.facebook.com/sharer/sharer.php?u=' + window.location.host + blogArticleLink;
|
||||
} else if ($element.hasClass('o_linkedin')) {
|
||||
url = 'https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.host + blogArticleLink + '&title=' + blogPostTitle;
|
||||
} else if ($element.hasClass('o_google')) {
|
||||
url = 'https://plus.google.com/share?url=' + window.location.host + blogArticleLink;
|
||||
}
|
||||
}
|
||||
window.open(url, "", "menubar=no, width=500, height=400");
|
||||
},
|
||||
/**
|
||||
* Archives years collapse
|
||||
*
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onToggleChevron: function (ev) {
|
||||
$(ev.currentTarget).find('i.fa').toggleClass('fa-chevron-down fa-chevron-right');
|
||||
window.open(url, '', 'menubar=no, width=500, height=400');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onHoverBlogPost: function (ev) {
|
||||
$('div.o_blog_post_complete a').not('#'+ev.srcElement.id).addClass('unhover');
|
||||
_onYearCollapseClick: function (ev) {
|
||||
this._toggleYearCollapse($(ev.currentTarget));
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onUnhoverBlogPost: function (ev) {
|
||||
$('div.o_blog_post_complete a').not('#'+ev.currentTarget.id).removeClass('unhover');
|
||||
_onBlogPostMouseEnter: function (ev) {
|
||||
$('div.o_blog_post_complete a').not('#' + ev.srcElement.id).addClass('unhover');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onBlogPostMouseLeave: function (ev) {
|
||||
$('div.o_blog_post_complete a').not('#' + ev.currentTarget.id).removeClass('unhover');
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -3,233 +3,260 @@ odoo.define('crm.partner_assign', function (require) {
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
/*
|
||||
* This file is intended to add interactivity to survey forms rendered by
|
||||
* the website engine.
|
||||
*/
|
||||
|
||||
sAnimations.registry.crmPartnerAssign = sAnimations.Class.extend({
|
||||
selector: "#portal_my_lead:has(.interested_partner_assign_form,.desinterested_partner_assign_form,.opp-stage-button,.new_opp_form')",
|
||||
selector: '#wrapwrap:has(.interested_partner_assign_form, .desinterested_partner_assign_form, .opp-stage-button, .new_opp_form)',
|
||||
read_events: {
|
||||
'click .interested_partner_assign_confirm': '_onInterestedPartnerAssignConfirm',
|
||||
'click .desinterested_partner_assign_confirm': '_onDesinterestedPartnerAssignConfirm',
|
||||
'click .opp-stage-button': '_onOppStageButtons',
|
||||
'change .edit_contact_form .country_id': '_onEditContactForm',
|
||||
'click .opp-stage-button': '_onOppStageButtonClick',
|
||||
'change .edit_contact_form .country_id': '_onEditContactFormChange',
|
||||
'click .edit_contact_confirm': '_onEditContactConfirm',
|
||||
'click .new_opp_confirm': '_onNewOppConfirm',
|
||||
'click .edit_opp_confirm': '_onEditOppConfirm',
|
||||
'change .edit_opp_form .next_activity': '_onEditOppConfirm',
|
||||
'click div.input-group span.fa-calendar': '_onCalendarIcon'
|
||||
'click div.input-group span.fa-calendar': '_onCalendarIconClick',
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {jQuery} $btn
|
||||
* @param {function} callback
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_buttonExec: function ($btn, callback) {
|
||||
// TODO remove once the automatic system which does this lands in master
|
||||
$btn.prop('disabled', true);
|
||||
return callback.call(this).fail(function () {
|
||||
$btn.prop('disabled', false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_confirmInterestedPartner: function () {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'partner_interested',
|
||||
args: [
|
||||
[parseInt($('.interested_partner_assign_form .assign_lead_id').val())],
|
||||
$('.interested_partner_assign_form .comment_interested').val()
|
||||
],
|
||||
}).then(function () {
|
||||
window.location.href = '/my/leads';
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_confirmDesinterestedPartner: function () {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'partner_desinterested',
|
||||
args: [
|
||||
[parseInt($('.desinterested_partner_assign_form .assign_lead_id').val())],
|
||||
$('.desinterested_partner_assign_form .comment_desinterested').val(),
|
||||
$('.desinterested_partner_assign_form .contacted_desinterested').prop('checked'),
|
||||
$('.desinterested_partner_assign_form .customer_mark_spam').prop('checked'),
|
||||
],
|
||||
}).then(function () {
|
||||
window.location.href = '/my/leads';
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {}
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_changeOppStage: function (leadID, stageID) {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'write',
|
||||
args: [[leadID], {
|
||||
stage_id: stageID,
|
||||
}],
|
||||
context: _.extend({website_partner_assign: 1}),
|
||||
}).then(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_editContact: function () {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'write',
|
||||
args: [[parseInt($('.edit_contact_form .opportunity_id').val())], {
|
||||
partner_name: $('.edit_contact_form .partner_name').val(),
|
||||
phone: $('.edit_contact_form .phone').val(),
|
||||
mobile: $('.edit_contact_form .mobile').val(),
|
||||
email_from: $('.edit_contact_form .email_from').val(),
|
||||
street: $('.edit_contact_form .street').val(),
|
||||
street2: $('.edit_contact_form .street2').val(),
|
||||
city: $('.edit_contact_form .city').val(),
|
||||
zip: $('.edit_contact_form .zip').val(),
|
||||
state_id: parseInt($('.edit_contact_form .state_id').find(':selected').attr('value')),
|
||||
country_id: parseInt($('.edit_contact_form .country_id').find(':selected').attr('value')),
|
||||
}],
|
||||
}).then(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_createOpportunity: function () {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'create_opp_portal',
|
||||
args: [{
|
||||
contact_name: $('.new_opp_form .contact_name').val(),
|
||||
title: $('.new_opp_form .title').val(),
|
||||
description: $('.new_opp_form .description').val(),
|
||||
}],
|
||||
}).then(function (response) {
|
||||
if (response.errors) {
|
||||
$('#new-opp-dialog .alert').remove();
|
||||
$('#new-opp-dialog div:first').prepend('<div class="alert alert-danger">' + response.errors + '</div>');
|
||||
return $.Deferred().reject(response);
|
||||
} else {
|
||||
window.location = '/my/opportunity/' + response.id;
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_editOpportunity: function () {
|
||||
return this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'update_lead_portal',
|
||||
args: [[parseInt($('.edit_opp_form .opportunity_id').val())], {
|
||||
date_deadline: $('.edit_opp_form .date_deadline').val(),
|
||||
planned_revenue: parseFloat($('.edit_opp_form .planned_revenue').val()),
|
||||
probability: parseFloat($('.edit_opp_form .probability').val()),
|
||||
activity_type_id: parseInt($('.edit_opp_form .next_activity').find(':selected').attr('data')),
|
||||
activity_summary: $('.edit_opp_form .activity_summary').val(),
|
||||
activity_date_deadline: $('.edit_opp_form .activity_date_deadline').val(),
|
||||
priority: $('input[name="PriorityRadioOptions"]:checked').val(),
|
||||
}],
|
||||
}).then(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onInterestedPartnerAssignConfirm: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
if ($('.interested_partner_assign_form .comment_interested').val() && $('.interested_partner_assign_form .contacted_interested').prop('checked')){
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: "partner_interested",
|
||||
args: [
|
||||
[parseInt($('.interested_partner_assign_form .assign_lead_id').val())],
|
||||
$('.interested_partner_assign_form .comment_interested').val()
|
||||
],
|
||||
})
|
||||
.then(function (){
|
||||
window.location.href = '/my/leads';
|
||||
})
|
||||
.always(function () {
|
||||
$btn.prop('disabled', false);
|
||||
});
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if ($('.interested_partner_assign_form .comment_interested').val() && $('.interested_partner_assign_form .contacted_interested').prop('checked')) {
|
||||
this._buttonExec($(ev.currentTarget), this._confirmInterestedPartner);
|
||||
} else {
|
||||
$('.interested_partner_assign_form .error_partner_assign_interested').css('display', 'block');
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onDesinterestedPartnerAssignConfirm: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'partner_desinterested',
|
||||
args: [
|
||||
[parseInt($('.desinterested_partner_assign_form .assign_lead_id').val())],
|
||||
$('.desinterested_partner_assign_form .comment_desinterested').val(),
|
||||
$('.desinterested_partner_assign_form .contacted_desinterested').prop('checked'),
|
||||
$('.desinterested_partner_assign_form .customer_mark_spam').prop('checked'),
|
||||
],
|
||||
})
|
||||
.then(function (){
|
||||
window.location.href = '/my/leads';
|
||||
}).always(function () {
|
||||
$btn.prop('disabled', false);
|
||||
});
|
||||
return false;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this._buttonExec($(ev.currentTarget), this._confirmDesinterestedPartner);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onOppStageButtons: function (ev) {
|
||||
_onOppStageButtonClick: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'write',
|
||||
args: [[parseInt(ev.currentTarget.getAttribute('opp'))],{
|
||||
stage_id: parseInt(ev.currentTarget.getAttribute('data')),
|
||||
},],
|
||||
context: _.extend({website_partner_assign:1}),
|
||||
})
|
||||
.fail(function () {
|
||||
$btn.prop('disabled', false);
|
||||
})
|
||||
.done(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
this._buttonExec(
|
||||
$btn,
|
||||
this._changeOppStage.bind(this, parseInt($btn.attr('opp')), parseInt($btn.attr('data')))
|
||||
);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditContactForm: function (ev) {
|
||||
var country_id = $('.edit_contact_form .country_id').find(":selected").attr('value');
|
||||
$(".edit_contact_form .state[country!="+country_id+"]").css('display','none');
|
||||
$(".edit_contact_form .state[country="+country_id+"]").css('display','block');
|
||||
_onEditContactFormChange: function (ev) {
|
||||
var countryID = $('.edit_contact_form .country_id').find(':selected').attr('value');
|
||||
$('.edit_contact_form .state[country!=' + countryID + ']').css('display', 'none');
|
||||
$('.edit_contact_form .state[country=' + countryID + ']').css('display', 'block');
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditContactConfirm: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: "write",
|
||||
args: [[parseInt($('.edit_contact_form .opportunity_id').val())],{
|
||||
partner_name: $('.edit_contact_form .partner_name').val(),
|
||||
phone: $('.edit_contact_form .phone').val(),
|
||||
mobile: $('.edit_contact_form .mobile').val(),
|
||||
email_from: $('.edit_contact_form .email_from').val(),
|
||||
street: $('.edit_contact_form .street').val(),
|
||||
street2: $('.edit_contact_form .street2').val(),
|
||||
city: $('.edit_contact_form .city').val(),
|
||||
zip: $('.edit_contact_form .zip').val(),
|
||||
state_id: parseInt($('.edit_contact_form .state_id').find(":selected").attr('value')),
|
||||
country_id: parseInt($('.edit_contact_form .country_id').find(":selected").attr('value')),
|
||||
}],
|
||||
})
|
||||
.fail(function () {
|
||||
$btn.prop('disabled', false);
|
||||
})
|
||||
.done(function (){
|
||||
window.location.reload();
|
||||
});
|
||||
return false;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this._buttonExec($(ev.currentTarget), this._editContact);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onNewOppConfirm: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'create_opp_portal',
|
||||
args: [{
|
||||
contact_name: $('.new_opp_form .contact_name').val(),
|
||||
title: $('.new_opp_form .title').val(),
|
||||
description: $('.new_opp_form .description').val(),
|
||||
}],
|
||||
})
|
||||
.done(function (response){
|
||||
if (response.errors) {
|
||||
$('#new-opp-dialog .alert').remove();
|
||||
$('#new-opp-dialog div:first').prepend("<div class='alert alert-danger'>" + response.errors + "</div>");
|
||||
$btn.prop('disabled', false);
|
||||
|
||||
}
|
||||
else {
|
||||
window.location = '/my/opportunity/' + response.id;
|
||||
}
|
||||
})
|
||||
.fail(function () {
|
||||
$btn.prop('disabled', false);
|
||||
});
|
||||
return false;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this._buttonExec($(ev.currentTarget), this._createOpportunity);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditOppConfirm: function (ev) {
|
||||
var $btn = $(ev.currentTarget);
|
||||
$btn.prop('disabled', true);
|
||||
this._rpc({
|
||||
model: 'crm.lead',
|
||||
method: 'update_lead_portal',
|
||||
args: [[parseInt($('.edit_opp_form .opportunity_id').val())],{
|
||||
date_deadline: $('.edit_opp_form .date_deadline').val(),
|
||||
planned_revenue: parseFloat($('.edit_opp_form .planned_revenue').val()),
|
||||
probability: parseFloat($('.edit_opp_form .probability').val()),
|
||||
activity_type_id: parseInt($('.edit_opp_form .next_activity').find(":selected").attr('data')),
|
||||
activity_summary: $('.edit_opp_form .activity_summary').val(),
|
||||
activity_date_deadline: $('.edit_opp_form .activity_date_deadline').val(),
|
||||
priority: $('input[name="PriorityRadioOptions"]:checked').val(),
|
||||
}],
|
||||
})
|
||||
.fail(function () {
|
||||
$btn.prop('disabled', false);
|
||||
})
|
||||
.done(function (){
|
||||
window.location.reload();
|
||||
});
|
||||
return false;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this._buttonExec($(ev.currentTarget), this._editOpportunity);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditOppForm: function (ev) {
|
||||
var selected = $('.edit_opp_form .next_activity').find(":selected");
|
||||
if (selected.attr('activity_summary')){
|
||||
$('.edit_opp_form .activity_summary').val(selected.attr('activity_summary'));
|
||||
var $selected = $('.edit_opp_form .next_activity').find(':selected');
|
||||
if ($selected.attr('activity_summary')) {
|
||||
$('.edit_opp_form .activity_summary').val($selected.attr('activity_summary'));
|
||||
}
|
||||
if (selected.attr('days')){
|
||||
var date_now = moment();
|
||||
var days = parseInt(selected.attr('days'));
|
||||
var date = date_now.add(days, 'days');
|
||||
if ($selected.attr('days')) {
|
||||
var now = moment();
|
||||
var days = parseInt($selected.attr('days'));
|
||||
var date = now.add(days, 'days');
|
||||
$('.edit_opp_form .activity_date_deadline').val(date.format('YYYY-MM-DD'));
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCalendarIcon: function (ev) {
|
||||
$(ev.currentTarget).closest("div.date").datetimepicker({
|
||||
icons : {
|
||||
_onCalendarIconClick: function (ev) {
|
||||
$(ev.currentTarget).closest('div.date').datetimepicker({
|
||||
icons: {
|
||||
time: 'fa fa-clock-o',
|
||||
date: 'fa fa-calendar',
|
||||
up: 'fa fa-chevron-up',
|
||||
down: 'fa fa-chevron-down'
|
||||
down: 'fa fa-chevron-down',
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
odoo.define('website_event_track.website_event_track', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
sAnimations.registry.websiteEventTrack = sAnimations.Class.extend({
|
||||
selector: '.o_website_event',
|
||||
read_events: {
|
||||
'keyup #event_track_search': '_onEventTrackSearch'
|
||||
'input #event_track_search': '_onEventTrackSearchInput',
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -15,23 +15,18 @@ sAnimations.registry.websiteEventTrack = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEventTrackSearch: function (ev) {
|
||||
var change_text = $(ev.currentTarget).val();
|
||||
$('.event_track').removeClass('invisible');
|
||||
|
||||
$("#search_summary").removeClass('invisible');
|
||||
if (change_text) {
|
||||
$("#search_number").text($(".event_track:containsLike("+change_text+")").length);
|
||||
$(".event_track:not(:containsLike("+change_text+"))").addClass('invisible');
|
||||
} else {
|
||||
$("#search_number").text(30);
|
||||
}
|
||||
|
||||
_onEventTrackSearchInput: function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
var text = $(ev.currentTarget).val();
|
||||
var filter = _.str.sprintf(':containsLike(%s)', text);
|
||||
|
||||
$('#search_summary').removeClass('invisible');
|
||||
var $tracks = $('.event_track');
|
||||
$('#search_number').text($tracks.filter(filter).length);
|
||||
$tracks.removeClass('invisible').not(filter).addClass('invisible');
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,63 +1,69 @@
|
||||
odoo.define('website_forum.website_forum', function (require) {
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
var lastsearch;
|
||||
|
||||
sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
selector: '.website_forum',
|
||||
selector: '#wrapwrap:has(.website_forum)',
|
||||
read_events: {
|
||||
'click .karma_required': '_onKarmaRequired',
|
||||
'hover .o_js_forum_tag_follow': '_onHoverTagFollowBox',
|
||||
'click .o_forum_profile_pic_edit': '_onEditProfilePic',
|
||||
'change .o_forum_file_upload': '_onChangeFileUpload',
|
||||
'click .o_forum_profile_pic_clear': '_onProfilePicClear',
|
||||
'hover .o_forum_user_info': '_onHoverUserInfo',
|
||||
'hover .o_forum_user_bio_expand': '_onHoverUserBioExpand',
|
||||
'click .flag:not(.karma_required)': '_onFlagAlert',
|
||||
'click .vote_up,.vote_down:not(.karma_required)': '_onVotePost',
|
||||
'click .o_js_validation_queue a[href*="/validate"]': '_onValidationQueue',
|
||||
'click .accept_answer:not(.karma_required)': '_onAcceptAnswer',
|
||||
'click .favourite_question': '_onFavQuestion',
|
||||
'click .comment_delete': '_onDeleteComment',
|
||||
'click .notification_close': '_onCloseNotification',
|
||||
'click .send_validation_email': '_onSendValidationEmail',
|
||||
'click .validated_email_close': '_onCloseValidatedEmail',
|
||||
'click .js_close_intro': '_onCloseIntro',
|
||||
'click .karma_required': '_onKarmaRequiredClick',
|
||||
'mouseenter .o_js_forum_tag_follow': '_onTagFollowBoxMouseEnter',
|
||||
'mouseleave .o_js_forum_tag_follow': '_onTagFollowBoxMouseLeave',
|
||||
'click .o_forum_profile_pic_edit': '_onEditProfilePicClick',
|
||||
'change .o_forum_file_upload': '_onFileUploadChange',
|
||||
'click .o_forum_profile_pic_clear': '_onProfilePicClearClick',
|
||||
'mouseenter .o_forum_user_info': '_onUserInfoMouseEnter',
|
||||
'mouseleave .o_forum_user_info': '_onUserInfoMouseLeave',
|
||||
'mouseleave .o_forum_user_bio_expand': '_onUserBioExpandMouseLeave',
|
||||
'click .flag:not(.karma_required)': '_onFlagAlertClick',
|
||||
'click .vote_up, .vote_down:not(.karma_required)': '_onVotePostClick',
|
||||
'click .o_js_validation_queue a[href*="/validate"]': '_onValidationQueueClick',
|
||||
'click .accept_answer:not(.karma_required)': '_onAcceptAnswerClick',
|
||||
'click .favourite_question': '_onFavoriteQuestionClick',
|
||||
'click .comment_delete': '_onDeleteCommentClick',
|
||||
'click .notification_close': '_onCloseNotificationClick',
|
||||
'click .send_validation_email': '_onSendValidationEmailClick',
|
||||
'click .validated_email_close': '_onCloseValidatedEmailClick',
|
||||
'click .js_close_intro': '_onCloseIntroClick',
|
||||
'change .link_url, .o_forum_post_link': '_onCheckPostURL',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var self = this;
|
||||
|
||||
this.lastsearch = [];
|
||||
|
||||
// float-left class messes up the post layout OPW 769721
|
||||
$('span[data-oe-model="forum.post"][data-oe-field="content"]').find('img.float-left').removeClass('float-left');
|
||||
|
||||
// welcome message action button
|
||||
var forum_login = _.string.sprintf('%s/web?redirect=%s',
|
||||
window.location.origin, escape(window.location.href));
|
||||
$('.forum_register_url').attr('href',forum_login);
|
||||
var forumLogin = _.string.sprintf('%s/web?redirect=%s',
|
||||
window.location.origin,
|
||||
escape(window.location.href)
|
||||
);
|
||||
$('.forum_register_url').attr('href', forumLogin);
|
||||
|
||||
$('input.js_select2').select2({
|
||||
tags: true,
|
||||
tokenSeparators: [",", " ", "_"],
|
||||
tokenSeparators: [',', ' ', '_'],
|
||||
maximumInputLength: 35,
|
||||
minimumInputLength: 2,
|
||||
maximumSelectionSize: 5,
|
||||
lastsearch: [],
|
||||
createSearchChoice: function (term) {
|
||||
if ($(lastsearch).filter(function () { return this.text.localeCompare(term) === 0;}).length === 0) {
|
||||
if (_.filter(self.lastsearch, function (s) {
|
||||
return s.text.localeCompare(term) === 0;
|
||||
}).length === 0) {
|
||||
//check Karma
|
||||
if (parseInt($("#karma").val()) >= parseInt($("#karma_edit_retag").val())) {
|
||||
if (parseInt($('#karma').val()) >= parseInt($('#karma_edit_retag').val())) {
|
||||
return {
|
||||
id: "_" + $.trim(term),
|
||||
id: '_' + $.trim(term),
|
||||
text: $.trim(term) + ' *',
|
||||
isNew: true,
|
||||
};
|
||||
@@ -67,8 +73,7 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
formatResult: function (term) {
|
||||
if (term.isNew) {
|
||||
return '<span class="badge badge-primary">New</span> ' + _.escape(term.text);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return _.escape(term.text);
|
||||
}
|
||||
},
|
||||
@@ -78,51 +83,55 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
data: function (term) {
|
||||
return {
|
||||
q: term,
|
||||
l: 50
|
||||
l: 50,
|
||||
};
|
||||
},
|
||||
results: function (data) {
|
||||
var ret = [];
|
||||
_.each(data, function (x) {
|
||||
ret.push({ id: x.id, text: x.name, isNew: false });
|
||||
ret.push({
|
||||
id: x.id,
|
||||
text: x.name,
|
||||
isNew: false,
|
||||
});
|
||||
});
|
||||
lastsearch = ret;
|
||||
return { results: ret };
|
||||
self.lastsearch = ret;
|
||||
return {results: ret};
|
||||
}
|
||||
},
|
||||
// Take default tags from the input value
|
||||
initSelection: function (element, callback) {
|
||||
var data = [];
|
||||
_.each(element.data('init-value'), function (x) {
|
||||
data.push({ id: x.id, text: x.name, isNew: false });
|
||||
data.push({id: x.id, text: x.name, isNew: false});
|
||||
});
|
||||
element.val('');
|
||||
callback(data);
|
||||
},
|
||||
});
|
||||
|
||||
$('textarea.load_editor').each(function () {
|
||||
var $textarea = $(this);
|
||||
var editor_karma = $textarea.data('karma') || 30; // default value for backward compatibility
|
||||
_.each($('textarea.load_editor'), function (textarea) {
|
||||
var $textarea = $(textarea);
|
||||
var editorKarma = $textarea.data('karma') || 30; // default value for backward compatibility
|
||||
if (!$textarea.val().match(/\S/)) {
|
||||
$textarea.val("<p><br/></p>");
|
||||
$textarea.val('<p><br/></p>');
|
||||
}
|
||||
var $form = $textarea.closest('form');
|
||||
var toolbar = [
|
||||
['style', ['style']],
|
||||
['font', ['bold', 'italic', 'underline', 'clear']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['history', ['undo', 'redo']],
|
||||
];
|
||||
if (parseInt($("#karma").val()) >= editor_karma) {
|
||||
['style', ['style']],
|
||||
['font', ['bold', 'italic', 'underline', 'clear']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['history', ['undo', 'redo']],
|
||||
];
|
||||
if (parseInt($('#karma').val()) >= editorKarma) {
|
||||
toolbar.push(['insert', ['link', 'picture']]);
|
||||
}
|
||||
$textarea.summernote({
|
||||
height: 150,
|
||||
toolbar: toolbar,
|
||||
styleWithSpan: false
|
||||
});
|
||||
height: 150,
|
||||
toolbar: toolbar,
|
||||
styleWithSpan: false
|
||||
});
|
||||
|
||||
// float-left class messes up the post layout OPW 769721
|
||||
$form.find('.note-editable').find('img.float-left').removeClass('float-left');
|
||||
@@ -132,9 +141,10 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
});
|
||||
|
||||
// Check all answer status to add text-success on answer if needed
|
||||
$('.accept_answer').each(function () {
|
||||
if ($(this).hasClass('oe_answer_true')) {
|
||||
$(this).addClass('text-success');
|
||||
_.each($('.accept_answer'), function (el) {
|
||||
var $el = $(el);
|
||||
if ($el.hasClass('oe_answer_true')) {
|
||||
$el.addClass('text-success');
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -145,67 +155,73 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onKarmaRequired: function (ev) {
|
||||
var karma = $(ev.currentTarget).data('karma');
|
||||
if (karma) {
|
||||
ev.preventDefault();
|
||||
var msg = karma + ' ' + _t(' karma is required to perform this action. You can earn karma by having your answers upvoted by the community.');
|
||||
if ($('a[href*="/login"]').length) {
|
||||
msg = _t('Sorry you must be logged in to perform this action');
|
||||
}
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert mt8" id="karma_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
msg + '</div>');
|
||||
var $voteAlert = $('#karma_alert');
|
||||
if ($voteAlert.length) {
|
||||
$voteAlert.remove();
|
||||
}
|
||||
$(ev.currentTarget).after($warning);
|
||||
_onKarmaRequiredClick: function (ev) {
|
||||
var $karma = $(ev.currentTarget);
|
||||
var karma = $karma.data('karma');
|
||||
if (!karma) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onHoverTagFollowBox: function (ev) {
|
||||
$(function (ev) {
|
||||
$(this).find('.o_forum_tag_follow_box').stop().fadeIn().css('display','block');
|
||||
});
|
||||
$(function (ev) {
|
||||
$(this).find('.o_forum_tag_follow_box').stop().fadeOut().css('display','none');
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onEditProfilePic: function (ev) {
|
||||
ev.preventDefault();
|
||||
$(this).closest('form').find('.o_forum_file_upload').trigger('click');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onChangeFileUpload: function (ev) {
|
||||
if (this.files.length) {
|
||||
var $form = $(this).closest('form');
|
||||
var reader = new window.FileReader();
|
||||
reader.onload = function (ev) {
|
||||
$form.find('.o_forum_avatar_img').attr('src', ev.target.result);
|
||||
};
|
||||
reader.readAsDataURL(this.files[0]);
|
||||
$form.find('#forum_clear_image').remove();
|
||||
var msg = karma + ' ' + _t("karma is required to perform this action. You can earn karma by having your answers upvoted by the community.");
|
||||
if ($('a[href*="/login"]').length) {
|
||||
msg = _t("Sorry you must be logged in to perform this action");
|
||||
}
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert mt8" id="karma_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
msg + '</div>');
|
||||
var $voteAlert = $('#karma_alert');
|
||||
if ($voteAlert.length) {
|
||||
$voteAlert.remove();
|
||||
}
|
||||
$karma.after($warning);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onProfilePicClear: function () {
|
||||
var $form = $(this).closest('form');
|
||||
$form.find('.o_forum_avatar_img').attr("src", "/web/static/src/img/placeholder.png");
|
||||
_onTagFollowBoxMouseEnter: function (ev) {
|
||||
$(ev.currentTarget).find('.o_forum_tag_follow_box').stop().fadeIn().css('display', 'block');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onTagFollowBoxMouseLeave: function (ev) {
|
||||
$(ev.currentTarget).find('.o_forum_tag_follow_box').stop().fadeOut().css('display', 'none');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditProfilePicClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
$(ev.currentTarget).closest('form').find('.o_forum_file_upload').trigger('click');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onFileUploadChange: function (ev) {
|
||||
if (!ev.currentTarget.files.length) {
|
||||
return;
|
||||
}
|
||||
var $form = $(ev.currentTarget).closest('form');
|
||||
var reader = new window.FileReader();
|
||||
reader.onload = function (ev) {
|
||||
$form.find('.o_forum_avatar_img').attr('src', ev.target.result);
|
||||
};
|
||||
reader.readAsDataURL(ev.currentTarget.files[0]);
|
||||
$form.find('#forum_clear_image').remove();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onProfilePicClearClick: function (ev) {
|
||||
var $form = $(ev.currentTarget).closest('form');
|
||||
$form.find('.o_forum_avatar_img').attr('src', '/web/static/src/img/placeholder.png');
|
||||
$form.append($('<input/>', {
|
||||
name: 'clear_image',
|
||||
id: 'forum_clear_image',
|
||||
@@ -214,215 +230,229 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onHoverUserInfo: function () {
|
||||
$(function () {
|
||||
$(this).parent().find('.o_forum_user_bio_expand').delay(500).toggle('fast');
|
||||
});
|
||||
$(function () {
|
||||
$(this).parent().find('.o_forum_user_bio_expand').clearQueue();
|
||||
});
|
||||
_onUserInfoMouseEnter: function (ev) {
|
||||
$(ev.currentTarget).parent().find('.o_forum_user_bio_expand').delay(500).toggle('fast');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onHoverUserBioExpand: function () {
|
||||
$(function () {});
|
||||
$(function () {
|
||||
$(this).fadeOut('fast');
|
||||
});
|
||||
_onUserInfoMouseLeave: function (ev) {
|
||||
$(ev.currentTarget).parent().find('.o_forum_user_bio_expand').clearQueue();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onFlagAlert: function (ev) {
|
||||
_onUserBioExpandMouseLeave: function (ev) {
|
||||
$(ev.currentTarget).fadeOut('fast');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onFlagAlertClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc($link.data('href'), 'call', {})
|
||||
.then(function (data) {
|
||||
if (data.error) {
|
||||
var $warning;
|
||||
if (data.error === 'anonymous_user') {
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
_t('Sorry you must be logged to flag a post') +
|
||||
'</div>');
|
||||
} else if (data.error === 'post_already_flagged') {
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
_t('This post is already flagged') +
|
||||
'</div>');
|
||||
} else if (data.error === 'post_non_flaggable') {
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
_t('This post can not be flagged') +
|
||||
'</div>');
|
||||
}
|
||||
var flag_alert = $link.parent().find("#flag_alert");
|
||||
if (flag_alert.length === 0) {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else if (data.success) {
|
||||
var elem = $link;
|
||||
if (data.success === 'post_flagged_moderator') {
|
||||
elem.html(' Flagged');
|
||||
var c = parseInt($('#count_flagged_posts').html(), 10);
|
||||
c++;
|
||||
$('#count_flagged_posts').html(c);
|
||||
} else if (data.success === 'post_flagged_non_moderator') {
|
||||
elem.html(' Flagged');
|
||||
var forum_answer = elem.closest('.forum_answer');
|
||||
forum_answer.fadeIn(1000);
|
||||
forum_answer.slideUp(1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onVotePost: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc($link.data('href'), 'call', {})
|
||||
.then(function (data) {
|
||||
if (data.error){
|
||||
var $warning;
|
||||
if (data.error === 'own_post'){
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert">×</button>'+
|
||||
_t('Sorry, you cannot vote for your own posts') +
|
||||
'</div>');
|
||||
} else if (data.error === 'anonymous_user'){
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert">×</button>'+
|
||||
_t('Sorry you must be logged to vote') +
|
||||
'</div>');
|
||||
}
|
||||
var vote_alert = $link.parent().find("#vote_alert");
|
||||
if (vote_alert.length === 0) {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else {
|
||||
$link.parent().find(".vote_count").html(data['vote_count']);
|
||||
if (data.user_vote === 0) {
|
||||
$link.parent().find(".text-success").removeClass("text-success");
|
||||
$link.parent().find(".text-warning").removeClass("text-warning");
|
||||
} else {
|
||||
if (data.user_vote === 1) {
|
||||
$link.addClass("text-success");
|
||||
} else {
|
||||
$link.addClass("text-warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onValidationQueue: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var self = $(this);
|
||||
$(this).parents('.post_to_validate').hide();
|
||||
$.get($link.attr('href'))
|
||||
.fail(function () {
|
||||
self.parents('.o_js_validation_queue > div').addClass('bg-danger text-white').css('background-color', '#FAA');
|
||||
self.parents('.post_to_validate').show();
|
||||
})
|
||||
.done(function () {
|
||||
var left = $('.o_js_validation_queue:visible').length;
|
||||
var type = $('h2.o_page_header a.active').data('type');
|
||||
$('#count_post').text(left);
|
||||
$('#moderation_tools a[href*="/'+type+'_"]').find('strong').text(left);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onAcceptAnswer: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
|
||||
this._rpc({
|
||||
route: $link.data('href'),
|
||||
}).then(function (data) {
|
||||
if (data.error) {
|
||||
var $warning;
|
||||
if (data.error === 'anonymous_user') {
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
_t('Sorry, anonymous users cannot choose correct answer.') +
|
||||
$warning = $(
|
||||
'<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
_t("Sorry you must be logged to flag a post") +
|
||||
'</div>'
|
||||
);
|
||||
} else if (data.error === 'post_already_flagged') {
|
||||
$warning = $(
|
||||
'<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
_t("This post is already flagged") +
|
||||
'</div>'
|
||||
);
|
||||
} else if (data.error === 'post_non_flaggable') {
|
||||
$warning = $(
|
||||
'<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
_t("This post can not be flagged") +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
var $flagAlert = $link.parent().find('#flag_alert');
|
||||
if ($flagAlert.length === 0) {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else if (data.success) {
|
||||
var elem = $link;
|
||||
if (data.success === 'post_flagged_moderator') {
|
||||
elem.html(' Flagged');
|
||||
var c = parseInt($('#count_flagged_posts').html(), 10);
|
||||
c++;
|
||||
$('#count_flagged_posts').html(c);
|
||||
} else if (data.success === 'post_flagged_non_moderator') {
|
||||
elem.html(' Flagged');
|
||||
var forumAnswer = elem.closest('.forum_answer');
|
||||
forumAnswer.fadeIn(1000);
|
||||
forumAnswer.slideUp(1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onVotePostClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
this._rpc({
|
||||
route: $link.data('href'),
|
||||
}).then(function (data) {
|
||||
if (data.error) {
|
||||
var $warning;
|
||||
if (data.error === 'own_post') {
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert">×</button>' +
|
||||
_t('Sorry, you cannot vote for your own posts') +
|
||||
'</div>');
|
||||
} else if (data.error === 'anonymous_user') {
|
||||
$warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert">×</button>' +
|
||||
_t('Sorry you must be logged to vote') +
|
||||
'</div>');
|
||||
}
|
||||
var correct_answer_alert = $link.parent().find("#correct_answer_alert");
|
||||
if (correct_answer_alert.length === 0) {
|
||||
var $voteAlert = $link.parent().find('#vote_alert');
|
||||
if ($voteAlert.length === 0) {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else {
|
||||
if (data) {
|
||||
$link.addClass("oe_answer_true").removeClass('oe_answer_false');
|
||||
$link.parent().find('.vote_count').html(data['vote_count']);
|
||||
if (data.user_vote === 0) {
|
||||
$link.parent().find('.text-success').removeClass('text-success');
|
||||
$link.parent().find('.text-warning').removeClass('text-warning');
|
||||
} else {
|
||||
$link.removeClass("oe_answer_true").addClass('oe_answer_false');
|
||||
if (data.user_vote === 1) {
|
||||
$link.addClass('text-success');
|
||||
} else {
|
||||
$link.addClass('text-warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onValidationQueueClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
$link.parents('.post_to_validate').hide();
|
||||
$.get($link.attr('href')).then(function () {
|
||||
var left = $('.o_js_validation_queue:visible').length;
|
||||
var type = $('h2.o_page_header a.active').data('type');
|
||||
$('#count_post').text(left);
|
||||
$('#moderation_tools a[href*="/' + type + '_"]').find('strong').text(left);
|
||||
}, function () {
|
||||
$link.parents('.o_js_validation_queue > div').addClass('bg-danger text-white').css('background-color', '#FAA');
|
||||
$link.parents('.post_to_validate').show();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onAcceptAnswerClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
this._rpc({
|
||||
route: $link.data('href'),
|
||||
}).then(function (data) {
|
||||
if (data.error) {
|
||||
if (data.error === 'anonymous_user') {
|
||||
var $warning = $(
|
||||
'<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
_t("Sorry, anonymous users cannot choose correct answer.") +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
var $correctAnswerAlert = $link.parent().find('#correct_answer_alert');
|
||||
if ($correctAnswerAlert.length === 0) {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else {
|
||||
$link.toggleClass('oe_answer_true', !!data)
|
||||
.toggleClass('oe_answer_false', !data);
|
||||
}
|
||||
});
|
||||
this._onCheckAnswerStatus(ev);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCheckAnswerStatus: function (ev) {
|
||||
var $link = $(ev.currentTarget);
|
||||
if ($link.hasClass('oe_answer_true')) {
|
||||
$link.removeClass('text-success');
|
||||
} else {
|
||||
$link.addClass('text-success');
|
||||
}
|
||||
$link.toggleClass('text-success', !$link.hasClass('oe_answer_true'));
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onFavQuestion: function (ev) {
|
||||
_onFavoriteQuestionClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
|
||||
$link.toggleClass("forum_favourite_question", !!data);
|
||||
this._rpc({
|
||||
route: $link.data('href'),
|
||||
}).then(function (data) {
|
||||
$link.toggleClass('forum_favourite_question', !!data);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onDeleteComment: function (ev) {
|
||||
_onDeleteCommentClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc($link.closest('form').attr('action'), 'call', {}).then(function () {
|
||||
this._rpc({
|
||||
route: $link.closest('form').attr('action'),
|
||||
}).then(function () {
|
||||
$link.parents('.comment').first().remove();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCloseNotification: function (ev) {
|
||||
_onCloseNotificationClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc("/forum/notification_read", 'call', {
|
||||
'notification_id': $link.attr("id")});
|
||||
this._rpc({
|
||||
route: '/forum/notification_read',
|
||||
params: {
|
||||
notification_id: $link.attr('id'),
|
||||
},
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onSendValidationEmail: function (ev) {
|
||||
_onSendValidationEmailClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
ajax.jsonRpc("/forum/send_validation_email", 'call', {
|
||||
'forum_id': $link.attr('forum-id'),
|
||||
this._rpc({
|
||||
route: '/forum/send_validation_email',
|
||||
params: {
|
||||
forum_id: $link.attr('forum-id'),
|
||||
},
|
||||
}).then(function (data) {
|
||||
if (data) {
|
||||
$('button.validation_email_close').click();
|
||||
@@ -432,91 +462,98 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onCloseValidatedEmail: function () {
|
||||
ajax.jsonRpc("/forum/validate_email/close", 'call', {});
|
||||
_onCloseValidatedEmailClick: function () {
|
||||
this._rpc({
|
||||
route: '/forum/validate_email/close',
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCloseIntro: function (ev) {
|
||||
_onCloseIntroClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
document.cookie = "forum_welcome_message = false";
|
||||
document.cookie = 'forum_welcome_message = false';
|
||||
$('.forum_intro').slideUp();
|
||||
return true;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCheckPostURL: function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var display_error = function (){
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" style="position:absolute; margin-top: -180px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Please enter valid URL. Example: http://www.odoo.com'+
|
||||
'</div>');
|
||||
var displayError = function () {
|
||||
var $warning = $(
|
||||
'<div class="alert alert-danger alert-dismissable" style="position:absolute; margin-top: -180px; margin-left: 90px;">' +
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
||||
_t("Please enter valid URL. Example: http://www.odoo.com") +
|
||||
'</div>'
|
||||
);
|
||||
$link.parent().append($warning);
|
||||
$link.parents('form').find('button')[0].disabled = true;
|
||||
};
|
||||
var url = $link.val();
|
||||
if (url.search("^http(s?)://.*")) {
|
||||
url = 'http://'+url;
|
||||
if (url.search('^http(s?)://.*')) {
|
||||
url = 'http://' + url;
|
||||
}
|
||||
|
||||
// https://gist.github.com/dperini/729294
|
||||
var regex = new RegExp(
|
||||
"^" +
|
||||
"^" +
|
||||
// protocol identifier
|
||||
"(?:(?:https?|ftp)://)" +
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?" +
|
||||
"(?:" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
||||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
||||
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
"|" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
// TLD may end with dot
|
||||
"\\.?" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
// TLD may end with dot
|
||||
"\\.?" +
|
||||
")" +
|
||||
// port number
|
||||
"(?::\\d{2,5})?" +
|
||||
// resource path
|
||||
"(?:[/?#]\\S*)?" +
|
||||
"$", "i"
|
||||
"$", "i"
|
||||
);
|
||||
|
||||
if (regex.test(url)){
|
||||
ajax.jsonRpc("/forum/get_url_title", 'call', {'url': url}).then(function (data) {
|
||||
if (regex.test(url)) {
|
||||
this._rpc({
|
||||
route: '/forum/get_url_title',
|
||||
params: {
|
||||
url: url,
|
||||
},
|
||||
}).then(function (data) {
|
||||
if (data) {
|
||||
$("input[name='post_name']")[0].value = data;
|
||||
$('input[name="post_name"]')[0].value = data;
|
||||
$link.parents('form').find('button')[0].disabled = false;
|
||||
} else {
|
||||
display_error();
|
||||
displayError();
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
display_error();
|
||||
displayError();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
odoo.define('website_forum.share', function (require) {
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var core = require('web.core');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var qweb = core.qweb;
|
||||
|
||||
// FIXME There is no reason to inherit from socialShare here
|
||||
var ForumShare = sAnimations.registry.socialShare.extend({
|
||||
selector: '',
|
||||
xmlDependencies: sAnimations.registry.socialShare.prototype.xmlDependencies
|
||||
.concat(['/website_forum/static/src/xml/website_forum_share_templates.xml']),
|
||||
read_events: {},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
* @param {Boolean} editableMode
|
||||
* @param {String} targetType
|
||||
* @param {boolean} editableMode
|
||||
* @param {string} targetType
|
||||
*/
|
||||
init: function (parent, editableMode, targetType) {
|
||||
this._super.apply(this, arguments);
|
||||
@@ -21,9 +25,8 @@ var ForumShare = sAnimations.registry.socialShare.extend({
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var def = this._super.apply(this, arguments);
|
||||
this._onMouseEnter();
|
||||
return def;
|
||||
@@ -64,31 +67,31 @@ var ForumShare = sAnimations.registry.socialShare.extend({
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
sAnimations.registry.websiteForumShare = sAnimations.Class.extend({
|
||||
selector: '.website_forum',
|
||||
selector: '#wrapwrap:has(.website_forum)',
|
||||
read_events: {
|
||||
'click :not(.karma_required).oe_social_share_call': '_onBody'
|
||||
'click :not(.karma_required).oe_social_share_call': '_onShareCallClick',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
// Retrieve stored social data
|
||||
if (sessionStorage.getItem('social_share')) {
|
||||
var socialData = JSON.parse(sessionStorage.getItem('social_share'));
|
||||
(new ForumShare(null, false, socialData.targetType)).attachTo($(document.body));
|
||||
(new ForumShare(this, false, socialData.targetType)).attachTo($(document.body));
|
||||
sessionStorage.removeItem('social_share');
|
||||
}
|
||||
// Display an alert if post has no reply and is older than 10 days
|
||||
var $questionContainer = $('.oe_js_bump');
|
||||
if ($questionContainer.length) {
|
||||
new ForumShare(null, false, 'social-alert').attachTo($questionContainer);
|
||||
new ForumShare(this, false, 'social-alert').attachTo($questionContainer);
|
||||
}
|
||||
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -96,16 +99,14 @@ sAnimations.registry.websiteForumShare = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Store social share data to display modal on next page
|
||||
* Stores social share data to display modal on next page.
|
||||
*
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onBody: function () {
|
||||
_onShareCallClick: function (ev) {
|
||||
sessionStorage.setItem('social_share', JSON.stringify({
|
||||
targetType: $(this).data('social-target-type'),
|
||||
targetType: $(ev.currentTarget).data('social-target-type'),
|
||||
}));
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,52 +1,62 @@
|
||||
odoo.define('website_links.website_links', function (require) {
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var Widget = require('web.Widget');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var _t = core._t;
|
||||
var exports = {};
|
||||
|
||||
var SelectBox = Widget.extend({
|
||||
xmlDependencies: ['/website_links/static/src/xml/recent_link.xml'],
|
||||
events: {
|
||||
'change': '_onChange',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @constructor
|
||||
* @param {Object} parent
|
||||
* @param {Object} obj
|
||||
* @param {String} placeholder
|
||||
*/
|
||||
init: function (obj) {
|
||||
init: function (parent, obj, placeholder) {
|
||||
this._super.apply(this, arguments);
|
||||
this.obj = obj;
|
||||
this.placeholder = placeholder;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
* @param {Object} element
|
||||
* @param {String} placeholder
|
||||
*/
|
||||
start: function (element, placeholder, parent) {
|
||||
willStart: function () {
|
||||
var self = this;
|
||||
this.element = element;
|
||||
this.placeholder = placeholder;
|
||||
|
||||
this._fetchObjects().then(function (results) {
|
||||
self.objects = results;
|
||||
|
||||
element.select2({
|
||||
placeholder: self.placeholder,
|
||||
allowClear: true,
|
||||
createSearchChoice: function (term) {
|
||||
if (self._objectExists(term)) { return null; }
|
||||
|
||||
return {id:term, text:_.str.sprintf("Create '%s'", term)};
|
||||
},
|
||||
createSearchChoicePosition: 'bottom',
|
||||
multiple: false,
|
||||
data: self.objects,
|
||||
});
|
||||
|
||||
element.on('change', function (e) {
|
||||
self._onChange(e);
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
defs.push(this._rpc({
|
||||
model: this.obj,
|
||||
method: 'search_read',
|
||||
}).then(function (result) {
|
||||
self.objects = _.map(result, function (val) {
|
||||
return {id: val.id, text: val.name};
|
||||
});
|
||||
}));
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
start: function () {
|
||||
var self = this;
|
||||
this.$el.select2({
|
||||
placeholder: self.placeholder,
|
||||
allowClear: true,
|
||||
createSearchChoice: function (term) {
|
||||
if (self._objectExists(term)) {
|
||||
return null;
|
||||
}
|
||||
return {id: term, text: _.str.sprintf("Create '%s'", term)};
|
||||
},
|
||||
createSearchChoicePosition: 'bottom',
|
||||
multiple: false,
|
||||
data: self.objects,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -54,20 +64,6 @@ var SelectBox = Widget.extend({
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_fetchObjects: function () {
|
||||
return this._rpc({
|
||||
model: this.obj,
|
||||
method: 'search_read',
|
||||
})
|
||||
.then(function (result) {
|
||||
return _.map(result, function (val) {
|
||||
return {id: val.id, text:val.name};
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {String} query
|
||||
@@ -84,14 +80,13 @@ var SelectBox = Widget.extend({
|
||||
_createObject: function (name) {
|
||||
var self = this;
|
||||
return this._rpc({
|
||||
model: this.obj,
|
||||
method: 'create',
|
||||
args: [{name:name}],
|
||||
})
|
||||
.then(function (record) {
|
||||
self.element.attr('value', record);
|
||||
self.objects.push({'id': record, 'text': name});
|
||||
});
|
||||
model: this.obj,
|
||||
method: 'create',
|
||||
args: [{name: name}],
|
||||
}).then(function (record) {
|
||||
self.$el.attr('value', record);
|
||||
self.objects.push({'id': record, 'text': name});
|
||||
});
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -99,53 +94,41 @@ var SelectBox = Widget.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onChange: function (e) {
|
||||
if (e.added && _.isString(e.added.id)) {
|
||||
this._createObject(e.added.id);
|
||||
_onChange: function (ev) {
|
||||
if (!ev.added || !_.isString(ev.added.id)) {
|
||||
return;
|
||||
}
|
||||
this._createObject(ev.added.id);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var RecentLinkBox = Widget.extend({
|
||||
template: 'website_links.RecentLink',
|
||||
events: {
|
||||
'click .btn_shorten_url_clipboard':'_toggleCopyButton',
|
||||
'click .o_website_links_edit_code':'_editCode',
|
||||
'click .o_website_links_ok_edit':function (e) {
|
||||
e.preventDefault();
|
||||
this._submitCode();
|
||||
},
|
||||
'click .o_website_links_cancel_edit': function (e) {
|
||||
e.preventDefault();
|
||||
this._cancelEdit();
|
||||
},
|
||||
'submit #o_website_links_edit_code_form': function (e) {
|
||||
e.preventDefault();
|
||||
this._submitCode();
|
||||
},
|
||||
'click .btn_shorten_url_clipboard': '_toggleCopyButton',
|
||||
'click .o_website_links_edit_code': '_editCode',
|
||||
'click .o_website_links_ok_edit': '_onLinksOkClick',
|
||||
'click .o_website_links_cancel_edit': '_onLinksCancelClick',
|
||||
'submit #o_website_links_edit_code_form': '_onSubmitCode',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @constructor
|
||||
* @param {Object} parent
|
||||
* @param {Object} obj
|
||||
*/
|
||||
init: function (parent, link_obj) {
|
||||
this._super(parent);
|
||||
this.link_obj = link_obj;
|
||||
init: function (parent, obj) {
|
||||
this._super.apply(this, arguments);
|
||||
this.link_obj = obj;
|
||||
this.animating_copy = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
* @param {Object} element
|
||||
* @param {String} placeholder
|
||||
*/
|
||||
start: function (element, placeholder, parent) {
|
||||
start: function () {
|
||||
new ClipboardJS(this.$('.btn_shorten_url_clipboard').get(0));
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
@@ -156,36 +139,30 @@ var RecentLinkBox = Widget.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {String} query
|
||||
*/
|
||||
_toggleCopyButton: function () {
|
||||
var self = this;
|
||||
|
||||
if (!this.animating_copy) {
|
||||
this.animating_copy = true;
|
||||
var top = this.$('.o_website_links_short_url').position().top;
|
||||
this.$('.o_website_links_short_url').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', 15)
|
||||
.css('top', top-2)
|
||||
.css('z-index', 2)
|
||||
.removeClass('o_website_links_short_url')
|
||||
.addClass('animated-link')
|
||||
.insertAfter(this.$('.o_website_links_short_url'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
top: "-=20",
|
||||
}, 500, function () {
|
||||
self.$('.animated-link').remove();
|
||||
self.animating_copy = false;
|
||||
});
|
||||
if (this.animating_copy) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_remove: function () {
|
||||
this.getParent().remove_link(this);
|
||||
|
||||
var self = this;
|
||||
this.animating_copy = true;
|
||||
var top = this.$('.o_website_links_short_url').position().top;
|
||||
this.$('.o_website_links_short_url').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', 15)
|
||||
.css('top', top - 2)
|
||||
.css('z-index', 2)
|
||||
.removeClass('o_website_links_short_url')
|
||||
.addClass('animated-link')
|
||||
.insertAfter(this.$('.o_website_links_short_url'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
top: '-=20',
|
||||
}, 500, function () {
|
||||
self.$('.animated-link').remove();
|
||||
self.animating_copy = false;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
@@ -198,8 +175,8 @@ var RecentLinkBox = Widget.extend({
|
||||
* @private
|
||||
*/
|
||||
_editCode: function () {
|
||||
var init_code = this.$('#o_website_links_code').html();
|
||||
this.$('#o_website_links_code').html("<form style='display:inline;' id='o_website_links_edit_code_form'><input type='hidden' id='init_code' value='" + init_code + "'/><input type='text' id='new_code' value='" + init_code + "'/></form>");
|
||||
var initCode = this.$('#o_website_links_code').html();
|
||||
this.$('#o_website_links_code').html('<form style="display:inline;" id="o_website_links_edit_code_form"><input type="hidden" id="init_code" value="' + initCode + '"/><input type="text" id="new_code" value="' + initCode + '"/></form>');
|
||||
this.$('.o_website_links_edit_code').hide();
|
||||
this.$('.copy-to-clipboard').hide();
|
||||
this.$('.o_website_links_edit_tools').show();
|
||||
@@ -213,8 +190,8 @@ var RecentLinkBox = Widget.extend({
|
||||
this.$('.o_website_links_edit_tools').hide();
|
||||
this.$('.o_website_links_code_error').hide();
|
||||
|
||||
var old_code = this.$('#o_website_links_edit_code_form #init_code').val();
|
||||
this.$('#o_website_links_code').html(old_code);
|
||||
var oldCode = this.$('#o_website_links_edit_code_form #init_code').val();
|
||||
this.$('#o_website_links_code').html(oldCode);
|
||||
|
||||
this.$('#code-error').remove();
|
||||
this.$('#o_website_links_code form').remove();
|
||||
@@ -225,16 +202,16 @@ var RecentLinkBox = Widget.extend({
|
||||
_submitCode: function () {
|
||||
var self = this;
|
||||
|
||||
var init_code = this.$('#o_website_links_edit_code_form #init_code').val();
|
||||
var new_code = this.$('#o_website_links_edit_code_form #new_code').val();
|
||||
var initCode = this.$('#o_website_links_edit_code_form #init_code').val();
|
||||
var newCode = this.$('#o_website_links_edit_code_form #new_code').val();
|
||||
|
||||
if (new_code === '') {
|
||||
self.$('.o_website_links_code_error').html("The code cannot be left empty");
|
||||
if (newCode === '') {
|
||||
self.$('.o_website_links_code_error').html(_t("The code cannot be left empty"));
|
||||
self.$('.o_website_links_code_error').show();
|
||||
return;
|
||||
}
|
||||
|
||||
function ShowNewCode(new_code) {
|
||||
function showNewCode(newCode) {
|
||||
self.$('.o_website_links_code_error').html('');
|
||||
self.$('.o_website_links_code_error').hide();
|
||||
|
||||
@@ -242,10 +219,10 @@ var RecentLinkBox = Widget.extend({
|
||||
|
||||
// Show new code
|
||||
var host = self.$('#o_website_links_host').html();
|
||||
self.$('#o_website_links_code').html(new_code);
|
||||
self.$('#o_website_links_code').html(newCode);
|
||||
|
||||
// Update button copy to clipboard
|
||||
self.$('.btn_shorten_url_clipboard').attr('data-clipboard-text', host + new_code);
|
||||
self.$('.btn_shorten_url_clipboard').attr('data-clipboard-text', host + newCode);
|
||||
|
||||
// Show action again
|
||||
self.$('.o_website_links_edit_code').show();
|
||||
@@ -253,30 +230,55 @@ var RecentLinkBox = Widget.extend({
|
||||
self.$('.o_website_links_edit_tools').hide();
|
||||
}
|
||||
|
||||
if (init_code === new_code) {
|
||||
ShowNewCode(new_code);
|
||||
}
|
||||
else {
|
||||
ajax.jsonRpc('/website_links/add_code', 'call', {'init_code':init_code, 'new_code':new_code})
|
||||
.then(function (result) {
|
||||
ShowNewCode(result[0].code);
|
||||
})
|
||||
.fail(function () {
|
||||
self.$('.o_website_links_code_error').show();
|
||||
self.$('.o_website_links_code_error').html("This code is already taken");
|
||||
}) ;
|
||||
if (initCode === newCode) {
|
||||
showNewCode(newCode);
|
||||
} else {
|
||||
this._rpc({
|
||||
route: '/website_links/add_code',
|
||||
params: {
|
||||
init_code: initCode,
|
||||
new_code: newCode,
|
||||
},
|
||||
}).then(function (result) {
|
||||
showNewCode(result[0].code);
|
||||
}, function () {
|
||||
self.$('.o_website_links_code_error').show();
|
||||
self.$('.o_website_links_code_error').html(_t("This code is already taken"));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onLinksOkClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
this._submitCode();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onLinksCancelClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
this._cancelEdit();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onSubmitCode: function (ev) {
|
||||
ev.preventDefault();
|
||||
this._submitCode();
|
||||
},
|
||||
});
|
||||
|
||||
var RecentLinks = Widget.extend({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super();
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
@@ -285,47 +287,42 @@ var RecentLinks = Widget.extend({
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_getRecentLinks: function (filter) {
|
||||
getRecentLinks: function (filter) {
|
||||
var self = this;
|
||||
ajax.jsonRpc('/website_links/recent_links', 'call', {'filter':filter, 'limit':20})
|
||||
.then(function (result) {
|
||||
_.each(result.reverse(), function (link) {
|
||||
self._addLink(link);
|
||||
});
|
||||
|
||||
self._updateNotification();
|
||||
})
|
||||
.fail(function () {
|
||||
var message = _t("Unable to get recent links");
|
||||
self.$el.append("<div class='alert alert-danger'>" + message + "</div>");
|
||||
return this._rpc({
|
||||
route: '/website_links/recent_links',
|
||||
params: {
|
||||
filter: filter,
|
||||
limit: 20,
|
||||
},
|
||||
}).then(function (result) {
|
||||
_.each(result.reverse(), function (link) {
|
||||
self._addLink(link);
|
||||
});
|
||||
self._updateNotification();
|
||||
}, function () {
|
||||
var message = _t("Unable to get recent links");
|
||||
self.$el.append('<div class="alert alert-danger">' + message + '</div>');
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_addLink: function (link) {
|
||||
var nb_links = this.getChildren().length;
|
||||
var recent_link_box = new RecentLinkBox(this, link);
|
||||
recent_link_box.prependTo(this.$el);
|
||||
var nbLinks = this.getChildren().length;
|
||||
var recentLinkBox = new RecentLinkBox(this, link);
|
||||
recentLinkBox.prependTo(this.$el);
|
||||
$('.link-tooltip').tooltip();
|
||||
|
||||
if (nb_links === 0) {
|
||||
if (nbLinks === 0) {
|
||||
this._updateNotification();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_removeLinks: function () {
|
||||
$('#o_website_links_recent_links .link-row').each(function () {
|
||||
this.remove();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_removeLink: function (link) {
|
||||
link.destroy();
|
||||
removeLinks: function () {
|
||||
_.invoke(this.getChildren(), 'destroy');
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
@@ -333,55 +330,54 @@ var RecentLinks = Widget.extend({
|
||||
_updateNotification: function () {
|
||||
if (this.getChildren().length === 0) {
|
||||
var message = _t("You don't have any recent links.");
|
||||
$('.o_website_links_recent_links_notification').html("<div class='alert alert-info'>" + message + "</div>");
|
||||
}
|
||||
else {
|
||||
$('.o_website_links_recent_links_notification').html('<div class="alert alert-info">' + message + '</div>');
|
||||
} else {
|
||||
$('.o_website_links_recent_links_notification').empty();
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
sAnimations.registry.websiteLinks = sAnimations.Class.extend({
|
||||
selector: '.o_website_links_create_tracked_url',
|
||||
read_events: {
|
||||
'click #filter-newest-links': '_onFilterNewestLinks',
|
||||
'click #filter-most-clicked-links': '_onFilterMostClickedLinks',
|
||||
'click #filter-recently-used-links': '_onFilterRecentlyUsedLinks',
|
||||
'click #generated_tracked_link a': '_onGeneratedTrackedLink',
|
||||
'click #filter-newest-links': '_onFilterNewestLinksClick',
|
||||
'click #filter-most-clicked-links': '_onFilterMostClickedLinksClick',
|
||||
'click #filter-recently-used-links': '_onFilterRecentlyUsedLinksClick',
|
||||
'click #generated_tracked_link a': '_onGeneratedTrackedLinkClick',
|
||||
'keyup #url': '_onUrlKeyUp',
|
||||
'click #btn_shorten_url': '_onBtnShortenUrl',
|
||||
'submit #o_website_links_link_tracker_form': '_onSubmitForm'
|
||||
'click #btn_shorten_url': '_onShortenUrlButtonClick',
|
||||
'submit #o_website_links_link_tracker_form': '_onFormSubmit',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
|
||||
// UTMS selects widgets
|
||||
var campaign_select = new SelectBox('utm.campaign');
|
||||
campaign_select.start($("#campaign-select"), _t('e.g. Promotion of June, Winter Newsletter, ..'));
|
||||
var campaignSelect = new SelectBox(this, 'utm.campaign', _t("e.g. Promotion of June, Winter Newsletter, .."));
|
||||
defs.push(campaignSelect.attachTo($('#campaign-select')));
|
||||
|
||||
var medium_select = new SelectBox('utm.medium');
|
||||
medium_select.start($("#channel-select"), _t('e.g. Newsletter, Social Network, ..'));
|
||||
var mediumSelect = new SelectBox(this, 'utm.medium', _t("e.g. Newsletter, Social Network, .."));
|
||||
defs.push(mediumSelect.attachTo($('#channel-select')));
|
||||
|
||||
var source_select = new SelectBox('utm.source');
|
||||
source_select.start($("#source-select"), _t('e.g. Search Engine, Website page, ..'));
|
||||
var sourceSelect = new SelectBox(this, 'utm.source', _t("e.g. Search Engine, Website page, .."));
|
||||
defs.push(sourceSelect.attachTo($('#source-select')));
|
||||
|
||||
// Recent Links Widgets
|
||||
this.recent_links = new RecentLinks();
|
||||
this.recent_links.appendTo($("#o_website_links_recent_links"));
|
||||
this.recent_links._getRecentLinks('newest');
|
||||
this.recentLinks = new RecentLinks();
|
||||
defs.push(this.recentLinks.appendTo($('#o_website_links_recent_links')));
|
||||
this.recentLinks.getRecentLinks('newest');
|
||||
|
||||
// Clipboard Library
|
||||
new ClipboardJS($("#btn_shorten_url").get(0));
|
||||
new ClipboardJS($('#btn_shorten_url').get(0));
|
||||
|
||||
this.url_copy_animating = false;
|
||||
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -389,143 +385,148 @@ sAnimations.registry.websiteLinks = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onFilterNewestLinks: function () {
|
||||
this.recent_links._removeLinks();
|
||||
this.recent_links._getRecentLinks('newest');
|
||||
_onFilterNewestLinksClick: function () {
|
||||
this.recentLinks.removeLinks();
|
||||
this.recentLinks.getRecentLinks('newest');
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onFilterMostClickedLinks: function () {
|
||||
this.recent_links._removeLinks();
|
||||
this.recent_links._getRecentLinks('most-clicked');
|
||||
_onFilterMostClickedLinksClick: function () {
|
||||
this.recentLinks.removeLinks();
|
||||
this.recentLinks.getRecentLinks('most-clicked');
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onFilterRecentlyUsedLinks: function () {
|
||||
this.recent_links._removeLinks();
|
||||
this.recent_links._getRecentLinks('recently-used');
|
||||
_onFilterRecentlyUsedLinksClick: function () {
|
||||
this.recentLinks.removeLinks();
|
||||
this.recentLinks.getRecentLinks('recently-used');
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onGeneratedTrackedLink: function () {
|
||||
$("#generated_tracked_link a").text("Copied").removeClass("btn-primary").addClass("btn-success");
|
||||
_onGeneratedTrackedLinkClick: function () {
|
||||
$('#generated_tracked_link a').text(_t("Copied")).removeClass('btn-primary').addClass('btn-success');
|
||||
setTimeout(function () {
|
||||
$("#generated_tracked_link a").text("Copy").removeClass("btn-success").addClass("btn-primary");
|
||||
}, '5000');
|
||||
$('#generated_tracked_link a').text(_t("Copy")).removeClass('btn-success').addClass('btn-primary');
|
||||
}, 5000);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onUrlKeyUp: function (e) {
|
||||
if ($('#btn_shorten_url').hasClass('btn-copy') && e.which !== 13) {
|
||||
$('#btn_shorten_url').removeClass('btn-success btn-copy').addClass('btn-primary').html('Get tracked link');
|
||||
$('#generated_tracked_link').css('display', 'none');
|
||||
$('.o_website_links_utm_forms').show();
|
||||
_onUrlKeyUp: function (ev) {
|
||||
if (!$('#btn_shorten_url').hasClass('btn-copy') || ev.which === 13) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_onBtnShortenUrl: function () {
|
||||
if ($('#btn_shorten_url').hasClass('btn-copy')) {
|
||||
if (!this.url_copy_animating) {
|
||||
this.url_copy_animating = true;
|
||||
|
||||
$('#generated_tracked_link').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', '78px')
|
||||
.css('bottom', '8px')
|
||||
.css('z-index', 2)
|
||||
.removeClass('#generated_tracked_link')
|
||||
.addClass('url-animated-link')
|
||||
.appendTo($('#generated_tracked_link'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
bottom: "+=20",
|
||||
}, 500, function () {
|
||||
$('.url-animated-link').remove();
|
||||
this.url_copy_animating = false;
|
||||
});
|
||||
}
|
||||
$('#btn_shorten_url').removeClass('btn-success btn-copy').addClass('btn-primary').html('Get tracked link');
|
||||
$('#generated_tracked_link').css('display', 'none');
|
||||
$('.o_website_links_utm_forms').show();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onShortenUrlButtonClick: function () {
|
||||
if (!$('#btn_shorten_url').hasClass('btn-copy') || this.url_copy_animating) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this.url_copy_animating = true;
|
||||
$('#generated_tracked_link').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', '78px')
|
||||
.css('bottom', '8px')
|
||||
.css('z-index', 2)
|
||||
.removeClass('#generated_tracked_link')
|
||||
.addClass('url-animated-link')
|
||||
.appendTo($('#generated_tracked_link'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
bottom: '+=20',
|
||||
}, 500, function () {
|
||||
$('.url-animated-link').remove();
|
||||
self.url_copy_animating = false;
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Add the RecentLinkBox widget and send the form when the user generate the link
|
||||
*
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onSubmitForm: function (ev) {
|
||||
_onFormSubmit: function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
if ($('#btn_shorten_url').hasClass('btn-copy')) {
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
// Get URL and UTMs
|
||||
var campaign_id = $('#campaign-select').attr('value');
|
||||
var medium_id = $('#channel-select').attr('value');
|
||||
var source_id = $('#source-select').attr('value');
|
||||
var campaignID = $('#campaign-select').attr('value');
|
||||
var mediumID = $('#channel-select').attr('value');
|
||||
var sourceID = $('#source-select').attr('value');
|
||||
|
||||
var params = {};
|
||||
params.url = $("#url").val();
|
||||
if (campaign_id !== '') { params.campaign_id = parseInt(campaign_id); }
|
||||
if (medium_id !== '') { params.medium_id = parseInt(medium_id); }
|
||||
if (source_id !== '') { params.source_id = parseInt(source_id); }
|
||||
params.url = $('#url').val();
|
||||
if (campaignID !== '') {
|
||||
params.campaign_id = parseInt(campaignID);
|
||||
}
|
||||
if (mediumID !== '') {
|
||||
params.medium_id = parseInt(mediumID);
|
||||
}
|
||||
if (sourceID !== '') {
|
||||
params.source_id = parseInt(sourceID);
|
||||
}
|
||||
|
||||
$('#btn_shorten_url').text(_t('Generating link...'));
|
||||
$('#btn_shorten_url').text(_t("Generating link..."));
|
||||
|
||||
ajax.jsonRpc("/website_links/new", 'call', params)
|
||||
.then(function (result) {
|
||||
if ('error' in result) {
|
||||
// Handle errors
|
||||
if (result.error === 'empty_url') {
|
||||
$('.notification').html("<div class='alert alert-danger'>The URL is empty.</div>");
|
||||
}
|
||||
else if (result.error === 'url_not_found') {
|
||||
$('.notification').html("<div class='alert alert-danger'>URL not found (404)</div>");
|
||||
}
|
||||
else {
|
||||
$('.notification').html("<div class='alert alert-danger'>An error occur while trying to generate your link. Try again later.</div>");
|
||||
}
|
||||
this._rpc({
|
||||
route: '/website_links/new',
|
||||
params: params,
|
||||
}).then(function (result) {
|
||||
if ('error' in result) {
|
||||
// Handle errors
|
||||
if (result.error === 'empty_url') {
|
||||
$('.notification').html('<div class="alert alert-danger">The URL is empty.</div>');
|
||||
} else if (result.error === 'url_not_found') {
|
||||
$('.notification').html('<div class="alert alert-danger">URL not found (404)</div>');
|
||||
} else {
|
||||
$('.notification').html('<div class="alert alert-danger">An error occur while trying to generate your link. Try again later.</div>');
|
||||
}
|
||||
else {
|
||||
// Link generated, clean the form and show the link
|
||||
var link = result[0];
|
||||
} else {
|
||||
// Link generated, clean the form and show the link
|
||||
var link = result[0];
|
||||
|
||||
$('#btn_shorten_url').removeClass('btn-primary').addClass('btn-success btn-copy').html('Copy');
|
||||
$('#btn_shorten_url').attr('data-clipboard-text', link.short_url);
|
||||
$('#btn_shorten_url').removeClass('btn-primary').addClass('btn-success btn-copy').html('Copy');
|
||||
$('#btn_shorten_url').attr('data-clipboard-text', link.short_url);
|
||||
|
||||
$('.notification').html('');
|
||||
$('#generated_tracked_link').html(link.short_url);
|
||||
$('#generated_tracked_link').css('display', 'inline');
|
||||
$('.notification').html('');
|
||||
$('#generated_tracked_link').html(link.short_url);
|
||||
$('#generated_tracked_link').css('display', 'inline');
|
||||
|
||||
this.recent_links._addLink(link);
|
||||
this.recentLinks._addLink(link);
|
||||
|
||||
// Clean URL and UTM selects
|
||||
$('#campaign-select').select2('val', '');
|
||||
$('#channel-select').select2('val', '');
|
||||
$('#source-select').select2('val', '');
|
||||
// Clean URL and UTM selects
|
||||
$('#campaign-select').select2('val', '');
|
||||
$('#channel-select').select2('val', '');
|
||||
$('#source-select').select2('val', '');
|
||||
|
||||
$('.o_website_links_utm_forms').hide();
|
||||
}
|
||||
});
|
||||
$('.o_website_links_utm_forms').hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
exports.SelectBox = SelectBox;
|
||||
exports.RecentLinkBox = RecentLinkBox;
|
||||
exports.RecentLinks = RecentLinks;
|
||||
|
||||
return exports;
|
||||
|
||||
return {
|
||||
SelectBox: SelectBox,
|
||||
RecentLinkBox: RecentLinkBox,
|
||||
RecentLinks: RecentLinks,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,87 +1,100 @@
|
||||
odoo.define('website_links.charts', function (require) {
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var Widget = require('web.Widget');
|
||||
var core = require('web.core');
|
||||
var Widget = require('web.Widget');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var _t = core._t;
|
||||
var exports = {};
|
||||
|
||||
var BarChart = Widget.extend({
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} $element
|
||||
* @param {Object} begin_date
|
||||
* @param {Object} end_date
|
||||
* @constructor
|
||||
* @param {Object} parent
|
||||
* @param {Object} beginDate
|
||||
* @param {Object} endDate
|
||||
* @param {Object} dates
|
||||
*/
|
||||
init: function ($element, begin_date, end_date, dates) {
|
||||
this.$element = $element;
|
||||
this.begin_date = begin_date;
|
||||
this.end_date = end_date;
|
||||
this.number_of_days = this.end_date.diff(this.begin_date, 'days') + 2;
|
||||
init: function (parent, beginDate, endDate, dates) {
|
||||
this._super.apply(this, arguments);
|
||||
this.beginDate = beginDate;
|
||||
this.endDate = endDate;
|
||||
this.number_of_days = this.endDate.diff(this.beginDate, 'days') + 2;
|
||||
this.dates = dates;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var self = this;
|
||||
|
||||
// Accessor functions
|
||||
function getDate(d) { return new Date(d[0]); }
|
||||
function getNbClicks(d) { return d[1]; }
|
||||
function getDate(d) {
|
||||
return new Date(d[0]);
|
||||
}
|
||||
function getNbClicks(d) {
|
||||
return d[1];
|
||||
}
|
||||
|
||||
// Prune tick values for visibility purpose
|
||||
function getPrunedTickValues(ticks, nb_desired_ticks) {
|
||||
var nb_values = ticks.length;
|
||||
var keep_one_of = Math.max(1, Math.floor(nb_values / nb_desired_ticks));
|
||||
function getPrunedTickValues(ticks, nbDesiredTicks) {
|
||||
var nbValues = ticks.length;
|
||||
var keepOneOf = Math.max(1, Math.floor(nbValues / nbDesiredTicks));
|
||||
|
||||
return _.filter(ticks, function (d, i) {
|
||||
return i % keep_one_of === 0;
|
||||
return i % keepOneOf === 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Fill data for each day (with 0 click for days without data)
|
||||
var clicks_array = [];
|
||||
var begin_date_copy = this.begin_date;
|
||||
for (var i = 0 ; i < this.number_of_days ; i++) {
|
||||
var date_key = begin_date_copy.format('YYYY-MM-DD');
|
||||
clicks_array.push([date_key, (date_key in this.dates) ? this.dates[date_key] : 0]);
|
||||
begin_date_copy.add(1, 'days');
|
||||
var clicksArray = [];
|
||||
var beginDateCopy = this.beginDate;
|
||||
for (var i = 0; i < this.number_of_days; i++) {
|
||||
var dateKey = beginDateCopy.format('YYYY-MM-DD');
|
||||
clicksArray.push([dateKey, (dateKey in this.dates) ? this.dates[dateKey] : 0]);
|
||||
beginDateCopy.add(1, 'days');
|
||||
}
|
||||
|
||||
// Set title
|
||||
var nb_clicks = _.reduce(clicks_array, function (total, val) { return total + val[1] ; }, 0);
|
||||
$(this.$element + ' .title').html(nb_clicks + _t(' clicks'));
|
||||
var nbClicks = _.reduce(clicksArray, function (total, val) {
|
||||
return total + val[1];
|
||||
}, 0);
|
||||
this.$('.title').html(nbClicks + _t(' clicks'));
|
||||
|
||||
// Fit data into the NVD3 scheme
|
||||
var chart_data = [{}];
|
||||
chart_data[0]['key'] = _t('# of clicks');
|
||||
chart_data[0]['values'] = clicks_array;
|
||||
var chartData = [{}];
|
||||
chartData[0]['key'] = _t('# of clicks');
|
||||
chartData[0]['values'] = clicksArray;
|
||||
|
||||
nv.addGraph(function () {
|
||||
var chart = nv.models.lineChart()
|
||||
.x(function (d) { return getDate(d); })
|
||||
.y(function (d) { return getNbClicks(d); })
|
||||
.x(function (d) {
|
||||
return getDate(d);
|
||||
})
|
||||
.y(function (d) {
|
||||
return getNbClicks(d);
|
||||
})
|
||||
.showYAxis(true)
|
||||
.showXAxis(true);
|
||||
|
||||
// Reduce the number of labels on the X axis for visibility
|
||||
var tick_values = getPrunedTickValues(chart_data[0]['values'], 10);
|
||||
var tickValues = getPrunedTickValues(chartData[0]['values'], 10);
|
||||
|
||||
chart.xAxis
|
||||
.tickFormat(function (d) { return d3.time.format("%d/%m/%y")(new Date(d)); })
|
||||
.tickValues(_.map(tick_values, function (d) { return getDate(d).getTime(); }))
|
||||
.tickFormat(function (d) {
|
||||
return d3.time.format('%d/%m/%y')(new Date(d));
|
||||
})
|
||||
.tickValues(_.map(tickValues, function (d) {
|
||||
return getDate(d).getTime();
|
||||
}))
|
||||
.rotateLabels(55);
|
||||
|
||||
chart.yAxis
|
||||
.tickFormat(d3.format("d"))
|
||||
.ticks(chart_data[0]['values'].length - 1);
|
||||
.tickFormat(d3.format('d'))
|
||||
.ticks(chartData[0]['values'].length - 1);
|
||||
|
||||
d3.select(self.$element + ' svg')
|
||||
.datum(chart_data)
|
||||
d3.select(self.$('svg')[0])
|
||||
.datum(chartData)
|
||||
.call(chart);
|
||||
|
||||
return self.chart = chart;
|
||||
@@ -92,38 +105,41 @@ var BarChart = Widget.extend({
|
||||
var PieChart = Widget.extend({
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} $element
|
||||
* @param {Object} parent
|
||||
* @param {Object} data
|
||||
*/
|
||||
init: function ($element, data) {
|
||||
init: function (parent, data) {
|
||||
this._super.apply(this, arguments);
|
||||
this.data = data;
|
||||
this.$element = $element;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var self = this;
|
||||
|
||||
// Process country data to fit into the NVD3 scheme
|
||||
var processed_data = [];
|
||||
for (var i = 0 ; i < this.data.length ; i++) {
|
||||
var country_name = this.data[i]['country_id'] ? this.data[i]['country_id'][1] : _t('Undefined');
|
||||
processed_data.push({'label':country_name + ' (' + this.data[i]['country_id_count'] + ')', 'value':this.data[i]['country_id_count']});
|
||||
var processedData = [];
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
var countryName = this.data[i]['country_id'] ? this.data[i]['country_id'][1] : _t('Undefined');
|
||||
processedData.push({'label': countryName + ' (' + this.data[i]['country_id_count'] + ')', 'value': this.data[i]['country_id_count']});
|
||||
}
|
||||
|
||||
// Set title
|
||||
$(this.$element + ' .title').html(this.data.length + _t(' countries'));
|
||||
this.$('.title').html(this.data.length + _t(' countries'));
|
||||
|
||||
nv.addGraph(function () {
|
||||
var chart = nv.models.pieChart()
|
||||
.x(function (d) { return d.label; })
|
||||
.y(function (d) { return d.value; })
|
||||
.x(function (d) {
|
||||
return d.label;
|
||||
})
|
||||
.y(function (d) {
|
||||
return d.value;
|
||||
})
|
||||
.showLabels(false);
|
||||
|
||||
d3.select(self.$element + ' svg')
|
||||
.datum(processed_data)
|
||||
d3.select(self.$('svg')[0])
|
||||
.datum(processedData)
|
||||
.transition().duration(1200)
|
||||
.call(chart);
|
||||
|
||||
@@ -135,78 +151,83 @@ var PieChart = Widget.extend({
|
||||
sAnimations.registry.websiteLinksCharts = sAnimations.Class.extend({
|
||||
selector: '.o_website_links_chart',
|
||||
read_events: {
|
||||
'click .graph-tabs li a': '_onResizeChart',
|
||||
'click .copy-to-clipboard': '_onCopyToClipboard'
|
||||
'click .graph-tabs li a': '_onGraphTabClick',
|
||||
'click .copy-to-clipboard': '_onCopyToClipboardClick',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
var self = this;
|
||||
this.charts = {};
|
||||
|
||||
// Get the code of the link
|
||||
var link_id = $('#link_id').val();
|
||||
var linkID = parseInt($('#link_id').val());
|
||||
this.links_domain = ['link_id', '=', linkID];
|
||||
|
||||
this.links_domain = ['link_id', '=', parseInt(link_id)];
|
||||
var defs = [];
|
||||
defs.push(this._totalClicks());
|
||||
defs.push(this._clicksByDay());
|
||||
defs.push(this._clicksByCountry());
|
||||
defs.push(this._lastWeekClicksByCountry());
|
||||
defs.push(this._lastMonthClicksByCountry());
|
||||
defs.push(this._super.apply(this, arguments));
|
||||
|
||||
$.when(this._totalClicks(),
|
||||
this._clicksByDay(),
|
||||
this._clicksByCountry(),
|
||||
this._lastWeekClicksByCountry(),
|
||||
this._lastMonthClicksByCountry())
|
||||
.done(function (_totalClicks, _clicksByDay, _clicksByCountry, _lastWeekClicksByCountry, _lastMonthClicksByCountry) {
|
||||
|
||||
if (_totalClicks) {
|
||||
this.charts = {};
|
||||
var formatted_clicks_by_day = {};
|
||||
var begin_date, end_date;
|
||||
for (var i = 0 ; i < _clicksByDay.length ; i++) {
|
||||
var date = moment(_clicksByDay[i]['create_date:day'], "DD MMMM YYYY");
|
||||
if (i === 0) { begin_date = date; }
|
||||
if (i === _clicksByDay.length - 1) { end_date = date; }
|
||||
formatted_clicks_by_day[date.format("YYYY-MM-DD")] = _clicksByDay[i]['create_date_count'];
|
||||
}
|
||||
|
||||
// Process all time line chart data
|
||||
var now = moment();
|
||||
this.charts.all_time_bar = new BarChart('#all_time_clicks_chart', begin_date, now, formatted_clicks_by_day);
|
||||
|
||||
// Process month line chart data
|
||||
begin_date = moment().subtract(30, 'days');
|
||||
this.charts.last_month_bar = new BarChart('#last_month_clicks_chart', begin_date, now, formatted_clicks_by_day);
|
||||
|
||||
// Process week line chart data
|
||||
begin_date = moment().subtract(7, 'days');
|
||||
this.charts.last_week_bar = new BarChart('#last_week_clicks_chart', begin_date, now, formatted_clicks_by_day);
|
||||
|
||||
// Process pie charts
|
||||
this.charts.all_time_pie = new PieChart('#all_time_countries_charts', _clicksByCountry);
|
||||
this.charts.last_month_pie = new PieChart('#last_month_countries_charts', _lastMonthClicksByCountry);
|
||||
this.charts.last_week_pie = new PieChart('#last_week_countries_charts', _lastWeekClicksByCountry);
|
||||
|
||||
var row_width = $('#all_time_countries_charts').parent().width();
|
||||
var charts_svg = $('#all_time_countries_charts,last_month_countries_charts,last_week_countries_charts').find('svg');
|
||||
charts_svg.css('height', Math.max(_clicksByCountry.length * (row_width > 750 ? 1 : 2), 20) + 'em');
|
||||
|
||||
_.invoke(this.charts, 'start');
|
||||
|
||||
nv.utils.windowResize(function () {
|
||||
_.chain(this.charts).pluck('chart').invoke('update');
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#all_time_charts').prepend(_t('There is no data to show'));
|
||||
$('#last_month_charts').prepend(_t('There is no data to show'));
|
||||
$('#last_week_charts').prepend(_t('There is no data to show'));
|
||||
}
|
||||
});
|
||||
|
||||
// Copy to clipboard link
|
||||
new ClipboardJS($('.copy-to-clipboard')[0]);
|
||||
|
||||
this.animating_copy = false;
|
||||
|
||||
return $.when.apply($, defs).then(function (_totalClicks, _clicksByDay, _clicksByCountry, _lastWeekClicksByCountry, _lastMonthClicksByCountry) {
|
||||
if (!_totalClicks) {
|
||||
$('#all_time_charts').prepend(_t("There is no data to show"));
|
||||
$('#last_month_charts').prepend(_t("There is no data to show"));
|
||||
$('#last_week_charts').prepend(_t("There is no data to show"));
|
||||
}
|
||||
|
||||
var formattedClicksByDay = {};
|
||||
var beginDate;
|
||||
for (var i = 0; i < _clicksByDay.length; i++) {
|
||||
var date = moment(_clicksByDay[i]['create_date:day'], 'DD MMMM YYYY');
|
||||
if (i === 0) {
|
||||
beginDate = date;
|
||||
}
|
||||
formattedClicksByDay[date.format('YYYY-MM-DD')] = _clicksByDay[i]['create_date_count'];
|
||||
}
|
||||
|
||||
// Process all time line chart data
|
||||
var now = moment();
|
||||
self.charts.all_time_bar = new BarChart(beginDate, now, formattedClicksByDay);
|
||||
self.charts.all_time_bar.attachTo($('#all_time_clicks_chart'));
|
||||
|
||||
// Process month line chart data
|
||||
beginDate = moment().subtract(30, 'days');
|
||||
self.charts.last_month_bar = new BarChart(beginDate, now, formattedClicksByDay);
|
||||
self.charts.last_month_bar.attachTo($('#last_month_clicks_chart'));
|
||||
|
||||
// Process week line chart data
|
||||
beginDate = moment().subtract(7, 'days');
|
||||
self.charts.last_week_bar = new BarChart(beginDate, now, formattedClicksByDay);
|
||||
self.charts.last_week_bar.attachTo($('#last_week_clicks_chart'));
|
||||
|
||||
// Process pie charts
|
||||
self.charts.all_time_pie = new PieChart(_clicksByCountry);
|
||||
self.charts.all_time_pie.attachTo($('#all_time_countries_charts'));
|
||||
|
||||
self.charts.last_month_pie = new PieChart(_lastMonthClicksByCountry);
|
||||
self.charts.last_month_pie.attachTo($('#last_month_countries_charts'));
|
||||
|
||||
self.charts.last_week_pie = new PieChart(_lastWeekClicksByCountry);
|
||||
self.charts.last_week_pie.attachTo($('#last_week_countries_charts'));
|
||||
|
||||
var rowWidth = $('#all_time_countries_charts').parent().width();
|
||||
var chartsSVG = $('#all_time_countries_charts,last_month_countries_charts,last_week_countries_charts').find('svg');
|
||||
chartsSVG.css('height', Math.max(_clicksByCountry.length * (rowWidth > 750 ? 1 : 2), 20) + 'em');
|
||||
|
||||
nv.utils.windowResize(function () {
|
||||
_.chain(self.charts).pluck('chart').invoke('update');
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -231,7 +252,7 @@ sAnimations.registry.websiteLinksCharts = sAnimations.Class.extend({
|
||||
model: 'link.tracker.click',
|
||||
method: 'read_group',
|
||||
args: [[this.links_domain], ['create_date']],
|
||||
kwargs: {groupby:'create_date:day'},
|
||||
kwargs: {groupby: 'create_date:day'},
|
||||
});
|
||||
},
|
||||
/**
|
||||
@@ -242,26 +263,26 @@ sAnimations.registry.websiteLinksCharts = sAnimations.Class.extend({
|
||||
model: 'link.tracker.click',
|
||||
method: 'read_group',
|
||||
args: [[this.links_domain], ['country_id']],
|
||||
kwargs: {groupby:'country_id'},
|
||||
kwargs: {groupby: 'country_id'},
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_lastWeekClicksByCountry: function () {
|
||||
var interval = moment().subtract(7, 'days').format("YYYY-MM-DD");
|
||||
var interval = moment().subtract(7, 'days').format('YYYY-MM-DD');
|
||||
return this._rpc({
|
||||
model: 'link.tracker.click',
|
||||
method: 'read_group',
|
||||
args: [[this.links_domain, ['create_date', '>', interval]], ['country_id']],
|
||||
kwargs: {groupby:'country_id'},
|
||||
kwargs: {groupby: 'country_id'},
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_lastMonthClicksByCountry: function () {
|
||||
var interval = moment().subtract(30, 'days').format("YYYY-MM-DD");
|
||||
var interval = moment().subtract(30, 'days').format('YYYY-MM-DD');
|
||||
return this._rpc({
|
||||
model: 'link.tracker.click',
|
||||
method: 'read_group',
|
||||
@@ -275,50 +296,50 @@ sAnimations.registry.websiteLinksCharts = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Resize the chart when a tab is opened, because NVD3 automatically reduce the size
|
||||
* of the chart to 5px width when the bootstrap tab is closed.
|
||||
* Resizes the chart when a tab is opened, because NVD3 automatically reduce
|
||||
* the size of the chart to 5px width when the bootstrap tab is closed.
|
||||
*
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onResizeChart: function (e) {
|
||||
e.preventDefault();
|
||||
_onGraphTabClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
$('.graph-tabs li a').tab('show');
|
||||
_.chain(this.charts).pluck('chart').invoke('update'); // Force NVD3 to redraw the chart
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCopyToClipboard: function (e) {
|
||||
e.preventDefault();
|
||||
_onCopyToClipboardClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
if (!this.animating_copy) {
|
||||
this.animating_copy = true;
|
||||
|
||||
$('.o_website_links_short_url').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', '15px')
|
||||
.css('bottom', '10px')
|
||||
.css('z-index', 2)
|
||||
.removeClass('.o_website_links_short_url')
|
||||
.addClass('animated-link')
|
||||
.appendTo($('.o_website_links_short_url'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
bottom: "+=20",
|
||||
}, 500, function () {
|
||||
$('.animated-link').remove();
|
||||
this.animating_copy = false;
|
||||
});
|
||||
if (this.animating_copy) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.animating_copy = true;
|
||||
|
||||
$('.o_website_links_short_url').clone()
|
||||
.css('position', 'absolute')
|
||||
.css('left', '15px')
|
||||
.css('bottom', '10px')
|
||||
.css('z-index', 2)
|
||||
.removeClass('.o_website_links_short_url')
|
||||
.addClass('animated-link')
|
||||
.appendTo($('.o_website_links_short_url'))
|
||||
.animate({
|
||||
opacity: 0,
|
||||
bottom: '+=20',
|
||||
}, 500, function () {
|
||||
$('.animated-link').remove();
|
||||
this.animating_copy = false;
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
exports.BarChart = BarChart;
|
||||
exports.PieChart = PieChart;
|
||||
|
||||
return exports;
|
||||
|
||||
return {
|
||||
BarChart: BarChart,
|
||||
PieChart: PieChart,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
odoo.define('website_links.code_editor', function (require) {
|
||||
'use strict';
|
||||
|
||||
var core = require('web.core');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({
|
||||
selector: '.o_website_links_edit_code',
|
||||
selector: '#wrapwrap:has(.o_website_links_edit_code)',
|
||||
read_events: {
|
||||
'click .o_website_links_edit_code': '_onEdit',
|
||||
'click .o_website_links_cancel_edit': '_onCancel',
|
||||
'submit #edit-code-form': '_onEditCodeForm',
|
||||
'click .o_website_links_ok_edit': '_onEditCodeForm'
|
||||
'click .o_website_links_edit_code': '_onEditCodeClick',
|
||||
'click .o_website_links_cancel_edit': '_onCancelEditClick',
|
||||
'submit #edit-code-form': '_onEditCodeFormSubmit',
|
||||
'click .o_website_links_ok_edit': '_onEditCodeFormSubmit',
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -19,9 +21,9 @@ sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {String} new_code
|
||||
* @param {String} newCode
|
||||
*/
|
||||
_showNewCode: function (new_code) {
|
||||
_showNewCode: function (newCode) {
|
||||
$('.o_website_links_code_error').html('');
|
||||
$('.o_website_links_code_error').hide();
|
||||
|
||||
@@ -29,10 +31,10 @@ sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({
|
||||
|
||||
// Show new code
|
||||
var host = $('#short-url-host').html();
|
||||
$('#o_website_links_code').html(new_code);
|
||||
$('#o_website_links_code').html(newCode);
|
||||
|
||||
// Update button copy to clipboard
|
||||
$('.copy-to-clipboard').attr('data-clipboard-text', host + new_code);
|
||||
$('.copy-to-clipboard').attr('data-clipboard-text', host + newCode);
|
||||
|
||||
// Show action again
|
||||
$('.o_website_links_edit_code').show();
|
||||
@@ -41,32 +43,39 @@ sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_submitCode: function () {
|
||||
var init_code = $('#edit-code-form #init_code').val();
|
||||
var new_code = $('#edit-code-form #new_code').val();
|
||||
var initCode = $('#edit-code-form #init_code').val();
|
||||
var newCode = $('#edit-code-form #new_code').val();
|
||||
var self = this;
|
||||
|
||||
if (new_code === '') {
|
||||
self.$('.o_website_links_code_error').html("The code cannot be left empty");
|
||||
if (newCode === '') {
|
||||
self.$('.o_website_links_code_error').html(_t("The code cannot be left empty"));
|
||||
self.$('.o_website_links_code_error').show();
|
||||
return;
|
||||
}
|
||||
|
||||
this._showNewCode(new_code);
|
||||
this._showNewCode(newCode);
|
||||
|
||||
if (init_code === new_code) {
|
||||
this._showNewCode(new_code);
|
||||
if (initCode === newCode) {
|
||||
this._showNewCode(newCode);
|
||||
} else {
|
||||
ajax.jsonRpc('/website_links/add_code', 'call', {'init_code':init_code, 'new_code':new_code})
|
||||
.then(function (result) {
|
||||
self._showNewCode(result[0].code);
|
||||
})
|
||||
.fail(function () {
|
||||
$('.o_website_links_code_error').show();
|
||||
$('.o_website_links_code_error').html("This code is already taken");
|
||||
});
|
||||
return this._rpc({
|
||||
route: '/website_links/add_code',
|
||||
params: {
|
||||
init_code: initCode,
|
||||
new_code: newCode,
|
||||
},
|
||||
}).then(function (result) {
|
||||
self._showNewCode(result[0].code);
|
||||
}, function () {
|
||||
$('.o_website_links_code_error').show();
|
||||
$('.o_website_links_code_error').html(_t("This code is already taken"));
|
||||
});
|
||||
}
|
||||
|
||||
return $.when();
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -74,41 +83,39 @@ sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onEdit: function () {
|
||||
var init_code = $('#o_website_links_code').html();
|
||||
$('#o_website_links_code').html("<form style='display:inline;' id='edit-code-form'><input type='hidden' id='init_code' value='" + init_code + "'/><input type='text' id='new_code' value='" + init_code + "'/></form>");
|
||||
_onEditCodeClick: function () {
|
||||
var initCode = $('#o_website_links_code').html();
|
||||
$('#o_website_links_code').html('<form style="display:inline;" id="edit-code-form"><input type="hidden" id="init_code" value="' + initCode + '"/><input type="text" id="new_code" value="' + initCode + '"/></form>');
|
||||
$('.o_website_links_edit_code').hide();
|
||||
$('.copy-to-clipboard').hide();
|
||||
$('.o_website_links_edit_tools').show();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCancel: function (e) {
|
||||
e.preventDefault();
|
||||
_onCancelEditClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
$('.o_website_links_edit_code').show();
|
||||
$('.copy-to-clipboard').show();
|
||||
$('.o_website_links_edit_tools').hide();
|
||||
$('.o_website_links_code_error').hide();
|
||||
|
||||
var old_code = $('#edit-code-form #init_code').val();
|
||||
$('#o_website_links_code').html(old_code);
|
||||
var oldCode = $('#edit-code-form #init_code').val();
|
||||
$('#o_website_links_code').html(oldCode);
|
||||
|
||||
$('#code-error').remove();
|
||||
$('#o_website_links_code form').remove();
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} e
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onEditCodeForm: function (e) {
|
||||
e.preventDefault();
|
||||
_onEditCodeFormSubmit: function (ev) {
|
||||
ev.preventDefault();
|
||||
this._submitCode();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
/* The purpose of this script is to copy the current URL of the website
|
||||
* into the URL form of the URL shortener (module website_links)
|
||||
* when the user click the link "Share this page" on top of the page.
|
||||
*/
|
||||
/**
|
||||
* The purpose of this script is to copy the current URL of the website
|
||||
* into the URL form of the URL shortener (module website_links)
|
||||
* when the user clicks the link "Share this page" on top of the page.
|
||||
*/
|
||||
|
||||
odoo.define('website_links.website_links_menu', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
sAnimations.registry.websiteLinksMenu = sAnimations.Class.extend({
|
||||
selector: '.navbar',
|
||||
selector: '#o_website_links_share_page',
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
$('#o_website_links_share_page').attr('href', '/r?u=' + encodeURIComponent(window.location.href));
|
||||
start: function () {
|
||||
this.$el.attr('href', '/r?u=' + encodeURIComponent(window.location.href));
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="website_links.RecentLink">
|
||||
<div class="row mb16 link-row">
|
||||
<div class="row mb16">
|
||||
<div class="col-md-1 col-2 text-center">
|
||||
<h4><t t-esc="widget.link_obj.count"/></h4>
|
||||
<p class="text-muted" style="margin-top: -5px;">clicks</p>
|
||||
</div>
|
||||
<div class="col-md-7 col-7">
|
||||
|
||||
|
||||
<h4 class="truncate_text">
|
||||
<img t-att-src="widget.link_obj.icon_src" alt="Icon"/>
|
||||
<img t-att-src="widget.link_obj.icon_src" alt="Icon"/>
|
||||
<a class="no-link-style" t-att-href="widget.link_obj.url"><t t-esc="widget.link_obj.title"/></a>
|
||||
</h4>
|
||||
<p class="text-muted mb0" style="margin-top: -5px;">
|
||||
@@ -19,14 +19,14 @@
|
||||
</span>
|
||||
|
||||
<span class="o_website_links_edit_tools" style="display:none;">
|
||||
<a role="button" class="o_website_links_ok_edit btn btn-sm btn-primary" href="#">ok</a> or
|
||||
<a role="button" class="o_website_links_ok_edit btn btn-sm btn-primary" href="#">ok</a> or
|
||||
<a class="o_website_links_cancel_edit" href="#">cancel</a>
|
||||
</span>
|
||||
|
||||
<a class="o_website_links_edit_code" aria-label="Edit code" title="Edit code"><span class="fa fa-pencil gray"></span></a>
|
||||
|
||||
|
||||
<br/>
|
||||
<span class="badge badge-success"><t t-esc="widget.link_obj.campaign_id[1]"/></span>
|
||||
<span class="badge badge-success"><t t-esc="widget.link_obj.campaign_id[1]"/></span>
|
||||
<span class="badge badge-success"><t t-esc="widget.link_obj.medium_id[1]"/></span>
|
||||
<span class="badge badge-success"><t t-esc="widget.link_obj.source_id[1]"/></span>
|
||||
</p>
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
odoo.define('website_mail_channel', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
|
||||
sAnimations.registry.websiteMailChannel = sAnimations.Class.extend({
|
||||
selector: '#group_message #messages_short',
|
||||
selector: '#wrapwrap',
|
||||
read_events: {
|
||||
'click .o_mg_link_hide': '_onHideLink',
|
||||
'click .o_mg_link_show': '_onShowLink',
|
||||
'click button.o_mg_read_more': '_onReadMore'
|
||||
'click .o_mg_link_hide': '_onHideLinkClick',
|
||||
'click .o_mg_link_show': '_onShowLinkClick',
|
||||
'click button.o_mg_read_more': '_onReadMoreClick',
|
||||
},
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onHideLink: function (ev) {
|
||||
_onHideLinkClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var $link = $(ev.currentTarget);
|
||||
var $container = $link.parents('div').first();
|
||||
$container.find('.o_mg_link_hide').first().hide();
|
||||
$container.find('.o_mg_link_show').first().show();
|
||||
$container.find('.o_mg_link_content').first().show();
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onShowLink: function (ev) {
|
||||
_onShowLinkClick: function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var $link = $(ev.currentTarget);
|
||||
var $container = $link.parents('div').first();
|
||||
$container.find('.o_mg_link_hide').first().show();
|
||||
$container.find('.o_mg_link_show').first().hide();
|
||||
$container.find('.o_mg_link_content').first().hide();
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onReadMore: function (ev) {
|
||||
_onReadMoreClick: function (ev) {
|
||||
var $link = $(ev.target);
|
||||
return ajax.jsonRpc($link.data('href'), 'call', {
|
||||
'last_displayed_id': $link.data('msg-id'),
|
||||
this._rpc({
|
||||
route: $link.data('href'),
|
||||
params: {
|
||||
last_displayed_id: $link.data('msg-id'),
|
||||
},
|
||||
}).then(function (data) {
|
||||
if (! data) {
|
||||
return true;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
var $thread_container = $link.parents('.o_mg_replies').first().find('ul.list-unstyled');
|
||||
if ($thread_container) {
|
||||
var $last_msg = $thread_container.find('li.media').last();
|
||||
$(data).find('li.media').insertAfter($last_msg);
|
||||
$(data).find('p.well').appendTo($thread_container);
|
||||
var $threadContainer = $link.parents('.o_mg_replies').first().find('ul.list-unstyled');
|
||||
if ($threadContainer) {
|
||||
var $lastMsg = $threadContainer.find('li.media').last();
|
||||
$(data).find('li.media').insertAfter($lastMsg);
|
||||
$(data).find('p.well').appendTo($threadContainer);
|
||||
}
|
||||
var $show_more = $link.parents('p.well').first();
|
||||
$show_more.remove();
|
||||
return true;
|
||||
var $showMore = $link.parents('p.well').first();
|
||||
$showMore.remove();
|
||||
return;
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,60 +1,48 @@
|
||||
odoo.define('website_sale_delivery.checkout', function (require) {
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
sAnimations.registry.websiteSaleDelivery = sAnimations.Class.extend({
|
||||
selector: '.oe_website_sale',
|
||||
read_events: {
|
||||
'change .oe_website_sale select[name="shipping_id"]': '_onSetAddress',
|
||||
'click #delivery_carrier input[name="delivery_type"]': '_onCarrierClick'
|
||||
'change select[name="shipping_id"]': '_onSetAddress',
|
||||
'click #delivery_carrier input[name="delivery_type"]': '_onCarrierClick',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
var $carriers = $("#delivery_carrier input[name='delivery_type']");
|
||||
start: function () {
|
||||
var $carriers = $('#delivery_carrier input[name="delivery_type"]');
|
||||
// Workaround to:
|
||||
// - update the amount/error on the label at first rendering
|
||||
// - prevent clicking on 'Pay Now' if the shipper rating fails
|
||||
if ($carriers.length > 0) {
|
||||
$carriers.filter(':checked').click();
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onCarrierClick: function (ev) {
|
||||
var $pay_button = $('#o_payment_form_pay');
|
||||
$pay_button.prop('disabled', true);
|
||||
var carrier_id = $(ev.currentTarget).val();
|
||||
var values = {'carrier_id': carrier_id};
|
||||
ajax.jsonRpc('/shop/update_carrier', 'call', values)
|
||||
.then(this._onCarrierUpdateAnswer);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} result
|
||||
*/
|
||||
_onCarrierUpdateAnswer: function (result) {
|
||||
var $pay_button = $('#o_payment_form_pay');
|
||||
var $amount_delivery = $('#order_delivery span.oe_currency_value');
|
||||
var $amount_untaxed = $('#order_total_untaxed span.oe_currency_value');
|
||||
var $amount_tax = $('#order_total_taxes span.oe_currency_value');
|
||||
var $amount_total = $('#order_total span.oe_currency_value');
|
||||
var $carrier_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .badge.d-none');
|
||||
var $compute_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .o_delivery_compute');
|
||||
_handleCarrierUpdateResult: function (result) {
|
||||
var $payButton = $('#o_payment_form_pay');
|
||||
var $amountDelivery = $('#order_delivery span.oe_currency_value');
|
||||
var $amountUntaxed = $('#order_total_untaxed span.oe_currency_value');
|
||||
var $amountTax = $('#order_total_taxes span.oe_currency_value');
|
||||
var $amountTotal = $('#order_total span.oe_currency_value');
|
||||
var $carrierBadge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .badge.d-none');
|
||||
var $computeBadge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .o_delivery_compute');
|
||||
var $discount = $('#order_discounted');
|
||||
|
||||
if ($discount && result.new_amount_order_discounted) {
|
||||
@@ -67,22 +55,21 @@ sAnimations.registry.websiteSaleDelivery = sAnimations.Class.extend({
|
||||
}
|
||||
|
||||
if (result.status === true) {
|
||||
$amount_delivery.text(result.new_amount_delivery);
|
||||
$amount_untaxed.text(result.new_amount_untaxed);
|
||||
$amount_tax.text(result.new_amount_tax);
|
||||
$amount_total.text(result.new_amount_total);
|
||||
$carrier_badge.children('span').text(result.new_amount_delivery);
|
||||
$carrier_badge.removeClass('d-none');
|
||||
$compute_badge.addClass('d-none');
|
||||
$pay_button.prop('disabled', false);
|
||||
}
|
||||
else {
|
||||
$amountDelivery.text(result.new_amount_delivery);
|
||||
$amountUntaxed.text(result.new_amount_untaxed);
|
||||
$amountTax.text(result.new_amount_tax);
|
||||
$amountTotal.text(result.new_amount_total);
|
||||
$carrierBadge.children('span').text(result.new_amount_delivery);
|
||||
$carrierBadge.removeClass('d-none');
|
||||
$computeBadge.addClass('d-none');
|
||||
$payButton.prop('disabled', false);
|
||||
} else {
|
||||
console.error(result.error_message);
|
||||
$compute_badge.text(result.error_message);
|
||||
$amount_delivery.text(result.new_amount_delivery);
|
||||
$amount_untaxed.text(result.new_amount_untaxed);
|
||||
$amount_tax.text(result.new_amount_tax);
|
||||
$amount_total.text(result.new_amount_total);
|
||||
$computeBadge.text(result.error_message);
|
||||
$amountDelivery.text(result.new_amount_delivery);
|
||||
$amountUntaxed.text(result.new_amount_untaxed);
|
||||
$amountTax.text(result.new_amount_tax);
|
||||
$amountTotal.text(result.new_amount_total);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -92,23 +79,34 @@ sAnimations.registry.websiteSaleDelivery = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onCarrierClick: function (ev) {
|
||||
$('#o_payment_form_pay').prop('disabled', true);
|
||||
this._rpc({
|
||||
route: '/shop/update_carrier',
|
||||
params: {
|
||||
carrier_id: $(ev.currentTarget).val(),
|
||||
},
|
||||
}).then(this._handleCarrierUpdateResult.bind(this));
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onSetAddress: function (ev) {
|
||||
var value = $(ev.currentTarget).val();
|
||||
var $provider_free = $("select[name='country_id']:not(.o_provider_restricted), select[name='state_id']:not(.o_provider_restricted)");
|
||||
var $provider_restricted = $("select[name='country_id'].o_provider_restricted, select[name='state_id'].o_provider_restricted");
|
||||
var $providerFree = $('select[name="country_id"]:not(.o_provider_restricted), select[name="state_id"]:not(.o_provider_restricted)');
|
||||
var $providerRestricted = $('select[name="country_id"].o_provider_restricted, select[name="state_id"].o_provider_restricted');
|
||||
if (value === 0) {
|
||||
// Ship to the same address : only show shipping countries available for billing
|
||||
$provider_free.hide().attr('disabled', true);
|
||||
$provider_restricted.show().attr('disabled', false).change();
|
||||
$providerFree.hide().attr('disabled', true);
|
||||
$providerRestricted.show().attr('disabled', false).change();
|
||||
} else {
|
||||
// Create a new address : show all countries available for billing
|
||||
$provider_free.show().attr('disabled', false).change();
|
||||
$provider_restricted.hide().attr('disabled', true);
|
||||
$providerFree.show().attr('disabled', false).change();
|
||||
$providerRestricted.hide().attr('disabled', true);
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,57 +1,53 @@
|
||||
/*global $, _, PDFJS */
|
||||
odoo.define('website_slides.slides', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var time = require('web.time');
|
||||
require('root.widget');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
var page_widgets = {};
|
||||
|
||||
sAnimations.registry.websiteSlides = sAnimations.Class.extend({
|
||||
selector: 'main',
|
||||
selector: '#wrapwrap',
|
||||
read_events: {
|
||||
'each timeago.timeago': '_onTimeAgo',
|
||||
'click .o_slides_hide_channel_settings': '_onHideChannelSettings',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
|
||||
_.each($("timeago.timeago"), function (el) {
|
||||
var datetime = $(el).attr('datetime');
|
||||
var datetimeObj = 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
|
||||
var displayStr = '';
|
||||
if (datetimeObj && new Date().getTime() - datetimeObj.getTime() > 7 * 24 * 60 * 60 * 1000) {
|
||||
displayStr = moment(datetimeObj).format('ll');
|
||||
} else {
|
||||
displayStr = moment(datetimeObj).fromNow();
|
||||
}
|
||||
$(el).text(displayStr);
|
||||
});
|
||||
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} index
|
||||
* @param {Object} el
|
||||
*/
|
||||
_onTimeAgo: function (index, el) {
|
||||
var datetime = $(el).attr('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 = "";
|
||||
if (datetime_obj && new Date().getTime() - datetime_obj.getTime() > 7 * 24 * 60 * 60 * 1000) {
|
||||
display_str = moment(datetime_obj).format('ll');
|
||||
} else {
|
||||
display_str = moment(datetime_obj).fromNow();
|
||||
}
|
||||
$(el).text(display_str);
|
||||
},
|
||||
/**
|
||||
* To prevent showing channel settings alert box once user closed it.
|
||||
*
|
||||
* @override
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_onHideChannelSettings: function (ev) {
|
||||
var channel_id = $(this).data("channelId");
|
||||
ev.preventDefault();
|
||||
document.cookie = "slides_channel_" + channel_id + " = closed";
|
||||
return true;
|
||||
var channelID = $(ev.currentTarget).data('channelId');
|
||||
document.cookie = 'slides_channel_' + channelID + ' = closed';
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
page_widgets: page_widgets,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,35 +1,47 @@
|
||||
/*global $, _, PDFSlidesViewer*/
|
||||
odoo.define('website_slides.slides_embed', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var Widget = require('web.Widget');
|
||||
require('website_slides.slides');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
|
||||
// Embedded Code Widget
|
||||
var SlideSocialEmbed = Widget.extend({
|
||||
events: {
|
||||
'change input' : '_changePage',
|
||||
'change input': '_onChangePage',
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @constructor
|
||||
* @param {Object} parent
|
||||
* @param {Number} max_page
|
||||
* @param {Number} maxPage
|
||||
*/
|
||||
init: function (parent, max_page){
|
||||
this._super(parent);
|
||||
this.max_page = max_page || false;
|
||||
init: function (parent, maxPage) {
|
||||
this._super.apply(this, arguments);
|
||||
this.max_page = maxPage || false;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Number} page
|
||||
*/
|
||||
_updateEmbeddedCode: function (page) {
|
||||
var $embedInput = this.$('.slide_embed_code');
|
||||
var newCode = $embedInput.val().replace(/(page=).*?([^\d]+)/, '$1' + page + '$2');
|
||||
$embedInput.val(newCode);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_changePage: function (ev){
|
||||
_onChangePage: function (ev) {
|
||||
ev.preventDefault();
|
||||
var input = this.$('input');
|
||||
var page = parseInt(input.val());
|
||||
@@ -38,21 +50,19 @@ var SlideSocialEmbed = Widget.extend({
|
||||
}
|
||||
this._updateEmbeddedCode(page);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Number} page
|
||||
*/
|
||||
_updateEmbeddedCode: function (page){
|
||||
var embed_input = this.$('.slide_embed_code');
|
||||
var new_code = embed_input.val().replace(/(page=).*?([^\d]+)/, '$1' + page + '$2');
|
||||
embed_input.val(new_code);
|
||||
},
|
||||
});
|
||||
|
||||
sAnimations.registry.websiteSlidesEmbed = sAnimations.Class.extend({
|
||||
selector: 'main',
|
||||
read_events: {
|
||||
'ready iframe.o_wslides_iframe_viewer': '_onIframeViewer',
|
||||
selector: '#wrapwrap', // TODO improve
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
$('iframe.o_wslides_iframe_viewer').on('ready', this._onIframeViewerReady.bind(this));
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -60,31 +70,31 @@ sAnimations.registry.websiteSlidesEmbed = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_onIframeViewer: function () {
|
||||
_onIframeViewerReady: function (ev) {
|
||||
// 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 $iframe = $(this);
|
||||
var max_page = $iframe.contents().find('#page_count').val();
|
||||
new SlideSocialEmbed($iframe, max_page).setElement($('.oe_slide_js_embed_code_widget'));
|
||||
var $iframe = $(ev.currentTarget);
|
||||
var maxPage = $iframe.contents().find('#page_count').val();
|
||||
new SlideSocialEmbed(this, maxPage).attachTo($('.oe_slide_js_embed_code_widget'));
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
This file is a minimal version of the PDFViewer widget.
|
||||
It is NOT use in the website_slides module, but it is
|
||||
called when embedding a slide/video/document.
|
||||
This code can depend on pdf.js, JQuery and Bootstrap
|
||||
(see website_slides.slide_embed_assets bundle, in website_slides_embed.xml)
|
||||
**/
|
||||
* This is a minimal version of the PDFViewer widget.
|
||||
* It is NOT use in the website_slides module, but it is called when embedding
|
||||
* a slide/video/document. This code can depend on pdf.js, JQuery and Bootstrap
|
||||
* (see website_slides.slide_embed_assets bundle, in website_slides_embed.xml)
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
|
||||
if($('#PDFViewer') && $('#PDFViewerCanvas')){ // check if presentation only
|
||||
if ($('#PDFViewer') && $('#PDFViewerCanvas')) { // check if presentation only
|
||||
|
||||
// define embedded viewer (minimal object of the website.slide.PDFViewer widget)
|
||||
var EmbeddedViewer = function($viewer){
|
||||
var EmbeddedViewer = function ($viewer) {
|
||||
var self = this;
|
||||
this.viewer = $viewer;
|
||||
this.slide_url = $viewer.find('#PDFSlideViewer').data('slideurl');
|
||||
@@ -93,17 +103,17 @@ $(document).ready(function () {
|
||||
this.canvas = $viewer.find('canvas')[0];
|
||||
|
||||
this.pdf_viewer = new PDFSlidesViewer(this.slide_url, this.canvas, true);
|
||||
this.pdf_viewer.loadDocument().then(function(file_content){
|
||||
this.pdf_viewer.loadDocument().then(function () {
|
||||
self.on_loaded_file();
|
||||
});
|
||||
};
|
||||
EmbeddedViewer.prototype.__proto__ = {
|
||||
// jquery inside the object (like Widget)
|
||||
$: function(selector){
|
||||
$: function (selector) {
|
||||
return this.viewer.find($(selector));
|
||||
},
|
||||
// post process action (called in '.then()')
|
||||
on_loaded_file: function(){
|
||||
on_loaded_file: function () {
|
||||
this.$('canvas').show();
|
||||
this.$('#page_count').text(this.pdf_viewer.pdf_page_total);
|
||||
this.$('#PDFViewerLoader').hide();
|
||||
@@ -112,34 +122,34 @@ $(document).ready(function () {
|
||||
}
|
||||
// init first page to display
|
||||
var initpage = this.defaultpage;
|
||||
var pageNum = (initpage > 0 && initpage <= this.pdf_viewer.pdf_page_total)? initpage : 1;
|
||||
var pageNum = (initpage > 0 && initpage <= this.pdf_viewer.pdf_page_total) ? initpage : 1;
|
||||
this.render_page(pageNum);
|
||||
},
|
||||
on_rendered_page: function(page_number){
|
||||
if(page_number){
|
||||
this.$('#page_number').val(page_number);
|
||||
on_rendered_page: function (pageNumber) {
|
||||
if (pageNumber) {
|
||||
this.$('#page_number').val(pageNumber);
|
||||
}
|
||||
},
|
||||
// page switching
|
||||
render_page: function (page_number) {
|
||||
this.pdf_viewer.renderPage(page_number).then(this.on_rendered_page.bind(this));
|
||||
render_page: function (pageNumber) {
|
||||
this.pdf_viewer.renderPage(pageNumber).then(this.on_rendered_page.bind(this));
|
||||
},
|
||||
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.bind(this));
|
||||
}else{
|
||||
var pageAsked = parseInt(this.$('#page_number').val(), 10);
|
||||
if (1 <= pageAsked && pageAsked <= this.pdf_viewer.pdf_page_total) {
|
||||
this.pdf_viewer.changePage(pageAsked).then(this.on_rendered_page.bind(this));
|
||||
} else {
|
||||
// if page number out of range, reset the page_counter to the actual page
|
||||
this.$('#page_number').val(this.pdf_viewer.pdf_page_current);
|
||||
}
|
||||
},
|
||||
next: function () {
|
||||
var self = this;
|
||||
this.pdf_viewer.nextPage().then(function(page_num){
|
||||
if(page_num){
|
||||
self.on_rendered_page(page_num);
|
||||
}else{
|
||||
if(self.pdf_viewer.pdf){ // avoid display suggestion when pdf is not loaded yet
|
||||
this.pdf_viewer.nextPage().then(function (pageNum) {
|
||||
if (pageNum) {
|
||||
self.on_rendered_page(pageNum);
|
||||
} else {
|
||||
if (self.pdf_viewer.pdf) { // avoid display suggestion when pdf is not loaded yet
|
||||
self.display_suggested_slides();
|
||||
}
|
||||
}
|
||||
@@ -147,24 +157,24 @@ $(document).ready(function () {
|
||||
},
|
||||
previous: function () {
|
||||
var self = this;
|
||||
this.pdf_viewer.previousPage().then(function(page_num){
|
||||
if(page_num){
|
||||
self.on_rendered_page(page_num);
|
||||
this.pdf_viewer.previousPage().then(function (pageNum) {
|
||||
if (pageNum) {
|
||||
self.on_rendered_page(pageNum);
|
||||
}
|
||||
self.$("#slide_suggest").hide();
|
||||
});
|
||||
},
|
||||
first: function () {
|
||||
var self = this;
|
||||
this.pdf_viewer.firstPage().then(function(page_num){
|
||||
self.on_rendered_page(page_num);
|
||||
this.pdf_viewer.firstPage().then(function (pageNum) {
|
||||
self.on_rendered_page(pageNum);
|
||||
self.$("#slide_suggest").hide();
|
||||
});
|
||||
},
|
||||
last: function () {
|
||||
var self = this;
|
||||
this.pdf_viewer.lastPage().then(function(page_num){
|
||||
self.on_rendered_page(page_num);
|
||||
this.pdf_viewer.lastPage().then(function (pageNum) {
|
||||
self.on_rendered_page(pageNum);
|
||||
self.$("#slide_suggest").hide();
|
||||
});
|
||||
},
|
||||
@@ -184,38 +194,38 @@ $(document).ready(function () {
|
||||
};
|
||||
|
||||
// embedded pdf viewer
|
||||
var embedded_viewer = new EmbeddedViewer($('#PDFViewer'));
|
||||
var embeddedViewer = new EmbeddedViewer($('#PDFViewer'));
|
||||
|
||||
// bind the actions
|
||||
$('#previous').on('click', function(){
|
||||
embedded_viewer.previous();
|
||||
$('#previous').on('click', function () {
|
||||
embeddedViewer.previous();
|
||||
});
|
||||
$('#next').on('click', function(){
|
||||
embedded_viewer.next();
|
||||
$('#next').on('click', function () {
|
||||
embeddedViewer.next();
|
||||
});
|
||||
$('#first').on('click', function(){
|
||||
embedded_viewer.first();
|
||||
$('#first').on('click', function () {
|
||||
embeddedViewer.first();
|
||||
});
|
||||
$('#last').on('click', function(){
|
||||
embedded_viewer.last();
|
||||
$('#last').on('click', function () {
|
||||
embeddedViewer.last();
|
||||
});
|
||||
$('#page_number').on('change', function(){
|
||||
embedded_viewer.change_page();
|
||||
$('#page_number').on('change', function () {
|
||||
embeddedViewer.change_page();
|
||||
});
|
||||
$('#fullscreen').on('click',function(){
|
||||
embedded_viewer.fullscreen();
|
||||
$('#fullscreen').on('click', function () {
|
||||
embeddedViewer.fullscreen();
|
||||
});
|
||||
$('#PDFViewer').on('click',function (ev){
|
||||
embedded_viewer.fullScreenFooter(ev);
|
||||
$('#PDFViewer').on('click', function (ev) {
|
||||
embeddedViewer.fullScreenFooter(ev);
|
||||
});
|
||||
|
||||
// switching slide with keyboard
|
||||
$(document).keydown(function (ev) {
|
||||
if (ev.keyCode === 37 || ev.keyCode === 38) {
|
||||
embedded_viewer.previous();
|
||||
embeddedViewer.previous();
|
||||
}
|
||||
if (ev.keyCode === 39 || ev.keyCode === 40) {
|
||||
embedded_viewer.next();
|
||||
embeddedViewer.next();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,7 +233,7 @@ $(document).ready(function () {
|
||||
$('.oe_slide_js_embed_option_link').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var toggleDiv = $(this).data('slide-option-id');
|
||||
$('.oe_slide_embed_option').not(toggleDiv).each(function() {
|
||||
$('.oe_slide_embed_option').not(toggleDiv).each(function () {
|
||||
$(this).hide();
|
||||
});
|
||||
$(toggleDiv).slideToggle();
|
||||
@@ -242,35 +252,35 @@ $(document).ready(function () {
|
||||
// embed widget page selector
|
||||
$('.oe_slide_js_embed_code_widget input').on('change', function () {
|
||||
var page = parseInt($(this).val());
|
||||
if (!(page > 0 && page <= embedded_viewer.pdf_viewer.pdf_page_total)) {
|
||||
if (!(page > 0 && page <= embeddedViewer.pdf_viewer.pdf_page_total)) {
|
||||
page = 1;
|
||||
}
|
||||
var actual_code = embedded_viewer.$('.slide_embed_code').val();
|
||||
var new_code = actual_code.replace(/(page=).*?([^\d]+)/, '$1' + page + '$2');
|
||||
embedded_viewer.$('.slide_embed_code').val(new_code);
|
||||
var actualCode = embeddedViewer.$('.slide_embed_code').val();
|
||||
var newCode = actualCode.replace(/(page=).*?([^\d]+)/, '$1' + page + '$2');
|
||||
embeddedViewer.$('.slide_embed_code').val(newCode);
|
||||
});
|
||||
|
||||
// To avoid create a dependancy to openerpframework.js, we use JQuery AJAX to post data instead of ajax.jsonRpc
|
||||
$('.oe_slide_js_share_email button').on('click', function () {
|
||||
var widget = $('.oe_slide_js_share_email');
|
||||
var input = widget.find('input');
|
||||
var slide_id = widget.find('button').data('slide-id');
|
||||
if(input.val() && input[0].checkValidity()){
|
||||
var slideID = widget.find('button').data('slide-id');
|
||||
if (input.val() && input[0].checkValidity()) {
|
||||
widget.removeClass('o_has_error').find('.form-control, .custom-select').removeClass('is-invalid');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
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()}}),
|
||||
data: JSON.stringify({'jsonrpc': "2.0", 'method': "call", "params": {'slide_id': slideID, 'email': input.val()}}),
|
||||
success: function () {
|
||||
widget.html($('<div class="alert alert-info" role="alert"><strong>Thank you!</strong> Mail has been sent.</div>'));
|
||||
},
|
||||
error: function(data){
|
||||
console.log("ERROR ", data);
|
||||
}
|
||||
error: function (data) {
|
||||
console.error("ERROR ", data);
|
||||
},
|
||||
});
|
||||
}else{
|
||||
} else {
|
||||
widget.addClass('o_has_error').find('.form-control, .custom-select').addClass('is-invalid');
|
||||
input.focus();
|
||||
}
|
||||
|
||||
@@ -1,49 +1,46 @@
|
||||
/*global $, _, PDFJS */
|
||||
odoo.define('website_slides.slides_like', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var Widget = require('web.Widget');
|
||||
var local_storage = require('web.local_storage');
|
||||
var localStorage = require('web.local_storage');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var slides = require('website_slides.slides');
|
||||
require('website_slides.slides');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
// Like/Dislike Buttons Widget
|
||||
var LikeButton = Widget.extend({
|
||||
events: {
|
||||
'click': '_onClick',
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} $el
|
||||
*/
|
||||
setElement: function ($el){
|
||||
this._super.apply(this, arguments);
|
||||
this.$el.on('click', this, _.bind(this._applyAction, this));
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_applyAction: function (ev){
|
||||
_applyAction: function (ev) {
|
||||
var button = $(ev.currentTarget);
|
||||
var slide_id = button.data('slide-id');
|
||||
var user_id = button.data('user-id');
|
||||
var is_public = button.data('public-user');
|
||||
var slideID = button.data('slide-id');
|
||||
var userID = button.data('user-id');
|
||||
var isPublic = button.data('public-user');
|
||||
var href = button.data('href');
|
||||
if (is_public){
|
||||
if (isPublic) {
|
||||
this._popoverAlert(button, _.str.sprintf(_t('Please <a href="/web?redirect=%s">login</a> to vote this slide'), (document.URL)));
|
||||
} else {
|
||||
var target = button.find('.fa');
|
||||
if (local_storage.getItem('slide_vote_' + slide_id) !== user_id.toString()) {
|
||||
ajax.jsonRpc(href, 'call', {slide_id: slide_id}).then(function (data) {
|
||||
if (localStorage.getItem('slide_vote_' + slideID) !== userID.toString()) {
|
||||
this._rpc({
|
||||
route: href,
|
||||
params: {
|
||||
slide_id: slideID,
|
||||
},
|
||||
}).then(function (data) {
|
||||
target.text(data);
|
||||
local_storage.setItem('slide_vote_' + slide_id, user_id);
|
||||
localStorage.setItem('slide_vote_' + slideID, userID);
|
||||
});
|
||||
} else {
|
||||
this._popoverAlert(button, _t('You have already voted for this slide'));
|
||||
@@ -55,7 +52,7 @@ var LikeButton = Widget.extend({
|
||||
* @param {Object} $el
|
||||
* @param {String} message
|
||||
*/
|
||||
_popoverAlert: function ($el, message){
|
||||
_popoverAlert: function ($el, message) {
|
||||
$el.popover({
|
||||
trigger: 'focus',
|
||||
placement: 'bottom',
|
||||
@@ -66,20 +63,31 @@ var LikeButton = Widget.extend({
|
||||
}
|
||||
}).popover('show');
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onClick: function () {
|
||||
this._applyAction();
|
||||
},
|
||||
});
|
||||
|
||||
sAnimations.registry.websiteSlidesLike = sAnimations.Class.extend({
|
||||
selector: 'main',
|
||||
selector: '#wrapwrap',
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
var widget_parent = $('body');
|
||||
slides.page_widgets['likeButton'] = new LikeButton(widget_parent).setElement($('.oe_slide_js_like'));
|
||||
slides.page_widgets['dislikeButton'] = new LikeButton(widget_parent).setElement($('.oe_slide_js_unlike'));
|
||||
return this._super.apply(this, arguments);
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
defs.push(new LikeButton(this).attachTo($('.oe_slide_js_like')));
|
||||
defs.push(new LikeButton(this).attachTo($('.oe_slide_js_unlike')));
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
odoo.define('website_slides.slides_share', function (require) {
|
||||
"use strict";
|
||||
var ajax = require('web.ajax');
|
||||
'use strict';
|
||||
|
||||
var Widget = require('web.Widget');
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var slides = require('website_slides.slides');
|
||||
require('website_slides.slides');
|
||||
|
||||
// Send by email Widget
|
||||
var ShareMail = Widget.extend({
|
||||
events: {
|
||||
'click button': '_sendMail',
|
||||
@@ -21,12 +20,15 @@ var ShareMail = Widget.extend({
|
||||
_sendMail: function () {
|
||||
var self = this;
|
||||
var input = this.$('input');
|
||||
var slide_id = this.$('button').data('slide-id');
|
||||
if (input.val() && input[0].checkValidity()){
|
||||
var slideID = this.$('button').data('slide-id');
|
||||
if (input.val() && input[0].checkValidity()) {
|
||||
this.$el.removeClass('o_has_error').find('.form-control, .custom-select').removeClass('is-invalid');
|
||||
ajax.jsonRpc('/slides/slide/send_share_email', 'call', {
|
||||
slide_id: slide_id,
|
||||
email: input.val(),
|
||||
this._rpc({
|
||||
route: '/slides/slide/send_share_email',
|
||||
params: {
|
||||
slide_id: slideID,
|
||||
email: input.val(),
|
||||
},
|
||||
}).then(function () {
|
||||
self.$el.html($('<div class="alert alert-info" role="alert"><strong>Thank you!</strong> Mail has been sent.</div>'));
|
||||
});
|
||||
@@ -38,9 +40,9 @@ var ShareMail = Widget.extend({
|
||||
});
|
||||
|
||||
sAnimations.registry.websiteSlidesShare = sAnimations.Class.extend({
|
||||
selector: 'main',
|
||||
selector: '#wrapwrap',
|
||||
read_events: {
|
||||
'click a.o_slides_social_share': '_onSlidesSocialShare'
|
||||
'click a.o_slides_social_share': '_onSlidesSocialShare',
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -48,22 +50,24 @@ sAnimations.registry.websiteSlidesShare = sAnimations.Class.extend({
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
var widget_parent = $('body');
|
||||
slides.page_widgets['share_mail'] = new ShareMail(widget_parent).setElement($('.oe_slide_js_share_email'));
|
||||
var defs = [this._super.apply(this, arguments)];
|
||||
defs.push(new ShareMail(this).attachTo($('.oe_slide_js_share_email')));
|
||||
|
||||
if ($('div#statistic').length) {
|
||||
var slide_url = $("div#statistic").attr('slide-url');
|
||||
var social_urls = {
|
||||
'linkedin': 'https://www.linkedin.com/countserv/count/share?url=',
|
||||
'twitter': 'https://cdn.api.twitter.com/1/urls/count.json?url=',
|
||||
'facebook': 'https://graph.facebook.com/?id=',
|
||||
'gplus': 'https://clients6.google.com/rpc'
|
||||
var slideURL = $('div#statistic').attr('slide-url');
|
||||
var socialURLs = {
|
||||
linkedin: 'https://www.linkedin.com/countserv/count/share?url=',
|
||||
twitter: 'https://cdn.api.twitter.com/1/urls/count.json?url=',
|
||||
facebook: 'https://graph.facebook.com/?id=',
|
||||
gplus: 'https://clients6.google.com/rpc',
|
||||
};
|
||||
}
|
||||
|
||||
$.each(social_urls, function (key, value) {
|
||||
this._updateStatistics(key, slide_url);
|
||||
_.each(socialURLs, function (value, key) {
|
||||
this._updateStatistics(key, slideURL);
|
||||
});
|
||||
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -72,29 +76,29 @@ sAnimations.registry.websiteSlidesShare = sAnimations.Class.extend({
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} social_site
|
||||
* @param {string} socialSite
|
||||
* @param {string} slide_url
|
||||
*/
|
||||
_updateStatistics: function (social_site, slide_url) {
|
||||
if (social_site === 'gplus') {
|
||||
_updateStatistics: function (socialSite, slideURL) {
|
||||
if (socialSite === 'gplus') {
|
||||
$.ajax({
|
||||
url: this.social_urls['gplus'],
|
||||
type: "POST",
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify([{
|
||||
"method": "pos.plusones.get",
|
||||
"id": "p",
|
||||
"params": {
|
||||
"nolog": true,
|
||||
"id": slide_url,
|
||||
"source": "widget",
|
||||
"userId": "@viewer",
|
||||
"groupId": "@self"
|
||||
method: 'pos.plusones.get',
|
||||
id: 'p',
|
||||
params: {
|
||||
nolog: true,
|
||||
id: slideURL,
|
||||
source: 'widget',
|
||||
userId: '@viewer',
|
||||
groupId: '@self'
|
||||
},
|
||||
// TDE NOTE: should there be a key here ?
|
||||
"jsonrpc": "2.0",
|
||||
"apiVersion": "v1"
|
||||
jsonrpc: '2.0',
|
||||
apiVersion: 'v1'
|
||||
}]),
|
||||
success: function (data) {
|
||||
$('#google-badge').text(data[0].result.metadata.globalCounts.count || 0);
|
||||
@@ -103,12 +107,12 @@ sAnimations.registry.websiteSlidesShare = sAnimations.Class.extend({
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: this.social_urls[social_site] + slide_url,
|
||||
url: this.social_urls[socialSite] + slideURL,
|
||||
dataType: 'jsonp',
|
||||
success: function (data) {
|
||||
var shareCount = (social_site === 'facebook' ? data.shares : data.count) || 0;
|
||||
$('#' + social_site + '-badge').text(shareCount);
|
||||
$('#total-share').text(parseInt($('#total-share').text()) + parseInt($('#' + social_site+ '-badge').text()));
|
||||
var shareCount = (socialSite === 'facebook' ? data.shares : data.count) || 0;
|
||||
$('#' + socialSite + '-badge').text(shareCount);
|
||||
$('#total-share').text(parseInt($('#total-share').text()) + parseInt($('#' + socialSite + '-badge').text()));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -126,10 +130,7 @@ sAnimations.registry.websiteSlidesShare = sAnimations.Class.extend({
|
||||
ev.preventDefault();
|
||||
var key = $(ev.currentTarget).attr('social-key');
|
||||
var popUpURL = $(ev.currentTarget).attr('href');
|
||||
var popUp = window.open(
|
||||
popUpURL,
|
||||
'Share Dialog',
|
||||
'width=626,height=436');
|
||||
var popUp = window.open(popUpURL, 'Share Dialog', 'width=626,height=436');
|
||||
$(window).on('focus', function () {
|
||||
if (popUp.closed) {
|
||||
this._updateStatistics(key, this.slide_url);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
odoo.define('website_slides.upload', function (require) {
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var sAnimations = require('website.content.snippets.animation');
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var Widget = require('web.Widget');
|
||||
var slides = require('website_slides.slides');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -28,22 +26,22 @@ var SlideDialog = Widget.extend({
|
||||
* @param {Object} el
|
||||
* @param {number} channel_id
|
||||
*/
|
||||
init: function (el, channel_id) {
|
||||
this._super(el, channel_id);
|
||||
this.channel_id = parseInt(channel_id, 10);
|
||||
init: function (el, channelID) {
|
||||
this._super(el, channelID);
|
||||
this.channel_id = parseInt(channelID, 10);
|
||||
this.file = {};
|
||||
this.index_content = "";
|
||||
this.index_content = '';
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
this.$el.modal({
|
||||
backdrop: 'static'
|
||||
});
|
||||
this._setCategoryId();
|
||||
this._setTagIds();
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -54,12 +52,12 @@ var SlideDialog = Widget.extend({
|
||||
* @private
|
||||
* @param {string} file_name
|
||||
*/
|
||||
_checkUniqueSlide: function (file_name) {
|
||||
_checkUniqueSlide: function (fileName) {
|
||||
var self = this;
|
||||
return this._rpc({
|
||||
model: 'slide.slide',
|
||||
method: 'search_count',
|
||||
args: [[['channel_id', '=', self.channel_id], ['name', '=', file_name]]],
|
||||
args: [[['channel_id', '=', self.channel_id], ['name', '=', fileName]]],
|
||||
});
|
||||
},
|
||||
/**
|
||||
@@ -89,7 +87,7 @@ var SlideDialog = Widget.extend({
|
||||
* resolved data should be array of object with id and name. eg. [{'id': id, 'name': 'text'}, ...]
|
||||
* @returns {Object} select2 wrapper object
|
||||
*/
|
||||
_select2Wrapper: function (tag, multi, fetch_fnc) {
|
||||
_select2Wrapper: function (tag, multi, fetchFNC) {
|
||||
return {
|
||||
width: '100%',
|
||||
placeholder: tag,
|
||||
@@ -97,7 +95,7 @@ var SlideDialog = Widget.extend({
|
||||
formatNoMatches: false,
|
||||
multiple: multi,
|
||||
selection_data: false,
|
||||
fetch_rpc_fnc : fetch_fnc,
|
||||
fetch_rpc_fnc: fetchFNC,
|
||||
formatSelection: function (data) {
|
||||
if (data.tag) {
|
||||
data.text = data.tag;
|
||||
@@ -105,8 +103,8 @@ var SlideDialog = Widget.extend({
|
||||
return data.text;
|
||||
},
|
||||
createSearchChoice: function (term, data) {
|
||||
var added_tags = $(this.opts.element).select2('data');
|
||||
if (_.filter(_.union(added_tags, data), function (tag) {
|
||||
var addedTags = $(this.opts.element).select2('data');
|
||||
if (_.filter(_.union(addedTags, data), function (tag) {
|
||||
return tag.text.toLowerCase().localeCompare(term.toLowerCase()) === 0;
|
||||
}).length === 0) {
|
||||
return {
|
||||
@@ -122,7 +120,7 @@ var SlideDialog = Widget.extend({
|
||||
tags = {results: []};
|
||||
_.each(data, function (obj) {
|
||||
if (that.matcher(query.term, obj.name)) {
|
||||
tags.results.push({id: obj.id, text: obj.name });
|
||||
tags.results.push({id: obj.id, text: obj.name});
|
||||
}
|
||||
});
|
||||
query.callback(tags);
|
||||
@@ -147,7 +145,7 @@ var SlideDialog = Widget.extend({
|
||||
* @private
|
||||
*/
|
||||
_setCategoryId: function () {
|
||||
var self = this;
|
||||
var self = this;
|
||||
$('#category_id').select2(this._select2Wrapper(_t('Category'), false,
|
||||
function () {
|
||||
return this._rpc({
|
||||
@@ -209,12 +207,12 @@ var SlideDialog = Widget.extend({
|
||||
// TODO: Remove this part, as now SVG support in image resize tools is included
|
||||
//Python PIL does not support SVG, so converting SVG to PNG
|
||||
_svgToPng: function () {
|
||||
var img = this.$el.find("img#slide-image")[0];
|
||||
var canvas = document.createElement("canvas");
|
||||
var img = this.$el.find('img#slide-image')[0];
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
canvas.getContext("2d").drawImage(img, 0, 0);
|
||||
return canvas.toDataURL("image/png").split(',')[1];
|
||||
canvas.getContext('2d').drawImage(img, 0, 0);
|
||||
return canvas.toDataURL('image/png').split(',')[1];
|
||||
},
|
||||
/**
|
||||
* Values and save
|
||||
@@ -283,7 +281,10 @@ var SlideDialog = Widget.extend({
|
||||
}
|
||||
this.$('.oe_slides_upload_loading').show();
|
||||
this.$('.modal-footer, .modal-body').hide();
|
||||
ajax.jsonRpc("/slides/add_slide", 'call', values).then(function (data) {
|
||||
this._rpc({
|
||||
route: '/slides/add_slide',
|
||||
params: values,
|
||||
}).then(function (data) {
|
||||
if (data.error) {
|
||||
self._displayAlert(data.error);
|
||||
self.$('.oe_slides_upload_loading').hide();
|
||||
@@ -299,20 +300,20 @@ var SlideDialog = Widget.extend({
|
||||
* @override
|
||||
*/
|
||||
_cancel: function () {
|
||||
this.trigger("cancel");
|
||||
this.trigger('cancel');
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_slideUpload: function (ev) {
|
||||
var self = this,
|
||||
file = ev.target.files[0],
|
||||
is_image = /^image\/.*/.test(file.type),
|
||||
loaded = false;
|
||||
var self = this;
|
||||
var file = ev.target.files[0];
|
||||
var isImage = /^image\/.*/.test(file.type);
|
||||
var loaded = false;
|
||||
this.file.name = file.name;
|
||||
this.file.type = file.type;
|
||||
if (!(is_image || this.file.type === 'application/pdf')) {
|
||||
if (!(isImage || this.file.type === 'application/pdf')) {
|
||||
this._displayAlert(_t("Invalid file type. Please select pdf or image file"));
|
||||
this._resetFile();
|
||||
return;
|
||||
@@ -328,8 +329,8 @@ var SlideDialog = Widget.extend({
|
||||
BinaryReader.readAsDataURL(file);
|
||||
BinaryReader.onloadend = function (upload) {
|
||||
var buffer = upload.target.result;
|
||||
if (is_image) {
|
||||
self.$("#slide-image").attr("src", buffer);
|
||||
if (isImage) {
|
||||
self.$('#slide-image').attr('src', buffer);
|
||||
}
|
||||
buffer = buffer.split(',')[1];
|
||||
self.file.data = buffer;
|
||||
@@ -360,8 +361,8 @@ var SlideDialog = Widget.extend({
|
||||
canvasContext: context,
|
||||
viewport: viewport
|
||||
}).then(function () {
|
||||
var image_data = self.$('#data_canvas')[0].toDataURL();
|
||||
self.$("#slide-image").attr("src", image_data);
|
||||
var imageData = self.$('#data_canvas')[0].toDataURL();
|
||||
self.$('#slide-image').attr('src', imageData);
|
||||
if (loaded) {
|
||||
self.$('.save').button('reset');
|
||||
}
|
||||
@@ -371,20 +372,20 @@ var SlideDialog = Widget.extend({
|
||||
});
|
||||
var maxPages = pdf.pdfInfo.numPages;
|
||||
var page, j;
|
||||
self.index_content = "";
|
||||
self.index_content = '';
|
||||
for (j = 1; j <= maxPages; j += 1) {
|
||||
page = pdf.getPage(j);
|
||||
page.then(function (page_obj) {
|
||||
var page_number = page_obj.pageIndex + 1;
|
||||
page_obj.getTextContent().then(function (data) {
|
||||
var page_content = '';
|
||||
page.then(function (pageObj) {
|
||||
var pageNumber = pageObj.pageIndex + 1;
|
||||
pageObj.getTextContent().then(function (data) {
|
||||
var pageContent = '';
|
||||
_.each(data.items, function (obj) {
|
||||
page_content = page_content + obj.str + " ";
|
||||
pageContent = pageContent + obj.str + ' ';
|
||||
});
|
||||
// page_content may contain null characters
|
||||
page_content = page_content.replace(/\0/g, "");
|
||||
self.index_content = self.index_content + page_number + ". " + page_content + '\n';
|
||||
if (maxPages === page_number) {
|
||||
pageContent = pageContent.replace(/\0/g, '');
|
||||
self.index_content = self.index_content + pageNumber + '. ' + pageContent + '\n';
|
||||
if (maxPages === pageNumber) {
|
||||
if (loaded) {
|
||||
self.$('.save').button('reset');
|
||||
}
|
||||
@@ -398,17 +399,17 @@ var SlideDialog = Widget.extend({
|
||||
}
|
||||
|
||||
var input = file.name;
|
||||
var input_val = input.substr(0, input.lastIndexOf('.')) || input;
|
||||
this._checkUniqueSlide(input_val).then(function (exist) {
|
||||
var inputVal = input.substr(0, input.lastIndexOf('.')) || input;
|
||||
this._checkUniqueSlide(inputVal).then(function (exist) {
|
||||
if (exist) {
|
||||
var message = _t("Channel contains the given title, please change before Save or Publish.");
|
||||
self._displayAlert(message);
|
||||
}
|
||||
self.$('#name').val(input_val);
|
||||
self.$('#name').val(inputVal);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
* @param {Object} ev
|
||||
*/
|
||||
_slideUrl: function (ev) {
|
||||
@@ -420,12 +421,15 @@ var SlideDialog = Widget.extend({
|
||||
this.$('.alert-warning').remove();
|
||||
this.is_valid_url = false;
|
||||
this.$('.save').button('loading');
|
||||
ajax.jsonRpc('/slides/dialog_preview/', 'call', value).then(function (data) {
|
||||
this._rpc({
|
||||
route: '/slides/dialog_preview/',
|
||||
params: value,
|
||||
}).then(function (data) {
|
||||
self.$('.save').button('reset');
|
||||
if (data.error) {
|
||||
self._displayAlert(data.error);
|
||||
} else {
|
||||
self.$("#slide-image").attr("src", data.url_src);
|
||||
self.$('#slide-image').attr('src', data.url_src);
|
||||
self.$('#name').val(data.title);
|
||||
self.$('#description').val(data.description);
|
||||
self.is_valid_url = true;
|
||||
@@ -439,18 +443,26 @@ sAnimations.registry.websiteSlidesUpload = sAnimations.Class.extend({
|
||||
selector: '.oe_slide_js_upload',
|
||||
xmlDependencies: ['/website_slides/static/src/xml/website_slides.xml'],
|
||||
read_events: {
|
||||
'click .oe_slide_js_upload': '_bindEventButton',
|
||||
'click': '_onUploadClick',
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param {Object} parent
|
||||
*/
|
||||
start: function (parent) {
|
||||
start: function () {
|
||||
// Automatically open the upload dialog if requested from query string
|
||||
if ($.deparam.querystring().enable_slide_upload !== undefined) {
|
||||
$('.oe_slide_js_upload').click();
|
||||
this._openDialog(this.$el.attr('channel_id'));
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
_openDialog: function (channelID) {
|
||||
new SlideDialog(this, channelID).appendTo(document.body);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -458,13 +470,11 @@ sAnimations.registry.websiteSlidesUpload = sAnimations.Class.extend({
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
* @param {Event} ev
|
||||
*/
|
||||
_bindEventButton: function () {
|
||||
var channel_id = $(this).attr('channel_id');
|
||||
slides.page_widgets['upload_dialog'] = new SlideDialog(this, channel_id).appendTo(document.body);
|
||||
_onUploadClick: function (ev) {
|
||||
this._openDialog($(ev.currentTarget).attr('channel_id'));
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user