2013-11-13 17:14:38 +00:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var website = openerp.website;
|
2014-02-06 14:52:36 +00:00
|
|
|
var _t = openerp._t;
|
2013-11-13 17:14:38 +00:00
|
|
|
website.add_template_file('/website_blog/static/src/xml/website_blog.xml');
|
2013-11-14 09:33:05 +00:00
|
|
|
|
|
|
|
website.EditorBar.include({
|
2014-01-16 18:05:35 +00:00
|
|
|
start: function() {
|
2014-01-21 12:39:12 +00:00
|
|
|
website.is_editable_button = website.is_editable_button || !!$("#wrap.js_blog").size();
|
2014-01-16 18:05:35 +00:00
|
|
|
var res = this._super();
|
|
|
|
this.$(".dropdown:has(.oe_content_menu)").removeClass("hidden");
|
|
|
|
return res;
|
|
|
|
},
|
2013-11-14 09:33:05 +00:00
|
|
|
events: _.extend({}, website.EditorBar.prototype.events, {
|
|
|
|
'click a[data-action=new_blog_post]': function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
website.prompt({
|
2014-02-06 14:52:36 +00:00
|
|
|
id: "editor_new_blog",
|
|
|
|
window_title: _t("New Blog Post"),
|
2013-11-14 21:28:56 +00:00
|
|
|
select: "Select Blog",
|
2013-11-14 09:33:05 +00:00
|
|
|
init: function (field) {
|
2014-01-24 16:22:51 +00:00
|
|
|
return website.session.model('blog.blog')
|
2013-11-14 09:33:05 +00:00
|
|
|
.call('name_search', [], { context: website.get_context() });
|
|
|
|
},
|
|
|
|
}).then(function (cat_id) {
|
2014-01-24 16:22:51 +00:00
|
|
|
document.location = '/blogpost/new?blog_id=' + cat_id;
|
2013-11-14 09:33:05 +00:00
|
|
|
});
|
2014-02-13 13:36:54 +00:00
|
|
|
},
|
2013-11-14 09:33:05 +00:00
|
|
|
}),
|
2014-02-13 13:36:54 +00:00
|
|
|
edit: function () {
|
2014-03-19 08:51:23 +00:00
|
|
|
$('.popover').remove();
|
2014-02-14 07:05:22 +00:00
|
|
|
this._super();
|
2014-03-19 13:39:34 +00:00
|
|
|
var vHeight = $(window).height();
|
2014-03-18 13:05:37 +00:00
|
|
|
$('body').on('click','#change_cover',_.bind(this.change_bg,{},vHeight));
|
|
|
|
$('body').on('click', '#clear_cover',_.bind(this.clean_bg,{},vHeight));
|
2014-02-13 13:36:54 +00:00
|
|
|
},
|
|
|
|
save : function() {
|
2014-03-24 05:59:38 +00:00
|
|
|
var res = this._super();
|
2014-04-02 14:02:00 +00:00
|
|
|
if ($('.cover').length) {
|
|
|
|
openerp.jsonRpc("/blogpost/change_background", 'call', {
|
2014-03-22 09:48:21 +00:00
|
|
|
'post_id' : $('#blog_post_name').attr('data-oe-id'),
|
2014-03-24 05:59:38 +00:00
|
|
|
'image' : $('.cover').css('background-image').replace(/url\(|\)|"|'/g,''),
|
2014-03-22 09:48:21 +00:00
|
|
|
});
|
|
|
|
}
|
2014-03-24 05:59:38 +00:00
|
|
|
return res;
|
2014-02-13 13:36:54 +00:00
|
|
|
},
|
2014-03-18 13:05:37 +00:00
|
|
|
clean_bg : function(vHeight) {
|
2014-04-01 07:25:04 +00:00
|
|
|
$('.js_fullheight').css({"background-image":'none', 'min-height': vHeight});
|
2014-02-24 05:15:02 +00:00
|
|
|
},
|
2014-03-18 13:05:37 +00:00
|
|
|
change_bg : function(vHeight) {
|
2014-02-14 07:05:22 +00:00
|
|
|
var self = this;
|
|
|
|
var editor = new website.editor.ImageDialog();
|
|
|
|
editor.on('start', self, function (o) {
|
2014-04-01 07:25:04 +00:00
|
|
|
o.url = $('.js_fullheight').length ? $('.js_fullheight').css('background-image').replace(/url\(|\)|"|'/g,'') : '';
|
2014-02-14 07:05:22 +00:00
|
|
|
});
|
|
|
|
editor.on('save', self, function (o) {
|
2014-04-01 07:25:04 +00:00
|
|
|
$('.js_fullheight').css({"background-image": o.url && o.url !== "" ? 'url(' + o.url + ')' : "", 'min-height': vHeight})
|
2014-02-14 07:05:22 +00:00
|
|
|
});
|
|
|
|
editor.appendTo('body');
|
|
|
|
},
|
2013-11-14 09:33:05 +00:00
|
|
|
});
|
2013-11-13 17:14:38 +00:00
|
|
|
})();
|