Files
tryton/src/tab.js
T

1495 lines
60 KiB
JavaScript
Raw Normal View History

2012-11-29 11:32:58 +01:00
/* This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. */
2013-01-04 21:29:48 +01:00
(function() {
'use strict';
2012-11-29 11:32:58 +01:00
2013-01-04 21:29:48 +01:00
Sao.Tab = Sao.class_(Object, {
2018-09-24 14:40:27 +02:00
init: function(attributes) {
2013-11-25 12:18:32 +01:00
Sao.Tab.tabs.push(this);
2018-09-24 14:40:27 +02:00
this.attributes = jQuery.extend({}, attributes);
2013-01-08 13:32:10 +01:00
this.buttons = {};
2017-08-30 18:19:04 +02:00
this.menu_buttons = {};
2015-02-06 00:32:51 +01:00
this.id = 'tab-' + Sao.Tab.counter++;
2017-02-25 18:38:58 +01:00
this.name = '';
this.name_el = jQuery('<span/>');
2018-05-12 00:39:59 +02:00
this.view_prm = jQuery.when();
2013-01-08 13:32:10 +01:00
},
2017-08-30 18:19:04 +02:00
menu_def: function() {
return [
{
id: 'switch_',
2018-08-19 20:01:49 +02:00
icon: 'tryton-switch',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Switch'),
tooltip: Sao.i18n.gettext('Switch view'),
}, {
id: 'previous',
2018-08-19 20:01:49 +02:00
icon: 'tryton-back',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Previous'),
tooltip: Sao.i18n.gettext('Previous Record')
}, {
id: 'next',
2018-08-19 20:01:49 +02:00
icon: 'tryton-forward',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Next'),
tooltip: Sao.i18n.gettext('Next Record'),
}, {
id: 'search',
2018-08-19 20:01:49 +02:00
icon: 'tryton-search',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Search'),
}, null, {
id: 'new_',
2018-08-19 20:01:49 +02:00
icon: 'tryton-create',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('New'),
tooltip: Sao.i18n.gettext('Create a new record'),
}, {
id: 'save',
2018-08-19 20:01:49 +02:00
icon: 'tryton-save',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Save'),
tooltip: Sao.i18n.gettext('Save this record'),
}, {
id: 'reload',
2018-08-19 20:01:49 +02:00
icon: 'tryton-refresh',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Reload/Undo'),
tooltip: Sao.i18n.gettext('Reload'),
}, {
id: 'copy',
2018-08-19 20:01:49 +02:00
icon: 'tryton-copy',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Duplicate'),
}, {
id: 'delete_',
2018-08-19 20:01:49 +02:00
icon: 'tryton-delete',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Delete'),
}, null, {
id: 'logs',
2018-08-19 20:01:49 +02:00
icon: 'tryton-log',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('View Logs...'),
}, {
2017-10-20 14:55:55 +02:00
id: (this.screen &&
Sao.common.MODELHISTORY.contains(this.screen.model_name)) ?
2017-08-30 18:19:04 +02:00
'revision': null,
2018-08-19 20:01:49 +02:00
icon: 'tryton-history',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Show revisions...'),
}, null, {
id: 'attach',
2018-08-19 20:01:49 +02:00
icon: 'tryton-attach',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Attachment'),
tooltip: Sao.i18n.gettext('Add an attachment to the record'),
2018-09-02 10:44:38 +02:00
dropdown: true,
2017-08-30 18:19:04 +02:00
}, {
id: 'note',
2018-08-19 20:01:49 +02:00
icon: 'tryton-note',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Note'),
tooltip: Sao.i18n.gettext('Add a note to the record'),
}, {
id: 'action',
2018-08-19 20:01:49 +02:00
icon: 'tryton-launch',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Action'),
}, null, {
id: 'relate',
2018-08-19 20:01:49 +02:00
icon: 'tryton-link',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Relate'),
}, {
id: 'print',
2018-08-19 20:01:49 +02:00
icon: 'tryton-print',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Print'),
2020-09-17 17:18:02 +02:00
}, {
id: 'email',
icon: 'tryton-email',
label: Sao.i18n.gettext('E-Mail...'),
tooltip: Sao.i18n.gettext('Send an e-mail using the record'),
2017-08-30 18:19:04 +02:00
}, null, {
id: 'export',
2018-08-19 20:01:49 +02:00
icon: 'tryton-export',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Export'),
}, {
id: 'import',
2018-08-19 20:01:49 +02:00
icon: 'tryton-import',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Import'),
}, null, {
id: 'close',
2018-08-19 20:01:49 +02:00
icon: 'tryton-close',
2017-08-30 18:19:04 +02:00
label: Sao.i18n.gettext('Close Tab'),
},
];
},
2013-10-14 09:02:47 +00:00
create_tabcontent: function() {
this.el = jQuery('<div/>', {
2019-09-02 18:36:52 +02:00
'class': 'panel panel-default ' + this.class_,
2013-10-14 09:02:47 +00:00
});
2015-10-24 13:30:12 +02:00
var toolbar = this.create_toolbar().appendTo(this.el);
2016-12-27 18:17:05 +01:00
this.title = toolbar.find('.title');
2015-10-24 13:30:12 +02:00
2019-09-02 18:36:52 +02:00
this.content = jQuery('<div/>', {
'class': 'panel-body',
}).appendTo(this.el);
2016-09-19 22:21:09 +02:00
2015-10-15 10:33:37 +02:00
if (this.info_bar) {
this.el.append(this.info_bar.el);
}
2013-10-14 09:02:47 +00:00
},
2015-02-06 00:32:51 +01:00
set_menu: function(menu) {
2017-08-30 18:19:04 +02:00
var previous;
this.menu_def().forEach(function(item) {
var menuitem;
if (item) {
if (!this[item.id]) {
return;
}
menuitem = jQuery('<li/>', {
'role': 'presentation'
});
var link = jQuery('<a/>', {
2017-08-30 18:27:52 +02:00
'id': item.id,
2017-08-30 18:19:04 +02:00
'role': 'menuitem',
'href': '#',
'tabindex': -1
2020-06-05 19:12:53 +02:00
}).text(' ' + item.label).prepend(
Sao.common.ICONFACTORY.get_icon_img(item.icon, {
'aria-hidden': 'true',
})).appendTo(menuitem);
2017-08-30 18:19:04 +02:00
this.menu_buttons[item.id] = menuitem;
2018-05-29 10:30:32 +02:00
link.click(function(evt) {
evt.preventDefault();
2017-08-30 18:19:04 +02:00
this[item.id]();
2015-10-22 11:41:16 +02:00
}.bind(this));
2017-08-30 18:19:04 +02:00
} else if (!item && previous) {
menuitem = jQuery('<li/>', {
'role': 'separator',
2018-03-23 22:26:45 +01:00
'class': 'divider hidden-xs',
2017-08-30 18:19:04 +02:00
});
2015-10-22 11:41:16 +02:00
} else {
2017-08-30 18:19:04 +02:00
return;
2015-10-22 11:41:16 +02:00
}
2017-08-30 18:19:04 +02:00
previous = menuitem;
menuitem.appendTo(menu);
2013-10-14 09:02:47 +00:00
}.bind(this));
},
2013-01-08 13:32:10 +01:00
create_toolbar: function() {
2016-12-27 18:17:05 +01:00
var toolbar = jQuery('<nav/>', {
2019-09-02 18:36:52 +02:00
'class': 'toolbar panel-heading',
2016-12-27 18:17:05 +01:00
'role': 'toolbar'
}).append(jQuery('<div/>', {
2020-08-16 17:43:21 +02:00
'class': 'container-fluid navbar-inverse'
2016-12-27 18:17:05 +01:00
}).append(jQuery('<div/>', {
2018-08-30 16:09:18 +02:00
'class': 'dropdown navbar-header navbar-left flip'
2016-12-27 18:17:05 +01:00
}).append(jQuery('<a/>', {
'href': "#",
'class': "navbar-brand dropdown-toggle",
'data-toggle': 'dropdown',
'role': 'button',
'aria-expanded': false,
'aria-haspopup': true
}).append(jQuery('<span/>', {
'class': 'title'
})).append(jQuery('<span/>', {
'class': 'caret'
}))).append(jQuery('<ul/>', {
'class': 'dropdown-menu',
'role': 'menu'
2017-01-15 18:59:21 +01:00
})).append(jQuery('<button/>', {
'type': 'button',
'class': 'close visible-xs',
2017-01-15 18:59:21 +01:00
'aria-label': Sao.i18n.gettext('Close')
}).append(jQuery('<span/>', {
'aria-hidden': true
}).append('&times;')).click(function() {
this.close();
}.bind(this)))).append(jQuery('<div/>', {
2018-08-30 16:09:18 +02:00
'class': 'btn-toolbar navbar-right flip',
2016-12-27 18:17:05 +01:00
'role': 'toolbar'
})));
2015-02-06 00:32:51 +01:00
this.set_menu(toolbar.find('ul[role*="menu"]'));
2016-12-27 18:17:05 +01:00
var group;
2017-08-30 18:19:04 +02:00
var add_button = function(item) {
if (!item || !item.tooltip) {
2016-12-27 18:17:05 +01:00
group = null;
return;
}
2017-10-20 14:55:55 +02:00
if (!item.id || !this[item.id]) {
2017-08-30 18:19:04 +02:00
return;
}
2016-12-27 18:17:05 +01:00
if (!group) {
group = jQuery('<div/>', {
'class': 'btn-group',
'role': 'group'
}).appendTo(toolbar.find('.btn-toolbar'));
}
2018-09-02 10:44:38 +02:00
var attributes = {
2016-12-27 18:17:05 +01:00
'type': 'button',
'class': 'btn btn-default navbar-btn',
2017-08-30 18:19:04 +02:00
'title': item.label,
'id': item.id
2018-09-02 10:44:38 +02:00
};
if (item.dropdown) {
attributes['class'] += ' dropdown-toggle';
attributes['data-toggle'] = 'dropdown';
attributes['aria-expanded'] = false;
attributes['aria-haspopup'] = true;
}
var button = jQuery('<button/>', attributes)
.append(Sao.common.ICONFACTORY.get_icon_img(item.icon, {
'aria-hidden': 'true',
}));
this.buttons[item.id] = button;
if (item.dropdown) {
var dropdown = jQuery('<div/>', {
'class': 'btn-group dropdown',
'role': 'group',
}).append(button.append(jQuery('<span/>', {
'class': 'caret',
}))).append(jQuery('<ul/>', {
'class': 'dropdown-menu',
'role': 'menu',
'aria-labelledby': item.id,
})).appendTo(group);
} else {
button.appendTo(group);
}
2018-03-27 10:49:21 +02:00
this.buttons[item.id].click(item, function(event) {
var item = event.data;
var button = this.buttons[item.id];
button.prop('disabled', true);
(this[item.id](this) || jQuery.when())
.always(function() {
button.prop('disabled', false);
});
}.bind(this));
2013-01-08 13:32:10 +01:00
};
2017-08-30 18:19:04 +02:00
this.menu_def().forEach(add_button.bind(this));
this.status_label = jQuery('<span/>', {
'class': 'badge',
}).appendTo(jQuery('<div/>', {
'class': 'navbar-text hidden-xs',
}).insertAfter(this.buttons.previous));
this.buttons.previous.addClass('hidden-xs');
this.buttons.next.addClass('hidden-xs');
2018-09-02 10:44:38 +02:00
toolbar.find('.btn-toolbar > .btn-group').last()
.addClass( 'hidden-xs')
.find('.dropdown')
.on('show.bs.dropdown', function() {
jQuery(this).parents('.btn-group')
.removeClass( 'hidden-xs');
})
.on('hide.bs.dropdown', function() {
jQuery(this).parents('.btn-group')
.addClass('hidden-xs');
});
2019-03-28 19:33:23 +01:00
return toolbar;
2013-10-14 09:02:47 +00:00
},
2018-05-12 00:39:59 +02:00
show: function() {
jQuery('#tablist').find('a[href="#' + this.id + '"]').tab('show');
},
2013-10-14 09:02:47 +00:00
close: function() {
2015-02-06 00:32:51 +01:00
var tabs = jQuery('#tabs');
2017-01-15 18:59:21 +01:00
var tablist = jQuery('#tablist');
var tab = tablist.find('#nav-' + this.id);
2015-02-06 00:32:51 +01:00
var content = tabs.find('#' + this.id);
2018-05-12 00:39:59 +02:00
this.show();
2015-03-16 19:14:57 +01:00
return this._close_allowed().then(function() {
2017-01-27 16:57:14 +01:00
var next = tab.nextAll('li').first();
2015-02-06 00:32:51 +01:00
if (!next.length) {
2017-01-27 16:57:14 +01:00
next = tab.prevAll('li').first();
2013-10-18 17:09:10 +02:00
}
2018-03-22 16:58:40 +01:00
tab.remove();
2015-02-06 00:32:51 +01:00
content.remove();
var i = Sao.Tab.tabs.indexOf(this);
if (i >= 0) {
Sao.Tab.tabs.splice(i, 1);
}
2018-05-12 00:39:59 +02:00
if (next.length) {
2015-02-06 00:32:51 +01:00
next.find('a').tab('show');
2018-05-12 00:39:59 +02:00
} else {
Sao.set_url();
2015-02-06 00:32:51 +01:00
}
2015-10-23 19:47:08 +02:00
tabs.trigger('ready');
2013-11-25 12:18:32 +01:00
}.bind(this));
2015-03-16 19:14:57 +01:00
},
_close_allowed: function() {
return jQuery.when();
},
set_name: function(name) {
2017-02-25 18:38:58 +01:00
this.name = name;
this.name_el.text(Sao.common.ellipsize(name, 20));
2021-02-20 00:54:38 +01:00
this.name_el.attr('title', name);
2018-05-12 00:39:59 +02:00
},
get_url: function() {
},
2018-09-27 22:21:30 +02:00
compare: function(attributes) {
return false;
},
2013-01-04 21:29:48 +01:00
});
2012-11-29 11:32:58 +01:00
2013-01-04 21:29:48 +01:00
Sao.Tab.counter = 0;
2013-11-25 12:18:32 +01:00
Sao.Tab.tabs = [];
Sao.Tab.tabs.close = function(warning) {
if (warning && Sao.Tab.tabs.length) {
return Sao.common.sur.run(
2015-05-29 10:44:10 +02:00
Sao.i18n.gettext(
'The following action requires to close all tabs.\n' +
'Do you want to continue?')).then(function() {
return Sao.Tab.tabs.close(false);
});
2013-11-25 12:18:32 +01:00
}
if (Sao.Tab.tabs.length) {
var tab = Sao.Tab.tabs[0];
return tab.close().then(function() {
if (!~Sao.Tab.tabs.indexOf(tab)) {
return Sao.Tab.tabs.close();
} else {
return jQuery.Deferred().reject();
}
});
}
if (Sao.main_menu_screen) {
2015-03-27 15:06:29 +01:00
return Sao.main_menu_screen.save_tree_state().then(function() {
Sao.main_menu_screen = null;
});
}
2013-11-25 12:18:32 +01:00
return jQuery.when();
};
Sao.Tab.tabs.get_current = function() {
2019-07-08 18:51:36 +02:00
return jQuery('#tablist').find('li.active').data('tab');
};
Sao.Tab.tabs.close_current = function() {
var tab = this.get_current();
tab.close();
};
2013-01-04 21:29:48 +01:00
Sao.Tab.create = function(attributes) {
2018-09-24 14:40:27 +02:00
var tablist = jQuery('#tablist');
2013-01-04 21:29:48 +01:00
if (attributes.context === undefined) {
attributes.context = {};
}
2018-09-24 14:40:27 +02:00
for (var i = 0; i < Sao.Tab.tabs.length; i++) {
var other = Sao.Tab.tabs[i];
if (other.compare(attributes)) {
tablist.find('a[href="#' + other.id + '"]').tab('show');
return;
}
}
2013-01-04 21:29:48 +01:00
var tab;
if (attributes.model) {
tab = new Sao.Tab.Form(attributes.model, attributes);
} else {
tab = new Sao.Tab.Board(attributes);
}
2018-05-12 00:39:59 +02:00
tab.view_prm.done(function() {
Sao.Tab.add(tab);
});
2015-03-16 19:14:57 +01:00
};
Sao.Tab.add = function(tab) {
2015-02-06 00:32:51 +01:00
var tabs = jQuery('#tabs');
2017-01-15 18:59:21 +01:00
var tablist = jQuery('#tablist');
var tabcontent = jQuery('#tabcontent');
2014-10-22 11:56:20 +02:00
var tab_link = jQuery('<a/>', {
2015-02-06 00:32:51 +01:00
'aria-controls': tab.id,
'role': 'tab',
'data-toggle': 'tab',
'href': '#' + tab.id
2018-05-12 00:39:59 +02:00
}).on('show.bs.tab', function() {
Sao.set_url(tab.get_url(), tab.name);
2014-10-22 11:56:20 +02:00
})
2015-02-06 00:32:51 +01:00
.append(jQuery('<button/>', {
'class': 'close'
}).append(jQuery('<span/>', {
'aria-hidden': true
}).append('&times;')).append(jQuery('<span/>', {
'class': 'sr-only'
2020-05-26 09:57:34 +02:00
}).text(Sao.i18n.gettext('Close'))).click(function(evt) {
evt.preventDefault();
2014-10-22 11:56:20 +02:00
tab.close();
2015-02-06 00:32:51 +01:00
}))
.append(tab.name_el);
2014-10-22 11:56:20 +02:00
jQuery('<li/>', {
2015-02-06 00:32:51 +01:00
'role': 'presentation',
2017-01-15 18:59:21 +01:00
'data-placement': 'bottom',
2014-10-22 11:56:20 +02:00
id: 'nav-' + tab.id
2015-02-06 00:32:51 +01:00
}).append(tab_link)
2019-07-08 18:51:36 +02:00
.appendTo(tablist)
.data('tab', tab);
2014-10-22 11:56:20 +02:00
jQuery('<div/>', {
2015-02-06 00:32:51 +01:00
role: 'tabpanel',
'class': 'tab-pane',
2014-10-22 11:56:20 +02:00
id: tab.id
2020-06-29 17:29:45 +02:00
}).append(tab.el)
2017-01-15 18:59:21 +01:00
.appendTo(tabcontent);
2015-02-06 00:32:51 +01:00
tab_link.tab('show');
2015-10-23 19:47:08 +02:00
tabs.trigger('ready');
2013-01-04 21:29:48 +01:00
};
2017-08-30 18:27:52 +02:00
Sao.Tab.previous_tab = function() {
Sao.Tab.move('prevAll');
};
Sao.Tab.next_tab = function() {
Sao.Tab.move('nextAll');
};
Sao.Tab.move = function(direction) {
var current_tab = this.tabs.get_current();
var tabs = jQuery('#tabs');
var tablist = jQuery('#tablist');
var tab = tablist.find('#nav-' + current_tab.id);
var next = tab[direction]('li').first();
2019-02-10 22:54:30 +01:00
if (!next.length) {
if (direction == 'prevAll') {
next = tablist.find('li').last();
} else {
next = tablist.find('li').first();
}
}
2017-08-30 18:27:52 +02:00
if (next) {
next.find('a').tab('show');
tabs.trigger('ready');
}
};
2013-01-04 21:29:48 +01:00
Sao.Tab.Form = Sao.class_(Sao.Tab, {
2013-10-14 09:02:47 +00:00
class_: 'tab-form',
2013-01-04 21:29:48 +01:00
init: function(model_name, attributes) {
2018-09-24 14:40:27 +02:00
Sao.Tab.Form._super.init.call(this, attributes);
2021-02-14 15:45:21 +01:00
attributes = jQuery.extend({}, attributes);
var name = attributes.name;
if (!name) {
name = Sao.common.MODELNAME.get(model_name);
}
this.set_name(name);
attributes.breadcrumb = [name];
2013-01-04 21:29:48 +01:00
var screen = new Sao.Screen(model_name, attributes);
2013-08-26 14:26:03 +02:00
screen.tab = this;
2013-01-04 21:29:48 +01:00
this.screen = screen;
2015-07-03 19:35:28 +02:00
this.info_bar = new Sao.Window.InfoBar();
2013-10-14 09:02:47 +00:00
this.create_tabcontent();
2013-08-21 16:26:20 +02:00
screen.message_callback = this.record_message.bind(this);
2018-05-12 00:39:59 +02:00
screen.switch_callback = function() {
if (this === Sao.Tab.tabs.get_current()) {
Sao.set_url(this.get_url(), this.name);
}
2018-05-12 00:39:59 +02:00
}.bind(this);
this.set_buttons_sensitive();
2013-08-21 16:26:20 +02:00
this.view_prm = this.screen.switch_view().done(function() {
2019-03-15 11:14:16 +01:00
this.screen.count_tab_domain();
2016-09-19 22:21:09 +02:00
this.content.append(screen.screen_container.el);
2013-11-25 12:18:32 +01:00
if (attributes.res_id) {
2016-08-12 13:23:28 +02:00
if (!jQuery.isArray(attributes.res_id)) {
attributes.res_id = [attributes.res_id];
}
screen.group.load(attributes.res_id);
screen.current_record = screen.group.get(
attributes.res_id);
2013-11-25 12:18:32 +01:00
screen.display();
} else {
if (screen.current_view.view_type == 'form') {
screen.new_();
}
if (~['tree', 'graph', 'calendar'].indexOf(
screen.current_view.view_type)) {
screen.search_filter();
}
}
2014-03-18 19:56:07 +01:00
this.update_revision();
2013-10-14 09:02:47 +00:00
}.bind(this));
2013-01-08 13:32:10 +01:00
},
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', [],
2019-02-14 16:31:31 +01:00
screen.context);
2013-01-08 13:32:10 +01:00
prm.done(function(toolbars) {
[
2018-08-19 20:01:49 +02:00
['action', 'tryton-launch',
2015-05-29 10:44:10 +02:00
Sao.i18n.gettext('Launch action')],
2018-08-19 20:01:49 +02:00
['relate', 'tryton-link',
2015-05-29 10:44:10 +02:00
Sao.i18n.gettext('Open related records')],
2018-08-19 20:01:49 +02:00
['print', 'tryton-print',
2015-05-29 10:44:10 +02:00
Sao.i18n.gettext('Print report')]
2013-01-08 13:32:10 +01:00
].forEach(function(menu_action) {
2016-12-27 18:17:05 +01:00
var button = jQuery('<div/>', {
2018-09-02 10:44:38 +02:00
'class': 'btn-group dropdown',
2016-12-27 18:17:05 +01:00
'role': 'group'
2015-02-06 00:32:51 +01:00
})
2016-12-27 18:17:05 +01:00
.append(jQuery('<button/>', {
'type': 'button',
'class': 'btn btn-default navbar-btn dropdown-toggle',
2015-02-06 00:32:51 +01:00
'data-toggle': 'dropdown',
2016-12-27 18:17:05 +01:00
'aria-expanded': false,
'aria-haspopup': true,
'title': menu_action[2],
2017-01-20 09:25:05 +01:00
'id': menu_action[0],
2015-02-06 00:32:51 +01:00
})
2018-08-19 20:01:49 +02:00
.append(Sao.common.ICONFACTORY.get_icon_img(
menu_action[1], {
'aria-hidden': 'true',
}))
2015-02-06 00:32:51 +01:00
.append(jQuery('<span/>', {
'class': 'caret'
2018-03-22 16:58:40 +01:00
})))
2015-02-06 00:32:51 +01:00
.append(jQuery('<ul/>', {
'class': 'dropdown-menu',
2016-12-27 18:17:05 +01:00
'role': 'menu',
2015-03-20 13:10:56 +01:00
'aria-labelledby': menu_action[0]
2015-02-06 00:32:51 +01:00
}))
2020-09-17 17:18:02 +02:00
.insertBefore(toolbar.find('button#email'));
2013-01-08 13:32:10 +01:00
buttons[menu_action[0]] = button;
2016-12-27 18:17:05 +01:00
var dropdown = button
.on('show.bs.dropdown', function() {
jQuery(this).parents('.btn-group').removeClass(
'hidden-xs');
}).on('hide.bs.dropdown', function() {
jQuery(this).parents('.btn-group').addClass(
'hidden-xs');
});
2018-09-02 10:44:38 +02:00
var menu = button.find('.dropdown-menu');
2018-01-24 14:35:44 +01:00
button.click(function() {
2019-03-22 17:21:20 +01:00
menu.find([
'.' + menu_action[0] + '_button',
'.divider-button',
'.' + menu_action[0] + '_plugin',
'.divider-plugin'].join(',')).remove();
var buttons = screen.get_buttons().filter(
function(button) {
return menu_action[0] == (
button.attributes.keyword || 'action');
});
if (buttons.length) {
menu.append(jQuery('<li/>', {
'role': 'separator',
2019-03-22 17:21:20 +01:00
'class': 'divider divider-button',
}));
}
2018-01-24 14:35:44 +01:00
buttons.forEach(function(button) {
var item = jQuery('<li/>', {
'role': 'presentation',
'class': menu_action[0] + '_button'
})
.append(
jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1
2020-05-26 09:57:34 +02:00
}).text(
2018-01-24 14:35:44 +01:00
button.attributes.string || ''))
.click(function(evt) {
evt.preventDefault();
2018-01-24 14:35:44 +01:00
screen.button(button.attributes);
})
.appendTo(menu);
2015-02-06 00:32:51 +01:00
});
var kw_plugins = [];
Sao.Plugins.forEach(function(plugin) {
plugin.get_plugins(screen.model.name).forEach(
function(spec) {
var name = spec[0],
func = spec[1],
keyword = spec[2] || 'action';
if (keyword != menu_action[0]) {
return;
}
kw_plugins.push([name, func]);
});
});
if (kw_plugins.length) {
menu.append(jQuery('<li/>', {
'role': 'separator',
2019-03-22 17:21:20 +01:00
'class': 'divider divider-plugin',
}));
}
kw_plugins.forEach(function(plugin) {
var name = plugin[0],
func = plugin[1];
jQuery('<li/>', {
'role': 'presentation',
'class': menu_action[0] + '_plugin',
}).append(
jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1,
2020-05-26 09:57:34 +02:00
}).text(name))
.click(function(evt) {
evt.preventDefault();
2019-02-14 16:31:31 +01:00
var ids = screen.current_view.selected_records
.map(function(record) {
return record.id;
});
var id = screen.current_record ?
screen.current_record.id : null;
func({
'model': screen.model.name,
'ids': ids,
'id': id,
});
})
.appendTo(menu);
});
2018-01-24 14:35:44 +01:00
});
2013-01-08 13:32:10 +01:00
toolbars[menu_action[0]].forEach(function(action) {
2015-03-20 13:10:56 +01:00
var item = jQuery('<li/>', {
'role': 'presentation'
})
.append(jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1
2020-05-26 09:57:34 +02:00
}).text(action.name))
.click(function(evt) {
evt.preventDefault();
this.modified_save().then(function() {
2014-02-20 23:36:38 +01:00
var exec_action = jQuery.extend({}, action);
var record_id = null;
if (screen.current_record) {
record_id = screen.current_record.id;
}
var record_ids = screen.current_view
2019-02-14 16:31:31 +01:00
.selected_records.map(function(record) {
2014-02-20 23:36:38 +01:00
return record.id;
});
var data = {
model: screen.model_name,
id: record_id,
ids: record_ids
};
2019-12-07 16:03:36 +01:00
Sao.Action.execute(exec_action, data,
jQuery.extend({}, screen.local_context));
2014-02-20 23:36:38 +01:00
});
}.bind(this))
2015-02-06 00:32:51 +01:00
.appendTo(menu);
}.bind(this));
2019-03-22 17:21:20 +01:00
if (menu_action[0] == 'print') {
if (toolbars.exports.length && toolbars.print.length) {
menu.append(jQuery('<li/>', {
'role': 'separator',
'class': 'divider',
}));
}
toolbars.exports.forEach(function(export_) {
var item = jQuery('<li/>', {
'role': 'presentation',
})
.append(jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1,
2020-05-26 09:57:34 +02:00
}).text(export_.name))
2019-03-22 17:21:20 +01:00
.click(function(evt) {
evt.preventDefault();
this.do_export(export_);
}.bind(this))
.appendTo(menu);
}.bind(this));
}
}.bind(this));
}.bind(this));
this.buttons.attach
.on('dragover', false)
.on('drop', this.attach_drop.bind(this));
2013-01-08 13:32:10 +01:00
return toolbar;
2013-01-08 14:58:18 +01:00
},
2018-09-24 14:40:27 +02:00
compare: function(attributes) {
if (!attributes) {
return false;
}
var compare = Sao.common.compare;
return ((this.screen.model_name === attributes.model) &&
(this.attributes.res_id === attributes.res_id) &&
(compare(
this.attributes.domain || [], attributes.domain || [])) &&
2018-09-24 14:40:27 +02:00
(compare(
this.attributes.view_ids || [],
attributes.view_ids || [])) &&
(attributes.view_ids ||
(compare(
this.attributes.mode || ['tree', 'form'],
attributes.mode || ['tree', 'form']))) &&
(JSON.stringify(this.screen.local_context) ===
2018-09-24 14:40:27 +02:00
JSON.stringify(attributes.context)) &&
(compare(
this.attributes.search_value || [],
attributes.search_value || []))
2018-09-24 14:40:27 +02:00
);
},
2015-03-16 19:14:57 +01:00
_close_allowed: function() {
return this.modified_save();
},
2013-03-04 19:08:16 +01:00
modified_save: function() {
2013-10-18 17:09:10 +02:00
this.screen.save_tree_state();
2013-03-04 19:08:16 +01:00
this.screen.current_view.set_value();
if (this.screen.modified()) {
2015-05-29 10:44:10 +02:00
return Sao.common.sur_3b.run(
Sao.i18n.gettext('This record has been modified\n' +
'do you want to save it?'))
2013-11-25 12:18:32 +01:00
.then(function(result) {
switch(result) {
case 'ok':
return this.save();
case 'ko':
var record_id = this.screen.current_record.id;
return this.reload(false).then(function() {
if (this.screen.current_record) {
if (record_id !=
this.screen.current_record.id) {
return jQuery.Deferred().reject();
}
} else if (record_id < 0) {
return jQuery.Deferred().resolve();
}
}.bind(this));
2013-11-25 12:18:32 +01:00
default:
return jQuery.Deferred().reject();
}
}.bind(this));
2013-03-04 19:08:16 +01:00
}
2013-11-25 12:18:32 +01:00
return jQuery.when();
2013-03-04 19:08:16 +01:00
},
new_: function() {
2013-08-21 16:26:20 +02:00
if (!Sao.common.MODELACCESS.get(this.screen.model_name).create) {
2018-03-27 10:49:21 +02:00
return jQuery.when();
2013-08-21 16:26:20 +02:00
}
2018-03-27 10:49:21 +02:00
return this.modified_save().then(function() {
return this.screen.new_().then(function() {
2015-07-03 19:35:28 +02:00
this.info_bar.message();
}.bind(this));
2013-11-25 12:18:32 +01:00
// TODO activate_save
}.bind(this));
2013-03-04 19:08:16 +01:00
},
2018-10-31 18:52:35 +01:00
save: function(tab) {
if (tab) {
// Called from button so we must save the tree state
this.screen.save_tree_state();
}
var access = Sao.common.MODELACCESS.get(this.screen.model_name);
if (!(access.write || access.create)) {
return jQuery.Deferred().reject();
2013-08-21 16:26:20 +02:00
}
2015-07-03 19:35:28 +02:00
return this.screen.save_current().then(
function() {
this.info_bar.message(
Sao.i18n.gettext('Record saved.'), 'info');
this.screen.count_tab_domain(true);
2015-07-03 19:35:28 +02:00
}.bind(this),
function() {
this.info_bar.message(
2015-07-16 22:36:11 +02:00
this.screen.invalid_message(), 'danger');
return jQuery.Deferred().reject();
2015-07-03 19:35:28 +02:00
}.bind(this));
2013-03-04 19:08:16 +01:00
},
2013-01-08 14:58:18 +01:00
switch_: function() {
return this.modified_save().then(function() {
return this.screen.switch_view();
2013-11-25 12:18:32 +01:00
}.bind(this));
2013-03-22 16:56:41 +01:00
},
reload: function(test_modified) {
2013-11-25 12:18:32 +01:00
if (test_modified === undefined) {
test_modified = true;
}
var reload = function() {
2015-03-13 16:45:47 +01:00
return this.screen.cancel_current().then(function() {
2018-07-24 19:10:09 +02:00
var set_cursor = false;
var record_id = null;
if (this.screen.current_record) {
record_id = this.screen.current_record.id;
}
2013-11-25 12:18:32 +01:00
if (this.screen.current_view.view_type != 'form') {
2018-07-24 19:10:09 +02:00
return this.screen.search_filter(
this.screen.screen_container.search_entry.val())
.then(function() {
this.screen.group.forEach(function(record) {
if (record.id == record_id) {
2019-02-14 16:31:31 +01:00
this.screen.current_record = record;
2018-07-24 19:10:09 +02:00
set_cursor = true;
}
}.bind(this));
return set_cursor;
}.bind(this));
2013-11-25 12:18:32 +01:00
}
2018-07-24 19:10:09 +02:00
return set_cursor;
}.bind(this))
.then(function(set_cursor) {
return this.screen.display(set_cursor).then(function() {
2015-07-03 19:35:28 +02:00
this.info_bar.message();
2018-07-24 19:10:09 +02:00
// TODO activate_save
this.screen.count_tab_domain();
2015-07-03 19:35:28 +02:00
}.bind(this));
2013-11-25 12:18:32 +01:00
}.bind(this));
}.bind(this);
if (test_modified) {
return this.modified_save().then(reload);
} else {
this.screen.save_tree_state(false);
2013-11-25 12:18:32 +01:00
return reload();
2013-03-22 16:56:41 +01:00
}
2013-08-26 14:26:03 +02:00
},
2013-10-14 09:02:47 +00:00
copy: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name).create) {
2018-03-27 10:49:21 +02:00
return jQuery.when();
2013-10-14 09:02:47 +00:00
}
2018-03-27 10:49:21 +02:00
return this.modified_save().then(function() {
return this.screen.copy().then(function() {
2015-07-03 19:35:28 +02:00
this.info_bar.message(
Sao.i18n.gettext(
'Working now on the duplicated record(s).'),
'info');
this.screen.count_tab_domain(true);
2015-07-03 19:35:28 +02:00
}.bind(this));
2013-11-25 12:18:32 +01:00
}.bind(this));
2013-10-14 09:02:47 +00:00
},
delete_: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name)['delete']) {
2018-03-27 10:49:21 +02:00
return jQuery.when();
2013-10-14 09:02:47 +00:00
}
2013-11-25 12:18:32 +01:00
var msg;
if (this.screen.current_view.view_type == 'form') {
2015-10-16 02:40:18 +02:00
msg = Sao.i18n.gettext('Are you sure to remove this record?');
2013-11-25 12:18:32 +01:00
} else {
2015-05-29 10:44:10 +02:00
msg = Sao.i18n.gettext('Are you sure to remove those records?');
2013-11-25 12:18:32 +01:00
}
2018-03-27 10:49:21 +02:00
return Sao.common.sur.run(msg).then(function() {
return this.screen.remove(true, false, true).then(
2015-07-03 19:35:28 +02:00
function() {
this.info_bar.message(
Sao.i18n.gettext('Records removed.'),
'info');
this.screen.count_tab_domain(true);
2015-07-03 19:35:28 +02:00
}.bind(this), function() {
this.info_bar.message(
Sao.i18n.gettext('Records not removed.'),
'danger');
}.bind(this));
2013-11-25 12:18:32 +01:00
}.bind(this));
2013-10-14 09:02:47 +00:00
},
previous: function() {
2018-03-27 10:49:21 +02:00
return this.modified_save().then(function() {
var prm = this.screen.display_previous();
2015-07-03 19:35:28 +02:00
this.info_bar.message();
// TODO activate_save
return prm;
2013-11-25 12:18:32 +01:00
}.bind(this));
},
next: function() {
2018-03-27 10:49:21 +02:00
return this.modified_save().then(function() {
var prm = this.screen.display_next();
2015-07-03 19:35:28 +02:00
this.info_bar.message();
// TODO activate_save
return prm;
2013-11-25 12:18:32 +01:00
}.bind(this));
},
2013-10-14 09:02:47 +00:00
search: function() {
var search_entry = this.screen.screen_container.search_entry;
if (search_entry.is(':visible')) {
window.setTimeout(function() {
search_entry.focus();
}, 0);
}
2018-03-27 10:49:21 +02:00
return jQuery.when();
2013-10-14 09:02:47 +00:00
},
logs: function() {
var record = this.screen.current_record;
if ((!record) || (record.id < 0)) {
2015-07-03 19:35:28 +02:00
this.info_bar.message(
Sao.i18n.gettext('You have to select one record.'),
'info');
2018-03-27 10:49:21 +02:00
return jQuery.when();
2013-10-14 09:02:47 +00:00
}
var fields = [
2015-05-29 10:44:10 +02:00
['id', Sao.i18n.gettext('ID:')],
['create_uid.rec_name',
Sao.i18n.gettext('Created by:')],
['create_date', Sao.i18n.gettext('Created at:')],
2015-05-29 10:44:10 +02:00
['write_uid.rec_name',
Sao.i18n.gettext('Edited by:')],
['write_date', Sao.i18n.gettext('Edited at:')]
2013-10-14 09:02:47 +00:00
];
2018-03-27 10:49:21 +02:00
return this.screen.model.execute('read', [[record.id],
2013-10-14 09:02:47 +00:00
fields.map(function(field) {
return field[0];
2019-02-14 16:31:31 +01:00
})], this.screen.context)
.then(function(data) {
data = data[0];
2013-10-14 09:02:47 +00:00
var message = '';
fields.forEach(function(field) {
var key = field[0];
var label = field[1];
var value = data;
var keys = key.split('.');
var name = keys.splice(-1);
keys.forEach(function(key) {
value = value[key + '.'] || {};
});
value = (value || {})[name] || '/';
if (value && value.isDateTime) {
2013-10-14 09:02:47 +00:00
value = Sao.common.format_datetime(
Sao.common.date_format() + ' %H:%M:%S',
2013-10-14 09:02:47 +00:00
value);
}
message += label + ' ' + value + '\n';
});
2015-05-29 10:44:10 +02:00
message += Sao.i18n.gettext('Model: ') + this.screen.model.name;
2013-10-14 09:02:47 +00:00
Sao.common.message.run(message);
}.bind(this));
},
2014-03-18 19:56:07 +01:00
revision: function() {
var current_id = null;
if (this.screen.current_record) {
current_id = this.screen.current_record.id;
}
2014-10-10 10:00:52 +02:00
var set_revision = function(revisions) {
return function(revision) {
if (revision) {
// Add a millisecond as microseconds are truncated
2016-04-02 15:23:39 +02:00
revision.add(1, 'milliseconds');
2014-03-18 19:56:07 +01:00
}
2014-10-10 10:00:52 +02:00
if ((this.screen.current_view.view_type == 'form') &&
(revision < revisions[revisions.length - 1][0])) {
revision = revisions[revisions.length - 1][0];
}
2019-02-14 16:31:31 +01:00
if (revision != this.screen.context._datetime) {
this.screen.clear();
2018-03-09 19:10:58 +01:00
// Update group context that will be propagated by
2014-10-10 10:00:52 +02:00
// recreating new group
2018-03-09 19:10:58 +01:00
this.screen.group._context._datetime = revision;
2014-10-10 10:00:52 +02:00
if (this.screen.current_view.view_type != 'form') {
this.screen.search_filter(
this.screen.screen_container
.search_entry.val());
} else {
2018-03-09 19:10:58 +01:00
this.screen.group.load([current_id]);
2014-10-10 10:00:52 +02:00
}
2015-10-27 10:55:57 +01:00
this.screen.display(true);
2014-10-10 10:00:52 +02:00
this.update_revision();
}
}.bind(this);
2014-03-18 19:56:07 +01:00
}.bind(this);
2018-03-27 10:49:21 +02:00
return this.modified_save().then(function() {
2019-02-14 16:31:31 +01:00
var ids = this.screen.current_view.selected_records.map(
2014-03-18 19:56:07 +01:00
function(record) {
return record.id;
});
2018-03-27 10:49:21 +02:00
return this.screen.model.execute('history_revisions',
2019-02-14 16:31:31 +01:00
[ids], this.screen.context)
2014-03-18 19:56:07 +01:00
.then(function(revisions) {
2014-10-10 10:00:52 +02:00
new Sao.Window.Revision(revisions, set_revision(revisions));
2014-03-18 19:56:07 +01:00
});
}.bind(this));
},
update_revision: function() {
2019-02-14 16:31:31 +01:00
var revision = this.screen.context._datetime;
2018-07-10 17:08:56 +02:00
var label, title;
2014-03-18 19:56:07 +01:00
if (revision) {
2021-02-14 14:03:55 +01:00
var date_format = Sao.common.date_format(
this.screen.context.date_format);
2014-03-18 19:56:07 +01:00
var time_format = '%H:%M:%S.%f';
2018-07-10 17:08:56 +02:00
var revision_label = ' @ ' + Sao.common.format_datetime(
date_format + ' ' + time_format, revision);
2018-07-10 17:08:56 +02:00
label = Sao.common.ellipsize(
this.name, 80 - revision_label.length) + revision_label;
title = this.name + revision_label;
2014-03-18 19:56:07 +01:00
} else {
2018-07-10 17:08:56 +02:00
label = Sao.common.ellipsize(this.name, 80);
title = this.name;
2014-03-18 19:56:07 +01:00
}
2018-07-10 17:08:56 +02:00
this.title.text(label);
this.title.attr('title', title);
this.set_buttons_sensitive(revision);
},
set_buttons_sensitive: function(revision) {
if (!revision) {
var access = Sao.common.MODELACCESS.get(this.screen.model_name);
2017-08-30 18:19:04 +02:00
[['new_', access.create],
['save', access.create || access.write],
['delete_', access.delete],
['copy', access.create],
['import', access.create],
].forEach(function(e) {
var name = e[0];
var access = e[1];
if (this.buttons[name]) {
this.buttons[name].toggleClass('disabled', !access);
2017-08-30 18:19:04 +02:00
}
if (this.menu_buttons[name]) {
this.menu_buttons[name]
.toggleClass('disabled', !access);
}
}.bind(this));
} else {
2017-08-30 18:19:04 +02:00
['new_', 'save', 'delete_', 'copy', 'import'].forEach(
function(name) {
if (this.buttons[name]) {
this.buttons[name].addClass('disabled');
}
if (this.menu_buttons[name]) {
this.menu_buttons[name].addClass('disabled');
}
}.bind(this));
}
2014-03-18 19:56:07 +01:00
},
2018-09-02 10:44:38 +02:00
attach: function(evt) {
var window_ = function() {
return new Sao.Window.Attachment(record, function() {
2019-03-22 12:16:36 +01:00
this.refresh_resources(true);
2018-09-02 10:44:38 +02:00
}.bind(this));
}.bind(this);
var dropdown = this.buttons.attach.parents('.dropdown');
if (!evt) {
window.setTimeout(function() {
this.buttons.attach.click();
}.bind(this));
2013-08-26 14:26:03 +02:00
return;
}
2018-09-02 10:44:38 +02:00
var record = this.screen.current_record;
var menu = dropdown.find('.dropdown-menu');
2019-06-27 14:32:36 +02:00
menu.empty();
2018-09-02 10:44:38 +02:00
Sao.Window.Attachment.get_attachments(record)
.then(function(attachments) {
attachments.forEach(function(value) {
var name = value[0],
callback = value[1];
var link = jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1,
2020-05-26 09:57:34 +02:00
}).text(name).appendTo(jQuery('<li/>', {
2018-09-02 10:44:38 +02:00
'role': 'presentation',
}).appendTo(menu));
if (typeof callback == 'string') {
link.attr('href', callback);
link.attr('target', '_new');
} else {
link.click(function(evt) {
evt.preventDefault();
callback();
});
}
});
}).always(function() {
menu.append(jQuery('<li/>', {
'class': 'divider',
}));
menu.append(jQuery('<li/>', {
'role': 'presentation',
'class': 'input-file',
}).append(jQuery('<input/>', {
'type': 'file',
'role': 'menuitem',
2018-09-26 23:05:11 +02:00
'multiple': true,
2018-09-02 10:44:38 +02:00
'tabindex': -1,
}).change(function() {
2018-09-26 23:05:11 +02:00
var attachment = window_();
2018-09-02 10:44:38 +02:00
Sao.common.get_input_data(
jQuery(this), function(data, filename) {
2018-09-26 23:05:11 +02:00
attachment.add_data(data, filename);
2018-09-02 10:44:38 +02:00
});
})).append(jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1,
2020-05-26 09:57:34 +02:00
}).text(Sao.i18n.gettext('Add...'))));
2018-09-02 10:44:38 +02:00
menu.append(jQuery('<li/>', {
'role': 'presentation',
}).append(jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1,
2020-05-26 09:57:34 +02:00
}).text(Sao.i18n.gettext('Manage...'))
2018-09-02 10:44:38 +02:00
.click(function(evt) {
evt.preventDefault();
window_();
})));
});
2013-08-26 14:26:03 +02:00
},
attach_drop: function(evt) {
evt.preventDefault();
evt.stopPropagation();
evt = evt.originalEvent;
var record = this.screen.current_record;
if (!record || record.id < 0) {
return;
}
var i, file;
var files = [],
uris = [],
texts = [];
if (evt.dataTransfer.items) {
console.log(evt.dataTransfer.items);
for (i = 0; i < evt.dataTransfer.items.length; i++) {
var item = evt.dataTransfer.items[i];
if (item.kind == 'string') {
var list;
if (item.type == 'text/uri-list') {
list = uris;
} else if (item.type == 'text/plain') {
list = texts;
} else {
continue;
}
var prm = jQuery.Deferred();
evt.dataTransfer.items[i].getAsString(prm.resolve);
list.push(prm);
break;
} else {
file = evt.dataTransfer.items[i].getAsFile();
if (file) {
files.push(file);
}
}
}
} else {
for (i = 0; i < evt.dataTransfer.files.length; i++) {
file = evt.dataTransfer.files[i];
if (file) {
files.push(file);
}
}
}
var window_ = new Sao.Window.Attachment(record, function() {
2019-03-22 12:16:36 +01:00
this.refresh_resources(true);
}.bind(this));
files.forEach(function(file) {
Sao.common.get_file_data(file, function(data, filename) {
window_.add_data(data, filename);
});
});
jQuery.when.apply(jQuery, uris).then(function() {
function empty(value) {
return Boolean(value);
}
for (var i = 0; i < arguments.length; i++) {
arguments[i].split('\r\n')
.filter(empty)
.forEach(window_.add_uri, window_);
}
});
jQuery.when.apply(jQuery, texts).then(function() {
for (var i = 0; i < arguments.length; i++) {
window_.add_text(arguments[i]);
}
});
if (evt.dataTransfer.items) {
evt.dataTransfer.items.clear();
} else {
evt.dataTransfer.clearData();
}
},
2016-02-02 19:15:58 +01:00
note: function() {
var record = this.screen.current_record;
if (!record || (record.id < 0)) {
return;
}
new Sao.Window.Note(record, function() {
2019-03-22 12:16:36 +01:00
this.refresh_resources(true);
2016-02-02 19:15:58 +01:00
}.bind(this));
},
2020-09-17 17:18:02 +02:00
email: function() {
function is_report(action) {
return action.type == 'ir.action.report';
}
if (!this.buttons.email.hasClass('disabled')) {
2020-12-18 00:25:57 +01:00
this.modified_save().then(function() {
var record = this.screen.current_record;
if (!record || (record.id < 0)) {
return;
}
var title = this.title.text();
this.screen.model.execute(
'view_toolbar_get', [], this.screen.context)
.then(function(toolbars) {
var prints = toolbars.print.filter(is_report);
var emails = {};
for (var i = 0; i < toolbars.emails.length; i++) {
var email = toolbars.emails[i];
emails[email.name] = email.id;
2020-09-17 17:18:02 +02:00
}
2020-12-18 00:25:57 +01:00
record.rec_name().then(function(rec_name) {
function email(template) {
new Sao.Window.Email(
title + ': ' + rec_name, record,
prints, template);
}
Sao.common.selection(
Sao.i18n.gettext("Template"), emails, true)
.then(email, email);
});
2020-09-17 17:18:02 +02:00
});
2020-12-18 00:25:57 +01:00
}.bind(this));
2020-09-17 17:18:02 +02:00
}
},
2019-03-22 12:16:36 +01:00
refresh_resources: function(reload) {
2016-02-02 19:15:58 +01:00
var record = this.screen.current_record;
if (record) {
2019-03-22 12:16:36 +01:00
record.get_resources(reload).always(
this.update_resources.bind(this));
2016-02-02 19:15:58 +01:00
} else {
2019-03-22 12:16:36 +01:00
this.update_resources();
2016-02-02 19:15:58 +01:00
}
},
2019-03-22 12:16:36 +01:00
update_resources: function(resources) {
if (!resources) {
resources = {};
2016-12-27 18:17:05 +01:00
}
2016-02-02 19:15:58 +01:00
var record_id = this.screen.get_id();
2019-03-22 12:16:36 +01:00
var disabled = record_id < 0 || record_id === null;
var update = function(name, title, text, color) {
var button = this.buttons[name];
var badge = button.find('.badge');
if (!badge.length) {
badge = jQuery('<span/>', {
'class': 'badge'
}).appendTo(button);
}
if (color) {
color = Sao.config.icon_colors[color];
} else {
color = '';
}
badge.css('background-color', color);
2020-08-16 17:43:21 +02:00
badge.css('color', '#fff');
2019-03-22 12:16:36 +01:00
badge.text(text);
button.attr('title', title);
button.prop('disabled', disabled);
}.bind(this);
var count = resources.attachment_count || 0;
var badge = count || '';
if (count > 99) {
badge = '99+';
}
var title= Sao.i18n.gettext("Attachment (%1)", count);
update('attach', title, badge, 1);
count = resources.note_count || 0;
var unread = resources.note_unread || 0;
badge = '';
var color = unread > 0 ? 2 : 1;
if (count) {
if (count > 9) {
badge = '+';
} else {
badge = count;
}
if (unread > 9) {
badge = '+/' + badge;
} else {
badge = unread + '/' + badge;
}
}
title = Sao.i18n.gettext("Note (%1/%2)", unread, count);
update('note', title, badge, color);
2016-02-02 19:15:58 +01:00
},
record_message: function(data) {
if (data) {
var name = "_";
if (data[0] !== 0) {
name = data[0];
}
var buttons = ['print', 'relate', 'attach'];
buttons.forEach(function(button_id){
var button = this.buttons[button_id];
if (button) {
var disabled = button.is(':disabled');
button.prop('disabled', disabled || data[0] === 0);
}
}.bind(this));
this.buttons.switch_.prop('disabled',
this.attributes.view_ids > 1);
this.menu_buttons.delete_.toggleClass(
'disabled', !this.screen.deletable);
this.menu_buttons.save.toggleClass(
'disabled', this.screen.readonly);
var msg = name + ' / ' + data[1];
if (data[1] < data[2]) {
msg += Sao.i18n.gettext(' of ') + data[2];
}
this.status_label.text(msg).attr('title', msg);
}
2015-07-03 19:35:28 +02:00
this.info_bar.message();
// TODO activate_save
2015-07-03 19:35:28 +02:00
},
2013-10-14 09:02:47 +00:00
action: function() {
2015-10-16 03:16:24 +02:00
window.setTimeout(function() {
this.buttons.action.find('button').click();
2015-10-16 03:16:24 +02:00
}.bind(this));
2013-10-14 09:02:47 +00:00
},
relate: function() {
2015-10-16 03:16:24 +02:00
window.setTimeout(function() {
this.buttons.relate.find('button').click();
2015-10-16 03:16:24 +02:00
}.bind(this));
2013-10-14 09:02:47 +00:00
},
print: function() {
2015-10-16 03:16:24 +02:00
window.setTimeout(function() {
this.buttons.print.find('button').click();
2015-10-16 03:16:24 +02:00
}.bind(this));
2016-10-31 10:09:43 +01:00
},
export: function(){
2019-03-22 17:21:20 +01:00
this.modified_save().then(function() {
new Sao.Window.Export(
this.title.text(), this.screen,
2020-04-12 23:10:30 +02:00
this.screen.current_view.get_fields());
2019-03-22 17:21:20 +01:00
}.bind(this));
},
do_export: function(export_) {
this.modified_save().then(function() {
var ids = this.screen.current_view.selected_records
.map(function(r) {
return r.id;
});
var fields = export_['export_fields.'].map(function(field) {
return field.name;
});
this.screen.model.execute(
'export_data', [ids, fields], this.screen.context)
.then(function(data) {
var unparse_obj = {
'fields': fields,
2019-09-11 23:43:30 +02:00
'data': data,
2019-03-22 17:21:20 +01:00
};
unparse_obj.data = data.map(function(row) {
return Sao.Window.Export.format_row(row);
});
2019-03-22 17:21:20 +01:00
var delimiter = ',';
if (navigator.platform &&
navigator.platform.slice(0, 3) == 'Win') {
delimiter = ';';
}
var csv = Papa.unparse(unparse_obj, {
quoteChar: '"',
delimiter: delimiter,
});
2020-09-12 18:30:11 +02:00
if (navigator.platform &&
navigator.platform.slice(0, 3) == 'Win') {
csv = Sao.BOM_UTF8 + csv;
}
2019-03-22 17:21:20 +01:00
Sao.common.download_file(
csv, export_.name + '.csv',
2020-09-12 18:30:11 +02:00
{'type': 'text/csv;charset=utf-8'});
2019-03-22 17:21:20 +01:00
});
}.bind(this));
2016-10-31 10:09:43 +01:00
},
import: function(){
if (!Sao.common.MODELACCESS.get(this.screen.model_name).create) {
return;
}
2018-08-30 15:57:43 +02:00
new Sao.Window.Import(this.title.text(), this.screen);
2018-05-12 00:39:59 +02:00
},
get_url: function() {
2020-10-04 00:35:23 +02:00
return this.screen.get_url(this.name);
2018-05-12 00:39:59 +02:00
},
2013-01-04 21:29:48 +01:00
});
2015-03-16 19:14:57 +01:00
2015-10-15 10:33:37 +02:00
Sao.Tab.Board = Sao.class_(Sao.Tab, {
class_: 'tab-board',
init: function(attributes) {
var UIView, view_prm;
2018-09-24 14:40:27 +02:00
Sao.Tab.Board._super.init.call(this, attributes);
2015-10-15 10:33:37 +02:00
this.model = attributes.model;
this.view_id = (attributes.view_ids.length > 0 ?
attributes.view_ids[0] : null);
this.context = attributes.context;
2020-10-04 00:35:23 +02:00
var name = attributes.name;
if (!name) {
name = Sao.common.MODELNAME.get(this.model);
}
this.name = name;
2015-10-15 10:33:37 +02:00
this.dialogs = [];
this.board = null;
UIView = new Sao.Model('ir.ui.view');
2018-05-12 00:39:59 +02:00
this.view_prm = UIView.execute('read', [[this.view_id], ['arch']],
2015-10-15 10:33:37 +02:00
this.context);
2018-05-12 00:39:59 +02:00
this.view_prm.done(function(views) {
2015-10-15 10:33:37 +02:00
var view, board;
view = jQuery(jQuery.parseXML(views[0].arch));
this.board = new Sao.View.Board(view, this.context);
this.board.actions_prms.done(function() {
var i, len, action;
for (i = 0, len = this.board.actions.length; i < len; i++) {
action = this.board.actions[i];
action.screen.tab = this;
}
2020-04-13 12:21:55 +02:00
this.board.reload();
2015-10-15 10:33:37 +02:00
}.bind(this));
2019-09-02 18:36:52 +02:00
this.content.append(this.board.el);
2015-10-15 10:33:37 +02:00
}.bind(this));
this.create_tabcontent();
this.set_name(this.name);
2020-06-29 17:29:45 +02:00
this.title.text(this.name_el.text());
2015-10-15 10:33:37 +02:00
},
2018-09-24 14:40:27 +02:00
compare: function(attributes) {
if (!attributes) {
2018-09-24 14:40:27 +02:00
return false;
}
var compare = Sao.common.compare;
return ((this.model === attributes.model) &&
(compare(
this.attributes.view_ids || [], attributes.view_ids || [])) &&
(JSON.stringify(this.context) === JSON.stringify(attributes.context))
);
},
2015-10-22 11:41:16 +02:00
reload: function() {
this.board.reload();
2015-10-15 10:33:37 +02:00
},
record_message: function() {
var i, len;
var action;
len = this.board.actions.length;
for (i = 0, len=len; i < len; i++) {
action = this.board.actions[i];
action.update_domain(this.board.actions);
}
},
2019-03-22 12:16:36 +01:00
refresh_resources: function() {
},
update_resources: function() {
},
2015-10-15 10:33:37 +02:00
});
2015-03-16 19:14:57 +01:00
Sao.Tab.Wizard = Sao.class_(Sao.Tab, {
class_: 'tab-wizard',
init: function(wizard) {
Sao.Tab.Wizard._super.init.call(this);
this.wizard = wizard;
this.set_name(wizard.name);
2015-03-16 19:14:57 +01:00
wizard.tab = this;
this.create_tabcontent();
2020-06-29 17:29:45 +02:00
this.title.text(this.name_el.text());
2021-01-06 11:00:07 +01:00
this.content.remove();
this.content = wizard.form;
2015-03-16 19:14:57 +01:00
this.el.append(wizard.form);
},
create_toolbar: function() {
return jQuery('<span/>');
},
_close_allowed: function() {
var wizard = this.wizard;
var prm = jQuery.when();
if ((wizard.state !== wizard.end_state) &&
(wizard.end_state in wizard.states)) {
prm = wizard.response(
wizard.states[wizard.end_state].attributes);
2015-03-16 19:14:57 +01:00
}
var dfd = jQuery.Deferred();
prm.always(function() {
if (wizard.state === wizard.end_state) {
dfd.resolve();
} else {
dfd.reject();
}
});
return dfd.promise();
}
});
2013-01-04 21:29:48 +01:00
}());