Add toolbar on Tab.Form

This commit is contained in:
Cédric Krier
2013-01-08 13:32:10 +01:00
parent 69a228ce85
commit ba5be4ecaf
3 changed files with 126 additions and 4 deletions
+3 -1
View File
@@ -43,7 +43,9 @@ this repository contains the full copyright notices and license terms. -->
'view_ids': [3],
'domain': [['parent', '=', null]]
});
$('#menu').html(form.el);
form.view_prm.done(function() {
jQuery('#menu').append(form.screen.el.detach());
});
});
});
</SCRIPT>
+16
View File
@@ -127,4 +127,20 @@
};
return prm.pipe(exec_action);
};
Sao.Action.evaluate = function(action, atype, record) {
action = jQuery.extend({}, action);
switch (atype) {
case 'print':
case 'action':
// TODO
break;
case 'relate':
// TODO
break;
default:
throw new Error('Action type ' + atype + ' is not supported');
}
return action;
};
}());
+107 -3
View File
@@ -5,7 +5,32 @@
Sao.Tab = Sao.class_(Object, {
init: function() {
}
this.buttons = {};
},
create_toolbar: function() {
var toolbar = jQuery('<div/>', {
'class': 'ui-widget-header ui-corner-all'
});
var add_button = function(tool) {
var click_func = function() {
this[tool[4]]();
};
var button = jQuery('<button/>').button({
id: tool[0],
text: tool[2],
icons: {
primary: tool[1]
},
label: tool[2]
})
.click(click_func.bind(this));
toolbar.append(button);
// TODO tooltip
this.buttons[tool[0]] = button;
};
this.toolbar_def.forEach(add_button.bind(this));
return toolbar;
}
});
Sao.Tab.counter = 0;
@@ -51,14 +76,93 @@
var el = jQuery('<div/>', {
'class': 'form'
});
// TODO title
var toolbar = this.create_toolbar();
el.append(toolbar);
this.el = el;
this.screen.load_next_view().done(function() {
el.html(screen.el);
this.view_prm = this.screen.load_next_view().done(function() {
el.append(screen.el);
}).done(function() {
screen.search_filter().done(function() {
screen.display();
});
});
},
// TODO translate labels
toolbar_def: [
['new', 'ui-icon-document', 'New', 'Create a new record', 'new_'],
['save', 'ui-icon-disk', 'Save', 'Save this record', 'save'],
['switch', 'ui-icon-arrow-4-diag', 'Switch', 'Switch view',
'switch'],
['reload', 'ui-icon-refresh', 'Reload', 'Reload', 'reload'],
['previous', 'ui-icon-arrowthick-1-w', 'Previous',
'Previous Record', 'previous'],
['next', 'ui-icon-arrowthick-1-e', 'Next', 'Next Record', 'next'],
['attach', 'ui-icon-pin-s', 'Attachment',
'Add an attachment to the record', 'attach']
],
create_toolbar: function() {
var toolbar = Sao.Tab.Form._super.create_toolbar.call(this);
var screen = this.screen;
var buttons = this.buttons;
var prm = screen.model.execute('view_toolbar_get', [],
screen.context);
prm.done(function(toolbars) {
// TODO translation
[
['action', 'ui-icon-gear', 'Action', 'Launch action'],
['relate', 'ui-icon-arrowreturn-1-e', 'Relate',
'Open related records'],
['print', 'ui-icon-print', 'Print', 'Print report']
].forEach(function(menu_action) {
var button = jQuery('<button/>').button({
id: menu_action[0],
text: menu_action[2],
icons: {
primary: menu_action[1],
secondary: 'ui-icon-triangle-1-s'
},
label: menu_action[2]
});
buttons[menu_action[0]] = button;
toolbar.append(button);
var menu = jQuery('<ul/>').menu({}).hide().css({
position: 'absolute'
});
button.click(function() {
menu.show().position({
my: 'left top',
at: 'left bottom',
of: button
});
jQuery(document).one('click', function() {
menu.hide();
});
return false;
});
toolbars[menu_action[0]].forEach(function(action) {
var item = jQuery('<li/>').append(
jQuery('<a/>').append(action.name));
menu.append(item);
item.click(function() {
var exec_action = jQuery.extend({}, action);
// TODO test save
exec_action = Sao.Action.evaluate(exec_action,
menu_action[0], screen.current_record);
var data = {
model: screen.model_name,
id: screen.get_id(),
ids: [screen.get_id()] // TODO ids selected
};
Sao.Action.exec_action(exec_action, data,
screen.context);
});
});
toolbar.append(menu);
});
});
return toolbar;
}
});
}());