Permalink
Browse files

[REV][IMP] base: Improve search and ordering in settings

This reverts commit 01173f3.

This commit added improvements in search and ordering of settings. However
due to DOM manipulation some events are not bound correctly. Notably saving
settings could be broken if several different tabs are modified before
saving.

After checking more in-depth settings code it appears it will be difficult
to ensure a proper re-rendering and re-ordering of settings without having
to modify deeply the code. This is therefore more a task for JS framework
team.

closes #29285
  • Loading branch information...
tde-banana-odoo committed Dec 5, 2018
1 parent 7398706 commit 58997a955759b8ffeaecff428dab7c83d08d09ad
@@ -21,7 +21,6 @@ var BaseSettingRenderer = FormRenderer.extend({
this._super.apply(this, arguments);
this.activeView = false;
this.activeTab = false;
this.initialTabElements = undefined;
},
start: function () {
@@ -200,17 +199,6 @@ var BaseSettingRenderer = FormRenderer.extend({
* @param {int} index
*/
_moveToTab: function (index) {
//Used to reorder the settings after a search and a tab switch
//Thought it would be better for the UX if the order stayed the same as the one on the left panel
var settingsNode = this.$('.settings')[0];
if(!this.initialTabElements && settingsNode){
//Converts an HtmlCollection into an array
this.initialTabElements = Array.prototype.slice.call(settingsNode.children);
} else {
this.$('.settings')
.empty()
.append(this.initialTabElements)
}
this.currentIndex = !index || index === -1 ? 0 : (index === this.modules.length ? index - 1 : index);
if (this.currentIndex !== -1) {
if (this.activeView) {
@@ -248,6 +236,7 @@ var BaseSettingRenderer = FormRenderer.extend({
_onKeyUpSearch: function (event) {
this.searchText = this.searchInput.val();
this.activeTab.removeClass('selected');
if (config.device.isMobile) {
this.$('.settings_tab').addClass('o_hidden');
this.$('.settings').addClass('d-block');
@@ -310,19 +299,13 @@ var BaseSettingRenderer = FormRenderer.extend({
_searchSetting: function () {
var self = this;
this.count = 0;
var settings = $(this.$el.find('.settings')[0].children);
//Results for active module should be at the top
var active_key = self.$el.find('.selected')[0].attributes['data-key'].value;
var selectedModule = self.$el.find('.app_settings_block[data-key="' + active_key + '"]');
var toInsertBefore = $(settings[1]);
selectedModule.insertBefore(toInsertBefore);
_.each(this.modules, function (module) {
self.inVisibleCount = 0;
module.settingView.find('.o_setting_box').addClass('o_hidden');
module.settingView.find('h2').addClass('o_hidden');
module.settingView.find('.settingSearchHeader').addClass('o_hidden');
module.settingView.find('.o_settings_container').removeClass('mt16');
var resultSetting = module.settingView.find(".o_form_label:containsTextLike('" + self.searchText + "'), .text-muted:containsTextLike('"+ self.searchText +"')");
var resultSetting = module.settingView.find("label:containsTextLike('" + self.searchText + "')");
if (resultSetting.length > 0) {
resultSetting.each(function () {
var settingBox = $(this).closest('.o_setting_box');
@@ -178,97 +178,5 @@ QUnit.module('base_settings_tests', {
form.destroy();
});
QUnit.test('Settings from the selected module are at the top results of a search', function (assert) {
assert.expect(3);
var form = createView({
View: BaseSettingsView,
model: 'project',
data: this.data,
arch: '<form string="Settings" class="oe_form_configuration o_base_settings">' +
'<div class="o_panel">' +
'<div class="setting_search">' +
'<input type="text" class="searchInput" placeholder="Search..."/>' +
'</div> ' +
'</div> ' +
'<header>' +
'<button string="Save" type="object" name="execute" class="oe_highlight" />' +
'<button string="Cancel" type="object" name="cancel" class="oe_link" />' +
'</header>' +
'<div class="o_setting_container">' +
'<div class="settings_tab">'+
'<div class="tab" data-key="crm">'+
'<span>CRM</span>'+
'</div>'+
'<div class="tab" data-key="sale">'+
'<span>Sales</span>'+
'</div>'+
'</div>'+
'<div class="settings">' +
'<div class="notFound o_hidden">No Record Found</div>' +
'<div class="app_settings_block" string="CRM" data-key="crm">' +
'<div class="row mt16 o_settings_container">'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="bar"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label class="o_form_label" for="bar"/>'+
'<div class="text-muted">'+
'this is bar'+
'</div>'+
'</div>' +
'</div>'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="foo"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label class="o_form_label" for="foo"/>'+
'<div class="text-muted">'+
'this is foo'+
'</div>'+
'</div>' +
'</div>'+
'</div>' +
'</div>' +
'<div class="app_settings_block" string="Sale" data-key="sale">' +
'<div class="row mt16 o_settings_container">'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="bar"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label for="bar"/>'+
'<div class="text-muted">'+
'this is bar'+
'</div>'+
'</div>' +
'</div>'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="foo"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label for="foo"/>'+
'<div class="text-muted">'+
'this is foo'+
'</div>'+
'</div>' +
'</div>'+
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</form>',
});
form.$('.tab,[data-key="sale"]').click()
assert.strictEqual(form.$('.tab.selected').attr('data-key'),"sale","sale setting selected");
form.$('.searchInput').val('t').trigger('keyup');
assert.strictEqual($('.highlighter').html(),"t","t word highlighted");
assert.strictEqual($(form.$('.settings')[0].children[1]).attr('data-key'),"sale","Results from Sales are at the top");
form.destroy();
});
});
});

0 comments on commit 58997a9

Please sign in to comment.