sidebar refactoring attachements broken

bzr revid: al@openerp.com-20120409131438-9nmd5192z2oahjt6
This commit is contained in:
Antony Lesuisse 2012-04-09 15:14:38 +02:00
parent 64974e24e6
commit b4157132e0
6 changed files with 81 additions and 108 deletions

View File

@ -602,7 +602,7 @@ $colour4: #8a89ba
&:hover
text-decoration: underline
// }}}
// Content Header {{{
// Content Header MIT {{{
.oe-view-manager-header
border-top: 1px solid #cacaca
border-bottom: 1px solid #cacaca
@ -647,7 +647,6 @@ $colour4: #8a89ba
height: 24px
line-height: 24px
padding: 0 8px
.button-group
display: inline-block
border: 1px solid #ababab

View File

@ -119,7 +119,7 @@ openerp.web.Dialog = openerp.web.Widget.extend({
open: function(options) {
// TODO fme: bind window on resize
if (this.template) {
this.$element.html(this.render());
this.$element.html(this.renderElement());
}
var o = this.get_options(options);
openerp.web.dialog(this.$element, o).dialog('open');

View File

@ -365,6 +365,9 @@ openerp.web.EventDispatcherMixin = _.extend({}, openerp.web.ParentedMixin, {
event.source.__edispatcherEvents.off(event.name, event.func, self);
});
this.__edispatcherRegisteredEvents = [];
if(!this.__edispatcherEvents) {
debugger;
}
this.__edispatcherEvents.off();
openerp.web.ParentedMixin.destroy.call(this);
}

View File

@ -1056,14 +1056,15 @@ openerp.web.form = {};
openerp.web.form.SidebarAttachments = openerp.web.OldWidget.extend({
init: function(parent, form_view) {
var $section = parent.add_section(_t('Attachments'), 'attachments');
this.$div = $('<div class="oe-sidebar-attachments"></div>');
$section.append(this.$div);
//var $section = parent.add_section(_t('Attachments'), 'attachments');
//this.$div = $('<div class="oe-sidebar-attachments"></div>');
//$section.append(this.$div);
this._super(parent, $section.attr('id'));
this._super(parent);
this.view = form_view;
},
do_update: function() {
return;
if (!this.view.datarecord.id) {
this.on_attachments_loaded([]);
} else {
@ -1077,12 +1078,14 @@ openerp.web.form.SidebarAttachments = openerp.web.OldWidget.extend({
}
},
on_attachments_loaded: function(attachments) {
return;
this.attachments = attachments;
this.$div.html(QWeb.render('FormView.sidebar.attachments', this));
this.$element.find('.oe-binary-file').change(this.on_attachment_changed);
this.$element.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
},
on_attachment_changed: function(e) {
return;
window[this.element_id + '_iframe'] = this.do_update;
var $e = $(e.target);
if ($e.val() != '') {
@ -1092,6 +1095,7 @@ openerp.web.form.SidebarAttachments = openerp.web.OldWidget.extend({
}
},
on_attachment_delete: function(e) {
return;
var self = this, $e = $(e.currentTarget);
var name = _.str.trim($e.parent().find('a.oe-sidebar-attachments-link').text());
if (confirm(_.str.sprintf(_t("Do you really want to delete the attachment %s?"), name))) {

View File

@ -719,52 +719,62 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
});
session.web.Sidebar = session.web.Widget.extend({
template: 'Sidebar',
init: function(parent) {
this._super(parent);
this.items = {};
this.sections = {};
},
start: function() {
var self = this;
this._super(this);
this.$element.find('.oe_dropdown_toggle').click(function() {
self.$element.find('.oe_dropdown_menu').toggle();
return false;
});
this.$element.on('click', '.oe_dropdown_menu li a', function() {
var f = self['on_menu_' + $(this).data('menu')];
f && f($(this));
self.$element.find('.oe_dropdown_menu').hide();
return false;
});
},
add_default_sections: function() {
var self = this;
var view = this.getParent();
var view_manager = view.getParent();
var action = view_manager.action;
if (this.session.uid === 1) {
this.add_section(_t('Customize'), 'customize');
this.add_items('customize', [{
label: _t("Translate"),
callback: view.on_sidebar_translate,
title: _t("Technical translation")
}]);
this.sections = [
{ 'name' : 'print', 'label' : _t('Print'), },
{ 'name' : 'files', 'label' : _t('Attachement'), },
{ 'name' : 'other', 'label' : _t('More'), }
];
this.items = {
'print' : [],
'files' : [],
'other' : [
{ label: _t("Import"), callback: view.on_sidebar_import },
{ label: _t("Export"), callback: view.on_sidebar_export }
]
}
this.add_section(_t('Other Options'), 'other');
this.add_items('other', [
{
label: _t("Import"),
callback: view.on_sidebar_import
}, {
label: _t("Export"),
callback: view.on_sidebar_export
if (this.session.uid === 1) {
var item = { label: _t("Translate"), callback: view.on_sidebar_translate, title: _t("Technical translation") };
this.items.other.push(item);
}
},
start: function() {
var self = this;
this._super(this);
this.redraw();
this.$element.on('click','.oe_dropdown_toggle',function(event) {
$(this).parent().find('ul').toggle();
return false;
});
this.$element.on('click','.oe_dropdown_menu li a', function(event) {
var section = $(this).data('section');
var index = $(this).data('index');
$(this).closest('ul').hide();
console.log('click item',section,index);
var item = self.items[section][index];
if (item.callback) {
item.callback.apply(self, [item]);
}
]);
if (item.action) {
self.on_item_action_clicked(item);
}
return false;
});
},
redraw: function() {
var self = this;
self.$element.html(QWeb.render('Sidebar', {widget: self}));
this.$element.find('ul').hide();
},
add_default_sections: function() {
var self = this;
},
add_section: function() {
var self = this;
},
add_toolbar: function(toolbar) {
var self = this;
@ -778,32 +788,15 @@ session.web.Sidebar = session.web.Widget.extend({
classname: 'oe_sidebar_' + type[0]
}
}
self.add_section(type[1], type[0]);
self.add_items(type[0], items);
}
});
},
add_section: function(name, code) {
if(!code) code = _.str.underscored(name);
var $section = this.sections[code];
if(!$section) {
var section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
$section = $(session.web.qweb.render("Sidebar.section", {
section_id: section_id,
name: name,
classname: 'oe_sidebar_' + code
}));
$section.appendTo(this.$element.find('div.sidebar-actions'));
this.sections[code] = $section;
}
return $section;
},
/**
* For each item added to the section:
*
* ``label``
* will be used as the item's name in the sidebar
* will be used as the item's name in the sidebar, can be html
*
* ``action``
* descriptor for the action which will be executed, ``action`` and
@ -825,34 +818,14 @@ session.web.Sidebar = session.web.Widget.extend({
* @param {Array<{label, action | callback[, classname][, title]}>} items
*/
add_items: function(section_code, items) {
var self = this,
$section = this.add_section(_.str.titleize(section_code.replace('_', ' ')), section_code),
section_id = $section.attr('id');
var self = this;
if (items) {
// generate unique id for items
for (var i = 0; i < items.length; i++) {
items[i].element_id = _.uniqueId(section_id + '_item_');
items[i].element_id = _.uniqueId(section_code + '_item_');
this.items[items[i].element_id] = items[i];
}
var $items = $(session.web.qweb.render("Sidebar.section.items", {items: items}));
$items.find('a.oe_sidebar_action_a').click(function() {
var item = self.items[$(this).attr('id')];
if (item.callback) {
item.callback.apply(self, [item]);
}
if (item.action) {
self.on_item_action_clicked(item);
}
return false;
});
var $ul = $section.find('ul');
if(!$ul.length) {
$ul = $('<ul class="oe_dropdown_menu"/>').appendTo($section);
}
$items.appendTo($ul);
this.redraw();
}
},
on_item_action_clicked: function(item) {
@ -860,11 +833,7 @@ session.web.Sidebar = session.web.Widget.extend({
self.getParent().sidebar_context().then(function (context) {
var ids = self.getParent().get_selected_ids();
if (ids.length == 0) {
//TODO: make prettier warning?
openerp.web.dialog($("<div />").text(_t("You must choose at least one record.")), {
title: _t("Warning"),
modal: true
});
openerp.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
return false;
}
var additional_context = _.extend({

View File

@ -493,23 +493,21 @@
</t>
<t t-name="Sidebar">
<div class="sidebar-content">
<div class="sidebar-actions">
</div>
<div class="oe_sidebar">
<t t-foreach="widget.sections" t-as="section">
<div class="oe_form_dropdown_section">
<button class="oe_dropdown_toggle"><t t-esc="section.label"/></button>
<ul class="oe_dropdown_menu">
<li t-foreach="widget.items[section.name]" t-as="item" t-att-class="item.classname">
<a class="oe_sidebar_action_a" t-att-title="item.title" href="#" t-att-data-section="section.name" t-att-data-index="item_index">
<t t-raw="item.label"/>
</a>
</li>
</ul>
</div>
</t>
</div>
</t>
<t t-name="Sidebar.section">
<div t-att-id="section_id" t-attf-class="#{classname} oe_form_dropdown_section ">
<button class="oe_dropdown_toggle"><t t-esc="name"/></button>
</div>
</t>
<t t-name="Sidebar.section.items">
<li t-foreach="items" t-as="item" t-att-class="item.classname">
<a class="oe_sidebar_action_a" t-att-id="item.element_id" t-att-title="item.title" href="#">
<t t-esc="item.label"/>
</a>
</li>
</t>
<t t-name="TreeView">
<select t-if="toolbar" style="width: 30%">