Files
tryton/src/tab.js
T

718 lines
29 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, {
init: function() {
2013-11-25 12:18:32 +01:00
Sao.Tab.tabs.push(this);
2013-01-08 13:32:10 +01:00
this.buttons = {};
2015-02-06 00:32:51 +01:00
this.id = 'tab-' + Sao.Tab.counter++;
this.name_el = jQuery('<span/>');
2013-01-08 13:32:10 +01:00
},
2013-10-14 09:02:47 +00:00
create_tabcontent: function() {
this.el = jQuery('<div/>', {
'class': this.class_
});
2015-02-06 00:32:51 +01:00
this.title = jQuery('<h4/>').appendTo(this.el);
2015-07-03 19:35:28 +02:00
this.el.append(this.info_bar.el);
2015-02-06 00:32:51 +01:00
this.create_toolbar().appendTo(this.el);
2013-10-14 09:02:47 +00:00
},
2015-02-06 00:32:51 +01:00
set_menu: function(menu) {
2013-10-14 09:02:47 +00:00
this.menu_def.forEach(function(definition) {
var icon = definition[0];
var name = definition[1];
var func = definition[2];
2014-03-18 19:56:07 +01:00
if (!func) {
return;
}
2013-10-14 09:02:47 +00:00
var item = jQuery('<li/>').append(
jQuery('<a/>').append(jQuery('<span/>', {
2015-02-06 00:32:51 +01:00
'class': 'glyphicon ' + icon,
'aria-hidden': 'true'
2015-03-27 16:04:13 +01:00
})).append(' ' + name));
2013-10-14 09:02:47 +00:00
menu.append(item);
item.click(function() {
this[func]();
}.bind(this));
}.bind(this));
},
2013-01-08 13:32:10 +01:00
create_toolbar: function() {
2015-02-06 00:32:51 +01:00
var toolbar = jQuery(
2015-02-20 19:10:18 +01:00
'<nav class="navbar navbar-default toolbar" role="navigation">' +
2015-02-06 00:32:51 +01:00
'<div class="container-fluid">' +
'<div class="navbar-header">' +
'<button type="button" class="navbar-toggle collapsed" ' +
2015-03-13 16:45:47 +01:00
'data-toggle="collapse" ' +
2015-02-06 00:32:51 +01:00
'data-target="#navbar-' + this.id + '">' +
2015-05-29 10:44:10 +02:00
'<span class="sr-only">' +
Sao.i18n.gettext('Toggle navigation') +
'</span>' +
2015-02-06 00:32:51 +01:00
'<span class="icon-bar"></span>' +
'<span class="icon-bar"></span>' +
'<span class="icon-bar"></span>' +
'</div>' +
'<div class="collapse navbar-collapse" ' +
'id="navbar-' + this.id + '">' +
'<ul class="nav navbar-nav">' +
'<li class="dropdown">' +
'<a href="#" class="dropdown-toggle" ' +
'data-toggle="dropdown" role="button" ' +
'aria-expanded="false">' +
'<span class="glyphicon glyphicon-wrench" ' +
'aria-hidden="true"></span>' +
2015-05-29 10:44:10 +02:00
'<span class="visible-xs">' +
Sao.i18n.gettext('Menu') +
'</span>' +
2015-02-06 00:32:51 +01:00
'<span class="caret"></span>' +
'</a>' +
'<ul class="dropdown-menu" role="menu">' +
'</ul>' +
'</li>' +
'</ul>' +
'</div>' +
'</div>' +
'</nav>'
);
this.set_menu(toolbar.find('ul[role*="menu"]'));
2013-01-08 13:32:10 +01:00
var add_button = function(tool) {
2015-02-06 00:32:51 +01:00
this.buttons[tool[0]] = jQuery('<a/>', {
href: '#',
id: tool[0]
2013-01-08 13:32:10 +01:00
})
2015-02-06 00:32:51 +01:00
.append(jQuery('<span/>', {
'class': 'glyphicon ' + tool[1],
'aria-hidden': 'true'
}))
.append(jQuery('<span/>', {
'class': 'hidden-sm'
}).append(' ' + tool[2]))
2015-02-06 00:32:51 +01:00
.click(this[tool[4]].bind(this))
.appendTo(jQuery('<li/>')
.appendTo(toolbar.find('.navbar-collapse > ul')));
2013-01-08 13:32:10 +01:00
// TODO tooltip
};
this.toolbar_def.forEach(add_button.bind(this));
return toolbar;
2013-10-14 09:02:47 +00:00
},
close: function() {
2015-02-06 00:32:51 +01:00
var tabs = jQuery('#tabs');
var tab = tabs.find('#nav-' + this.id);
var content = tabs.find('#' + this.id);
tabs.find('a[href="#' + this.id + '"]').tab('show');
2015-03-16 19:14:57 +01:00
return this._close_allowed().then(function() {
2015-02-06 00:32:51 +01:00
var next = tab.next();
if (!next.length) {
next = tab.prev();
2013-10-18 17:09:10 +02:00
}
2015-02-06 00:32:51 +01:00
tab.remove();
content.remove();
2013-11-25 12:18:32 +01:00
Sao.Tab.tabs.splice(Sao.Tab.tabs.indexOf(this), 1);
2015-02-06 00:32:51 +01:00
if (next) {
next.find('a').tab('show');
}
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) {
this.name_el.text(name);
2013-01-08 13:32:10 +01:00
}
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() {
2015-02-06 00:32:51 +01:00
var tabs = jQuery('#tabs > ul');
var i = tabs.find('li').index(tabs.find('li.active'));
return Sao.Tab.tabs[i];
};
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) {
if (attributes.context === undefined) {
attributes.context = {};
}
var tab;
if (attributes.model) {
tab = new Sao.Tab.Form(attributes.model, attributes);
} else {
tab = new Sao.Tab.Board(attributes);
}
2015-03-16 19:14:57 +01:00
Sao.Tab.add(tab);
};
Sao.Tab.add = function(tab) {
2015-02-06 00:32:51 +01:00
var tabs = jQuery('#tabs');
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
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'
2015-05-29 10:44:10 +02:00
}).append(Sao.i18n.gettext('Close'))).click(function() {
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',
2014-10-22 11:56:20 +02:00
id: 'nav-' + tab.id
2015-02-06 00:32:51 +01:00
}).append(tab_link)
.appendTo(tabs.find('> .nav-tabs'));
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
2015-02-06 00:32:51 +01:00
}).html(tab.el)
.appendTo(tabs.find('> .tab-content'));
tab_link.tab('show');
2013-01-04 21:29:48 +01:00
};
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) {
Sao.Tab.Form._super.init.call(this);
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;
this.attributes = jQuery.extend({}, attributes);
2013-10-14 09:02:47 +00:00
2014-03-18 19:56:07 +01:00
if (!Sao.common.MODELHISTORY.contains(model_name)) {
this.menu_def = jQuery.extend([], this.menu_def);
this.menu_def[10] = jQuery.extend([], this.menu_def[10]);
// Remove callback to revision
this.menu_def[10][2] = null;
}
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
var access = Sao.common.MODELACCESS.get(model_name);
[['new', 'create'], ['save', 'write']].forEach(function(e) {
var button = e[0];
var access_type = e[1];
this.buttons[button].prop('disabled', !access[access_type]);
}.bind(this));
this.view_prm = this.screen.switch_view().done(function() {
this.set_name(attributes.name ||
this.screen.current_view.attributes.string);
2013-10-14 09:02:47 +00:00
this.el.append(screen.screen_container.el);
2013-11-25 12:18:32 +01:00
if (attributes.res_id) {
screen.group.load([attributes.res_id]);
screen.set_current_record(
screen.group.get(attributes.res_id));
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
},
toolbar_def: [
2015-05-29 10:44:10 +02:00
['new', 'glyphicon-edit',
Sao.i18n.gettext('New'),
Sao.i18n.gettext('Create a new record'), 'new_'],
['save', 'glyphicon-save',
Sao.i18n.gettext('Save'),
Sao.i18n.gettext('Save this record'), 'save'],
['switch', 'glyphicon-list-alt',
Sao.i18n.gettext('Switch'),
Sao.i18n.gettext('Switch view'), 'switch_'],
['reload', 'glyphicon-refresh',
Sao.i18n.gettext('Reload'),
Sao.i18n.gettext('Reload'), 'reload'],
['previous', 'glyphicon-chevron-left',
Sao.i18n.gettext('Previous'),
Sao.i18n.gettext('Previous Record'), 'previous'],
['next', 'glyphicon-chevron-right',
Sao.i18n.gettext('Next'),
Sao.i18n.gettext('Next Record'), 'next'],
['attach', 'glyphicon-paperclip',
Sao.i18n.gettext('Attachment'),
Sao.i18n.gettext('Add an attachment to the record'), 'attach']
2013-01-08 13:32:10 +01:00
],
2013-10-14 09:02:47 +00:00
menu_def: [
2015-05-29 10:44:10 +02:00
['glyphicon-edit', Sao.i18n.gettext('New'), 'new_'],
['glyphicon-save', Sao.i18n.gettext('Save'), 'save'],
['glyphicon-list-alt', Sao.i18n.gettext('Switch'), 'switch_'],
['glyphicon-refresh', Sao.i18n.gettext('Reload/Undo'), 'reload'],
['glyphicon-duplicate', Sao.i18n.gettext('Duplicate'), 'copy'],
['glyphicon-trash', Sao.i18n.gettext('Delete'), 'delete_'],
['glyphicon-chevron-left', Sao.i18n.gettext('Previous'),
'previous'],
['glyphicon-chevron-right', Sao.i18n.gettext('Next'), 'next'],
['glyphicon-search', Sao.i18n.gettext('Search'), 'search'],
['glyphicon-time', Sao.i18n.gettext('View Logs...'), 'logs'],
['glyphicon-time', Sao.i18n.gettext('Show revisions...'),
'revision'],
['glyphicon-remove', Sao.i18n.gettext('Close Tab'), 'close'],
['glyphicon-paperclip', Sao.i18n.gettext('Attachment'), 'attach'],
['glyphicon-cog', Sao.i18n.gettext('Action'), 'action'],
['glyphicon-share-alt', Sao.i18n.gettext('Relate'), 'relate'],
['glyphicon-print', Sao.i18n.gettext('Print'), 'print']
2013-10-14 09:02:47 +00:00
],
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', [],
screen.context);
prm.done(function(toolbars) {
[
2015-05-29 10:44:10 +02:00
['action', 'glyphicon-cog',
Sao.i18n.gettext('Action'),
Sao.i18n.gettext('Launch action')],
['relate', 'glyphicon-share-alt',
Sao.i18n.gettext('Relate'),
Sao.i18n.gettext('Open related records')],
['print', 'glyphicon-print',
Sao.i18n.gettext('Print'),
Sao.i18n.gettext('Print report')]
2013-01-08 13:32:10 +01:00
].forEach(function(menu_action) {
2015-02-06 00:32:51 +01:00
var button = jQuery('<li/>', {
'class': 'dropdown'
})
.append(jQuery('<a/>', {
href: '#',
2013-01-08 13:32:10 +01:00
id: menu_action[0],
2015-02-06 00:32:51 +01:00
'class': 'dropdown-toggle',
'data-toggle': 'dropdown',
role: 'button',
'aria-expanded': 'false'
})
.append(jQuery('<span/>', {
'class': 'glyphicon ' + menu_action[1],
'aria-hidden': 'true'
}))
.append(jQuery('<span/>', {
'class': 'hidden-sm'
}).append(' ' + menu_action[2] + ' '))
2015-02-06 00:32:51 +01:00
.append(jQuery('<span/>', {
'class': 'caret'
})))
.append(jQuery('<ul/>', {
'class': 'dropdown-menu',
2015-03-20 13:10:56 +01:00
role: 'menu',
'aria-labelledby': menu_action[0]
2015-02-06 00:32:51 +01:00
}))
.appendTo(toolbar.find('.navbar-collapse > ul'));
2013-01-08 13:32:10 +01:00
buttons[menu_action[0]] = button;
2015-02-06 00:32:51 +01:00
var menu = button.find('ul[role*="menu"]');
if (menu_action[0] == 'action') {
button.find('a').click(function() {
2014-02-13 19:53:33 +01:00
menu.find('.action_button').remove();
var buttons = screen.get_buttons();
buttons.forEach(function(button) {
2015-03-20 13:10:56 +01:00
var item = jQuery('<li/>', {
2015-07-17 18:26:22 +02:00
'role': 'presentation',
'class': 'action_button'
2015-03-20 13:10:56 +01:00
})
2015-02-06 00:32:51 +01:00
.append(
2015-03-20 13:10:56 +01:00
jQuery('<a/>', {
'role': 'menuitem',
'href': '#',
'tabindex': -1
}).append(
2015-02-06 00:32:51 +01:00
button.attributes.string || ''))
.click(function() {
2014-02-13 19:53:33 +01:00
screen.button(button.attributes);
2015-02-06 00:32:51 +01:00
})
.appendTo(menu);
2014-02-13 19:53:33 +01:00
});
2015-02-06 00:32:51 +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
}).append(action.name))
2015-02-06 00:32:51 +01:00
.click(function() {
2014-02-20 23:36:38 +01:00
screen.save_current().then(function() {
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
.selected_records().map(function(record) {
return record.id;
});
exec_action = Sao.Action.evaluate(exec_action,
menu_action[0], screen.current_record);
var data = {
model: screen.model_name,
id: record_id,
ids: record_ids
};
Sao.Action.exec_action(exec_action, data,
screen.context);
});
2015-02-06 00:32:51 +01:00
})
.appendTo(menu);
2013-01-08 13:32:10 +01:00
});
});
});
return toolbar;
2013-01-08 14:58:18 +01: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':
return this.reload(false);
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) {
return;
}
2013-11-25 12:18:32 +01:00
this.modified_save().done(function() {
2015-07-03 19:35:28 +02:00
this.screen.new_().then(function() {
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
},
save: function() {
2013-08-21 16:26:20 +02:00
if (!Sao.common.MODELACCESS.get(this.screen.model_name).write) {
2015-05-07 12:10:11 +02:00
return jQuery.when();
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');
}.bind(this),
function() {
this.info_bar.message(
2015-07-16 22:36:11 +02:00
this.screen.invalid_message(), 'danger');
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() {
2013-11-25 12:18:32 +01:00
this.modified_save().done(function() {
this.screen.switch_view();
}.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() {
2013-11-25 12:18:32 +01:00
this.screen.save_tree_state(false);
if (this.screen.current_view.view_type != 'form') {
this.screen.search_filter(
this.screen.screen_container.search_entry.val());
2013-11-25 12:18:32 +01:00
// TODO set current_record
}
2015-07-03 19:35:28 +02:00
return this.screen.display().then(function() {
this.info_bar.message();
}.bind(this));
2013-11-25 12:18:32 +01:00
// TODO activate_save
}.bind(this));
}.bind(this);
if (test_modified) {
return this.modified_save().then(reload);
} else {
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) {
return;
}
2013-11-25 12:18:32 +01:00
this.modified_save().done(function() {
2015-07-03 19:35:28 +02:00
this.screen.copy().then(function() {
this.info_bar.message(
Sao.i18n.gettext(
'Working now on the duplicated record(s).'),
'info');
}.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']) {
return;
}
2013-11-25 12:18:32 +01:00
var msg;
if (this.screen.current_view.view_type == 'form') {
2015-05-29 10:44:10 +02:00
msg = Soa.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
}
Sao.common.sur.run(msg).done(function() {
2015-07-03 19:35:28 +02:00
this.screen.remove(true, false, true).then(
function() {
this.info_bar.message(
Sao.i18n.gettext('Records removed.'),
'info');
}.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() {
2013-11-25 12:18:32 +01:00
this.modified_save().done(function() {
this.screen.display_previous();
2015-07-03 19:35:28 +02:00
this.info_bar.message();
// TODO activate_save
2013-11-25 12:18:32 +01:00
}.bind(this));
},
next: function() {
2013-11-25 12:18:32 +01:00
this.modified_save().done(function() {
this.screen.display_next();
2015-07-03 19:35:28 +02:00
this.info_bar.message();
// TODO activate_save
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);
}
},
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');
2013-10-14 09:02:47 +00:00
return;
}
var fields = [
2015-05-29 10:44:10 +02:00
['id', Sao.i18n.gettext('ID:')],
['create_uid.rec_name',
Sao.i18n.gettext('Creation User:')],
['create_date', Sao.i18n.gettext('Creation Date:')],
['write_uid.rec_name',
Sao.i18n.gettext('Latest Modification by:')],
['write_date', Sao.i18n.gettext('Latest Modification Date:')]
2013-10-14 09:02:47 +00:00
];
this.screen.model.execute('read', [[record.id],
fields.map(function(field) {
return field[0];
})], this.screen.context)
.then(function(result) {
result = result[0];
var message = '';
fields.forEach(function(field) {
var key = field[0];
var label = field[1];
var value = result[key] || '/';
if (result[key] &&
~['create_date', 'write_date'].indexOf(key)) {
value = Sao.common.format_datetime(
Sao.common.date_format(),
'%H:%M:%S',
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
revision.setMilliseconds(revision.getMilliseconds() + 1);
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];
}
if (revision != this.screen.context._datetime) {
// Update screen context that will be propagated by
// recreating new group
this.screen.context._datetime = revision;
if (this.screen.current_view.view_type != 'form') {
this.screen.search_filter(
this.screen.screen_container
.search_entry.val());
} else {
// Test if record exist in revisions
this.screen.new_group([current_id]);
}
this.screen.display();
this.update_revision();
}
}.bind(this);
2014-03-18 19:56:07 +01:00
}.bind(this);
this.modified_save().done(function() {
var ids = this.screen.current_view.selected_records().map(
function(record) {
return record.id;
});
this.screen.model.execute('history_revisions',
[ids], this.screen.context)
.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() {
var revision = this.screen.context._datetime;
var label;
if (revision) {
var date_format = Sao.common.date_format();
var time_format = '%H:%M:%S.%f';
revision = Sao.common.format_datetime(date_format, time_format,
revision);
label = this.name_el.text() + ' @ '+ revision;
2014-03-18 19:56:07 +01:00
} else {
label = this.name_el.text();
2014-03-18 19:56:07 +01:00
}
2015-02-06 00:32:51 +01:00
this.title.html(label);
2014-03-18 19:56:07 +01:00
['new', 'save'].forEach(function(button) {
this.buttons[button].prop('disabled', revision);
}.bind(this));
},
2013-08-26 14:26:03 +02:00
attach: function() {
var record = this.screen.current_record;
if (!record || (record.id < 0)) {
return;
}
new Sao.Window.Attachment(record, function() {
this.update_attachment_count(true);
}.bind(this));
},
update_attachment_count: function(reload) {
var record = this.screen.current_record;
if (record) {
record.get_attachment_count(reload).always(
this.attachment_count.bind(this));
} else {
this.attachment_count(0);
}
},
attachment_count: function(count) {
2015-05-29 10:44:10 +02:00
var label = Sao.i18n.gettext('Attachment(%1)', count);
2015-02-06 00:32:51 +01:00
this.buttons.attach.text(label);
2013-08-26 14:26:03 +02:00
var record_id = this.screen.get_id();
this.buttons.attach.prop('disabled',
record_id < 0 || record_id === null);
2013-10-14 09:02:47 +00:00
},
2015-07-03 19:35:28 +02:00
record_message: function() {
this.info_bar.message();
},
2013-10-14 09:02:47 +00:00
action: function() {
this.buttons.action.click();
},
relate: function() {
this.buttons.relate.click();
},
print: function() {
this.buttons.print.click();
2013-01-04 21:29:48 +01: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();
this.title.html(this.name_el.text());
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.end_state);
}
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
}());