|
@ -1,7 +1,7 @@ |
|
|
/* Copyright 2015-2019 Onestein (<https://www.onestein.eu>) |
|
|
/* Copyright 2015-2019 Onestein (<https://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"); |
|
@ -11,14 +11,14 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
|
|
|
|
|
|
var FieldListContextMenu = Widget.extend( |
|
|
var FieldListContextMenu = Widget.extend( |
|
|
_.extend({}, mixins.EventDispatcherMixin, { |
|
|
_.extend({}, mixins.EventDispatcherMixin, { |
|
|
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("d-none"); |
|
|
$(this).addClass("d-none"); |
|
|
}); |
|
|
}); |
|
|
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", |
|
@ -31,7 +31,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, $item) { |
|
|
|
|
|
|
|
|
open: function (x, y, $item) { |
|
|
var field = $item.data("field"); |
|
|
var field = $item.data("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); |
|
@ -49,7 +49,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"); |
|
@ -62,13 +62,13 @@ 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, $item) { |
|
|
|
|
|
|
|
|
open: function (x, y, $item) { |
|
|
var node = $item.data("field"); |
|
|
var node = $item.data("field"); |
|
|
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"); |
|
@ -84,14 +84,14 @@ 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); |
|
|
this.contextmenu.on( |
|
|
this.contextmenu.on( |
|
|
"change", |
|
|
"change", |
|
|
this, |
|
|
this, |
|
|
function(f, $item) { |
|
|
|
|
|
|
|
|
function (f, $item) { |
|
|
$item.data("field", f); |
|
|
$item.data("field", f); |
|
|
this.refreshItem($item); |
|
|
this.refreshItem($item); |
|
|
this.trigger("updated"); |
|
|
this.trigger("updated"); |
|
@ -102,7 +102,7 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
this.contextmenu_join.on( |
|
|
this.contextmenu_join.on( |
|
|
"change", |
|
|
"change", |
|
|
this, |
|
|
this, |
|
|
function(f, $item) { |
|
|
|
|
|
|
|
|
function (f, $item) { |
|
|
$item.data("field", f); |
|
|
$item.data("field", f); |
|
|
this.refreshItem($item); |
|
|
this.refreshItem($item); |
|
|
this.trigger("updated"); |
|
|
this.trigger("updated"); |
|
@ -112,7 +112,7 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
this.mode = null; |
|
|
this.mode = null; |
|
|
return res; |
|
|
return res; |
|
|
}, |
|
|
}, |
|
|
setMode: function(mode) { |
|
|
|
|
|
|
|
|
setMode: function (mode) { |
|
|
if (mode === "readonly") { |
|
|
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").addClass("d-none"); |
|
|
this.$el.find(".delete-button").addClass("d-none"); |
|
@ -122,28 +122,26 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
} |
|
|
} |
|
|
this.mode = mode; |
|
|
this.mode = mode; |
|
|
}, |
|
|
}, |
|
|
get: function() { |
|
|
|
|
|
|
|
|
get: function () { |
|
|
return $.makeArray( |
|
|
return $.makeArray( |
|
|
this.$el.find("tbody tr").map(function() { |
|
|
|
|
|
|
|
|
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(); |
|
|
return field; |
|
|
return field; |
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
getModelIds: function() { |
|
|
|
|
|
|
|
|
getModelIds: function () { |
|
|
var model_ids = {}; |
|
|
var model_ids = {}; |
|
|
this.$el.find("tbody tr").each(function() { |
|
|
|
|
|
|
|
|
this.$el.find("tbody tr").each(function () { |
|
|
var data = $(this).data("field"); |
|
|
var data = $(this).data("field"); |
|
|
model_ids[data.table_alias] = data.model_id; |
|
|
model_ids[data.table_alias] = data.model_id; |
|
|
}); |
|
|
}); |
|
|
return model_ids; |
|
|
return model_ids; |
|
|
}, |
|
|
}, |
|
|
getModelData: function() { |
|
|
|
|
|
|
|
|
getModelData: function () { |
|
|
var model_data = {}; |
|
|
var model_data = {}; |
|
|
this.$el.find("tbody tr").each(function() { |
|
|
|
|
|
|
|
|
this.$el.find("tbody tr").each(function () { |
|
|
var data = $(this).data("field"); |
|
|
var data = $(this).data("field"); |
|
|
model_data[data.table_alias] = { |
|
|
model_data[data.table_alias] = { |
|
|
model_id: data.model_id, |
|
|
model_id: data.model_id, |
|
@ -152,7 +150,7 @@ 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; |
|
@ -169,7 +167,7 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
var i = 0; |
|
|
var i = 0; |
|
|
var name = field.name; |
|
|
var name = field.name; |
|
|
while ( |
|
|
while ( |
|
|
this.get().filter(function(item) { |
|
|
|
|
|
|
|
|
this.get().filter(function (item) { |
|
|
return item.name === field.name; |
|
|
return item.name === field.name; |
|
|
}).length > 0 |
|
|
}).length > 0 |
|
|
) { |
|
|
) { |
|
@ -189,7 +187,7 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
.data("field", field) |
|
|
.data("field", field) |
|
|
.contextmenu(function(e) { |
|
|
|
|
|
|
|
|
.contextmenu(function (e) { |
|
|
var $item = $(this); |
|
|
var $item = $(this); |
|
|
if (self.mode === "readonly") { |
|
|
if (self.mode === "readonly") { |
|
|
return; |
|
|
return; |
|
@ -200,12 +198,12 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
|
|
|
|
|
|
this.$el.find("tbody").append($html); |
|
|
this.$el.find("tbody").append($html); |
|
|
}, |
|
|
}, |
|
|
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.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 = []; |
|
@ -215,7 +213,7 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
this.add(set_fields[i]); |
|
|
this.add(set_fields[i]); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
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 |
|
|
var contextmenu = field.join_node |
|
|
? this.contextmenu_join |
|
|
? this.contextmenu_join |
|
@ -226,10 +224,10 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
} |
|
|
} |
|
|
contextmenu.open(x - 20, y - 20, $item); |
|
|
contextmenu.open(x - 20, y - 20, $item); |
|
|
}, |
|
|
}, |
|
|
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) { |
|
@ -239,12 +237,12 @@ odoo.define("bi_view_editor.FieldList", function(require) { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
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"); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|