[REF] website_version: update to the new module system

This commit is contained in:
Géry Debongnie
2015-03-18 09:23:36 +01:00
parent 65586f8ef3
commit d6254a264b
4 changed files with 550 additions and 550 deletions
@@ -1,79 +1,80 @@
(function() {
'use strict';
var hash = "#advanced-view-editor";
var _t = openerp._t;
var website=openerp.website;
odoo.define('website_version.edit', ['web.ajax', 'web.core', 'website.editor'], function (require) {
'use strict';
website.action= {};
website.EditorBar.include({
start: function() {
var self = this;
this.$el.on('click', '#save_as_new_version', function() {
var wizardA = $(openerp.qweb.render("website_version.new_version",{'default_name': moment().format('L')}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_create', function(){
wizardA.find('.o_message').remove();
var version_name = wizardA.find('.o_version_name').val();
if(version_name.length == 0){
wizardA.find(".o_version_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
}
else{
wizardA.modal("hide");
openerp.jsonRpc( '/website_version/create_version', 'call', { 'name': version_name, 'version_id': 0}).then(function (result) {
$('html').data('version_id', result);
var wizard = $(openerp.qweb.render("website_version.dialogue",{message:_.str.sprintf("You are now working on version: %s.", version_name),
dialogue:_.str.sprintf("If you edit this page or others, all changes will be recorded in the version. It will not be visible by visitors until you publish the version.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
self.save();
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}).fail(function(){
var wizard = $(openerp.qweb.render("website_version.message",{message:_t("This name already exists.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
}
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
});
this.$el.on('click', '#save_and_publish', function() {
var version_id = parseInt($('html').data('version_id'));
if(version_id)
{
self.save();
}
else
{
var wizard = $(openerp.qweb.render("website_version.publish",{message:_t("Are you sure you want to publish your modifications.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
self.save();
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}
var ajax = require('web.ajax');
var core = require('web.core');
var editor = require('website.editor');
});
var _t = core._t;
var qweb = core.qweb;
$('.option_choice').click(function() {
self.$el.find(".o_second_choice").remove();
var name = $('#version-menu-button').data('version_name');
if(name){
self.$el.find(".o_first_choice").before(openerp.qweb.render("all_options", {version:'Save on '+name}));
editor.EditorBar.include({
start: function() {
var self = this;
this.$el.on('click', '#save_as_new_version', function() {
var wizardA = $(qweb.render("website_version.new_version",{'default_name': moment().format('L')}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_create', function(){
wizardA.find('.o_message').remove();
var version_name = wizardA.find('.o_version_name').val();
if(version_name.length === 0){
wizardA.find(".o_version_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
}
else{
self.$el.find(".o_first_choice").before(openerp.qweb.render("all_options", {version:'Save and Publish'}));
wizardA.modal("hide");
ajax.jsonRpc( '/website_version/create_version', 'call', { 'name': version_name, 'version_id': 0}).then(function (result) {
$('html').data('version_id', result);
var wizard = $(qweb.render("website_version.dialogue",{message:_.str.sprintf("You are now working on version: %s.", version_name),
dialogue:_.str.sprintf("If you edit this page or others, all changes will be recorded in the version. It will not be visible by visitors until you publish the version.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
self.save();
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}).fail(function(){
var wizard = $(qweb.render("website_version.message",{message:_t("This name already exists.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
}
});
return this._super();
}
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
})();
});
this.$el.on('click', '#save_and_publish', function() {
var version_id = parseInt($('html').data('version_id'));
if(version_id)
{
self.save();
}
else
{
var wizard = $(qweb.render("website_version.publish",{message:_t("Are you sure you want to publish your modifications.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
self.save();
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}
});
$('.option_choice').click(function() {
self.$el.find(".o_second_choice").remove();
var name = $('#version-menu-button').data('version_name');
if(name){
self.$el.find(".o_first_choice").before(qweb.render("all_options", {version:'Save on '+name}));
}
else{
self.$el.find(".o_first_choice").before(qweb.render("all_options", {version:'Save and Publish'}));
}
});
return this._super();
}
});
});
@@ -1,291 +1,293 @@
(function() {
'use strict';
var _t = openerp._t;
var website=openerp.website;
var QWeb = openerp.qweb;
website.add_template_file('/website_version/static/src/xml/version_templates.xml');
website.EditorVersion = openerp.Widget.extend({
start: function() {
var self = this;
odoo.define('website_version.menu_version', ['web.ajax', 'web.core', 'web.Widget', 'website.website'], function (require) {
'use strict';
$('html').data('version_id', this.$el.find("#version-menu-button").data("version_id"));
var _get_context = website.get_context;
website.get_context = function (dict) {
return _.extend({ 'version_id': $('html').data('version_id') }, _get_context(dict));
};
var ajax = require('web.ajax');
var core = require('web.core');
var Widget = require('web.Widget');
var website = require('website.website');
self.$el.on('click', 'a[data-action]', function(ev) {
ev.preventDefault();
self[$(this).data('action')](ev);
var _t = core._t;
var QWeb = core.qweb;
website.add_template_file('/website_version/static/src/xml/version_templates.xml');
var EditorVersion = Widget.extend({
start: function() {
var self = this;
$('html').data('version_id', this.$el.find("#version-menu-button").data("version_id"));
var _get_context = website.get_context;
website.get_context = function (dict) {
return _.extend({ 'version_id': $('html').data('version_id') }, _get_context(dict));
};
self.$el.on('click', 'a[data-action]', function(ev) {
ev.preventDefault();
self[$(this).data('action')](ev);
});
this.$el.find('#version-menu-button').click(function() {
var view_id = parseInt($('html').attr('data-view-xmlid'));
ajax.jsonRpc( '/website_version/all_versions', 'call', {'view_id': view_id}).then(function (result) {
self.$el.find(".o_version_choice").remove();
self.$el.find(".first_divider").before(QWeb.render("all_versions", {versions:result}));
});
ajax.jsonRpc( '/website_version/has_experiments', 'call', {'view_id': view_id}).then(function (result) {
self.$el.find(".o_experiment").remove();
if(result){
self.$el.find(".create_experiment").after(QWeb.render("experiment_menu"));
}
});
this.$el.find('#version-menu-button').click(function() {
var view_id = parseInt($('html').attr('data-view-xmlid'));
openerp.jsonRpc( '/website_version/all_versions', 'call', {'view_id': view_id}).then(function (result) {
self.$el.find(".o_version_choice").remove();
self.$el.find(".first_divider").before(QWeb.render("all_versions", {versions:result}));
});
return this._super();
},
duplicate_version: function() {
var version_id = $('html').data('version_id');
var wizardA = $(QWeb.render("website_version.new_version",{'default_name': moment().format('L')}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_create', function(){
wizardA.find('.o_message').remove();
var version_name = wizardA.find('.o_version_name').val();
if(version_name.length === 0){
wizardA.find(".o_version_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
}
else{
wizardA.modal("hide");
ajax.jsonRpc( '/website_version/create_version', 'call', { 'name': version_name, 'version_id': version_id}).then(function (result) {
var wizard = $(QWeb.render("website_version.dialogue",{message:_.str.sprintf("You are now working on version: %s.", version_name),
dialogue:_.str.sprintf("If you edit this page or others, all changes will be recorded in the version. It will not be visible by visitors until you publish the version.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
window.location.href = '\?enable_editor';
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}).fail(function(){
var wizard = $(QWeb.render("website_version.message",{message:_t("This name already exists.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
openerp.jsonRpc( '/website_version/has_experiments', 'call', {'view_id': view_id}).then(function (result) {
self.$el.find(".o_experiment").remove();
if(result){
self.$el.find(".create_experiment").after(QWeb.render("experiment_menu"));
}
});
}
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
},
change_version: function(event) {
var version_id = parseInt($(event.target).parent().data("version_id"));
if(! version_id){
version_id = 0;//By default master
}
ajax.jsonRpc( '/website_version/change_version', 'call', { 'version_id':version_id }).then(function () {
location.reload();
});
return this._super();
},
duplicate_version: function(event) {
var version_id = $('html').data('version_id');
var wizardA = $(openerp.qweb.render("website_version.new_version",{'default_name': moment().format('L')}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_create', function(){
wizardA.find('.o_message').remove();
var version_name = wizardA.find('.o_version_name').val();
if(version_name.length == 0){
wizardA.find(".o_version_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
},
delete_version: function(event) {
console.log(event);
var version_id = parseInt($(event.currentTarget).parent().data("version_id"));
var name = $(event.currentTarget).parent().children(':last-child').text();
ajax.jsonRpc( '/website_version/check_version', 'call', { 'version_id':version_id }).then(function (result) {
if (result){
var wizard = $(QWeb.render("website_version.message",{message:_.str.sprintf("You cannot delete the %s version because it is in a running or paused experiment", name)}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}
else{
wizardA.modal("hide");
openerp.jsonRpc( '/website_version/create_version', 'call', { 'name': version_name, 'version_id': version_id}).then(function (result) {
var wizard = $(openerp.qweb.render("website_version.dialogue",{message:_.str.sprintf("You are now working on version: %s.", version_name),
dialogue:_.str.sprintf("If you edit this page or others, all changes will be recorded in the version. It will not be visible by visitors until you publish the version.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){
window.location.href = '\?enable_editor';
var wizardA = $(QWeb.render("website_version.delete_message",{message:_.str.sprintf("Are you sure you want to delete the %s version ?", name)}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_confirm', function(){
ajax.jsonRpc( '/website_version/delete_version', 'call', { 'version_id':version_id }).then(function (result) {
var wizardB = $(QWeb.render("website_version.message",{message:_.str.sprintf("The %s version has been deleted.", result)}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
});
});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}).fail(function(){
var wizard = $(openerp.qweb.render("website_version.message",{message:_t("This name already exists.")}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
}
});
},
publish_version: function() {
var version_id = parseInt($('html').data('version_id'));
var name = $('#version-menu-button').attr('data-version_name');
ajax.jsonRpc( '/website_version/diff_version', 'call', { 'version_id':version_id}).then(function (result) {
console.log(result);
var wizardA = $(QWeb.render("website_version.publish_message",{message:_.str.sprintf("Publish Version %s", name), list:result}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_confirm', function(){
wizardA.find('.o_message').remove();
var check = wizardA.find('.o_check').is(':checked');
var copy_master_name = wizardA.find('.o_name').val();
if(check){
if(copy_master_name.length === 0){
wizardA.find(".o_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
}
else{
ajax.jsonRpc( '/website_version/publish_version', 'call', { 'version_id':version_id, 'save_master':true, 'copy_master_name':copy_master_name}).then(function (result) {
var wizardB = $(QWeb.render("website_version.dialogue",{message:_.str.sprintf("The %s version has been published", result), dialogue:_.str.sprintf("The master has been saved on a new version called %s.",copy_master_name)}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
});
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
});
}
}
else{
ajax.jsonRpc( '/website_version/publish_version', 'call', { 'version_id':version_id, 'save_master':false, 'copy_master_name':""}).then(function (result) {
var wizardC = $(QWeb.render("website_version.message",{message:_.str.sprintf("The %s version has been published.", result)}));
wizardC.appendTo($('body')).modal({"keyboard" :true});
wizardC.on('click','.o_confirm', function(){
location.reload();
});
wizardC.on('hidden.bs.modal', function () {$(this).remove();});
});
}
});
wizardA.on('click','input[name="optionsRadios"]', function(){
wizardA.find('.o_message').remove();
wizardA.find('.o_name').toggle( wizardA.find('.o_check').is(':checked') );
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
},
change_version: function(event) {
var version_id = parseInt($(event.target).parent().data("version_id"));
if(! version_id){
version_id = 0;//By default master
}
openerp.jsonRpc( '/website_version/change_version', 'call', { 'version_id':version_id }).then(function (result) {
location.reload();
});
},
});
},
delete_version: function(event) {
console.log(event);
var version_id = parseInt($(event.currentTarget).parent().data("version_id"));
var name = $(event.currentTarget).parent().children(':last-child').text();
openerp.jsonRpc( '/website_version/check_version', 'call', { 'version_id':version_id }).then(function (result) {
if (result){
var wizard = $(openerp.qweb.render("website_version.message",{message:_.str.sprintf("You cannot delete the %s version because it is in a running or paused experiment", name)}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
}
else{
var wizardA = $(openerp.qweb.render("website_version.delete_message",{message:_.str.sprintf("Are you sure you want to delete the %s version ?", name)}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_confirm', function(){
openerp.jsonRpc( '/website_version/delete_version', 'call', { 'version_id':version_id }).then(function (result) {
var wizardB = $(openerp.qweb.render("website_version.message",{message:_.str.sprintf("The %s version has been deleted.", result)}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
});
});
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
}
});
},
diff_version: function() {
var version_id = parseInt($('html').data('version_id'));
var name = $('#version-menu-button').data('version_name');
ajax.jsonRpc( '/website_version/diff_version', 'call', { 'version_id':version_id}).then(function (result) {
var wizard = $(QWeb.render("website_version.diff",{list:result, version_name:name}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
},
publish_version: function(event) {
var version_id = parseInt($('html').data('version_id'));
var name = $('#version-menu-button').attr('data-version_name');
openerp.jsonRpc( '/website_version/diff_version', 'call', { 'version_id':version_id}).then(function (result) {
console.log(result);
var wizardA = $(openerp.qweb.render("website_version.publish_message",{message:_.str.sprintf("Publish Version %s", name), list:result}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_confirm', function(){
wizardA.find('.o_message').remove();
var check = wizardA.find('.o_check').is(':checked');
var copy_master_name = wizardA.find('.o_name').val();
if(check){
if(copy_master_name.length == 0){
wizardA.find(".o_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
}
else{
openerp.jsonRpc( '/website_version/publish_version', 'call', { 'version_id':version_id, 'save_master':true, 'copy_master_name':copy_master_name}).then(function (result) {
var wizardB = $(openerp.qweb.render("website_version.dialogue",{message:_.str.sprintf("The %s version has been published", result), dialogue:_.str.sprintf("The master has been saved on a new version called %s.",copy_master_name)}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
});
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
});
}
google_analytics: function(){
window.location.href = 'https://www.google.com/analytics/web';
},
create_experiment: function() {
var view_id = parseInt($('html').attr('data-view-xmlid'));
ajax.jsonRpc( '/website_version/all_versions_all_goals', 'call', { 'view_id': view_id }).then(function (result) {
var wizardA = $(QWeb.render("website_version.create_experiment",{versions:result.tab_version, goals:result.tab_goal, config:result.check_conf}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_launch', function(){
wizardA.find('.o_message').remove();
var name = wizardA.find('.o_name').val();
var tab = wizardA.find('.o_version');
var result = [];
var i;
for (i = 0; i < tab.length; i++){
if ($(tab[i]).is(':checked')) {
result.push(parseInt($(tab[i]).attr('data-version_id')));
}
else{
openerp.jsonRpc( '/website_version/publish_version', 'call', { 'version_id':version_id, 'save_master':false, 'copy_master_name':""}).then(function (result) {
var wizardC = $(openerp.qweb.render("website_version.message",{message:_.str.sprintf("The %s version has been published.", result)}));
wizardC.appendTo($('body')).modal({"keyboard" :true});
wizardC.on('click','.o_confirm', function(){
}
var goal_id = wizardA.find('.box').val();
var check = true;
if (name.length === 0){
wizardA.find(".o_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
check = false;
}
if (result.length === 0 && check){
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_t("You must select at least one version which is not Master.")+"</p>");
check = false;
}
if(check){
ajax.jsonRpc( '/website_version/launch_experiment', 'call', { 'name':name, 'version_ids':result, 'goal_id':goal_id }).then(function (existing_experiment) {
if (!existing_experiment.existing){
var wizardB = $(QWeb.render("website_version.dialogue",{message:_.str.sprintf("Your %s experiment is created.", name), dialogue:_t(" Now you can manage this experiment by clicking on Manage A/B tests.")}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
});
wizardC.on('hidden.bs.modal', function () {$(this).remove();});
});
}
});
wizardA.on('click','input[name="optionsRadios"]', function(){
wizardA.find('.o_message').remove();
wizardA.find('.o_name').toggle( wizardA.find('.o_check').is(':checked') );
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
});
},
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
diff_version: function(event) {
var version_id = parseInt($('html').data('version_id'));
var name = $('#version-menu-button').data('version_name');
openerp.jsonRpc( '/website_version/diff_version', 'call', { 'version_id':version_id}).then(function (result) {
var wizard = $(openerp.qweb.render("website_version.diff",{list:result, version_name:name}));
wizard.appendTo($('body')).modal({"keyboard" :true});
wizard.on('click','.o_confirm', function(){});
wizard.on('hidden.bs.modal', function () {$(this).remove();});
});
},
google_analytics: function(event){
window.location.href = 'https://www.google.com/analytics/web';
},
create_experiment: function() {
var self = this;
var view_id = parseInt($('html').attr('data-view-xmlid'));
openerp.jsonRpc( '/website_version/all_versions_all_goals', 'call', { 'view_id': view_id }).then(function (result) {
var wizardA = $(openerp.qweb.render("website_version.create_experiment",{versions:result.tab_version, goals:result.tab_goal, config:result.check_conf}));
wizardA.appendTo($('body')).modal({"keyboard" :true});
wizardA.on('click','.o_launch', function(){
wizardA.find('.o_message').remove();
var name = wizardA.find('.o_name').val();
var tab = wizardA.find('.o_version');
var result = [];
var i;
for (var i = 0; i < tab.length; i++){
if ($(tab[i]).is(':checked')) {
result.push(parseInt($(tab[i]).attr('data-version_id')));
}
}
var goal_id = wizardA.find('.box').val();
var check = true;
if (name.length == 0){
wizardA.find(".o_name").after("<p class='o_message' style='color : red'> *"+_t("This field is required")+"</p>");
check = false;
}
if (result.length == 0 && check){
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_t("You must select at least one version which is not Master.")+"</p>");
check = false;
}
if(check){
openerp.jsonRpc( '/website_version/launch_experiment', 'call', { 'name':name, 'version_ids':result, 'goal_id':goal_id }).then(function (existing_experiment) {
if (!existing_experiment['existing']){
var wizardB = $(openerp.qweb.render("website_version.dialogue",{message:_.str.sprintf("Your %s experiment is created.", name), dialogue:_t(" Now you can manage this experiment by clicking on Manage A/B tests.")}));
wizardB.appendTo($('body')).modal({"keyboard" :true});
wizardB.on('click','.o_confirm', function(){
location.reload();
});
wizardB.on('hidden.bs.modal', function () {$(this).remove();});
else{
if(existing_experiment.existing == 1){
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_.str.sprintf("Your %s experiment cannot be launched because this experiment contains a view which is already used in the running %s experiment.", name, existing_experiment['name'])+"</p>");
}
else{
if(existing_experiment['existing'] == 1){
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_.str.sprintf("Your %s experiment cannot be launched because this experiment contains a view which is already used in the running %s experiment.", name, existing_experiment['name'])+"</p>");
}
else{
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_.str.sprintf("You cannot have more then 24 running/paused experiments.")+"</p>");
}
wizardA.find(".o_versions").after("<p class='o_message' style='color : red'> *"+_.str.sprintf("You cannot have more then 24 running/paused experiments.")+"</p>");
}
});
}
});
wizardA.on('click','.o_configure', function(){
var website_id = $('html').attr('data-website-id');
window.location.href ='/web#id='+website_id+'&view_type=form&model=website&action=website_version.action_website_view';
});
wizardA.on('click','.o_validate_0', function(){
wizardA.find('.o_message').remove();
var website_id = $('html').attr('data-website-id');
var ga_key = wizardA.find('.o_ga_key').val();
var view_id = wizardA.find('.o_view_id').val();
var client_id = wizardA.find('.o_client_id').val();
var client_secret = wizardA.find('.o_client_secret').val();
if(ga_key.length == 0 || view_id.length == 0 || client_id.length == 0 || client_secret.length == 0){
wizardA.find(".o_configure_ab").after("<p class='o_message' style='color : red'> *"+_t("You must fill all the fields.")+"</p>");
}
else{
openerp.jsonRpc( '/website_version/set_google_access', 'call', {'ga_key':ga_key, 'view_id':view_id, 'client_id':client_id, 'client_secret':client_secret}).then(function (result) {
var context = website.get_context();
openerp.jsonRpc( '/website_version/google_access', 'call', {
fromurl: window.location.href,
local_context: context
}).done(function(o) {
if (o.status === "need_auth") {
var wizardC = $(openerp.qweb.render("website_version.message",{message:_t("You will be redirected to Google to authorize access to your Analytics Account!")}));
wizardC.appendTo($('body')).modal({"keyboard" :true});
wizardC.on('click','.o_confirm', function(){
window.location.href = o.url;
});
wizardC.on('hidden.bs.modal', function () {$(this).remove();});
}
else if (o.status === "need_config_from_admin"){
if (confirm(_t("The Google Management API key needs to be configured before you can use it, do you want to do it now?"))) {
window.location.href = o.action;
}
}
}).always(function(o) { $('button.GoogleAccess').prop('disabled', false); });
});
}
});
wizardA.on('click','.o_validate_2', function(){
var website_id = $('html').attr('data-website-id');
var ga_key = wizardA.find('.o_ga_key').val();
var view_id = wizardA.find('.o_view_id').val();
if(ga_key.length == 0 || view_id.length == 0){
wizardA.find(".o_configure_ab").after("<p class='o_message' style='color : red'> *"+_t("You must fill all the fields.")+"</p>");
}
else{
openerp.jsonRpc( '/website_version/set_google_access', 'call', {'ga_key':ga_key, 'view_id':view_id, 'client_id':0, 'client_secret':0});
}
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
}
});
}
});
},
wizardA.on('click','.o_configure', function(){
var website_id = $('html').attr('data-website-id');
window.location.href ='/web#id='+website_id+'&view_type=form&model=website&action=website_version.action_website_view';
});
wizardA.on('click','.o_validate_0', function(){
wizardA.find('.o_message').remove();
var ga_key = wizardA.find('.o_ga_key').val();
var view_id = wizardA.find('.o_view_id').val();
var client_id = wizardA.find('.o_client_id').val();
var client_secret = wizardA.find('.o_client_secret').val();
if(ga_key.length === 0 || view_id.length === 0 || client_id.length === 0 || client_secret.length === 0){
wizardA.find(".o_configure_ab").after("<p class='o_message' style='color : red'> *"+_t("You must fill all the fields.")+"</p>");
}
else{
ajax.jsonRpc( '/website_version/set_google_access', 'call', {'ga_key':ga_key, 'view_id':view_id, 'client_id':client_id, 'client_secret':client_secret}).then(function (result) {
var context = website.get_context();
ajax.jsonRpc( '/website_version/google_access', 'call', {
fromurl: window.location.href,
local_context: context
}).done(function(o) {
if (o.status === "need_auth") {
var wizardC = $(QWeb.render("website_version.message",{message:_t("You will be redirected to Google to authorize access to your Analytics Account!")}));
wizardC.appendTo($('body')).modal({"keyboard" :true});
wizardC.on('click','.o_confirm', function(){
window.location.href = o.url;
});
wizardC.on('hidden.bs.modal', function () {$(this).remove();});
}
else if (o.status === "need_config_from_admin"){
if (confirm(_t("The Google Management API key needs to be configured before you can use it, do you want to do it now?"))) {
window.location.href = o.action;
}
}
}).always(function() { $('button.GoogleAccess').prop('disabled', false); });
});
}
});
wizardA.on('click','.o_validate_2', function(){
var ga_key = wizardA.find('.o_ga_key').val();
var view_id = wizardA.find('.o_view_id').val();
if(ga_key.length === 0 || view_id.length === 0){
wizardA.find(".o_configure_ab").after("<p class='o_message' style='color : red'> *"+_t("You must fill all the fields.")+"</p>");
}
else{
ajax.jsonRpc( '/website_version/set_google_access', 'call', {'ga_key':ga_key, 'view_id':view_id, 'client_id':0, 'client_secret':0});
}
});
wizardA.on('hidden.bs.modal', function () {$(this).remove();});
});
},
manage_experiment: function() {
window.location.href = '/web#return_label=Website&action=website_version.action_experiment';
},
manage_experiment: function() {
window.location.href = '/web#return_label=Website&action=website_version.action_experiment';
},
statistics: function() {
window.open('https://www.google.com/analytics/web/?authuser=0#report/siteopt-experiments/','_blank');
}
});
statistics: function() {
window.open('https://www.google.com/analytics/web/?authuser=0#report/siteopt-experiments/','_blank');
}
$(document).ready(function() {
var version = new website.EditorVersion();
version.setElement($("#version-menu"));
version.start();
});
})();
});
$(document).ready(function() {
var version = new EditorVersion();
version.setElement($("#version-menu"));
version.start();
});
});
@@ -1,193 +1,192 @@
(function () {
'use strict';
odoo.define('website_version.tour', ['web.core', 'web.Tour'], function (require) {
'use strict';
var _t = openerp._t;
var core = require('web.core');
var Tour = require('web.Tour');
openerp.Tour.register({
id: 'versioning',
name: "Tutorial versioning",
path: '/',
mode: 'tutorial',
steps: [
//1.
var _t = core._t;
{
title: _t("Welcome to the tutorial"),
content: _t("This tutorial will guide you to build a version of your home page."),
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
{
title: _t("Click on Version"),
content: _t("You can create a version for every page of your website."),
popover: { fixed: true },
element: 'a#version-menu-button',
},
{
title: _t("Click on New version"),
popover: { fixed: true },
element: 'a[data-action="duplicate_version"]:first',
},
{
title: _t("Give a version name"),
content: _t("Give a clever name to retrieve it easily."),
popover: { fixed: true },
waitFor: '.modal button.btn-primary',
element: '.modal input[type="text"]',
sampleText: 'Test',
},
{
title: _t("Validate the version name"),
popover: { fixed: true },
element: '.modal button.btn-primary',
},
{
title: _t("Confirm"),
popover: { fixed: true },
waitNot: '.modal input',
element: '.modal button.o_confirm',
},
{
title: _t("You are on your new version"),
content: _t("All the modifications you will do, will be saved in this version."),
waitNot: '.modal button.o_confirm',
},
{
title: _t("Click on Edit"),
content: _t("Every page of your website can be modified through the <i>Edit</i> button."),
waitFor: 'button[data-action="edit"]',
element: 'button[data-action="edit"]',
},
{
snippet: '#snippet_structure .oe_snippet:first',
placement: 'bottom',
title: _t("Drag & Drop a Banner"),
content: _t("Drag the Banner block and drop it in your page."),
popover: { fixed: true },
},
{
waitFor: '.oe_overlay_options .oe_options:visible',
element: '#wrapwrap .carousel:first div.carousel-content',
placement: 'top',
title: _t("Customize banner's text"),
content: _t("Click in the text and start editing it."),
sampleText: 'Here, a customized text',
popover: { next: _t("Continue") },
},
{
waitNot: '#wrap .carousel:first div.carousel-content:has(h2:'+
'containsExact('+_t('Your Banner Title')+')):has(h3:'+
'containsExact('+_t('Click to customize this text')+'))',
element: '.oe_snippet_parent:visible',
placement: 'bottom',
title: _t("Get banner properties"),
content: _t("Select the parent container to get the global options of the banner."),
popover: { fixed: true },
},
{
element: '.oe_overlay_options .oe_options:visible',
placement: 'left',
title: _t("Customize the banner"),
content: _t("Customize any block through this menu. Try to change the background of the banner."),
popover: { next: _t("Continue") },
},
{
snippet: '#snippet_structure .oe_snippet:eq(6)',
placement: 'bottom',
title: _t("Drag & Drop This Block"),
content: _t("Drag the <em>'Features'</em> block and drop it below the banner."),
popover: { fixed: true },
},
{
waitFor: '.oe_overlay_options .oe_options:visible',
element: 'button[data-action=save]',
placement: 'right',
title: _t("Save your modifications"),
content: _t("Publish your page by clicking on the <em>'Save'</em> button."),
popover: { fixed: true },
},
{
waitFor: 'button[data-action=save]:not(:visible)',
title: _t("Good Job!"),
content: _t("Well done, you created a version of your homepage."),
popover: { next: _t("Continue") },
},
Tour.register({
id: 'versioning',
name: "Tutorial versioning",
path: '/',
mode: 'tutorial',
steps: [
//1.
//2.
{
title: _t("Welcome to the tutorial"),
content: _t("This tutorial will guide you to build a version of your home page."),
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
{
title: _t("Click on Version"),
content: _t("You can create a version for every page of your website."),
popover: { fixed: true },
element: 'a#version-menu-button',
},
{
title: _t("Click on New version"),
popover: { fixed: true },
element: 'a[data-action="duplicate_version"]:first',
},
{
title: _t("Give a version name"),
content: _t("Give a clever name to retrieve it easily."),
popover: { fixed: true },
waitFor: '.modal button.btn-primary',
element: '.modal input[type="text"]',
sampleText: 'Test',
},
{
title: _t("Validate the version name"),
popover: { fixed: true },
element: '.modal button.btn-primary',
},
{
title: _t("Confirm"),
popover: { fixed: true },
waitNot: '.modal input',
element: '.modal button.o_confirm',
},
{
title: _t("You are on your new version"),
content: _t("All the modifications you will do, will be saved in this version."),
waitNot: '.modal button.o_confirm',
},
{
title: _t("Click on Edit"),
content: _t("Every page of your website can be modified through the <i>Edit</i> button."),
waitFor: 'button[data-action="edit"]',
element: 'button[data-action="edit"]',
},
{
snippet: '#snippet_structure .oe_snippet:first',
placement: 'bottom',
title: _t("Drag & Drop a Banner"),
content: _t("Drag the Banner block and drop it in your page."),
popover: { fixed: true },
},
{
waitFor: '.oe_overlay_options .oe_options:visible',
element: '#wrapwrap .carousel:first div.carousel-content',
placement: 'top',
title: _t("Customize banner's text"),
content: _t("Click in the text and start editing it."),
sampleText: 'Here, a customized text',
popover: { next: _t("Continue") },
},
{
waitNot: '#wrap .carousel:first div.carousel-content:has(h2:'+
'containsExact('+_t('Your Banner Title')+')):has(h3:'+
'containsExact('+_t('Click to customize this text')+'))',
element: '.oe_snippet_parent:visible',
placement: 'bottom',
title: _t("Get banner properties"),
content: _t("Select the parent container to get the global options of the banner."),
popover: { fixed: true },
},
{
element: '.oe_overlay_options .oe_options:visible',
placement: 'left',
title: _t("Customize the banner"),
content: _t("Customize any block through this menu. Try to change the background of the banner."),
popover: { next: _t("Continue") },
},
{
snippet: '#snippet_structure .oe_snippet:eq(6)',
placement: 'bottom',
title: _t("Drag & Drop This Block"),
content: _t("Drag the <em>'Features'</em> block and drop it below the banner."),
popover: { fixed: true },
},
{
waitFor: '.oe_overlay_options .oe_options:visible',
element: 'button[data-action=save]',
placement: 'right',
title: _t("Save your modifications"),
content: _t("Publish your page by clicking on the <em>'Save'</em> button."),
popover: { fixed: true },
},
{
waitFor: 'button[data-action=save]:not(:visible)',
title: _t("Good Job!"),
content: _t("Well done, you created a version of your homepage."),
popover: { next: _t("Continue") },
},
{
title: _t("Publish the version"),
content: _t("Now we will publish your version in production."),
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
//2.
{
title: _t("Click on Version"),
element: 'a#version-menu-button',
popover: { fixed: true },
},
{
title: _t("Publish the version"),
content: _t("Now we will publish your version in production."),
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
{
title: _t("Click on Publish Version"),
element: 'a[data-action="publish_version"]:first',
popover: { fixed: true },
},
{
title: _t("Click on Version"),
element: 'a#version-menu-button',
popover: { fixed: true },
},
{
title: _t("Click on Publish button"),
element: '.modal button.o_confirm',
placement: 'left',
},
{
title: _t("Click on Publish Version"),
element: 'a[data-action="publish_version"]:first',
popover: { fixed: true },
},
{
title: _t("Confirm"),
element: '.modal button.o_confirm[data-dismiss]',
popover: { fixed: true },
},
{
title: _t("Click on Publish button"),
element: '.modal button.o_confirm',
placement: 'left',
},
{
title: _t("Confirm"),
element: '.modal button.o_confirm[data-dismiss]',
popover: { fixed: true },
},
//3.
{
title: _t("Delete the version"),
content: _t("Now we will delete the version you have just published."),
waitNot: '.modal button.o_confirm[data-dismiss]',
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
//3.
{
title: _t("Delete the version"),
content: _t("Now we will delete the version you have just published."),
waitNot: '.modal button.o_confirm[data-dismiss]',
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
{
title: _t("Click on Version"),
element: 'a#version-menu-button',
popover: { fixed: true },
},
{
title: _t("Click on Version"),
element: 'a#version-menu-button',
popover: { fixed: true },
},
{
title: _t("Delete Version Test"),
element: 'li > a[data-action="delete_version"]:last',
popover: { fixed: true },
},
{
title: _t("Delete Version Test"),
element: 'li > a[data-action="delete_version"]:last',
popover: { fixed: true },
},
{
title: _t("Click on delete version button"),
element: '.modal:has(.cancel) button.o_confirm',
popover: { fixed: true },
},
{
title: _t("Confirm"),
element: '.modal:not(:has(.cancel)) button.o_confirm[data-dismiss]',
popover: { fixed: true },
},
{
title: _t("Finish"),
content: _t("Felicitation, now you are able to edit and manage your versions."),
waitNot: '.modal button.o_confirm[data-dismiss]',
},
]
});
}());
{
title: _t("Click on delete version button"),
element: '.modal:has(.cancel) button.o_confirm',
popover: { fixed: true },
},
{
title: _t("Confirm"),
element: '.modal:not(:has(.cancel)) button.o_confirm[data-dismiss]',
popover: { fixed: true },
},
{
title: _t("Finish"),
content: _t("Felicitation, now you are able to edit and manage your versions."),
waitNot: '.modal button.o_confirm[data-dismiss]',
},
]
});
});
+39 -41
View File
@@ -1,45 +1,43 @@
(function() {
"use strict";
odoo.define('website_version.widget', ['web.core','web.form_common', 'web.framework', 'web.pyeval'], function (require) {
"use strict";
var instance = openerp;
openerp.website_version = instance.website_version || {};
var core = require('web.core');
var form_common = require('web.form_common');
var framework = require('web.framework');
var pyeval = require('web.pyeval');
var module = instance.website_version;
var QWeb = instance.web.qweb;
var _t = openerp._t;
var _t = core._t;
var rtoken = form_common.AbstractField.extend({
template: 'website_version.GoogleAccess',
start: function() {
var self = this;
this.$el.on('click', 'button.GoogleAccess', function() {
self.allow_google();
});
},
allow_google: function() {
var self = this;
$('button.GoogleAccess').prop('disabled', true);
var context = pyeval.eval('context');
self.rpc('/website_version/google_access', {
fromurl: window.location.href,
local_context: context
}).done(function(o) {
if (o.status === "need_auth") {
alert(_t("You will be redirected to Google to authorize access to your Analytics Account!"));
framework.redirect(o.url);
}
else if (o.status === "need_config_from_admin"){
if (confirm(_t("The Google Management API key needs to be configured before you can use it, do you want to do it now?"))) {
self.do_action(o.action);
}
}
}).always(function() { $('button.GoogleAccess').prop('disabled', false); });
}
});
core.form_widget_registry.add('rtoken', rtoken);
instance.website_version.rtoken = instance.web.form.AbstractField.extend({
template: 'website_version.GoogleAccess',
start: function() {
var self = this;
this.$el.on('click', 'button.GoogleAccess', function() {
self.allow_google();
});
},
allow_google: function() {
var self = this;
$('button.GoogleAccess').prop('disabled', true);
var context = instance.web.pyeval.eval('context');
self.rpc('/website_version/google_access', {
fromurl: window.location.href,
local_context: context
}).done(function(o) {
if (o.status === "need_auth") {
alert(_t("You will be redirected to Google to authorize access to your Analytics Account!"));
instance.web.redirect(o.url);
}
else if (o.status === "need_config_from_admin"){
if (confirm(_t("The Google Management API key needs to be configured before you can use it, do you want to do it now?"))) {
self.do_action(o.action);
}
}
}).always(function(o) { $('button.GoogleAccess').prop('disabled', false); });
}
});
instance.web.form.widgets.add('rtoken', 'openerp.website_version.rtoken');
})();
});