diff --git a/addons/website/models/website.py b/addons/website/models/website.py
index 966810297ea..1a541865987 100644
--- a/addons/website/models/website.py
+++ b/addons/website/models/website.py
@@ -89,7 +89,7 @@ def slug(value):
else:
# assume name_search result tuple
id, name = value
- slugname = slugify(name)
+ slugname = slugify(name or '')
if not slugname:
return str(id)
return "%s-%d" % (slugname, id)
@@ -580,10 +580,26 @@ class ir_attachment(osv.osv):
return hashlib.new('sha1', attachment_dict['datas']).hexdigest()
return None
+ def _datas_big(self, cr, uid, ids, name, arg, context=None):
+ result = dict.fromkeys(ids, False)
+ if context and context.get('bin_size'):
+ return result
+
+ for record in self.browse(cr, uid, ids, context=context):
+ if not record.datas: continue
+ try:
+ result[record.id] = openerp.tools.image_resize_image_big(record.datas)
+ except IOError: # apparently the error PIL.Image.open raises
+ pass
+
+ return result
+
_columns = {
'datas_checksum': fields.function(_datas_checksum, size=40,
string="Datas checksum", type='char', store=True, select=True),
- 'website_url': fields.function(_website_url_get, string="Attachment URL", type='char')
+ 'website_url': fields.function(_website_url_get, string="Attachment URL", type='char'),
+ 'datas_big': fields.function (_datas_big, type='binary', store=True,
+ string="Resized file content"),
}
def create(self, cr, uid, values, context=None):
diff --git a/addons/website/static/src/css/bootswatch/amelia.fix.css b/addons/website/static/src/css/bootswatch/amelia.fix.css
new file mode 100644
index 00000000000..2f16ea5465c
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/amelia.fix.css
@@ -0,0 +1,27 @@
+#website-top-navbar a.btn-link {
+ color: #ad1d28;
+}
+.oe_product section {
+ background: rgba(16, 138, 147, 0.75) !important;
+}
+.oe_product section .text-info {
+ color: #DFD6F5;
+}
+ul.wizard li {
+ background: #debb27 !important;
+}
+ul.wizard .chevron:before {
+ border-left: 10px solid #debb27 !important;
+}
+ul.wizard .text-primary {
+ color: #ad1d28 !important;
+}
+ul.wizard .text-success {
+ color: #ffffff !important;
+}
+.oe_structure.oe_empty:empty:before, [data-oe-type=html]:empty:before {
+ color: #79D5DB !important;
+}
+.input-group-addon .fa {
+ color: #444;
+}
diff --git a/addons/website/static/src/css/bootswatch/cosmo.fix.css b/addons/website/static/src/css/bootswatch/cosmo.fix.css
new file mode 100644
index 00000000000..907aa7bf757
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/cosmo.fix.css
@@ -0,0 +1,7 @@
+#website-top-navbar button.btn-primary {
+ color: #fff;
+ border: 2px solid #0061c2;
+}
+#website-top-navbar a.btn-link {
+ color: #fff;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/cyborg.fix.css b/addons/website/static/src/css/bootswatch/cyborg.fix.css
new file mode 100644
index 00000000000..e93b2aa8ded
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/cyborg.fix.css
@@ -0,0 +1,30 @@
+.oe_product section {
+ background: rgba(40, 40, 40, 0.85) !important;
+}
+.oe_product section .text-info {
+ color: #BA66E4;
+}
+ul.wizard li {
+ background: #222 !important;
+}
+ul.wizard .chevron:before {
+ border-left: 10px solid #222 !important;
+}
+.popover, .modal-content {
+ border: 1px solid rgba(200,200,200,0.5);
+}
+.close {
+ color: #fff;
+}
+.popover.bottom .arrow:after {
+ border-bottom-color: #333;
+}
+.popover.top .arrow:after {
+ border-top-color: #333;
+}
+.popover.left .arrow:after {
+ border-left-color: #333;
+}
+.popover.right .arrow:after {
+ border-right-color: #333;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/flatly.fix.css b/addons/website/static/src/css/bootswatch/flatly.fix.css
new file mode 100644
index 00000000000..c2d9500f5da
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/flatly.fix.css
@@ -0,0 +1,3 @@
+#website-top-navbar a.btn-link {
+ color: #2c3e50;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/journal.fix.css b/addons/website/static/src/css/bootswatch/journal.fix.css
new file mode 100644
index 00000000000..e9f41a33e8f
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/journal.fix.css
@@ -0,0 +1,6 @@
+#website-top-navbar button.btn-primary {
+ border: 2px solid #e4332e;
+}
+#website-top-navbar a.btn-link {
+ color: #fff;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/readable.fix.css b/addons/website/static/src/css/bootswatch/readable.fix.css
new file mode 100644
index 00000000000..8e22d318615
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/readable.fix.css
@@ -0,0 +1,3 @@
+.oe_product section .text-info {
+ color: #2A9CBE;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/simplex.fix.css b/addons/website/static/src/css/bootswatch/simplex.fix.css
new file mode 100644
index 00000000000..56dbb1fdd5f
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/simplex.fix.css
@@ -0,0 +1,3 @@
+#website-top-navbar a.btn-link {
+ color: #fff;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/slate.fix.css b/addons/website/static/src/css/bootswatch/slate.fix.css
new file mode 100644
index 00000000000..c2e1a999b03
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/slate.fix.css
@@ -0,0 +1,21 @@
+.oe_product section {
+ background: rgba(40, 40, 45, 0.80) !important;
+}
+ul.wizard li {
+ background-image: -webkit-linear-gradient(#8a9196,#7a8288 60%,#788084) !important;
+ background-image: linear-gradient(#8a9196,#7a8288 60%,#788084 ) !important;
+ color: #ccc;
+}
+ul.wizard .chevron:before {
+ border-left: 10px solid #7C8386 !important;
+}
+ul.wizard li.text-primary {
+ color: #fff;
+}
+.close {
+ color: #fff;
+}
+.popover {
+ -webkit-box-shadow: 0px 0px 20px rgba(0,0,0,0.5);
+ box-shadow: 0px 0px 20px rgba(0,0,0,0.5);
+}
diff --git a/addons/website/static/src/css/bootswatch/spacelab.fix.css b/addons/website/static/src/css/bootswatch/spacelab.fix.css
new file mode 100644
index 00000000000..6d01e9a2485
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/spacelab.fix.css
@@ -0,0 +1,8 @@
+.carousel .carousel-caption.content,
+.carousel .carousel-caption.content h1,
+.carousel .carousel-caption.content h2,
+.carousel .carousel-caption.content h3,
+.carousel .carousel-caption.content h4,
+.carousel .carousel-caption.content h5 {
+ color: #ccc;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/bootswatch/yeti.fix.css b/addons/website/static/src/css/bootswatch/yeti.fix.css
new file mode 100644
index 00000000000..3fd285c826e
--- /dev/null
+++ b/addons/website/static/src/css/bootswatch/yeti.fix.css
@@ -0,0 +1,6 @@
+#website-top-navbar a.btn-link {
+ color: #fff;
+}
+.popover .close {
+ color: #fff;
+}
\ No newline at end of file
diff --git a/addons/website/static/src/css/snippets.css b/addons/website/static/src/css/snippets.css
index a19baa33fd6..726855f311b 100644
--- a/addons/website/static/src/css/snippets.css
+++ b/addons/website/static/src/css/snippets.css
@@ -328,14 +328,10 @@
}
.oe_overlay .oe_handle.size .oe_handle_button {
z-index: 3;
- content: "Resize";
- width: 64px;
text-align: center;
margin-left: -32px;
margin-top: -10px;
- cursor: row-resize;
left: 0px;
- top: 9px;
}
.oe_overlay .oe_handle.size .oe_handle_button:hover {
background: rgba(30, 30, 30, 0.8);
@@ -344,6 +340,24 @@
-moz-box-shadow: 0 0 5px 3px rgba(255, 255, 255, 0.7);
box-shadow: 0 0 5px 3px rgba(255, 255, 255, 0.7);
}
+.oe_overlay .oe_handle.size .size {
+ width: 64px;
+ cursor: row-resize;
+ top: 9px;
+}
+.oe_overlay .oe_handle.size .auto_size {
+ width: 20px;
+ padding: 0 5px;
+ top: 1px;
+ margin-left: 36px;
+ cursor: pointer;
+}
+.oe_overlay .oe_handle.readonly {
+ cursor: auto !important;
+}
+.oe_overlay .oe_handle.readonly:before, .oe_overlay .oe_handle.readonly.size {
+ display: none !important;
+}
.oe_overlay .icon.btn {
display: inline-block;
}
@@ -351,7 +365,7 @@
position: absolute;
left: 50% !important;
text-align: center;
- top: -11px;
+ top: -20px;
z-index: 1002;
}
.oe_overlay .oe_overlay_options > .btn-group {
@@ -618,8 +632,3 @@
height: 16px;
display: inline-block;
}
-
-[data-snippet-id] {
- min-height: 10px;
- min-width: 10px;
-}
diff --git a/addons/website/static/src/css/snippets.sass b/addons/website/static/src/css/snippets.sass
index afdb261a2a5..9b12e9df246 100644
--- a/addons/website/static/src/css/snippets.sass
+++ b/addons/website/static/src/css/snippets.sass
@@ -240,18 +240,28 @@
bottom: -6px
.oe_handle_button
z-index: 3
- content: "Resize"
- width: 64px
text-align: center
margin-left: -32px
margin-top: -10px
- cursor: row-resize
left: 0px
- top: 9px
&:hover
background: rgba(30, 30, 30, .8)
color: #fff
+box-shadow(0 0 5px 3px rgba(255,255,255,.7))
+ .size
+ width: 64px
+ cursor: row-resize
+ top: 9px
+ .auto_size
+ width: 20px
+ padding: 0 5px
+ top: 1px
+ margin-left: 36px
+ cursor: pointer
+ &.readonly
+ cursor: auto !important
+ &:before, &.size
+ display: none !important
.icon.btn
display: inline-block
@@ -260,7 +270,7 @@
position: absolute
left: 50% !important
text-align: center
- top: -11px
+ top: -20px
z-index: 1002
> .btn-group
left: -50%
@@ -485,10 +495,6 @@
height: 16px
display: inline-block
-[data-snippet-id]
- min-height: 10px
- min-width: 10px
-
diff --git a/addons/website/static/src/css/website.css b/addons/website/static/src/css/website.css
index 774be6ae09a..e9df2841347 100644
--- a/addons/website/static/src/css/website.css
+++ b/addons/website/static/src/css/website.css
@@ -102,6 +102,10 @@ header a.navbar-brand img {
max-height: 50px;
}
+#wrapwrap p:empty:after {
+ content: "\2060";
+}
+
/* ----- Snippets Styles ----- */
.readable {
font-size: 120%;
@@ -116,9 +120,10 @@ header a.navbar-brand img {
}
/* ----- BOOTSTRAP FIX ----- */
-.container .container {
+.container .container, .readable .container {
padding-left: 0;
padding-right: 0;
+ width: auto;
}
/* ----- BOOTSTRAP HACK FOR HEADER NAV BAR ----- */
@@ -216,7 +221,6 @@ footer {
/* -- Hack for removing double scrollbar from mobile preview -- */
div#mobile-preview.modal {
overflow: hidden;
- overflow-y: hidden;
}
ul.nav-stacked > li > a {
@@ -236,7 +240,7 @@ ul.nav-stacked > li > a {
display: none;
}
-[data-publish='off'] {
+[data-publish='off'] > *:not(.css_options) {
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
opacity: 0.5;
}
@@ -280,12 +284,16 @@ ul.nav-stacked > li > a {
background-size: 100%;
}
-[data-snippet-id], .colmd, .hr, .blockquote {
+section, .carousel, .parallax, .row, .hr, .blockquote {
+ min-height: 30px;
+}
+
+.carousel, .parallax, .blockquote {
overflow: hidden;
}
@media (max-width: 400px) {
- [data-snippet-id]:not([data-snippet-id="carousel"]) {
+ section, .parallax, .row, .hr, .blockquote {
height: auto !important;
}
}
@@ -380,10 +388,10 @@ ul.nav-stacked > li > a {
}
/* Parallax Theme */
-div.carousel[data-snippet-id="slider"] .carousel-indicators li {
+div.carousel .carousel-indicators li {
border: 1px solid grey;
}
-div.carousel[data-snippet-id="slider"] .carousel-indicators .active {
+div.carousel .carousel-indicators .active {
background-color: grey;
}
diff --git a/addons/website/static/src/css/website.sass b/addons/website/static/src/css/website.sass
index 4796d88cbb8..2c8d5d2fdda 100644
--- a/addons/website/static/src/css/website.sass
+++ b/addons/website/static/src/css/website.sass
@@ -68,6 +68,12 @@ header
img
max-height: 50px
+// add {WORD JOINER} (equivalent to deprecated ZERO WIDTH NO-BREAK SPACE) at
+// the beginning of paragraphs so they don't "disappear" after saving when
+// used solely for spacing.
+#wrapwrap p:empty:after
+ content: '\2060'
+
/* ----- Snippets Styles ----- */
.readable
@@ -78,17 +84,16 @@ header
/* ----- EDITOR ----- */
-
.css_non_editable_mode_hidden
display: none
-
/* ----- BOOTSTRAP FIX ----- */
-.container
+.container, .readable
.container
padding-left: 0
padding-right: 0
+ width: auto
/* ----- BOOTSTRAP HACK FOR HEADER NAV BAR ----- */
@@ -179,7 +184,6 @@ footer
/* -- Hack for removing double scrollbar from mobile preview -- */
div#mobile-preview.modal
overflow: hidden
- overflow-y: hidden
ul.nav-stacked > li > a
padding: 2px 15px
@@ -195,7 +199,7 @@ ul.nav-stacked > li > a
.btn-success, .css_unpublish
display: none
-[data-publish='off']
+[data-publish='off']>*:not(.css_options)
+opacity(0.5)
/* ---- END of PUBLISH ---- */
@@ -230,11 +234,13 @@ ul.nav-stacked > li > a
.oe_img_bg
background-size: 100%
-[data-snippet-id],.colmd,.hr,.blockquote
+section, .carousel, .parallax, .row, .hr, .blockquote
+ min-height: 30px
+.carousel, .parallax, .blockquote
overflow: hidden
@media (max-width: 400px)
- [data-snippet-id]:not([data-snippet-id="carousel"])
+ section, .parallax, .row, .hr, .blockquote
height: auto !important
.carousel-inner
@@ -312,7 +318,7 @@ ul.nav-stacked > li > a
/* Parallax Theme */
-div.carousel[data-snippet-id="slider"]
+div.carousel
.carousel-indicators
li
border: 1px solid grey
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 3965e1c3d1a..c89bf9ec2fb 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -106,6 +106,7 @@
},
canUndo: false,
editorFocus: true,
+ context: 'a',
});
//noinspection JSValidateTypes
editor.addCommand('image', {
@@ -115,6 +116,7 @@
},
canUndo: false,
editorFocus: true,
+ context: 'img',
});
editor.ui.addButton('Link', {
@@ -205,8 +207,9 @@
icon: '/website/static/src/img/bglink.png',
modes: { wysiwyg: true },
editorFocus: true,
+ context: 'a',
panel: {
- css: '/website/static/lib/bootstrap/css/bootstrap.css',
+ css: '/web/static/lib/bootstrap/css/bootstrap.css',
attributes: { 'role': 'listbox', 'aria-label': label },
},
@@ -346,14 +349,40 @@
requires: 'widget',
init: function (editor) {
+ var specials = {
+ // Can't find the correct ACL rule to only allow img tags
+ image: { content: '*' },
+ html: { text: '*' },
+ monetary: {
+ text: {
+ selector: 'span.oe_currency_value',
+ allowedContent: { }
+ }
+ }
+ };
+ _(specials).each(function (editable, type) {
+ editor.widgets.add(type, {
+ draggable: false,
+ editables: editable,
+ upcast: function (el) {
+ return el.attributes['data-oe-type'] === type;
+
+ }
+ });
+ });
editor.widgets.add('oeref', {
- editables: { text: '*' },
draggable: false,
-
+ editables: {
+ text: {
+ selector: '*',
+ allowedContent: { }
+ },
+ },
upcast: function (el) {
- var matches = el.attributes['data-oe-type'] && el.attributes['data-oe-type'] !== 'monetary';
- if (!matches) { return false; }
-
+ var type = el.attributes['data-oe-type'];
+ if (!type || (type in specials)) {
+ return false;
+ }
if (el.attributes['data-oe-original']) {
while (el.children.length) {
el.children[0].remove();
@@ -363,16 +392,9 @@
));
}
return true;
- },
- });
- editor.widgets.add('monetary', {
- editables: { text: 'span.oe_currency_value' },
- draggable: false,
-
- upcast: function (el) {
- return el.attributes['data-oe-type'] === 'monetary';
}
});
+
editor.widgets.add('icons', {
draggable: false,
diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js
index 54ee4689814..065928df1cf 100644
--- a/addons/website/static/src/js/website.js
+++ b/addons/website/static/src/js/website.js
@@ -2,9 +2,11 @@
"use strict";
var website = {};
- // The following line can be removed in 2017
openerp.website = website;
+ /* ----------------------------------------------------
+ Helpers
+ ---------------------------------------------------- */
website.get_context = function (dict) {
var html = document.documentElement;
return _.extend({
@@ -34,26 +36,11 @@
}
return parsedSearch;
};
+
website.parseHash = function () {
return website.parseQS(window.location.hash.substring(1));
};
- /* ----- TEMPLATE LOADING ---- */
- var templates_def = $.Deferred().resolve();
- website.add_template_file = function(template) {
- templates_def = templates_def.then(function() {
- var def = $.Deferred();
- openerp.qweb.add_template(template, function(err) {
- if (err) {
- def.reject(err);
- } else {
- def.resolve();
- }
- });
- return def;
- });
- };
- website.add_template_file('/website/static/src/xml/website.xml');
website.reload = function () {
location.hash = "scrollTop=" + window.document.body.scrollTop;
if (location.search.indexOf("enable_editor") > -1) {
@@ -63,103 +50,9 @@
}
};
- var all_ready = null;
- var dom_ready = website.dom_ready = $.Deferred();
- $(document).ready(function () {
- website.is_editable = website.is_editable || $('html').data('editable');
- website.is_editable_button= website.is_editable_button || $('html').data('editable');
- dom_ready.resolve();
- // fix for ie
- if($.fn.placeholder) $('input, textarea').placeholder();
- });
-
- website.init_kanban = function ($kanban) {
- $('.js_kanban_col', $kanban).each(function () {
- var $col = $(this);
- var $pagination = $('.pagination', $col);
- if(!$pagination.size()) {
- return;
- }
-
- var page_count = $col.data('page_count');
- var scope = $pagination.last().find("li").size()-2;
- var kanban_url_col = $pagination.find("li a:first").attr("href").replace(/[0-9]+$/, '');
-
- var data = {
- 'domain': $col.data('domain'),
- 'model': $col.data('model'),
- 'template': $col.data('template'),
- 'step': $col.data('step'),
- 'orderby': $col.data('orderby')
- };
-
- $pagination.on('click', 'a', function (ev) {
- ev.preventDefault();
- var $a = $(ev.target);
- if($a.parent().hasClass('active')) {
- return;
- }
-
- var page = +$a.attr("href").split(",").pop().split('-')[1];
- data['page'] = page;
-
- $.post('/website/kanban/', data, function (col) {
- $col.find("> .thumbnail").remove();
- $pagination.last().before(col);
- });
-
- var page_start = page - parseInt(Math.floor((scope-1)/2), 10);
- if (page_start < 1 ) page_start = 1;
- var page_end = page_start + (scope-1);
- if (page_end > page_count ) page_end = page_count;
-
- if (page_end - page_start < scope) {
- page_start = page_end - scope > 0 ? page_end - scope : 1;
- }
-
- $pagination.find('li.prev a').attr("href", kanban_url_col+(page-1 > 0 ? page-1 : 1));
- $pagination.find('li.next a').attr("href", kanban_url_col+(page < page_end ? page+1 : page_end));
- for(var i=0; i < scope; i++) {
- $pagination.find('li:not(.prev):not(.next):eq('+i+') a').attr("href", kanban_url_col+(page_start+i)).html(page_start+i);
- }
- $pagination.find('li.active').removeClass('active');
- $pagination.find('li:has(a[href="'+kanban_url_col+page+'"])').addClass('active');
-
- });
-
- });
- };
-
- /**
- * Returns a deferred resolved when the templates are loaded
- * and the Widgets can be instanciated.
- */
- website.ready = function() {
- if (!all_ready) {
- all_ready = dom_ready.then(function () {
- return templates_def;
- }).then(function () {
- if (website.is_editable) {
- website.id = $('html').data('website-id');
- website.session = new openerp.Session();
- var modules = ['website'];
- return openerp._t.database.load_translations(website.session, modules, website.get_context().lang);
- }
- }).promise();
- }
- return all_ready;
- };
-
- website.error = function(data, url) {
- var $error = $(openerp.qweb.render('website.error_dialog', {
- 'title': data.data ? data.data.arguments[0] : "",
- 'message': data.data ? data.data.arguments[1] : data.statusText,
- 'backend_url': url
- }));
- $error.appendTo("body");
- $error.modal('show');
- };
-
+ /* ----------------------------------------------------
+ Widgets
+ ---------------------------------------------------- */
website.prompt = function (options) {
/**
* A bootstrapped version of prompt() albeit asynchronous
@@ -231,11 +124,13 @@
dialog.on('click', '.btn-primary', function () {
def.resolve(field.val(), field, dialog);
dialog.remove();
+ $('.modal-backdrop').remove();
});
});
dialog.on('hidden.bs.modal', function () {
def.reject();
dialog.remove();
+ $('.modal-backdrop').remove();
});
if (field.is('input[type="text"], select')) {
field.keypress(function (e) {
@@ -248,6 +143,16 @@
return def;
};
+ website.error = function(data, url) {
+ var $error = $(openerp.qweb.render('website.error_dialog', {
+ 'title': data.data ? data.data.arguments[0] : "",
+ 'message': data.data ? data.data.arguments[1] : data.statusText,
+ 'backend_url': url
+ }));
+ $error.appendTo("body");
+ $error.modal('show');
+ };
+
website.form = function (url, method, params) {
var form = document.createElement('form');
form.setAttribute('action', url);
@@ -263,11 +168,117 @@
form.submit();
};
- dom_ready.then(function () {
+ website.init_kanban = function ($kanban) {
+ $('.js_kanban_col', $kanban).each(function () {
+ var $col = $(this);
+ var $pagination = $('.pagination', $col);
+ if(!$pagination.size()) {
+ return;
+ }
- /* ----- BOOTSTRAP STUFF ---- */
- // $('.js_tooltip').bstooltip();
+ var page_count = $col.data('page_count');
+ var scope = $pagination.last().find("li").size()-2;
+ var kanban_url_col = $pagination.find("li a:first").attr("href").replace(/[0-9]+$/, '');
+ var data = {
+ 'domain': $col.data('domain'),
+ 'model': $col.data('model'),
+ 'template': $col.data('template'),
+ 'step': $col.data('step'),
+ 'orderby': $col.data('orderby')
+ };
+
+ $pagination.on('click', 'a', function (ev) {
+ ev.preventDefault();
+ var $a = $(ev.target);
+ if($a.parent().hasClass('active')) {
+ return;
+ }
+
+ var page = +$a.attr("href").split(",").pop().split('-')[1];
+ data['page'] = page;
+
+ $.post('/website/kanban/', data, function (col) {
+ $col.find("> .thumbnail").remove();
+ $pagination.last().before(col);
+ });
+
+ var page_start = page - parseInt(Math.floor((scope-1)/2), 10);
+ if (page_start < 1 ) page_start = 1;
+ var page_end = page_start + (scope-1);
+ if (page_end > page_count ) page_end = page_count;
+
+ if (page_end - page_start < scope) {
+ page_start = page_end - scope > 0 ? page_end - scope : 1;
+ }
+
+ $pagination.find('li.prev a').attr("href", kanban_url_col+(page-1 > 0 ? page-1 : 1));
+ $pagination.find('li.next a').attr("href", kanban_url_col+(page < page_end ? page+1 : page_end));
+ for(var i=0; i < scope; i++) {
+ $pagination.find('li:not(.prev):not(.next):eq('+i+') a').attr("href", kanban_url_col+(page_start+i)).html(page_start+i);
+ }
+ $pagination.find('li.active').removeClass('active');
+ $pagination.find('li:has(a[href="'+kanban_url_col+page+'"])').addClass('active');
+
+ });
+
+ });
+ };
+
+ /* ----------------------------------------------------
+ Async Ready and Template loading
+ ---------------------------------------------------- */
+ var templates_def = $.Deferred().resolve();
+ website.add_template_file = function(template) {
+ templates_def = templates_def.then(function() {
+ var def = $.Deferred();
+ openerp.qweb.add_template(template, function(err) {
+ if (err) {
+ def.reject(err);
+ } else {
+ def.resolve();
+ }
+ });
+ return def;
+ });
+ };
+ website.add_template_file('/website/static/src/xml/website.xml');
+
+ website.dom_ready = $.Deferred();
+ $(document).ready(function () {
+ website.is_editable = website.is_editable || $('html').data('editable');
+ website.is_editable_button= website.is_editable_button || $('html').data('editable');
+ website.dom_ready.resolve();
+ // fix for ie
+ if($.fn.placeholder) $('input, textarea').placeholder();
+ });
+
+ var all_ready = null;
+ /**
+ * Returns a deferred resolved when the templates are loaded
+ * and the Widgets can be instanciated.
+ */
+ website.ready = function() {
+ if (!all_ready) {
+ all_ready = website.dom_ready.then(function () {
+ return templates_def;
+ }).then(function () {
+ if (website.is_editable) {
+ website.id = $('html').data('website-id');
+ website.session = new openerp.Session();
+ var modules = ['website'];
+ return openerp._t.database.load_translations(website.session, modules, website.get_context().lang);
+ }
+ }).promise();
+ }
+ return all_ready;
+ };
+
+ website.inject_tour = function() {
+ // if a tour is active inject tour js
+ }
+
+ website.dom_ready.then(function () {
/* ----- PUBLISHING STUFF ---- */
$(document).on('click', '.js_publish_management .js_publish_btn', function () {
var $data = $(this).parents(".js_publish_management:first");
diff --git a/addons/website/static/src/js/website.snippets.animation.js b/addons/website/static/src/js/website.snippets.animation.js
index f1d19125a0c..56ad596d71a 100644
--- a/addons/website/static/src/js/website.snippets.animation.js
+++ b/addons/website/static/src/js/website.snippets.animation.js
@@ -5,20 +5,26 @@
if (!website.snippet) website.snippet = {};
website.snippet.readyAnimation = [];
- website.snippet.start_animation = function () {
+ website.snippet.start_animation = function (editable_mode, $target) {
for (var k in website.snippet.animationRegistry) {
var Animation = website.snippet.animationRegistry[k];
- var selector = "[data-snippet-id='"+k+"']";
+ var selector = "";
if (Animation.prototype.selector) {
- selector += ", " + Animation.prototype.selector;
+ if (selector != "") selector += ", "
+ selector += Animation.prototype.selector;
}
+ if ($target) {
+ if ($target.is(selector)) selector = $target;
+ else continue;
+ }
+
$(selector).each(function() {
var $snipped_id = $(this);
if ( !$snipped_id.parents("#oe_snippets").length &&
!$snipped_id.parent("body").length &&
!$snipped_id.data("snippet-view")) {
website.snippet.readyAnimation.push($snipped_id);
- $snipped_id.data("snippet-view", new Animation($snipped_id));
+ $snipped_id.data("snippet-view", new Animation($snipped_id, editable_mode));
}
});
}
@@ -32,7 +38,9 @@
}
});
};
- $(document).ready(website.snippet.start_animation);
+ $(document).ready(function () {
+ website.snippet.start_animation();
+ });
website.snippet.animationRegistry = {};
@@ -41,9 +49,9 @@
$: function () {
return this.$el.find.apply(this.$el, arguments);
},
- init: function (dom) {
+ init: function (dom, editable_mode) {
this.$el = this.$target = $(dom);
- this.start();
+ this.start(editable_mode);
},
/*
* start
@@ -71,7 +79,7 @@
});
website.snippet.animationRegistry.parallax = website.snippet.Animation.extend({
- parallax: ".parallax",
+ selector: ".parallax",
start: function () {
var self = this;
setTimeout(function () {self.set_values();});
@@ -108,7 +116,7 @@
img.onload = function () {
var offset = 0;
var padding = parseInt($(document.body).css("padding-top"));
- if (speed < 1) {
+ if (speed > 1) {
var inner_offset = - self.$target.outerHeight() + this.height / this.width * document.body.clientWidth;
var outer_offset = self.$target.offset().top - (document.body.clientHeight - self.$target.outerHeight()) - padding;
offset = - outer_offset * speed + inner_offset;
@@ -123,4 +131,21 @@
}
});
+ website.snippet.animationRegistry.share = website.snippet.Animation.extend({
+ selector: ".oe_share",
+ start: function () {
+ var url = encodeURIComponent(window.location.href);
+ var title = encodeURIComponent($("title").text());
+ this.$target.find("a").each(function () {
+ var $a = $(this);
+ $a.attr("href", $(this).attr("href").replace("{url}", url).replace("{title}", title));
+ if ($a.attr("target") && $a.attr("target").match(/_blank/i)) {
+ $a.click(function () {
+ window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=550,width=600');
+ return false;
+ });
+ }
+ });
+ },
+ });
})();
diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js
index ee07840b12d..1eee1fee65b 100644
--- a/addons/website/static/src/js/website.snippets.editor.js
+++ b/addons/website/static/src/js/website.snippets.editor.js
@@ -18,7 +18,7 @@
},
edit: function () {
var self = this;
- $("body").off('click');
+ $("[data-oe-model] *, [data-oe-type=html] *").off('click');
website.snippet.stop_animation();
window.snippets = this.snippets = new website.snippet.BuildingBlock(this);
this.snippets.appendTo(this.$el);
@@ -41,12 +41,7 @@
return this._super.apply(this, arguments);
},
save: function () {
- this.snippets.make_active(false);
-
- // FIXME: call clean_for_save on all snippets of the page, not only modified ones
- // important for banner of parallax that changes data automatically.
this.snippets.clean_for_save();
- remove_added_snippet_id();
this._super();
},
});
@@ -59,38 +54,14 @@
})) {
return;
}
- hack_to_add_snippet_id()
- });
-
- // puts $el at the same absolute position as $target
- function hack_to_add_snippet_id () {
- _.each(website.snippet.selector, function (val) {
- $(val[0]).each(function() {
- if (!$(this).is("[data-snippet-id]") && $(this).parents("[data-oe-model]").length) {
- $(this).attr("data-snippet-id", val[1]);
- }
- });
- });
- }
- function remove_added_snippet_id () {
- _.each(website.snippet.selector, function (val) {
- $(val[0]).each(function() {
- if ($(this).data("snippet-id") === val[1]) {
- $(this).removeAttr("data-snippet-id");
- }
- });
- });
- }
-
- $(document).ready(function() {
- hack_to_add_snippet_id();
});
// 'snippet-dropped' is triggered on '#oe_snippets' whith $target as attribute when a snippet is dropped
// 'snippet-activated' is triggered on '#oe_snippets' (and on snippet) when a snippet is activated
if (!website.snippet) website.snippet = {};
- website.snippet.styles = {};
+ website.snippet.templateOptions = {};
+ website.snippet.globalSelector = "";
website.snippet.selector = [];
website.snippet.BuildingBlock = openerp.Widget.extend({
template: 'website.snippets',
@@ -102,7 +73,6 @@
$("
").appendTo('body');
}
this.$active_snipped_id = false;
- hack_to_add_snippet_id();
this.snippets = [];
observer.observe(document.body, {
@@ -169,17 +139,23 @@
.then(function (html) {
var $html = $(html);
- var $styles = $html.find("[data-snippet-style-id]");
+ var selector = [];
+ var $styles = $html.find("[data-snippet-option-id]");
$styles.each(function () {
var $style = $(this);
- var style_id = $style.data('snippet-style-id');
- website.snippet.styles[style_id] = {
- 'snippet-style-id' : style_id,
+ var style_id = $style.data('snippet-option-id');
+ website.snippet.templateOptions[style_id] = {
+ 'snippet-option-id' : style_id,
'selector': $style.data('selector'),
'$el': $style,
+ 'selector-siblings': $style.data('selector-siblings'),
+ 'selector-children': $style.data('selector-children'),
+ 'selector-vertical-children': $style.data('selector-vertical-children')
};
+ selector.push($style.data('selector'));
});
$styles.addClass("hidden");
+ website.snippet.globalSelector = selector.join(",");
self.$snippets = $html.find(".tab-content > div > div").addClass("oe_snippet");
self.$el.append($html);
@@ -204,10 +180,10 @@
'top': pos.top - mt - 5,
'left': pos.left
});
- $el.find(">.e,>.w").css({'height': $target.outerHeight() + mt + mb+1});
- $el.find(">.s").css({'top': $target.outerHeight() + mt + mb});
- $el.find(">.size").css({'top': $target.outerHeight() + mt});
- $el.find(">.s,>.n").css({'width': $target.outerWidth()-2});
+ $el.find(".oe_handle.e,.oe_handle.w").css({'height': $target.outerHeight() + mt + mb+1});
+ $el.find(".oe_handle.s").css({'top': $target.outerHeight() + mt + mb});
+ $el.find(".oe_handle.size").css({'top': $target.outerHeight() + mt});
+ $el.find(".oe_handle.s,.oe_handle.n").css({'width': $target.outerWidth()-2});
},
show: function () {
this.$el.removeClass("hidden");
@@ -224,12 +200,24 @@
bind_snippet_click_editor: function () {
var self = this;
+ var snipped_event_flag;
$("#wrapwrap").on('click', function (event) {
- var $target = $(event.srcElement || event.target);
- if (!$target.attr("data-snippet-id")) {
- $target = $target.parents("[data-snippet-id]:first");
+ if (snipped_event_flag || !event.srcElement) {
+ return;
}
- if (!$target.attr("data-oe-model") && !$target.parents("[data-oe-model]:first").length) {
+ snipped_event_flag = true;
+
+ setTimeout(function () {snipped_event_flag = false;}, 0);
+ var $target = $(event.srcElement);
+
+ if ($target.parents(".oe_overlay").length) {
+ return;
+ }
+
+ if (!$target.is(website.snippet.globalSelector)) {
+ $target = $target.parents(website.snippet.globalSelector).first();
+ }
+ if (!self.dom_filter($target).length) {
$target = false;
}
if (self.$active_snipped_id && self.$active_snipped_id.is($target)) {
@@ -253,13 +241,16 @@
}
},
clean_for_save: function () {
- for (var k in this.snippets) {
- if (!this.snippets.hasOwnProperty(k)) { continue; }
- var editor = $(this.snippets[k]).data("snippet-editor");
+ var self = this;
+ $(website.snippet.globalSelector).each(function () {
+ var $snippet = $(this);
+ self.make_active($snippet);
+ self.make_active(false);
+ var editor = $snippet.data("snippet-editor");
if (editor) {
editor.clean_for_save();
}
- }
+ });
},
make_active: function ($snippet) {
if ($snippet && this.$active_snipped_id && this.$active_snipped_id.get(0) === $snippet.get(0)) {
@@ -286,8 +277,7 @@
if (typeof $snippet.data("snippet-editor") === 'undefined') {
var $targets = this.activate_overlay_zones($snippet);
if (!$targets.length) return;
- var editor = website.snippet.editorRegistry[$snippet.data("snippet-id")] || website.snippet.editorRegistry.resize;
- $snippet.data("snippet-editor", new editor(this, $snippet));
+ $snippet.data("snippet-editor", new website.snippet.Editor(this, $snippet));
}
this.cover_target($snippet.data('overlay'), $snippet);
},
@@ -323,36 +313,47 @@
start: function(){
self.hide();
dropped = false;
+ // snippet_selectors => to get selector-siblings, selector-children, selector-vertical-children
$snippet = $(this);
- snipped_id = $snippet.data('snippet-id');
+ $toInsert = $snippet.find('.oe_snippet_body').clone();
+ $toInsert.removeClass('oe_snippet_body');
+
+ var selector = [];
+ var selector_siblings = [];
+ var selector_children = [];
+ var selector_vertical_children = [];
+ for (var k in website.snippet.templateOptions) {
+ if ($toInsert.is(website.snippet.templateOptions[k].selector)) {
+ selector.push(website.snippet.templateOptions[k].selector);
+ if (website.snippet.templateOptions[k]['selector-siblings'])
+ selector_siblings.push(website.snippet.templateOptions[k]['selector-siblings']);
+ if (website.snippet.templateOptions[k]['selector-children'])
+ selector_children.push(website.snippet.templateOptions[k]['selector-children']);
+ if (website.snippet.templateOptions[k]['selector-vertical-children'])
+ selector_vertical_children.push(website.snippet.templateOptions[k]['selector-vertical-children']);
+ }
+ }
+
action = $snippet.find('.oe_snippet_body').size() ? 'insert' : 'mutate';
+
if( action === 'insert'){
- if (!$snippet.data('selector-siblings') && !$snippet.data('selector-children') && !$snippet.data('selector-vertical-children')) {
+ if (!selector_siblings.length && !selector_children.length && !selector_vertical_children.length) {
console.debug($snippet.data("snippet-id") + " have oe_snippet_body class and have not for insert action"+
"data-selector-siblings, data-selector-children or data-selector-vertical-children tag for mutate action");
return;
}
self.activate_insertion_zones({
- siblings: $snippet.data('selector-siblings'),
- children: $snippet.data('selector-children'),
- vertical_children: $snippet.data('selector-vertical-children')
+ siblings: selector_siblings.join(","),
+ children: selector_children.join(","),
+ vertical_children: selector_vertical_children.join(","),
});
- $toInsert = $snippet.find('.oe_snippet_body').clone();
- $toInsert.removeClass('oe_snippet_body');
- $toInsert.data('src-snippet-id', snipped_id);
- if (!$toInsert.data('snippet-id')) {
- $toInsert.attr('data-snippet-id', snipped_id);
- } else {
- snipped_id = $toInsert.data('snippet-id');
- }
-
} else if( action === 'mutate' ){
if (!$snippet.data('selector')) {
console.debug($snippet.data("snippet-id") + " have not oe_snippet_body class and have not data-selector tag");
return;
}
- var $targets = self.activate_overlay_zones($snippet.data('selector'));
+ var $targets = self.activate_overlay_zones(selector_children.join(","));
$targets.each(function(){
var $clone = $(this).data('overlay').clone();
$clone.addClass("oe_drop_zone").data('target', $(this));
@@ -387,38 +388,30 @@
}
$('.oe_drop_zone').droppable('destroy').remove();
+
if (dropped) {
var $target = false;
- if(action === 'insert'){
- $target = $toInsert;
+ $target = $toInsert;
- website.snippet.start_animation();
+ setTimeout(function () {
+ $("#oe_snippets").trigger('snippet-dropped', $target);
+ website.snippet.start_animation(true, $target);
+
+ // drop_and_build_snippet
self.create_overlay($target);
if ($target.data("snippet-editor")) {
$target.data("snippet-editor").drop_and_build_snippet($target);
}
-
- $target.find("[data-snippet-id]").each(function () {
- var $snippet = $(this);
- var snippet_id = $snippet.data("data-snippet-id");
- self.create_overlay($snippet);
- if ($snippet.data("snippet-editor")) {
- $snippet.data("snippet-editor").drop_and_build_snippet($snippet);
- }
- });
-
- } else {
- $target = $(this).data('target');
-
- self.create_overlay($target);
- if (website.snippet.editorRegistry[snipped_id]) {
- var snippet = new website.snippet.editorRegistry[snipped_id](self, $target);
- snippet.drop_and_build_snippet($target);
+ for (var k in website.snippet.templateOptions) {
+ $target.find(website.snippet.templateOptions[k].selector).each(function () {
+ var $snippet = $(this);
+ self.create_overlay($snippet);
+ if ($snippet.data("snippet-editor")) {
+ $snippet.data("snippet-editor").drop_and_build_snippet($snippet);
+ }
+ });
}
- }
- setTimeout(function () {
- $("#oe_snippets").trigger('snippet-dropped', $target);
// reset snippet for rte
$target.removeData("snippet-editor");
@@ -426,7 +419,7 @@
$target.data("overlay").remove();
$target.removeData("overlay");
}
- $target.find("[data-snippet-id]").each(function () {
+ $target.find(website.snippet.globalSelector).each(function () {
var $snippet = $(this);
$snippet.removeData("snippet-editor");
if ($snippet.data("overlay")) {
@@ -434,9 +427,9 @@
$snippet.removeData("overlay");
}
});
+ self.create_overlay($target);
// end
- self.create_overlay($target);
self.make_active($target);
},0);
} else {
@@ -554,7 +547,7 @@
// generate drop zones covering the elements selected by the selector
// we generate overlay drop zones only to get an idea of where the snippet are, the drop
activate_overlay_zones: function(selector){
- var $targets = this.dom_filter(selector || '[data-snippet-id]');
+ var $targets = this.dom_filter(selector);
var self = this;
if (typeof selector !== 'string' && !$targets.length) {
@@ -613,23 +606,24 @@
});
- website.snippet.styleRegistry = {};
- website.snippet.StyleEditor = openerp.Class.extend({
+ website.snippet.options = {};
+ website.snippet.Option = openerp.Class.extend({
// initialisation (don't overwrite)
- init: function (parent, $target, snippet_id) {
- this.parent = parent;
+ init: function (BuildingBlock, editor, $target, snippet_id) {
+ this.BuildingBlock = BuildingBlock;
+ this.editor = editor;
this.$target = $target;
- var styles = this.$target.data("snippet-style-ids") || {};
+ var styles = this.$target.data("snippet-option-ids") || {};
styles[snippet_id] = this;
- this.$target.data("snippet-style-ids", styles);
+ this.$target.data("snippet-option-ids", styles);
this.$overlay = this.$target.data('overlay');
- this['snippet-style-id'] = snippet_id;
- this.$el = website.snippet.styles[snippet_id].$el.find(">li").clone();
+ this['snippet-option-id'] = snippet_id;
+ this.$el = website.snippet.templateOptions[snippet_id].$el.find(">li").clone();
this.required = this.$el.data("required");
this.set_active();
- this.$el.find('li[data-class] a').on('mouseover mouseout click', _.bind(this._mouse, this));
+ this.$el.find('li[data-value] a').on('mouseover mouseout click', _.bind(this._mouse, this));
this.$target.on('snippet-style-reset', _.bind(this.set_active, this));
this.start();
@@ -649,9 +643,9 @@
var $prev, $next;
if (event.type === 'mouseout') {
$prev = $(event.currentTarget).parent();
- $next = this.$el.find("li[data-class].active");
+ $next = this.$el.find("li[data-value].active");
} else {
- $prev = this.$el.find("li[data-class].active");
+ $prev = this.$el.find("li[data-value].active");
$next = $(event.currentTarget).parent();
}
if (!$prev.length) {
@@ -682,8 +676,40 @@
// start is call just after the init
start: function () {
},
+ /* onFocus
+ * This method is called when the user click inside the snippet in the dom
+ */
+ onFocus : function () {
+ },
+
+ /* onFocus
+ * This method is called when the user click outside the snippet in the dom, after a focus
+ */
+ onBlur : function () {
+ },
+
+ /* on_clone
+ * This method is called when the snippet is cloned ($clone is allready inserted)
+ */
+ on_clone: function ($clone) {
+ },
+
+ /* on_remove
+ * This method is called when the snippet is removed (dom is removing after this call)
+ */
+ on_remove: function () {
+ },
+
+ /*
+ * drop_and_build_snippet
+ * This method is called just after that a thumbnail is drag and dropped into a drop zone
+ * (after the insertion of this.$body, if this.$body exists)
+ */
+ drop_and_build_snippet: function ($target) {
+ },
/* select
* called when a user select an item
+ * li must have data-value attribute
* variables: np = {$next, $prev}
* $next is false if they are no next item selected
* $prev is false if they are no previous item selected
@@ -692,10 +718,10 @@
var self = this;
// add or remove html class
if (np.$prev) {
- this.$target.removeClass(np.$prev.data('class' || ""));
+ this.$target.removeClass(np.$prev.data('value' || ""));
}
if (np.$next) {
- this.$target.addClass(np.$next.data('class') || "");
+ this.$target.addClass(np.$next.data('value') || "");
}
},
/* preview
@@ -709,10 +735,10 @@
// add or remove html class
if (np.$prev) {
- this.$target.removeClass(np.$prev.data('class') || "");
+ this.$target.removeClass(np.$prev.data('value') || "");
}
if (np.$next) {
- this.$target.addClass(np.$next.data('class') || "");
+ this.$target.addClass(np.$next.data('value') || "");
}
},
/* set_active
@@ -722,19 +748,23 @@
set_active: function () {
var self = this;
this.$el.find('li').removeClass("active");
- var $active = this.$el.find('li[data-class]')
+ var $active = this.$el.find('li[data-value]')
.filter(function () {
var $li = $(this);
- return ($li.data('class') && self.$target.hasClass($li.data('class')));
+ return ($li.data('value') && self.$target.hasClass($li.data('value')));
})
.first()
.addClass("active");
- this.$el.find('li:has(li[data-class].active)').addClass("active");
+ this.$el.find('li:has(li[data-value].active)').addClass("active");
+ },
+ /* clean_for_save
+ * function called just before save vue
+ */
+ clean_for_save: function () {
}
});
-
- website.snippet.styleRegistry.background = website.snippet.StyleEditor.extend({
+ website.snippet.options.background = website.snippet.Option.extend({
_get_bg: function () {
return this.$target.css("background-image").replace(/url\(['"]*|['"]*\)|^none$/g, "");
},
@@ -744,7 +774,7 @@
start: function () {
this._super();
var src = this._get_bg();
- this.$el.find("li[data-class].active.oe_custom_bg").data("src", src);
+ this.$el.find("li[data-value].active.oe_custom_bg").data("src", src);
},
select: function(event, np) {
var self = this;
@@ -760,7 +790,7 @@
});
editor.on('cancel', self, function () {
if (!np.$prev || np.$prev.data("src") === "") {
- self.$target.removeClass(np.$next.data("class"));
+ self.$target.removeClass(np.$next.data("value"));
self.$target.trigger("snippet-style-change", [self, np]);
}
});
@@ -770,7 +800,7 @@
}
} else {
this._set_bg(false);
- this.$target.removeClass(np.$prev.data("class"));
+ this.$target.removeClass(np.$prev.data("value"));
}
},
preview: function (event, np) {
@@ -783,249 +813,215 @@
var self = this;
var bg = self.$target.css("background-image");
this.$el.find('li').removeClass("active");
- var $active = this.$el.find('li[data-class]')
+ var $active = this.$el.find('li[data-value]')
.filter(function () {
var $li = $(this);
return ($li.data('src') && bg.indexOf($li.data('src')) >= 0) ||
- (!$li.data('src') && self.$target.hasClass($li.data('class')));
+ (!$li.data('src') && self.$target.hasClass($li.data('value')));
})
.first();
if (!$active.length) {
$active = this.$target.css("background-image") !== 'none' ?
- this.$el.find('li[data-class].oe_custom_bg') :
- this.$el.find('li[data-class=""]');
+ this.$el.find('li[data-value].oe_custom_bg') :
+ this.$el.find('li[data-value=""]');
}
$active.addClass("active");
- this.$el.find('li:has(li[data-class].active)').addClass("active");
+ this.$el.find('li:has(li[data-value].active)').addClass("active");
}
});
-
- website.snippet.editorRegistry = {};
- website.snippet.Editor = openerp.Class.extend({
- init: function (parent, dom) {
- this.parent = parent;
- this.$target = $(dom);
- this.$overlay = this.$target.data('overlay');
- this.$overlay.find('a[data-toggle="dropdown"]').dropdown();
- this.snippet_id = this.$target.data("snippet-id");
- this._readXMLData();
- this.load_style_options();
- this.get_parent_block();
- this.start();
- },
-
- /*
- * _readXMLData
- * Read data XML and set value into:
- * this.$el :
- * all xml data
- * this.$overlay :
- * Dom hover the $target who content options
- * this.$editor :
- * content of .oe_snippet_options
- * Displayed into the overlay options on focus
- */
- _readXMLData: function() {
- var self = this;
- this.$el = this.parent.$snippets.filter(function () { return $(this).data("snippet-id") == self.snippet_id; }).clone();
- this.$editor = this.$el.find(".oe_snippet_options");
- var $options = this.$overlay.find(".oe_overlay_options");
- this.$editor.prependTo($options.find(".oe_options ul"));
- if ($options.find(".oe_options ul li").length) {
- $options.find(".oe_options").removeClass("hidden");
- }
- },
-
-
- // activate drag and drop for the snippets in the snippet toolbar
- _drag_and_drop: function(){
- var self = this;
- this.dropped = false;
- this.$overlay.draggable({
- greedy: true,
- appendTo: 'body',
- cursor: "move",
- handle: ".oe_snippet_move",
- cursorAt: {
- left: 18,
- top: 14
- },
- helper: function() {
- var $clone = $(this).clone().css({width: "24px", height: "24px", border: 0});
- $clone.find(".oe_overlay_options >:not(:contains(.oe_snippet_move)), .oe_handle").remove();
- $clone.find(":not(.glyphicon)").css({position: 'absolute', top: 0, left: 0});
- $clone.appendTo("body").removeClass("hidden");
- return $clone;
- },
- start: _.bind(self._drag_and_drop_start, self),
- stop: _.bind(self._drag_and_drop_stop, self)
+ website.snippet.options.slider = website.snippet.Option.extend({
+ unique_id: function () {
+ var id = 0;
+ $(".carousel").each(function () {
+ var cid = 1 + parseInt($(this).attr("id").replace(/[^0123456789]/g, ''),10);
+ if (id < cid) id = cid;
});
+ return "myCarousel" + id;
},
- _drag_and_drop_after_insert_dropzone: function (){},
- _drag_and_drop_active_drop_zone: function ($zones){
+ drop_and_build_snippet: function() {
+ this.id = this.unique_id();
+ this.$target.attr("id", this.id);
+ this.$target.find("[data-slide]").attr("href", "#" + this.id);
+ this.$target.find("[data-slide-to]").attr("data-target", "#" + this.id);
+
+ this.rebind_event();
+ },
+ on_clone: function ($clone) {
+ var id = this.unique_id();
+ $clone.attr("id", id);
+ $clone.find("[data-slide]").attr("href", "#" + id);
+ $clone.find("[data-slide-to]").attr("data-target", "#" + id);
+ },
+ // rebind event to active carousel on edit mode
+ rebind_event: function () {
var self = this;
- $zones.droppable({
- over: function(){
- $(".oe_drop_zone.hide").removeClass("hide");
- $(this).addClass("hide").first().after(self.$target);
- self.dropped = true;
- },
- out: function(){
- $(this).removeClass("hide");
- self.$target.detach();
- self.dropped = false;
- },
- });
+ this.$target.find('.carousel-indicators [data-slide-to]').off('click').on('click', function () {
+ self.$target.carousel(+$(this).data('slide-to')); });
+
+ this.$target.attr('contentEditable', 'false');
+ this.$target.find('.oe_structure, .content>.row, [data-slide]').attr('contentEditable', 'true');
},
- _drag_and_drop_start: function (){
- var self = this;
- self.parent.hide();
- self.parent.editor_busy = true;
- self.size = {
- width: self.$target.width(),
- height: self.$target.height()
- };
- self.$target.after("
");
- self.$target.detach();
- self.$overlay.addClass("hidden");
-
- self.parent.activate_insertion_zones({
- siblings: self.$el ? self.$el.data('selector-siblings') : false,
- children: self.$el ? self.$el.data('selector-children') : false,
- vertical_children: self.$el ? self.$el.data('selector-vertical-children') : false,
- });
-
- $("body").addClass('move-important');
-
- self._drag_and_drop_after_insert_dropzone();
- self._drag_and_drop_active_drop_zone($('.oe_drop_zone'));
- },
- _drag_and_drop_stop: function (){
- var self = this;
- if (!self.dropped) {
- $(".oe_drop_clone").after(self.$target);
- }
- self.$overlay.removeClass("hidden");
- $("body").removeClass('move-important');
- $('.oe_drop_zone').droppable('destroy').remove();
- $(".oe_drop_clone, .oe_drop_to_remove").remove();
- self.parent.editor_busy = false;
- self.get_parent_block();
- setTimeout(function () {self.parent.create_overlay(self.$target);},0);
- },
-
- load_style_options: function () {
- var self = this;
- var $styles = this.$overlay.find('.oe_options');
- var $ul = $styles.find('ul:first');
- _.each(website.snippet.styles, function (val) {
- if (!self.parent.dom_filter(val.selector).is(self.$target)) {
- return;
- }
- var Editor = website.snippet.styleRegistry[val['snippet-style-id']] || website.snippet.StyleEditor;
- var editor = new Editor(self, self.$target, val['snippet-style-id']);
- $ul.prepend(editor.$el.addClass("snippet-style-" + val['snippet-style-id']));
- });
-
- if ($ul.find("li").length) {
- $styles.removeClass("hidden");
- }
- },
-
- get_parent_block: function () {
- var self = this;
- var $button = this.$overlay.find('.oe_snippet_parent');
- var $parent = this.$target.parents("[data-snippet-id]:first");
- if ($parent.length) {
- $button.removeClass("hidden");
- $button.off("click").on('click', function (event) {
- event.preventDefault();
- setTimeout(function () {
- self.parent.make_active($parent);
- }, 0);
- });
- } else {
- $button.addClass("hidden");
- }
- },
-
- /*
- * start
- * This method is called after init and _readXMLData
- */
- start: function () {
- var self = this;
- this.$overlay.on('click', '.oe_snippet_clone', _.bind(this.on_clone, this));
- this.$overlay.on('click', '.oe_snippet_remove', _.bind(this.on_remove, this));
- this._drag_and_drop();
- },
-
- on_clone: function () {
- var $clone = this.$target.clone(false);
- this.$target.after($clone);
- return false;
- },
-
- on_remove: function () {
- this.onBlur();
- var index = _.indexOf(this.parent.snippets, this.$target.get(0));
- delete this.parent.snippets[index];
- this.$target.remove();
- this.$overlay.remove();
- return false;
- },
-
- /*
- * drop_and_build_snippet
- * This method is called just after that a thumbnail is drag and dropped into a drop zone
- * (after the insertion of this.$body, if this.$body exists)
- */
- drop_and_build_snippet: function ($target) {
- },
-
- /* onFocus
- * This method is called when the user click inside the snippet in the dom
- */
- onFocus : function () {
- this.$overlay.addClass('oe_active');
- },
-
- /* onFocus
- * This method is called when the user click outside the snippet in the dom, after a focus
- */
- onBlur : function () {
- this.$overlay.removeClass('oe_active');
- },
-
- /* clean_for_save
- * function called just before save vue
- */
clean_for_save: function () {
- this.$target.removeAttr('contentEditable')
- .find('*').removeAttr('contentEditable');
- this.$target.removeAttr('attributeEditable')
- .find('*').removeAttr('attributeEditable');
+ this._super();
+ this.$target.find(".item").removeClass("next prev left right");
+ if(!this.$target.find(".item.active").length) {
+ this.$target.find(".item:first").addClass("active");
+ }
+ },
+ start : function () {
+ var self = this;
+ this._super();
+ this.id = this.$target.attr("id");
+ this.$inner = this.$target.find('.carousel-inner');
+ this.$indicators = this.$target.find('.carousel-indicators');
+
+ this.$el.find(".js_add").on('click', function () {self.on_add_slide(); return false;});
+ this.$el.find(".js_remove").on('click', function () {self.on_remove_slide(); return false;});
+
+ this.$target.carousel('pause');
+ this.rebind_event();
+ },
+ on_add_slide: function () {
+ var self = this;
+ var cycle = this.$inner.find('.item').length;
+ var $active = this.$inner.find('.item.active, .item.prev, .item.next').first();
+ var index = $active.index();
+ this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden");
+ this.$indicators.append('
');
+
+ var $clone = this.$target.find(".item.active").clone();
+
+ // insert
+ $clone.removeClass('active').insertAfter($active);
+ setTimeout(function() {
+ self.$target.carousel().carousel(++index);
+ self.rebind_event();
+ },0);
+ return $clone;
+ },
+ on_remove_slide: function () {
+ if (this.remove_process) {
+ return;
+ }
+ var self = this;
+ var new_index = 0;
+ var cycle = this.$inner.find('.item').length - 1;
+ var index = this.$inner.find('.item.active').index();
+
+ if (cycle > 0) {
+ this.remove_process = true;
+ var $el = this.$inner.find('.item.active');
+ self.$target.on('slid.bs.carousel', function (event) {
+ $el.remove();
+ self.$indicators.find("li:last").remove();
+ self.$target.off('slid.bs.carousel');
+ self.rebind_event();
+ self.remove_process = false;
+ if (cycle == 1) {
+ self.on_remove_slide(event);
+ }
+ });
+ setTimeout(function () {
+ self.$target.carousel( index > 0 ? --index : cycle );
+ }, 500);
+ } else {
+ this.$target.find('.carousel-control, .carousel-indicators').addClass("hidden");
+ }
+ },
+ });
+ website.snippet.options.carousel = website.snippet.options.slider.extend({
+ getSize: function () {
+ this.grid = this._super();
+ this.grid.size = 8;
+ return this.grid;
+ },
+ clean_for_save: function () {
+ this._super();
+ this.$target.css("background-image", "");
+ this.$target.removeClass(this._class);
+ },
+ load_style_options : function () {
+ this._super();
+ $(".snippet-style-size li[data-value='']").remove();
+ },
+ start : function () {
+ var self = this;
+ this._super();
+
+ // set background and prepare to clean for save
+ var add_class = function (c){
+ if (c) self._class = (self._class || "").replace(new RegExp("[ ]+" + c.replace(" ", "|[ ]+")), '') + ' ' + c;
+ return self._class || "";
+ };
+ this.$target.on('snippet-style-change snippet-style-preview', function (event, style, np) {
+ var $active = self.$target.find(".item.active");
+ if (style['snippet-option-id'] === "size") return;
+ if (style['snippet-option-id'] === "background") {
+ $active.css("background-image", self.$target.css("background-image"));
+ }
+ if (np.$prev) {
+ $active.removeClass(np.$prev.data("value"));
+ }
+ if (np.$next) {
+ $active.addClass(np.$next.data("value"));
+ add_class(np.$next.data("value"));
+ }
+ });
+ this.$target.on('slid', function () { // slide.bs.carousel
+ var $active = self.$target.find(".item.active");
+ self.$target
+ .css("background-image", $active.css("background-image"))
+ .removeClass(add_class($active.attr("class")))
+ .addClass($active.attr("class"))
+ .trigger("snippet-style-reset");
+
+ self.$target.carousel("pause");
+ });
+ this.$target.trigger('slid');
+ },
+ on_add_slide: function () {
+ var $clone = this._super();
+
+ // choose an other background
+ var bg = this.$target.data("snippet-option-ids").background;
+ if (!bg) return $clone;
+
+ var $styles = bg.$el.find("li[data-value]:not(.oe_custom_bg)");
+ var styles_index = $styles.index($styles.filter(".active")[0]);
+ $styles.removeClass("active");
+ var $select = $($styles[styles_index >= $styles.length-1 ? 0 : styles_index+1]);
+ $select.addClass("active");
+ $clone.css("background-image", $select.data("src") ? "url('"+ $select.data("src") +"')" : "");
+ $clone.addClass($select.data("value") || "");
+
+ return $clone;
+ },
+ // rebind event to active carousel on edit mode
+ rebind_event: function () {
+ var self = this;
+ this.$target.find('.carousel-control').off('click').on('click', function () {
+ self.$target.carousel( $(this).data('slide')); });
+
+ this.$target.find('.carousel-image, .carousel-inner .content > div').attr('contentEditable', 'true');
+ this.$target.find('.carousel-image').attr('attributeEditable', 'true');
+ this._super();
},
});
-
- website.snippet.editorRegistry.resize = website.snippet.Editor.extend({
+ website.snippet.options.marginAndResize = website.snippet.Option.extend({
start: function () {
var self = this;
this._super();
- var $box = $(openerp.qweb.render("website.snippets.resize"));
var resize_values = this.getSize();
- if (!resize_values.n) $box.find(".oe_handle.n").remove();
- if (!resize_values.s) $box.find(".oe_handle.s").remove();
- if (!resize_values.e) $box.find(".oe_handle.e").remove();
- if (!resize_values.w) $box.find(".oe_handle.w").remove();
- if (!resize_values.size) $box.find(".oe_handle.size").remove();
+ if (resize_values.n) this.$overlay.find(".oe_handle.n").removeClass("readonly");
+ if (resize_values.s) this.$overlay.find(".oe_handle.s").removeClass("readonly");
+ if (resize_values.e) this.$overlay.find(".oe_handle.e").removeClass("readonly");
+ if (resize_values.w) this.$overlay.find(".oe_handle.w").removeClass("readonly");
+ if (resize_values.size) this.$overlay.find(".oe_handle.size").removeClass("readonly");
- this.$overlay.append($box.find(".oe_handles").html());
-
- this.$overlay.find(".oe_handle:not(:has(.oe_handle_button)), .oe_handle .oe_handle_button").on('mousedown', function (event){
+ this.$overlay.find(".oe_handle:not(.size), .oe_handle.size .size").on('mousedown', function (event){
event.preventDefault();
var $handle = $(this);
@@ -1076,7 +1072,7 @@
var regClass = new RegExp("\\s*" + resize[0][begin].replace(/[-]*[0-9]+/, '[-]*[0-9]+'), 'g');
}
- self.parent.editor_busy = true;
+ self.BuildingBlock.editor_busy = true;
var cursor = $handle.css("cursor")+'-important';
var $body = $(document.body);
@@ -1090,7 +1086,7 @@
if (dy <= 0) dy = resize;
self.$target.css("height", dy+"px");
self.on_resize(compass, null, dy);
- self.parent.cover_target(self.$overlay, self.$target);
+ self.BuildingBlock.cover_target(self.$overlay, self.$target);
return;
}
var dd = event['page'+XY] - xy + resize[1][begin];
@@ -1113,7 +1109,7 @@
if (change) {
self.on_resize(compass, beginClass, current);
- self.parent.cover_target(self.$overlay, self.$target);
+ self.BuildingBlock.cover_target(self.$overlay, self.$target);
}
};
@@ -1121,22 +1117,20 @@
$body.unbind('mousemove', body_mousemove);
$body.unbind('mouseup', body_mouseup);
$body.removeClass(cursor);
- self.parent.editor_busy = false;
+ self.BuildingBlock.editor_busy = false;
self.$target.removeClass("resize_editor_busy");
};
$body.mousemove(body_mousemove);
$body.mouseup(body_mouseup);
});
+ this.$overlay.find(".oe_handle.size .auto_size").on('click', function (event){
+ self.$target.css("height", "");
+ self.BuildingBlock.cover_target(self.$overlay, self.$target);
+ return false;
+ });
},
getSize: function () {
- var grid = [0,4,8,16,32,48,64,92,128];
- this.grid = {
- // list of class (Array), grid (Array), default value (INT)
- n: [_.map(grid, function (v) {return 'mt'+v;}), grid],
- s: [_.map(grid, function (v) {return 'mb'+v;}), grid],
- // INT if the user can resize the snippet (resizing per INT px)
- size: null
- };
+ this.grid = {};
return this.grid;
},
@@ -1182,8 +1176,21 @@
this.change_cursor();
}
});
-
- website.snippet.editorRegistry.colmd = website.snippet.editorRegistry.resize.extend({
+ website.snippet.options["margin-y"] = website.snippet.options.marginAndResize.extend({
+ getSize: function () {
+ this.grid = this._super();
+ var grid = [0,4,8,16,32,48,64,92,128];
+ this.grid = {
+ // list of class (Array), grid (Array), default value (INT)
+ n: [_.map(grid, function (v) {return 'mt'+v;}), grid],
+ s: [_.map(grid, function (v) {return 'mb'+v;}), grid],
+ // INT if the user can resize the snippet (resizing per INT px)
+ size: null
+ };
+ return this.grid;
+ },
+ });
+ website.snippet.options["margin-x"] = website.snippet.options.marginAndResize.extend({
getSize: function () {
this.grid = this._super();
var width = this.$target.parents(".row:first").first().outerWidth();
@@ -1225,29 +1232,26 @@
this._super();
},
hide_remove_button: function() {
- this.$overlay.find('.oe_snippet_remove').toggleClass("hidden",
- !this.$target.siblings().length && this.$target.parents("[data-snippet-id]:first").find("[data-snippet-id='colmd']").length > 1);
+ this.$overlay.find('.oe_snippet_remove').toggleClass("hidden", !this.$target.siblings().length);
},
onFocus : function () {
this._super();
this.hide_remove_button();
},
- on_clone: function () {
- var $clone = this.$target.clone(false);
+ on_clone: function ($clone) {
var _class = $clone.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, '');
$clone.attr("class", _class);
- this.$target.after($clone);
this.hide_remove_button();
return false;
},
on_remove: function () {
if (!this.$target.siblings().length) {
- var $parent = this.$target.parents("[data-snippet-id]:first");
- if($parent.find("[data-snippet-id='colmd']").length > 1) {
+ var $parent = this.$target.parents(".row:first");
+ if($parent.find("[class*='col-md']").length > 1) {
return false;
} else {
if (!$parent.data("snippet-editor")) {
- this.parent.create_overlay($parent);
+ this.BuildingBlock.create_overlay($parent);
}
$parent.data("snippet-editor").on_remove();
}
@@ -1281,168 +1285,15 @@
},
});
- website.snippet.editorRegistry.slider = website.snippet.editorRegistry.resize.extend({
+ website.snippet.options["resize"] = website.snippet.options.marginAndResize.extend({
getSize: function () {
this.grid = this._super();
this.grid.size = 8;
return this.grid;
},
- drop_and_build_snippet: function() {
- var id = $(".carousel").length;
- this.id = "myCarousel" + id;
- this.$target.attr("id", this.id);
- this.$target.find(".carousel-control").attr("href", "#myCarousel" + id);
- this.$target.find("[data-target]").attr("data-target", "#myCarousel" + id);
-
- this.rebind_event();
- },
- // rebind event to active carousel on edit mode
- rebind_event: function () {
- var self = this;
- this.$target.find('.carousel-indicators [data-target]').off('click').on('click', function () {
- self.$target.carousel(+$(this).data('slide-to')); });
-
- this.$target.attr('contentEditable', 'false');
- this.$target.find('.oe_structure, .content>.row').attr('contentEditable', 'true');
- },
- clean_for_save: function () {
- this._super();
- this.$target.find(".item").removeClass("next prev left right");
- if(!this.$target.find(".item.active").length) {
- this.$target.find(".item:first").addClass("active");
- }
- },
- start : function () {
- var self = this;
- this._super();
- this.id = this.$target.attr("id");
- this.$inner = this.$target.find('.carousel-inner');
- this.$indicators = this.$target.find('.carousel-indicators');
-
- this.$editor.find(".js_add").on('click', function () {self.on_add_slide(); return false;});
- this.$editor.find(".js_remove").on('click', function () {self.on_remove_slide(); return false;});
-
- this.rebind_event();
- },
- on_add_slide: function () {
- var self = this;
- var cycle = this.$inner.find('.item').length;
- var $active = this.$inner.find('.item.active, .item.prev, .item.next').first();
- var index = $active.index();
- this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden");
- this.$indicators.append('
');
-
- var $clone = this.$el.find(".item.active").clone();
-
- // insert
- $clone.removeClass('active').insertAfter($active);
- setTimeout(function() {
- self.$target.carousel().carousel(++index);
- self.rebind_event();
- },0);
- return $clone;
- },
- on_remove_slide: function () {
- if (this.remove_process) {
- return;
- }
- var self = this;
- var new_index = 0;
- var cycle = this.$inner.find('.item').length - 1;
- var index = this.$inner.find('.item.active').index();
-
- if (cycle > 0) {
- this.remove_process = true;
- var $el = this.$inner.find('.item.active');
- self.$target.on('slid.bs.carousel', function (event) {
- $el.remove();
- self.$indicators.find("li:last").remove();
- self.$target.off('slid.bs.carousel');
- self.rebind_event();
- self.remove_process = false;
- if (cycle == 1) {
- self.on_remove_slide(event);
- }
- });
- setTimeout(function () {
- self.$target.carousel( index > 0 ? --index : cycle );
- }, 500);
- } else {
- this.$target.find('.carousel-control, .carousel-indicators').addClass("hidden");
- }
- },
});
- website.snippet.editorRegistry.carousel = website.snippet.editorRegistry.slider.extend({
- clean_for_save: function () {
- this._super();
- this.$target.css("background-image", "");
- this.$target.removeClass(this._class);
- },
- load_style_options : function () {
- this._super();
- $(".snippet-style-size li[data-class='']").remove();
- },
- start : function () {
- var self = this;
- this._super();
-
- // set background and prepare to clean for save
- var add_class = function (c){
- if (c) self._class = (self._class || "").replace(new RegExp("[ ]+" + c.replace(" ", "|[ ]+")), '') + ' ' + c;
- return self._class || "";
- };
- this.$target.on('snippet-style-change snippet-style-preview', function (event, style, np) {
- var $active = self.$target.find(".item.active");
- if (style['snippet-style-id'] === "size") return;
- if (style['snippet-style-id'] === "background") {
- $active.css("background-image", self.$target.css("background-image"));
- }
- if (np.$prev) {
- $active.removeClass(np.$prev.data("class"));
- }
- if (np.$next) {
- $active.addClass(np.$next.data("class"));
- add_class(np.$next.data("class"));
- }
- });
- this.$target.on('slid', function () { // slide.bs.carousel
- var $active = self.$target.find(".item.active");
- self.$target
- .css("background-image", $active.css("background-image"))
- .removeClass(add_class($active.attr("class")))
- .addClass($active.attr("class"))
- .trigger("snippet-style-reset");
-
- self.$target.carousel();
- });
- this.$target.trigger('slid');
- },
- on_add_slide: function () {
- var $clone = this._super();
-
- // choose an other background
- var $styles = this.$target.data("snippet-style-ids").background.$el.find("li[data-class]:not(.oe_custom_bg)");
- var styles_index = $styles.index($styles.filter(".active")[0]);
- var $select = $($styles[styles_index >= $styles.length-1 ? 0 : styles_index+1]);
- $clone.css("background-image", $select.data("src") ? "url('"+ $select.data("src") +"')" : "");
- $clone.addClass($select.data("class") || "");
-
- return $clone;
- },
- // rebind event to active carousel on edit mode
- rebind_event: function () {
- var self = this;
- this.$target.find('.carousel-control').off('click').on('click', function () {
- self.$target.carousel( $(this).data('slide')); });
-
- this.$target.find('.carousel-inner .content > div').attr('contentEditable', 'true');
- this.$target.find('.carousel-image').attr('attributeEditable', 'true');
- this._super();
- },
- });
-
- website.snippet.editorRegistry.parallax = website.snippet.editorRegistry.resize.extend({
+ website.snippet.options.parallax = website.snippet.Option.extend({
getSize: function () {
this.grid = this._super();
this.grid.size = 8;
@@ -1466,7 +1317,7 @@
},
scroll: function () {
var self = this;
- var $ul = this.$editor.find('ul[name="parallax-scroll"]');
+ var $ul = this.$el.find('ul[name="parallax-scroll"]');
var $li = $ul.find("li");
var speed = this.$target.data('scroll-background-ratio') || 0.6 ;
$ul.find('[data-value="' + speed + '"]').addClass('active');
@@ -1488,13 +1339,244 @@
}
});
- /*
- * data-snippet-id automatically setted
- * Don't need to add data-snippet-id="..." into the views
- */
- website.snippet.selector.push([".row > [class*='col-md-']", 'colmd']);
- website.snippet.selector.push(['hr', 'hr']);
- website.snippet.selector.push(['blockquote', 'quote']);
+ website.snippet.Editor = openerp.Class.extend({
+ init: function (BuildingBlock, dom) {
+ this.BuildingBlock = BuildingBlock;
+ this.$target = $(dom);
+ this.$overlay = this.$target.data('overlay');
+ this.snippet_id = this.$target.data("snippet-id");
+ this._readXMLData();
+ this.load_style_options();
+ this.get_parent_block();
+ this.start();
+ },
+
+ /*
+ * _readXMLData
+ * Read data XML and set value into:
+ * this.$el :
+ * all xml data
+ * this.$overlay :
+ * Dom hover the $target who content options
+ */
+ _readXMLData: function() {
+ var self = this;
+ this.$el = this.BuildingBlock.$snippets.filter(function () { return $(this).data("snippet-id") == self.snippet_id; }).clone();
+ var $options = this.$overlay.find(".oe_overlay_options");
+ if ($options.find(".oe_options ul li").length) {
+ $options.find(".oe_options").removeClass("hidden");
+ }
+ },
+
+
+ // activate drag and drop for the snippets in the snippet toolbar
+ _drag_and_drop: function(){
+ var self = this;
+ this.dropped = false;
+ this.$overlay.draggable({
+ greedy: true,
+ appendTo: 'body',
+ cursor: "move",
+ handle: ".oe_snippet_move",
+ cursorAt: {
+ left: 18,
+ top: 14
+ },
+ helper: function() {
+ var $clone = $(this).clone().css({width: "24px", height: "24px", border: 0});
+ $clone.find(".oe_overlay_options >:not(:contains(.oe_snippet_move)), .oe_handle").remove();
+ $clone.find(":not(.glyphicon)").css({position: 'absolute', top: 0, left: 0});
+ $clone.appendTo("body").removeClass("hidden");
+ return $clone;
+ },
+ start: _.bind(self._drag_and_drop_start, self),
+ stop: _.bind(self._drag_and_drop_stop, self)
+ });
+ },
+ _drag_and_drop_after_insert_dropzone: function (){},
+ _drag_and_drop_active_drop_zone: function ($zones){
+ var self = this;
+ $zones.droppable({
+ over: function(){
+ $(".oe_drop_zone.hide").removeClass("hide");
+ $(this).addClass("hide").first().after(self.$target);
+ self.dropped = true;
+ },
+ out: function(){
+ $(this).removeClass("hide");
+ self.$target.detach();
+ self.dropped = false;
+ },
+ });
+ },
+ _drag_and_drop_start: function (){
+ var self = this;
+ self.BuildingBlock.hide();
+ self.BuildingBlock.editor_busy = true;
+ self.size = {
+ width: self.$target.width(),
+ height: self.$target.height()
+ };
+ self.$target.after("
");
+ self.$target.detach();
+ self.$overlay.addClass("hidden");
+
+ self.BuildingBlock.activate_insertion_zones({
+ siblings: self.selector_siblings,
+ children: self.selector_children,
+ vertical_children: self.selector_vertical_children,
+ });
+
+ $("body").addClass('move-important');
+
+ self._drag_and_drop_after_insert_dropzone();
+ self._drag_and_drop_active_drop_zone($('.oe_drop_zone'));
+ },
+ _drag_and_drop_stop: function (){
+ var self = this;
+ if (!self.dropped) {
+ $(".oe_drop_clone").after(self.$target);
+ }
+ self.$overlay.removeClass("hidden");
+ $("body").removeClass('move-important');
+ $('.oe_drop_zone').droppable('destroy').remove();
+ $(".oe_drop_clone, .oe_drop_to_remove").remove();
+ self.BuildingBlock.editor_busy = false;
+ self.get_parent_block();
+ setTimeout(function () {self.BuildingBlock.create_overlay(self.$target);},0);
+ },
+
+ load_style_options: function () {
+ var self = this;
+ var $styles = this.$overlay.find('.oe_options');
+ var $ul = $styles.find('ul:first');
+ this.styles = {};
+ this.selector_siblings = [];
+ this.selector_children = [];
+ this.selector_vertical_children = [];
+ _.each(website.snippet.templateOptions, function (val) {
+ if (!self.$target.is(val.selector)) {
+ return;
+ }
+ if (val['selector-siblings']) self.selector_siblings.push(val['selector-siblings']);
+ if (val['selector-children']) self.selector_children.push(val['selector-children']);
+ if (val['selector-vertical-children']) self.selector_vertical_children.push(val['selector-vertical-children']);
+
+ var style = val['snippet-option-id'];
+ var Editor = website.snippet.options[style] || website.snippet.Option;
+ var editor = self.styles[style] = new Editor(self.BuildingBlock, self, self.$target, style);
+ $ul.append(editor.$el.addClass("snippet-style-" + style));
+ });
+ this.selector_siblings = this.selector_siblings.join(",");
+ if (this.selector_siblings === "")
+ this.selector_siblings = false;
+ this.selector_children = this.selector_children.join(",");
+ if (this.selector_children === "")
+ this.selector_children = false;
+ this.selector_vertical_children = this.selector_vertical_children.join(",");
+ if (this.selector_vertical_children === "")
+ this.selector_vertical_children = false;
+
+
+ if ($ul.find("li").length) {
+ $styles.removeClass("hidden");
+ }
+ this.$overlay.find('[data-toggle="dropdown"]').dropdown();
+ },
+
+ get_parent_block: function () {
+ var self = this;
+ var $button = this.$overlay.find('.oe_snippet_parent');
+ var $parent = this.$target.parents(website.snippet.globalSelector).first();
+ if ($parent.length) {
+ $button.removeClass("hidden");
+ $button.off("click").on('click', function (event) {
+ event.preventDefault();
+ setTimeout(function () {
+ self.BuildingBlock.make_active($parent);
+ }, 0);
+ });
+ } else {
+ $button.addClass("hidden");
+ }
+ },
+
+ /*
+ * start
+ * This method is called after init and _readXMLData
+ */
+ start: function () {
+ var self = this;
+ this.$overlay.on('click', '.oe_snippet_clone', _.bind(this.on_clone, this));
+ this.$overlay.on('click', '.oe_snippet_remove', _.bind(this.on_remove, this));
+ this._drag_and_drop();
+ },
+
+ on_clone: function () {
+ var $clone = this.$target.clone(false);
+ this.$target.after($clone);
+ for (var i in this.styles){
+ this.styles[i].on_clone($clone);
+ }
+ return false;
+ },
+
+ on_remove: function () {
+ this.onBlur();
+ var index = _.indexOf(this.BuildingBlock.snippets, this.$target.get(0));
+ for (var i in this.styles){
+ this.styles[i].on_remove();
+ }
+ delete this.BuildingBlock.snippets[index];
+ this.$target.remove();
+ this.$overlay.remove();
+ return false;
+ },
+
+ /*
+ * drop_and_build_snippet
+ * This method is called just after that a thumbnail is drag and dropped into a drop zone
+ * (after the insertion of this.$body, if this.$body exists)
+ */
+ drop_and_build_snippet: function ($target) {
+ for (var i in this.styles){
+ this.styles[i].drop_and_build_snippet($target);
+ }
+ },
+
+ /* onFocus
+ * This method is called when the user click inside the snippet in the dom
+ */
+ onFocus : function () {
+ this.$overlay.addClass('oe_active');
+ for (var i in this.styles){
+ this.styles[i].onFocus();
+ }
+ },
+
+ /* onFocus
+ * This method is called when the user click outside the snippet in the dom, after a focus
+ */
+ onBlur : function () {
+ for (var i in this.styles){
+ this.styles[i].onBlur();
+ }
+ this.$overlay.removeClass('oe_active');
+ },
+
+ /* clean_for_save
+ * function called just before save vue
+ */
+ clean_for_save: function () {
+ for (var i in this.styles){
+ this.styles[i].clean_for_save();
+ }
+ this.$target.removeAttr('contentEditable')
+ .find('*').removeAttr('contentEditable');
+ this.$target.removeAttr('attributeEditable')
+ .find('*').removeAttr('attributeEditable');
+ },
+ });
})();
diff --git a/addons/website/static/src/js/website.tour.banner.js b/addons/website/static/src/js/website.tour.banner.js
index 40730e5dc09..9c8afcd61e5 100644
--- a/addons/website/static/src/js/website.tour.banner.js
+++ b/addons/website/static/src/js/website.tour.banner.js
@@ -35,11 +35,11 @@
element: 'button[data-action=snippet]',
placement: 'bottom',
title: _t("Insert building blocks"),
- content: _t("To add content in a page, you can insert building blocks."),
+ content: _t("Click here to insert blocks of centent in the page."),
popover: { fixed: true },
},
{
- snippet: 'carousel',
+ 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."),
@@ -47,14 +47,14 @@
},
{
waitFor: '.oe_overlay_options .oe_options:visible',
- element: '#wrap [data-snippet-id=carousel]:first .carousel-caption > div',
+ element: '#wrap .carousel:first .carousel-caption > div',
placement: 'top',
title: _t("Customize banner's text"),
content: _t("Click in the text and start editing it."),
popover: { next: _t("Continue") },
},
{
- element: '.oe_overlay_options .oe_options',
+ 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."),
@@ -69,14 +69,7 @@
popover: { fixed: true },
},
{
- element: 'a[href="#snippet_feature"]',
- placement: 'bottom',
- title: _t("Feature blocks list"),
- content: _t("Click on 'Features' to see the feature blocks list."),
- popover: { fixed: true },
- },
- {
- snippet: 'features',
+ snippet: '#snippet_structure .oe_snippet:eq(6)',
placement: 'bottom',
title: _t("Drag & Drop This Block"),
content: _t("Drag the
'Features' block and drop it below the banner."),
@@ -92,8 +85,8 @@
},
{
waitFor: 'button[data-action=edit]:visible',
- title: _("Good Job!"),
- content: _("Well done, you created your homepage."),
+ title: _t("Good Job!"),
+ content: _t("Well done, you created your homepage."),
popover: { next: _t("Continue") },
},
{
@@ -108,13 +101,13 @@
element: '.modal:has(#mobile-viewport) button[data-dismiss=modal]',
placement: 'right',
title: _t("Check Mobile Preview"),
- content: _t("Scroll in the mobile preview to test the rendering. Once it's ok, close this dialog."),
+ content: _t("Scroll to check rendering and then close the mobile preview."),
popover: { next: _t("Continue") },
},
{
waitNot: '.modal',
element: '#content-menu-button',
- placement: 'bottom',
+ placement: 'left',
title: _t("Add new pages and menus"),
content: _t("The 'Content' menu allows you to add pages or add the top menu."),
popover: { next: _t("Close Tutorial") },
diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js
index 2416cb511f1..61b8f851339 100644
--- a/addons/website/static/src/js/website.tour.js
+++ b/addons/website/static/src/js/website.tour.js
@@ -3,9 +3,22 @@
var website = openerp.website;
+// don't need template to use bootstrap Tour in automatic mode
if (typeof QWeb2 !== "undefined")
website.add_template_file('/website/static/src/xml/website.tour.xml');
+// don't need to use bootstrap Tour to launch an automatic tour
+function bootstrap_tour_stub () {
+ if (typeof Tour === "undefined") {
+ window.Tour = function Tour() {};
+ Tour.prototype.addSteps = function () {};
+ Tour.prototype.end = function () {};
+ Tour.prototype.goto = function () {};
+ }
+}
+
+
+
if (website.EditorBar)
website.EditorBar.include({
tours: [],
@@ -175,6 +188,9 @@ website.Tour = openerp.Class.extend({
},
registerTour: function () {
+ if (this.automatic) {
+ bootstrap_tour_stub();
+ }
this.tour = new Tour({
name: this.id,
storage: this.tourStorage,
@@ -205,7 +221,7 @@ website.Tour = openerp.Class.extend({
if (!step.element) step.orphan = true;
if (step.snippet) {
- step.element = '#oe_snippets div.oe_snippet[data-snippet-id="'+step.snippet+'"] .oe_snippet_thumbnail';
+ step.element = '#oe_snippets '+step.snippet+' .oe_snippet_thumbnail';
}
}
@@ -377,7 +393,7 @@ website.Tour = openerp.Class.extend({
if (step.snippet) {
- var selector = '#oe_snippets div.oe_snippet[data-snippet-id="'+step.snippet+'"] .oe_snippet_thumbnail';
+ var selector = '#oe_snippets '+step.snippet+' .oe_snippet_thumbnail';
self.autoDragAndDropSnippet(selector);
} else if (step.element.match(/#oe_snippets .* \.oe_snippet_thumbnail/)) {
diff --git a/addons/website/static/src/js/website.tour.test.admin.js b/addons/website/static/src/js/website.tour.test.admin.js
deleted file mode 100644
index 787f05beb23..00000000000
--- a/addons/website/static/src/js/website.tour.test.admin.js
+++ /dev/null
@@ -1,106 +0,0 @@
-(function () {
- 'use strict';
-
- var website = openerp.website;
-
- website.Tour.LoginEdit = website.Tour.extend({
- id: 'login_edit',
- name: "Try to log as admin and check editor",
- path: '/',
- init: function () {
- var self = this;
- self.steps = [
- {
- title: "click login",
- element: '#top_menu a[href*="/web/login"]',
- },
- {
- title: "insert login",
- element: '.oe_login_form input[name="login"]',
- sampleText: "admin",
- },
- {
- title: "insert password",
- waitFor: '.oe_login_form input[name="login"][value!=""]',
- element: '.oe_login_form input[name="password"]',
- sampleText: "admin",
- },
- {
- title: "select 2 Standard tickets",
- waitFor: '.oe_login_form input[name="password"][value!=""]',
- element: '.oe_login_form button',
- },
- {
- title: "go back to website from backend",
- element: 'a[data-action-model="ir.actions.act_url"]:contains("Website")',
- },
- {
- title: 'try to edit',
- waitNot: '#wrap .carousel',
- element: 'button[data-action=edit]:visible',
- },
- {
- title: 'check edit mode',
- waitFor: 'button[data-action=save]:visible',
- },
- {
- title: 'check branding',
- waitFor: '#wrap[data-oe-model="ir.ui.view"]',
- },
- {
- title: 'check rte',
- waitFor: '#oe_rte_toolbar',
- },
- {
- title: 'check insert block button',
- element: '[data-action="snippet"]:visible',
- },
- {
- title: 'add snippets',
- snippet: 'carousel',
- },
- {
- title: 'try to save',
- waitFor: '.oe_overlay_options .oe_options:visible',
- element: 'button[data-action=save]:visible',
- },
- {
- title: 'check saved',
- waitFor: '#wrap div.carousel',
- element: 'button[data-action=edit]:visible',
- },
- {
- title: 'try to re-edit',
- waitFor: 'button[data-action=save]:visible',
- element: '#wrap .carousel',
- },
- {
- title: 'remove snippet',
- element: '.oe_snippet_remove',
- },
- {
- title: 'try to re-save',
- waitNot: '#wrap .carousel',
- element: 'button[data-action=save]:visible',
- },
- {
- title: "click admin",
- waitFor: 'button[data-action=edit]:visible',
- element: 'a:contains("Administrator")',
- },
- {
- title: "click logout",
- element: '#top_menu a[href*="/logout"]',
- },
- {
- title: "check logout",
- waitFor: '#top_menu a[href*="/web/login"]',
- },
- ];
- return this._super();
- },
- });
- // for test without editor bar
- website.Tour.add(website.Tour.LoginEdit);
-
-}());
diff --git a/addons/website/static/src/js/website.tour.test.js b/addons/website/static/src/js/website.tour.test.js
deleted file mode 100644
index 3e85ce20dae..00000000000
--- a/addons/website/static/src/js/website.tour.test.js
+++ /dev/null
@@ -1,34 +0,0 @@
-(function () {
-
-function LoadScript(src) {
- xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if(xmlHttp.readyState == 4) {
- if (xmlHttp.status == 200 || xmlHttp.status == 304) {
- new Function(xmlHttp.responseText)();
- } else {
- throw new Error("Can't load JavaScript.\nhref: " + window.location.href + "\nsrc: " + src);
- }
- }
- };
- xmlHttp.open("GET", src, false);
- xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xmlHttp.send(null);
-}
-
-if (typeof jQuery === "undefined")
- LoadScript("/web/static/lib/jquery/jquery.js");
-if (typeof _ === "undefined")
- LoadScript("/web/static/lib/underscore/underscore.js");
-if (typeof openerp === "undefined") {
- LoadScript("/web/static/lib/qweb/qweb2.js");
- LoadScript("/web/static/src/js/openerpframework.js");
-}
-if (typeof openerp === "undefined" || !openerp.website || !openerp.website.add_template_file)
- LoadScript("/website/static/src/js/website.js");
-if (typeof Tour === "undefined")
- LoadScript("/website/static/lib/bootstrap-tour/bootstrap-tour.js");
-if (typeof openerp === "undefined" || !openerp.website.Tour)
- LoadScript("/website/static/src/js/website.tour.js");
-
-})();
\ No newline at end of file
diff --git a/addons/website/static/src/js/website.translator.js b/addons/website/static/src/js/website.translator.js
index 399e5e731b2..44e2117a7f0 100644
--- a/addons/website/static/src/js/website.translator.js
+++ b/addons/website/static/src/js/website.translator.js
@@ -65,6 +65,7 @@
},
processTranslatableNodes: function () {
var self = this;
+ var source_attr = 'data-oe-source-id';
var $editables = $('[data-oe-model="ir.ui.view"]')
.not('link, script')
.not('.oe_snippets,.oe_snippet, .oe_snippet *')
@@ -72,7 +73,8 @@
$editables.each(function () {
var $node = $(this);
- var view_id = $node.attr('data-oe-source-id') || $node.attr('data-oe-id');
+ var source_id = $node.parents('[' + source_attr + ']:first').attr(source_attr)|0;
+ var view_id = $node.attr('data-oe-source-id') || source_id || $node.attr('data-oe-id');
self.transNode(this, view_id|0);
});
$('.oe_translatable_text').on('paste', function () {
diff --git a/addons/website/static/src/xml/website.editor.xml b/addons/website/static/src/xml/website.editor.xml
index 1010ec05127..6edf553b7cb 100644
--- a/addons/website/static/src/xml/website.editor.xml
+++ b/addons/website/static/src/xml/website.editor.xml
@@ -6,7 +6,7 @@
or
-
Discard
+
Discard
@@ -97,7 +97,7 @@
target="fileframe"
class="col-sm-8">
-
+
diff --git a/addons/website/static/src/xml/website.snippets.xml b/addons/website/static/src/xml/website.snippets.xml
index ae109139e3c..c5cf94d4791 100644
--- a/addons/website/static/src/xml/website.snippets.xml
+++ b/addons/website/static/src/xml/website.snippets.xml
@@ -22,7 +22,7 @@
-
+
@@ -45,13 +55,6 @@
diff --git a/addons/website/tests/test_converter.py b/addons/website/tests/test_converter.py
index d31df8e6956..ca72a361ac2 100644
--- a/addons/website/tests/test_converter.py
+++ b/addons/website/tests/test_converter.py
@@ -135,7 +135,7 @@ class TestConvertBack(common.TransactionCase):
rendered = self.registry('website.qweb').render_tag_field(
e, {'field': field_value}, '', ir_qweb.QWebContext(self.cr, self.uid, {
'record': record,
- }))
+ }, context={'inherit_branding': True}))
element = html.fromstring(
rendered, parser=html.HTMLParser(encoding='utf-8'))
@@ -216,7 +216,7 @@ class TestConvertBack(common.TransactionCase):
rendered = self.registry('website.qweb').render_tag_field(
e, {'field': field_value}, '', ir_qweb.QWebContext(self.cr, self.uid, {
'record': record,
- }))
+ }, context={'inherit_branding': True}))
element = html.fromstring(rendered, parser=html.HTMLParser(encoding='utf-8'))
# emulate edition
diff --git a/addons/website/tests/test_requests.py b/addons/website/tests/test_requests.py
index 9fb29b63c75..2a22ae04445 100644
--- a/addons/website/tests/test_requests.py
+++ b/addons/website/tests/test_requests.py
@@ -121,6 +121,6 @@ class URL(object):
def load_tests(loader, base, _):
base.addTest(CrawlSuite())
- base.addTest(CrawlSuite('admin', tools.config['admin_passwd']))
+ base.addTest(CrawlSuite('admin', 'admin'))
base.addTest(CrawlSuite('demo', 'demo'))
return base
diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py
index c9dd80ff885..54cd8a73a67 100644
--- a/addons/website/tests/test_ui.py
+++ b/addons/website/tests/test_ui.py
@@ -8,6 +8,6 @@ class TestUi(openerp.tests.HttpCase):
self.phantom_js("/", "console.log('ok')", "openerp.website.editor", login='admin')
def test_04_admin_tour_banner(self):
- self.phantom_js("/", "openerp.website.Tour.run_test('banner')", "openerp.website.Tour", login='admin')
+ self.phantom_js("/", "openerp.website.Tour.run_test('banner')", "openerp.website.Tour.tours.banner", login='admin')
# vim:et:
diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml
index eb32feef194..55bd7679b66 100644
--- a/addons/website/views/snippets.xml
+++ b/addons/website/views/snippets.xml
@@ -13,14 +13,7 @@
-
-
-
- Add Slide
-
-
- Remove Slide
-
+
Banner
@@ -51,7 +44,7 @@
-
+
Text-Image
@@ -79,7 +72,7 @@
-
+
Image-Text
@@ -107,7 +100,7 @@
-
+
Big Message
@@ -128,7 +121,7 @@
-
+
Text Block
@@ -166,7 +159,7 @@
-
+
Title
@@ -183,7 +176,7 @@
-
+
Features
@@ -214,7 +207,7 @@
-
+
Big Picture
@@ -246,7 +239,7 @@
-
+
Three Columns
@@ -291,7 +284,7 @@
-
+
Well
@@ -303,7 +296,7 @@
-
+
Quote
@@ -318,7 +311,7 @@
-
+
Panel
@@ -335,7 +328,7 @@
-
+
Separator
@@ -343,11 +336,29 @@
+
+
+
+

+
Share
+
+
+
+
-
+
Portfolio
@@ -380,7 +391,7 @@
-
+
Image Gallery
@@ -422,7 +433,7 @@
-
+
Comparisons
@@ -528,7 +539,7 @@
-
+
Button
@@ -545,7 +556,7 @@
-
+
FAQ
@@ -592,7 +603,7 @@
-
+
References
@@ -609,7 +620,7 @@
-
+
Write a quote here from one of your customers. Quotes are a
great way to build confidence in your products or services.
@@ -618,7 +629,7 @@
-
+
OpenERP provides essential platform for our project management.
Things are better organized and more visible with it.
@@ -646,14 +657,7 @@
-
-
-
- Add Slide
-
-
- Remove Slide
-
+
Quotes Slider
@@ -706,7 +710,7 @@
-
+
Feature Grid
@@ -766,22 +770,11 @@
-
+
Parallax
-
-
+
Parallax Slider
-
-
+
-
-
+
-
-
-

-
Add Column
-
-
-

-
Feature
-
- Delete the above image or replace it with a picture
- that illustrates your message. Click on the picture to
- change it's rounded corner style.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/addons/website/views/themes.xml b/addons/website/views/themes.xml
index f56ab2b5dd7..82f5105adcd 100644
--- a/addons/website/views/themes.xml
+++ b/addons/website/views/themes.xml
@@ -206,6 +206,7 @@
+
@@ -218,48 +219,56 @@
+
+
+
+
+
+
+
+
@@ -272,6 +281,7 @@
+
diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml
index 580957b81d6..4b4cca1a19a 100644
--- a/addons/website/views/website_templates.xml
+++ b/addons/website/views/website_templates.xml
@@ -364,7 +364,7 @@
- Edit
diff --git a/addons/website_blog/static/src/js/website.tour.blog.js b/addons/website_blog/static/src/js/website.tour.blog.js
index e76e793dfda..3470e2e383b 100644
--- a/addons/website_blog/static/src/js/website.tour.blog.js
+++ b/addons/website_blog/static/src/js/website.tour.blog.js
@@ -65,7 +65,7 @@
popover: { fixed: true },
},
{
- snippet: 'image-text',
+ snippet: '#snippet_structure .oe_snippet:eq(2)',
placement: 'bottom',
title: _t("Drag & Drop a Block"),
content: _t("Drag this block and drop it in your page."),
@@ -79,7 +79,7 @@
popover: { fixed: true },
},
{
- snippet: 'text-block',
+ snippet: '#snippet_structure .oe_snippet:eq(4)',
placement: 'bottom',
title: _t("Drag & Drop a block"),
content: _t("Drag this block and drop it below the image block."),
diff --git a/addons/website_blog/views/website_blog_templates.xml b/addons/website_blog/views/website_blog_templates.xml
index 203dcc3bb71..179b1b49ff0 100644
--- a/addons/website_blog/views/website_blog_templates.xml
+++ b/addons/website_blog/views/website_blog_templates.xml
@@ -155,7 +155,19 @@
-
+
+
+
+
+
+
+ Duplicate
+
+
+
+
@@ -167,18 +179,6 @@
-
diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py
index af7f77d080f..eb38e2dbe55 100644
--- a/addons/website_event/controllers/main.py
+++ b/addons/website_event/controllers/main.py
@@ -187,7 +187,7 @@ class website_event(http.Controller):
}
return request.website.render("website_event.event_description_full", values)
- @http.route('/event/add_event/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
+ @http.route('/event/add_event', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def add_event(self, event_name="New Event", **kwargs):
return self._add_event(event_name, request.context, **kwargs)
diff --git a/addons/website_event/static/src/js/website.tour.event.js b/addons/website_event/static/src/js/website.tour.event.js
index a9e40a5f65b..ef013398acb 100644
--- a/addons/website_event/static/src/js/website.tour.event.js
+++ b/addons/website_event/static/src/js/website.tour.event.js
@@ -65,7 +65,7 @@
popover: { fixed: true },
},
{
- snippet: 'image-text',
+ snippet: '#snippet_structure .oe_snippet:eq(2)',
placement: 'bottom',
title: _t("Drag & Drop a block"),
content: _t("Drag the 'Image-Text' block and drop it in your page."),
@@ -80,7 +80,7 @@
popover: { fixed: true },
},
{
- snippet: 'text-block',
+ snippet: '#snippet_structure .oe_snippet:eq(4)',
placement: 'bottom',
title: _t("Drag & Drop a block"),
content: _t("Drag the 'Text Block' in your event page."),
diff --git a/addons/website_event/views/website_event.xml b/addons/website_event/views/website_event.xml
index e490b1a0687..20d3499cf4a 100644
--- a/addons/website_event/views/website_event.xml
+++ b/addons/website_event/views/website_event.xml
@@ -189,6 +189,11 @@
+
+
+
+
+
diff --git a/addons/website_mail/__openerp__.py b/addons/website_mail/__openerp__.py
index 74fe86c6193..ec10f2268ca 100644
--- a/addons/website_mail/__openerp__.py
+++ b/addons/website_mail/__openerp__.py
@@ -32,14 +32,9 @@
'views/website_mail.xml',
'views/website_email_designer.xml',
'views/email_template_view.xml',
+ 'data/mail_groups.xml',
'security/website_mail.xml',
],
- 'css': [
- 'static/src/css/website_mail.css',
- ],
- 'js': [
- 'static/src/js/website_mail.js',
- ],
'qweb': [
'static/src/xml/website_mail.xml'
],
diff --git a/addons/website_mail/controllers/main.py b/addons/website_mail/controllers/main.py
index f700fa7dc67..a6b400ec4a1 100644
--- a/addons/website_mail/controllers/main.py
+++ b/addons/website_mail/controllers/main.py
@@ -26,33 +26,67 @@ from openerp.addons.web.http import request
class WebsiteMail(http.Controller):
- def _find_or_create_partner(self, email, context=None):
- # TDE TODO: FIXME: use mail_thread method
+ @http.route(['/website_mail/follow'], type='json', auth="public", website=True)
+ def website_message_subscribe(self, id=0, object=None, message_is_follower="on", email=False, **post):
+ cr, uid, context = request.cr, request.uid, request.context
+
partner_obj = request.registry['res.partner']
user_obj = request.registry['res.users']
- partner_ids = []
- if email and email != u'false': # post contains stringified booleans
- partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)], context=request.context)
- if not partner_ids:
- partner_ids = [partner_obj.name_create(request.cr, SUPERUSER_ID, email, request.context)[0]]
- else:
- partner_ids = [user_obj.browse(request.cr, request.uid, request.uid, request.context).partner_id.id]
- return partner_ids
+ website = request.registry['website']
- @http.route(['/website_mail/follow/'], type='json', auth="public", website=True)
- def website_message_subscribe(self, id=0, object=None, message_is_follower="on", email=False, **post):
_id = int(id)
_message_is_follower = message_is_follower == 'on'
_object = request.registry[object]
- partner_ids = self._find_or_create_partner(email, request.context)
- if _message_is_follower:
- _object.check_access_rule(request.cr, request.uid, [_id], 'read', request.context)
- _object.message_unsubscribe(request.cr, SUPERUSER_ID, [_id], partner_ids, context=request.context)
+ # search partner_id
+ public_id = website.get_public_user(cr, uid, context)
+ if uid != public_id:
+ partner_ids = [user_obj.browse(cr, uid, uid, context).partner_id.id]
else:
- _object.check_access_rule(request.cr, request.uid, [_id], 'read', request.context)
- _object.message_subscribe(request.cr, SUPERUSER_ID, [_id], partner_ids, context=request.context)
- obj = _object.browse(request.cr, request.uid, _id)
- follower_ids = [p.id for p in obj.message_follower_ids]
+ # mail_thread method
+ partner_ids = _object._find_partner_from_emails(
+ cr, SUPERUSER_ID, _id, [email], context=context, check_followers=True)
+ if not partner_ids or not partner_ids[0]:
+ partner_ids = [partner_obj.create(cr, SUPERUSER_ID, {'name': email, 'email': email}, context=context)]
+
+ # add or remove follower
+ if _message_is_follower:
+ _object.check_access_rule(cr, uid, [_id], 'read', context)
+ _object.message_unsubscribe(cr, SUPERUSER_ID, [_id], partner_ids, context=context)
+ return False
+ else:
+ _object.check_access_rule(cr, uid, [_id], 'read', context)
+ # add partner to session
+ request.session['partner_id'] = partner_ids[0]
+ _object.message_subscribe(cr, SUPERUSER_ID, [_id], partner_ids, context=context)
+ return True
+
+ @http.route(['/website_mail/is_follower'], type='json', auth="public", website=True)
+ def call(self, model, id, **post):
+ cr, uid, context = request.cr, request.uid, request.context
+
+ partner_obj = request.registry.get('res.partner')
+ users_obj = request.registry.get('res.users')
+ obj = request.registry.get(model)
+ website = request.registry['website']
+
+ partner_id = None
+ public_id = website.get_public_user(cr, uid, context)
+ if uid != public_id:
+ partner_id = users_obj.browse(cr, SUPERUSER_ID, uid, context).partner_id
+ elif request.session.get('partner_id'):
+ partner_id = partner_obj.browse(cr, SUPERUSER_ID, request.session.get('partner_id'), context)
+
+ email = ""
+ is_follower = False
+ if partner_id:
+ email = partner_id and partner_id.email
+ is_follower = partner_id.id in [
+ fol.id for fol in obj.browse(cr, SUPERUSER_ID, id, context).message_follower_ids]
+
+ return {
+ 'is_user': uid != public_id,
+ 'email': email,
+ 'is_follower': is_follower
+ }
- return partner_ids[0] in follower_ids and 1 or 0
diff --git a/addons/website_mail/data/mail_groups.xml b/addons/website_mail/data/mail_groups.xml
new file mode 100644
index 00000000000..0bc8d3e81d1
--- /dev/null
+++ b/addons/website_mail/data/mail_groups.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+ Newsletter
+ public
+ Public Newsletter.
+
+
+
+
diff --git a/addons/website_mail/models/mail_message.py b/addons/website_mail/models/mail_message.py
index c708d9c3e33..12c35f3e83f 100644
--- a/addons/website_mail/models/mail_message.py
+++ b/addons/website_mail/models/mail_message.py
@@ -54,7 +54,7 @@ class MailMessage(osv.Model):
args = ['&', ('website_published', '=', True)] + list(args)
return super(MailMessage, self)._search(cr, uid, args, offset=offset, limit=limit, order=order,
- context=context, count=False, access_rights_uid=access_rights_uid)
+ context=context, count=count, access_rights_uid=access_rights_uid)
def check_access_rule(self, cr, uid, ids, operation, context=None):
""" Add Access rules of mail.message for non-employee user:
diff --git a/addons/website_mail/static/src/js/website_mail.editor.js b/addons/website_mail/static/src/js/website_mail.editor.js
new file mode 100644
index 00000000000..7a26920682b
--- /dev/null
+++ b/addons/website_mail/static/src/js/website_mail.editor.js
@@ -0,0 +1,40 @@
+(function () {
+ 'use strict';
+
+ var website = openerp.website;
+ var _t = openerp._t;
+
+ website.snippet.options.subscribe = website.snippet.Option.extend({
+ on_prompt: function () {
+ var self = this;
+ return website.prompt({
+ id: "editor_new_subscribe_button",
+ window_title: _t("Add a Subscribe Button"),
+ select: _t("Mailing List"),
+ init: function (field) {
+ return website.session.model('mail.group')
+ .call('name_search', ['', [['public','=','public']]], { context: website.get_context() });
+ },
+ }).then(function (mail_group_id) {
+ self.$target.attr("data-id", mail_group_id);
+ });
+ },
+ drop_and_build_snippet: function() {
+ var self = this;
+ this._super();
+ this.on_prompt().fail(function () {
+ self.editor.on_remove();
+ });
+ },
+ start : function () {
+ var self = this;
+ this.$el.find(".js_mailing_list").on("click", _.bind(this.on_prompt, this));
+ this._super();
+ },
+ clean_for_save: function () {
+ this.$target.addClass("hidden");
+ },
+ });
+})();
+
+
diff --git a/addons/website_mail/static/src/js/website_mail.js b/addons/website_mail/static/src/js/website_mail.js
index 862e061afd6..bd34b526ddd 100644
--- a/addons/website_mail/static/src/js/website_mail.js
+++ b/addons/website_mail/static/src/js/website_mail.js
@@ -1,30 +1,59 @@
-$(document).ready(function () {
+(function () {
+ 'use strict';
- $(document).on('click', '.js_follow_btn, .js_unfollow_btn', function (ev) {
- ev.preventDefault();
+ var website = openerp.website;
- var self = this;
- var $data = $(this).parents("div.js_follow");
- var $email = $data.find(".js_follow_email");
+ website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
+ selector: ".js_follow",
+ start: function (editable_mode) {
+ var self = this;
- if ($email.length && !$email.val().match(/.+@.+/)) {
- return false;
- }
+ // set value and display button
+ self.$target.find("input").removeClass("hidden");
+ openerp.jsonRpc('/website_mail/is_follower', 'call', {
+ model: this.$target.data('object'),
+ id: +this.$target.data('id'),
+ }).always(function (data) {
+ self.$target.find('input.js_follow_email')
+ .val(data.email ? data.email : "")
+ .attr("disabled", data.is_follower && data.email.length ? "disabled" : false);
+ self.$target.attr("data-follow", data.is_follower ? 'on' : 'off');
+ self.$target.removeClass("hidden");
+ });
- var message_is_follower = $data.attr("data-follow") || "off";
- $data.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
-
- openerp.jsonRpc('/website_mail/follow', 'call', {
- 'id': $data.data('id'),
- 'object': $data.data('object'),
- 'message_is_follower': message_is_follower,
- 'email': $email.length ? $email.val() : false,
- }).then(function (result) {
- if (result) {
- $data.find(" > *").toggleClass("hidden");
+ // not if editable mode to allow designer to edit alert field
+ if (!editable_mode) {
+ $('.js_follow > .alert').addClass("hidden");
+ $('.js_follow > .input-group-btn.hidden').removeClass("hidden");
+ this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) {
+ event.preventDefault();
+ self.on_click();
+ });
}
- $data.attr("data-follow", result ? 'on' : 'off');
- });
- });
+ },
+ on_click: function () {
+ var self = this;
+ var $email = this.$target.find(".js_follow_email:visible");
-});
+ if ($email.length && !$email.val().match(/.+@.+/)) {
+ this.$target.addClass('has-error');
+ return false;
+ }
+ this.$target.removeClass('has-error');
+
+ openerp.jsonRpc('/website_mail/follow', 'call', {
+ 'id': +this.$target.data('id'),
+ 'object': this.$target.data('object'),
+ 'message_is_follower': this.$target.attr("data-follow") || "off",
+ 'email': $email.length ? $email.val() : false,
+ }).then(function (follow) {
+ if (follow) {
+ self.$target.find(".js_follow_email, .input-group-btn").addClass("hidden");
+ self.$target.find(".alert").removeClass("hidden");
+ }
+ self.$target.find('input.js_follow_email').attr("disabled", follow ? "disabled" : false);
+ self.$target.attr("data-follow", follow ? 'on' : 'off');
+ });
+ },
+ });
+})();
diff --git a/addons/website_mail/views/snippets.xml b/addons/website_mail/views/snippets.xml
index 35932f6f7c3..a930f2852a1 100644
--- a/addons/website_mail/views/snippets.xml
+++ b/addons/website_mail/views/snippets.xml
@@ -13,7 +13,7 @@
-
+
Text Block
@@ -63,7 +63,7 @@
-
+
Text-Image
@@ -104,7 +104,7 @@
-
+
Image-Text
@@ -145,7 +145,7 @@
-
+
Two Columns
@@ -185,7 +185,7 @@
-
+
Three Columns
@@ -236,7 +236,7 @@
-
+
Separator
@@ -262,7 +262,7 @@
-
+
Big Picture
@@ -298,7 +298,7 @@
-
+
Comparisons
@@ -389,7 +389,7 @@
-
+
Big Message
@@ -413,7 +413,7 @@
-
+
Button
@@ -478,18 +478,59 @@