|
@ -1,7 +1,7 @@ |
|
|
/* Copyright 2015-2018 Onestein (<http://www.onestein.eu>) |
|
|
/* Copyright 2015-2018 Onestein (<http://www.onestein.eu>) |
|
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
|
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
|
|
|
|
|
|
|
|
odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
|
|
|
|
|
|
odoo.define('bi_view_editor.FieldList', function (require) { |
|
|
"use strict"; |
|
|
"use strict"; |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
var core = require('web.core'); |
|
@ -9,14 +9,14 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
var Widget = require('web.Widget'); |
|
|
var Widget = require('web.Widget'); |
|
|
|
|
|
|
|
|
var FieldListContextMenu = Widget.extend({ |
|
|
var FieldListContextMenu = Widget.extend({ |
|
|
start: function() { |
|
|
|
|
|
|
|
|
start: function () { |
|
|
var res = this._super.apply(this, arguments); |
|
|
var res = this._super.apply(this, arguments); |
|
|
this.$el.mouseleave(function() { |
|
|
|
|
|
|
|
|
this.$el.mouseleave(function () { |
|
|
$(this).addClass('hidden'); |
|
|
$(this).addClass('hidden'); |
|
|
}); |
|
|
}); |
|
|
return res; |
|
|
return res; |
|
|
}, |
|
|
}, |
|
|
open: function(x, y) { |
|
|
|
|
|
|
|
|
open: function (x, y) { |
|
|
this.$el.css({ |
|
|
this.$el.css({ |
|
|
'left': x + 'px', |
|
|
'left': x + 'px', |
|
|
'top': y + 'px' |
|
|
'top': y + 'px' |
|
@ -28,7 +28,7 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
|
|
|
|
|
|
var FieldListFieldContextMenu = FieldListContextMenu.extend({ |
|
|
var FieldListFieldContextMenu = FieldListContextMenu.extend({ |
|
|
template: 'bi_view_editor.FieldList.FieldContextMenu', |
|
|
template: 'bi_view_editor.FieldList.FieldContextMenu', |
|
|
open: function(x, y, field) { |
|
|
|
|
|
|
|
|
open: function (x, y, field) { |
|
|
this.$el.find('.checkbox-column').prop('checked', field.column); |
|
|
this.$el.find('.checkbox-column').prop('checked', field.column); |
|
|
this.$el.find('.checkbox-row').prop('checked', field.row); |
|
|
this.$el.find('.checkbox-row').prop('checked', field.row); |
|
|
this.$el.find('.checkbox-measure').prop('checked', field.measure); |
|
|
this.$el.find('.checkbox-measure').prop('checked', field.measure); |
|
@ -47,7 +47,7 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
|
|
|
|
|
|
var events = this._super(x, y, field); |
|
|
var events = this._super(x, y, field); |
|
|
this.$el.find('input').unbind('change'); |
|
|
this.$el.find('input').unbind('change'); |
|
|
this.$el.find('input').change(function() { |
|
|
|
|
|
|
|
|
this.$el.find('input').change(function () { |
|
|
var $checkbox = $(this); |
|
|
var $checkbox = $(this); |
|
|
var property = $checkbox.attr('data-for'); |
|
|
var property = $checkbox.attr('data-for'); |
|
|
field[property] = $checkbox.is(':checked'); |
|
|
field[property] = $checkbox.is(':checked'); |
|
@ -60,12 +60,12 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
|
|
|
|
|
|
var FieldListJoinContextMenu = FieldListContextMenu.extend({ |
|
|
var FieldListJoinContextMenu = FieldListContextMenu.extend({ |
|
|
template: 'bi_view_editor.FieldList.JoinContextMenu', |
|
|
template: 'bi_view_editor.FieldList.JoinContextMenu', |
|
|
open: function(x, y, node) { |
|
|
|
|
|
|
|
|
open: function (x, y, node) { |
|
|
this.$el.find('.checkbox-join-left').prop('checked', node.join_left); |
|
|
this.$el.find('.checkbox-join-left').prop('checked', node.join_left); |
|
|
|
|
|
|
|
|
var events = this._super(x, y, node); |
|
|
var events = this._super(x, y, node); |
|
|
this.$el.find('input').unbind('change'); |
|
|
this.$el.find('input').unbind('change'); |
|
|
this.$el.find('input').change(function() { |
|
|
|
|
|
|
|
|
this.$el.find('input').change(function () { |
|
|
var $checkbox = $(this); |
|
|
var $checkbox = $(this); |
|
|
var property = $checkbox.attr('data-for'); |
|
|
var property = $checkbox.attr('data-for'); |
|
|
node[property] = $checkbox.is(':checked'); |
|
|
node[property] = $checkbox.is(':checked'); |
|
@ -81,7 +81,7 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
'click .delete-button': 'removeClicked', |
|
|
'click .delete-button': 'removeClicked', |
|
|
'keyup input[name="description"]': 'keyupDescription' |
|
|
'keyup input[name="description"]': 'keyupDescription' |
|
|
}, |
|
|
}, |
|
|
start: function() { |
|
|
|
|
|
|
|
|
start: function () { |
|
|
var res = this._super.apply(this, arguments); |
|
|
var res = this._super.apply(this, arguments); |
|
|
this.contextmenu = new FieldListFieldContextMenu(this); |
|
|
this.contextmenu = new FieldListFieldContextMenu(this); |
|
|
this.contextmenu.appendTo(this.$el); |
|
|
this.contextmenu.appendTo(this.$el); |
|
@ -91,8 +91,8 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
this.mode = null; |
|
|
this.mode = null; |
|
|
return res; |
|
|
return res; |
|
|
}, |
|
|
}, |
|
|
setMode: function(mode) { |
|
|
|
|
|
if(mode === 'readonly') { |
|
|
|
|
|
|
|
|
setMode: function (mode) { |
|
|
|
|
|
if (mode === 'readonly') { |
|
|
this.$el.find('input[type="text"]').attr('disabled', true); |
|
|
this.$el.find('input[type="text"]').attr('disabled', true); |
|
|
this.$el.find(".delete-button:last").addClass('hidden'); |
|
|
this.$el.find(".delete-button:last").addClass('hidden'); |
|
|
} else { |
|
|
} else { |
|
@ -101,7 +101,7 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
} |
|
|
} |
|
|
this.mode = mode; |
|
|
this.mode = mode; |
|
|
}, |
|
|
}, |
|
|
get: function() { |
|
|
|
|
|
|
|
|
get: function () { |
|
|
return $.makeArray(this.$el.find("tbody tr").map(function () { |
|
|
return $.makeArray(this.$el.find("tbody tr").map(function () { |
|
|
var field = $(this).data('field'); |
|
|
var field = $(this).data('field'); |
|
|
field.description = $(this).find('input[name="description"]').val(); |
|
|
field.description = $(this).find('input[name="description"]').val(); |
|
@ -127,20 +127,20 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
}); |
|
|
}); |
|
|
return model_data; |
|
|
return model_data; |
|
|
}, |
|
|
}, |
|
|
add: function(field) { |
|
|
|
|
|
|
|
|
add: function (field) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
field.row = typeof field.row === 'undefined' ? false : field.row; |
|
|
field.row = typeof field.row === 'undefined' ? false : field.row; |
|
|
field.column = typeof field.column === 'undefined' ? false : field.column; |
|
|
field.column = typeof field.column === 'undefined' ? false : field.column; |
|
|
field.measure = typeof field.measure === 'undefined' ? false : field.measure; |
|
|
field.measure = typeof field.measure === 'undefined' ? false : field.measure; |
|
|
field.list = typeof field.list === 'undefined' ? true : field.list; |
|
|
field.list = typeof field.list === 'undefined' ? true : field.list; |
|
|
field._id = typeof field._id === 'undefined' ? _.uniqueId('node_') : field._id; |
|
|
field._id = typeof field._id === 'undefined' ? _.uniqueId('node_') : field._id; |
|
|
if(field.join_node) { |
|
|
|
|
|
|
|
|
if (field.join_node) { |
|
|
field.join_left = typeof field.join_left === 'undefined' ? false : field.join_left; |
|
|
field.join_left = typeof field.join_left === 'undefined' ? false : field.join_left; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var i = 0; |
|
|
var i = 0; |
|
|
var name = field.name; |
|
|
var name = field.name; |
|
|
while (this.get().filter(function(item) { |
|
|
|
|
|
|
|
|
while (this.get().filter(function (item) { |
|
|
return item.name === field.name; |
|
|
return item.name === field.name; |
|
|
}).length > 0) { |
|
|
}).length > 0) { |
|
|
field.name = name + '_' + i; |
|
|
field.name = name + '_' + i; |
|
@ -150,9 +150,9 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
// Render table row
|
|
|
// Render table row
|
|
|
var $html = $(qweb.render(field.join_node ? 'bi_view_editor.JoinListItem' : 'bi_view_editor.FieldListItem', { |
|
|
var $html = $(qweb.render(field.join_node ? 'bi_view_editor.JoinListItem' : 'bi_view_editor.FieldListItem', { |
|
|
'field': field |
|
|
'field': field |
|
|
})).data('field', field).contextmenu(function(e) { |
|
|
|
|
|
|
|
|
})).data('field', field).contextmenu(function (e) { |
|
|
var $item = $(this); |
|
|
var $item = $(this); |
|
|
if(self.mode === 'readonly') { |
|
|
|
|
|
|
|
|
if (self.mode === 'readonly') { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
e.preventDefault(); |
|
|
e.preventDefault(); |
|
@ -165,7 +165,7 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
this.order(); |
|
|
this.order(); |
|
|
}, |
|
|
}, |
|
|
remove: function(id) { |
|
|
|
|
|
|
|
|
remove: function (id) { |
|
|
var $item = this.$el.find('tr[data-id="' + id + '"]'); |
|
|
var $item = this.$el.find('tr[data-id="' + id + '"]'); |
|
|
$item.remove(); |
|
|
$item.remove(); |
|
|
this.cleanJoinNodes(); |
|
|
this.cleanJoinNodes(); |
|
@ -173,53 +173,53 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
this.trigger('removed', id); |
|
|
this.trigger('removed', id); |
|
|
}, |
|
|
}, |
|
|
set: function(fields) { |
|
|
|
|
|
|
|
|
set: function (fields) { |
|
|
var set_fields = fields; |
|
|
var set_fields = fields; |
|
|
if (!set_fields) { |
|
|
if (!set_fields) { |
|
|
set_fields = []; |
|
|
set_fields = []; |
|
|
} |
|
|
} |
|
|
this.$el.find('tbody tr').remove(); |
|
|
this.$el.find('tbody tr').remove(); |
|
|
for(var i = 0; i < set_fields.length; i++) { |
|
|
|
|
|
|
|
|
for (var i = 0; i < set_fields.length; i++) { |
|
|
this.add(set_fields[i]); |
|
|
this.add(set_fields[i]); |
|
|
} |
|
|
} |
|
|
this.$el.find(".delete-button").addClass('hidden'); |
|
|
this.$el.find(".delete-button").addClass('hidden'); |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
this.$el.find(".delete-button:last").removeClass('hidden'); |
|
|
}, |
|
|
}, |
|
|
openContextMenu: function($item, x, y) { |
|
|
|
|
|
|
|
|
openContextMenu: function ($item, x, y) { |
|
|
var field = $item.data('field'); |
|
|
var field = $item.data('field'); |
|
|
var contextmenu = field.join_node ? this.contextmenu_join : this.contextmenu; |
|
|
var contextmenu = field.join_node ? this.contextmenu_join : this.contextmenu; |
|
|
// Temporary disable contextmenu for join node (until left join is implemented)
|
|
|
// Temporary disable contextmenu for join node (until left join is implemented)
|
|
|
if (field.join_node) { |
|
|
if (field.join_node) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
contextmenu.open(x - 20, y - 20, $item.data('field')).on('change', function(f) { |
|
|
|
|
|
|
|
|
contextmenu.open(x - 20, y - 20, $item.data('field')).on('change', function (f) { |
|
|
$item.data('field', f); |
|
|
$item.data('field', f); |
|
|
this.refreshItem($item); |
|
|
this.refreshItem($item); |
|
|
this.trigger('updated'); |
|
|
this.trigger('updated'); |
|
|
}.bind(this)); |
|
|
}.bind(this)); |
|
|
}, |
|
|
}, |
|
|
refreshItem: function($item) { |
|
|
|
|
|
|
|
|
refreshItem: function ($item) { |
|
|
var data = $item.data('field'); |
|
|
var data = $item.data('field'); |
|
|
var $attributes = $item.find('span[data-for], img[data-for]'); |
|
|
var $attributes = $item.find('span[data-for], img[data-for]'); |
|
|
$.each($attributes, function() { |
|
|
|
|
|
|
|
|
$.each($attributes, function () { |
|
|
var $attribute = $(this); |
|
|
var $attribute = $(this); |
|
|
var value = data[$attribute.attr('data-for')]; |
|
|
var value = data[$attribute.attr('data-for')]; |
|
|
if(value) { |
|
|
|
|
|
|
|
|
if (value) { |
|
|
$attribute.removeClass('hidden'); |
|
|
$attribute.removeClass('hidden'); |
|
|
} else { |
|
|
} else { |
|
|
$attribute.addClass('hidden'); |
|
|
$attribute.addClass('hidden'); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
removeClicked: function(e) { |
|
|
|
|
|
|
|
|
removeClicked: function (e) { |
|
|
var $button = $(e.currentTarget); |
|
|
var $button = $(e.currentTarget); |
|
|
var id = $button.attr('data-id'); |
|
|
var id = $button.attr('data-id'); |
|
|
this.remove(id); |
|
|
this.remove(id); |
|
|
}, |
|
|
}, |
|
|
keyupDescription: function() { |
|
|
|
|
|
|
|
|
keyupDescription: function () { |
|
|
this.trigger('updated'); |
|
|
this.trigger('updated'); |
|
|
}, |
|
|
}, |
|
|
cleanJoinNodes: function() { |
|
|
|
|
|
|
|
|
cleanJoinNodes: function () { |
|
|
var aliases = $.makeArray(this.$el.find("tbody tr").map(function () { |
|
|
var aliases = $.makeArray(this.$el.find("tbody tr").map(function () { |
|
|
var data = $(this).data('field'); |
|
|
var data = $(this).data('field'); |
|
|
return data.table_alias.localeCompare(data.join_node) > 0 ? data.join_node : data.table_alias; |
|
|
return data.table_alias.localeCompare(data.join_node) > 0 ? data.join_node : data.table_alias; |
|
@ -238,22 +238,22 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
getOrder: function() { |
|
|
|
|
|
|
|
|
getOrder: function () { |
|
|
var items = this.get(); |
|
|
var items = this.get(); |
|
|
var ordered = items.sort(function(a, b) { |
|
|
|
|
|
|
|
|
var ordered = items.sort(function (a, b) { |
|
|
var res = a.table_alias.localeCompare(b.table_alias); |
|
|
var res = a.table_alias.localeCompare(b.table_alias); |
|
|
if (res === 0) { |
|
|
if (res === 0) { |
|
|
var both_join_node = a.join_node && b.join_node; |
|
|
var both_join_node = a.join_node && b.join_node; |
|
|
var both_not_join_node = !a.join_node && !b.join_node; |
|
|
var both_not_join_node = !a.join_node && !b.join_node; |
|
|
if(both_join_node || both_not_join_node) { |
|
|
|
|
|
|
|
|
if (both_join_node || both_not_join_node) { |
|
|
return 0; |
|
|
return 0; |
|
|
} else if(!a.join_node && b.join_node) { |
|
|
|
|
|
if(b.table_alias.localeCompare(b.join_node) > 0) { |
|
|
|
|
|
|
|
|
} else if (!a.join_node && b.join_node) { |
|
|
|
|
|
if (b.table_alias.localeCompare(b.join_node) > 0) { |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
return -1; |
|
|
return -1; |
|
|
} else if(a.join_node && !b.join_node) { |
|
|
|
|
|
if(a.table_alias.localeCompare(a.join_node) > 0) { |
|
|
|
|
|
|
|
|
} else if (a.join_node && !b.join_node) { |
|
|
|
|
|
if (a.table_alias.localeCompare(a.join_node) > 0) { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
return 1; |
|
|
return 1; |
|
@ -263,16 +263,16 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
var res = []; |
|
|
var res = []; |
|
|
_.each(ordered, function(item) { |
|
|
|
|
|
var already_exists = _.findIndex(res, function(f) { |
|
|
|
|
|
|
|
|
_.each(ordered, function (item) { |
|
|
|
|
|
var already_exists = _.findIndex(res, function (f) { |
|
|
return f._id === item._id; |
|
|
return f._id === item._id; |
|
|
}) !== -1; |
|
|
}) !== -1; |
|
|
if(already_exists) { |
|
|
|
|
|
|
|
|
if (already_exists) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
res.push(item); |
|
|
res.push(item); |
|
|
if(item.join_node) { |
|
|
|
|
|
var join_node_fields = _.filter(ordered, function(f) { |
|
|
|
|
|
|
|
|
if (item.join_node) { |
|
|
|
|
|
var join_node_fields = _.filter(ordered, function (f) { |
|
|
return f.table_alias === item.join_node && !f.join_node; |
|
|
return f.table_alias === item.join_node && !f.join_node; |
|
|
}); |
|
|
}); |
|
|
res = _.union(res, join_node_fields); |
|
|
res = _.union(res, join_node_fields); |
|
@ -280,15 +280,15 @@ odoo.define('bi_view_editor.FieldList', function(require) { |
|
|
}); |
|
|
}); |
|
|
return res; |
|
|
return res; |
|
|
}, |
|
|
}, |
|
|
order: function() { |
|
|
|
|
|
|
|
|
order: function () { |
|
|
var order = this.getOrder(); |
|
|
var order = this.getOrder(); |
|
|
var $rows = this.$el.find("tbody tr"); |
|
|
var $rows = this.$el.find("tbody tr"); |
|
|
|
|
|
|
|
|
$rows.sort(function(a, b) { |
|
|
|
|
|
var a_index = _.findIndex(order, function(item) { |
|
|
|
|
|
|
|
|
$rows.sort(function (a, b) { |
|
|
|
|
|
var a_index = _.findIndex(order, function (item) { |
|
|
return item._id === $(a).data('field')._id; |
|
|
return item._id === $(a).data('field')._id; |
|
|
}); |
|
|
}); |
|
|
var b_index = _.findIndex(order, function(item) { |
|
|
|
|
|
|
|
|
var b_index = _.findIndex(order, function (item) { |
|
|
return item._id === $(b).data('field')._id; |
|
|
return item._id === $(b).data('field')._id; |
|
|
}); |
|
|
}); |
|
|
return a_index - b_index; |
|
|
return a_index - b_index; |
|
|