mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
pre-commit
This commit is contained in:
@@ -1,57 +1,55 @@
|
||||
/* Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
|
||||
* 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";
|
||||
|
||||
var core = require('web.core');
|
||||
var core = require("web.core");
|
||||
var qweb = core.qweb;
|
||||
var Widget = require('web.Widget');
|
||||
var Widget = require("web.Widget");
|
||||
|
||||
var FieldListContextMenu = Widget.extend({
|
||||
start: function () {
|
||||
start: function() {
|
||||
var res = this._super.apply(this, arguments);
|
||||
this.$el.mouseleave(function () {
|
||||
$(this).addClass('d-none');
|
||||
this.$el.mouseleave(function() {
|
||||
$(this).addClass("d-none");
|
||||
});
|
||||
return res;
|
||||
},
|
||||
open: function (x, y) {
|
||||
open: function(x, y) {
|
||||
this.$el.css({
|
||||
'left': x + 'px',
|
||||
'top': y + 'px',
|
||||
left: x + "px",
|
||||
top: y + "px",
|
||||
});
|
||||
this.$el.removeClass('d-none');
|
||||
this.$el.removeClass("d-none");
|
||||
return _.extend({}, window.Backbone.Events);
|
||||
},
|
||||
});
|
||||
|
||||
var FieldListFieldContextMenu = FieldListContextMenu.extend({
|
||||
template: 'bi_view_editor.FieldList.FieldContextMenu',
|
||||
open: function (x, y, field) {
|
||||
this.$el.find('.checkbox-column').prop('checked', field.column);
|
||||
this.$el.find('.checkbox-row').prop('checked', field.row);
|
||||
this.$el.find('.checkbox-measure').prop('checked', field.measure);
|
||||
this.$el.find('.checkbox-list').prop('checked', field.list);
|
||||
template: "bi_view_editor.FieldList.FieldContextMenu",
|
||||
open: function(x, y, field) {
|
||||
this.$el.find(".checkbox-column").prop("checked", field.column);
|
||||
this.$el.find(".checkbox-row").prop("checked", field.row);
|
||||
this.$el.find(".checkbox-measure").prop("checked", field.measure);
|
||||
this.$el.find(".checkbox-list").prop("checked", field.list);
|
||||
|
||||
var measureable =
|
||||
field.type === "float" ||
|
||||
field.type === "integer" ||
|
||||
field.type === "monetary"
|
||||
;
|
||||
|
||||
this.$el.find('.checkbox-column').attr('disabled', measureable);
|
||||
this.$el.find('.checkbox-row').attr('disabled', measureable);
|
||||
this.$el.find('.checkbox-measure').attr('disabled', !measureable);
|
||||
this.$el.find('.checkbox-list').attr('disabled', false);
|
||||
field.type === "monetary";
|
||||
this.$el.find(".checkbox-column").attr("disabled", measureable);
|
||||
this.$el.find(".checkbox-row").attr("disabled", measureable);
|
||||
this.$el.find(".checkbox-measure").attr("disabled", !measureable);
|
||||
this.$el.find(".checkbox-list").attr("disabled", false);
|
||||
|
||||
var events = this._super(x, y, field);
|
||||
this.$el.find('input').unbind('change');
|
||||
this.$el.find('input').change(function () {
|
||||
this.$el.find("input").unbind("change");
|
||||
this.$el.find("input").change(function() {
|
||||
var $checkbox = $(this);
|
||||
var property = $checkbox.attr('data-for');
|
||||
field[property] = $checkbox.is(':checked');
|
||||
events.trigger('change', field);
|
||||
var property = $checkbox.attr("data-for");
|
||||
field[property] = $checkbox.is(":checked");
|
||||
events.trigger("change", field);
|
||||
});
|
||||
|
||||
return events;
|
||||
@@ -59,67 +57,71 @@ odoo.define('bi_view_editor.FieldList', function (require) {
|
||||
});
|
||||
|
||||
var FieldListJoinContextMenu = FieldListContextMenu.extend({
|
||||
template: 'bi_view_editor.FieldList.JoinContextMenu',
|
||||
open: function (x, y, node) {
|
||||
this.$el.find('.checkbox-join-left').prop('checked', node.join_left);
|
||||
template: "bi_view_editor.FieldList.JoinContextMenu",
|
||||
open: function(x, y, node) {
|
||||
this.$el.find(".checkbox-join-left").prop("checked", node.join_left);
|
||||
|
||||
var events = this._super(x, y, node);
|
||||
this.$el.find('input').unbind('change');
|
||||
this.$el.find('input').change(function () {
|
||||
this.$el.find("input").unbind("change");
|
||||
this.$el.find("input").change(function() {
|
||||
var $checkbox = $(this);
|
||||
var property = $checkbox.attr('data-for');
|
||||
node[property] = $checkbox.is(':checked');
|
||||
events.trigger('change', node);
|
||||
var property = $checkbox.attr("data-for");
|
||||
node[property] = $checkbox.is(":checked");
|
||||
events.trigger("change", node);
|
||||
});
|
||||
return events;
|
||||
},
|
||||
});
|
||||
|
||||
var FieldList = Widget.extend({
|
||||
template: 'bi_view_editor.FieldList',
|
||||
template: "bi_view_editor.FieldList",
|
||||
events: {
|
||||
'click .delete-button': 'removeClicked',
|
||||
'keyup input[name="description"]': 'keyupDescription',
|
||||
"click .delete-button": "removeClicked",
|
||||
'keyup input[name="description"]': "keyupDescription",
|
||||
},
|
||||
start: function () {
|
||||
start: function() {
|
||||
var res = this._super.apply(this, arguments);
|
||||
this.contextmenu = new FieldListFieldContextMenu(this);
|
||||
this.contextmenu.appendTo(this.$el);
|
||||
this.contextmenu_join = new FieldListJoinContextMenu(this);
|
||||
this.contextmenu_join.appendTo(this.$el);
|
||||
this.$table = this.$el.find('tbody');
|
||||
this.$table = this.$el.find("tbody");
|
||||
this.mode = null;
|
||||
return res;
|
||||
},
|
||||
setMode: function (mode) {
|
||||
if (mode === 'readonly') {
|
||||
this.$el.find('input[type="text"]').attr('disabled', true);
|
||||
this.$el.find(".delete-button").addClass('d-none');
|
||||
setMode: function(mode) {
|
||||
if (mode === "readonly") {
|
||||
this.$el.find('input[type="text"]').attr("disabled", true);
|
||||
this.$el.find(".delete-button").addClass("d-none");
|
||||
} else {
|
||||
this.$el.find('input[type="text"]').removeAttr('disabled');
|
||||
this.$el.find(".delete-button").removeClass('d-none');
|
||||
this.$el.find('input[type="text"]').removeAttr("disabled");
|
||||
this.$el.find(".delete-button").removeClass("d-none");
|
||||
}
|
||||
this.mode = mode;
|
||||
},
|
||||
get: function () {
|
||||
return $.makeArray(this.$el.find("tbody tr").map(function () {
|
||||
var field = $(this).data('field');
|
||||
field.description = $(this).find('input[name="description"]').val();
|
||||
return field;
|
||||
}));
|
||||
get: function() {
|
||||
return $.makeArray(
|
||||
this.$el.find("tbody tr").map(function() {
|
||||
var field = $(this).data("field");
|
||||
field.description = $(this)
|
||||
.find('input[name="description"]')
|
||||
.val();
|
||||
return field;
|
||||
})
|
||||
);
|
||||
},
|
||||
getModelIds: function () {
|
||||
getModelIds: function() {
|
||||
var model_ids = {};
|
||||
this.$el.find("tbody tr").each(function () {
|
||||
var data = $(this).data('field');
|
||||
this.$el.find("tbody tr").each(function() {
|
||||
var data = $(this).data("field");
|
||||
model_ids[data.table_alias] = data.model_id;
|
||||
});
|
||||
return model_ids;
|
||||
},
|
||||
getModelData: function () {
|
||||
getModelData: function() {
|
||||
var model_data = {};
|
||||
this.$el.find("tbody tr").each(function () {
|
||||
var data = $(this).data('field');
|
||||
this.$el.find("tbody tr").each(function() {
|
||||
var data = $(this).data("field");
|
||||
model_data[data.table_alias] = {
|
||||
model_id: data.model_id,
|
||||
model_name: data.model_name,
|
||||
@@ -127,95 +129,114 @@ odoo.define('bi_view_editor.FieldList', function (require) {
|
||||
});
|
||||
return model_data;
|
||||
},
|
||||
add: function (field) {
|
||||
add: function(field) {
|
||||
var self = this;
|
||||
field.row = typeof field.row === 'undefined' ? false : field.row;
|
||||
field.column = typeof field.column === 'undefined' ? false : field.column;
|
||||
field.measure = typeof field.measure === 'undefined' ? false : field.measure;
|
||||
field.list = typeof field.list === 'undefined' ? true : field.list;
|
||||
field._id = typeof field._id === 'undefined' ? _.uniqueId('node_') : field._id;
|
||||
field.row = typeof field.row === "undefined" ? false : field.row;
|
||||
field.column = typeof field.column === "undefined" ? false : field.column;
|
||||
field.measure =
|
||||
typeof field.measure === "undefined" ? false : field.measure;
|
||||
field.list = typeof field.list === "undefined" ? true : field.list;
|
||||
field._id =
|
||||
typeof field._id === "undefined" ? _.uniqueId("node_") : field._id;
|
||||
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 name = field.name;
|
||||
while (this.get().filter(function (item) {
|
||||
return item.name === field.name;
|
||||
}).length > 0) {
|
||||
field.name = name + '_' + i;
|
||||
while (
|
||||
this.get().filter(function(item) {
|
||||
return item.name === field.name;
|
||||
}).length > 0
|
||||
) {
|
||||
field.name = name + "_" + i;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Render table row
|
||||
var $html = $(qweb.render(field.join_node ? 'bi_view_editor.JoinListItem' : 'bi_view_editor.FieldListItem', {
|
||||
'field': field,
|
||||
})).data('field', field).contextmenu(function (e) {
|
||||
var $item = $(this);
|
||||
if (self.mode === 'readonly') {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
self.openContextMenu($item, e.pageX, e.pageY);
|
||||
});
|
||||
var $html = $(
|
||||
qweb.render(
|
||||
field.join_node
|
||||
? "bi_view_editor.JoinListItem"
|
||||
: "bi_view_editor.FieldListItem",
|
||||
{
|
||||
field: field,
|
||||
}
|
||||
)
|
||||
)
|
||||
.data("field", field)
|
||||
.contextmenu(function(e) {
|
||||
var $item = $(this);
|
||||
if (self.mode === "readonly") {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
self.openContextMenu($item, e.pageX, e.pageY);
|
||||
});
|
||||
|
||||
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 + '"]');
|
||||
$item.remove();
|
||||
this.trigger('removed', id);
|
||||
this.trigger("removed", id);
|
||||
},
|
||||
set: function (fields) {
|
||||
set: function(fields) {
|
||||
var set_fields = fields;
|
||||
if (!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++) {
|
||||
this.add(set_fields[i]);
|
||||
}
|
||||
},
|
||||
openContextMenu: function ($item, x, y) {
|
||||
var field = $item.data('field');
|
||||
var contextmenu = field.join_node ? this.contextmenu_join : this.contextmenu;
|
||||
openContextMenu: function($item, x, y) {
|
||||
var field = $item.data("field");
|
||||
var contextmenu = field.join_node
|
||||
? this.contextmenu_join
|
||||
: this.contextmenu;
|
||||
// Temporary disable contextmenu for join node (until left join is implemented)
|
||||
if (field.join_node) {
|
||||
return;
|
||||
}
|
||||
contextmenu.open(x - 20, y - 20, $item.data('field')).on('change', function (f) {
|
||||
$item.data('field', f);
|
||||
this.refreshItem($item);
|
||||
this.trigger('updated');
|
||||
}.bind(this));
|
||||
contextmenu.open(x - 20, y - 20, $item.data("field")).on(
|
||||
"change",
|
||||
function(f) {
|
||||
$item.data("field", f);
|
||||
this.refreshItem($item);
|
||||
this.trigger("updated");
|
||||
}.bind(this)
|
||||
);
|
||||
},
|
||||
refreshItem: function ($item) {
|
||||
var data = $item.data('field');
|
||||
var $attributes = $item.find('span[data-for], img[data-for]');
|
||||
$.each($attributes, function () {
|
||||
refreshItem: function($item) {
|
||||
var data = $item.data("field");
|
||||
var $attributes = $item.find("span[data-for], img[data-for]");
|
||||
$.each($attributes, function() {
|
||||
var $attribute = $(this);
|
||||
var value = data[$attribute.attr('data-for')];
|
||||
var value = data[$attribute.attr("data-for")];
|
||||
if (value) {
|
||||
$attribute.removeClass('d-none');
|
||||
$attribute.removeClass("d-none");
|
||||
} else {
|
||||
$attribute.addClass('d-none');
|
||||
$attribute.addClass("d-none");
|
||||
}
|
||||
});
|
||||
},
|
||||
removeClicked: function (e) {
|
||||
removeClicked: function(e) {
|
||||
var $button = $(e.currentTarget);
|
||||
var id = $button.attr('data-id');
|
||||
var id = $button.attr("data-id");
|
||||
this.remove(id);
|
||||
},
|
||||
keyupDescription: function () {
|
||||
this.trigger('updated');
|
||||
keyupDescription: function() {
|
||||
this.trigger("updated");
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
'FieldList': FieldList,
|
||||
'FieldListContextMenu': FieldListContextMenu,
|
||||
'FieldListFieldContextMenu': FieldListFieldContextMenu,
|
||||
'FieldListJoinContextMenu': FieldListJoinContextMenu,
|
||||
FieldList: FieldList,
|
||||
FieldListContextMenu: FieldListContextMenu,
|
||||
FieldListFieldContextMenu: FieldListFieldContextMenu,
|
||||
FieldListJoinContextMenu: FieldListJoinContextMenu,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,48 +1,51 @@
|
||||
/* Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define('bi_view_editor.JoinNodeDialog', function (require) {
|
||||
odoo.define("bi_view_editor.JoinNodeDialog", function(require) {
|
||||
"use strict";
|
||||
|
||||
var Dialog = require("web.Dialog");
|
||||
var core = require('web.core');
|
||||
var core = require("web.core");
|
||||
var qweb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
||||
var JoinNodeDialog = Dialog.extend({
|
||||
xmlDependencies: Dialog.prototype.xmlDependencies.concat([
|
||||
'/bi_view_editor/static/src/xml/bi_view_editor.xml',
|
||||
"/bi_view_editor/static/src/xml/bi_view_editor.xml",
|
||||
]),
|
||||
events: {
|
||||
"click li": "choiceClicked",
|
||||
},
|
||||
init: function (parent, options, choices, model_data) {
|
||||
init: function(parent, options, choices, model_data) {
|
||||
this.choices = choices;
|
||||
// Prepare data for view
|
||||
for (var i = 0; i < choices.length; i++) {
|
||||
if (choices[i].join_node !== -1 && choices[i].table_alias !== -1) {
|
||||
choices[i].model_name = model_data[choices[i].table_alias].model_name;
|
||||
choices[i].model_name =
|
||||
model_data[choices[i].table_alias].model_name;
|
||||
}
|
||||
choices[i].index = i;
|
||||
}
|
||||
|
||||
var defaults = _.defaults(options || {}, {
|
||||
title: _t("Join..."),
|
||||
dialogClass: 'oe_act_window',
|
||||
$content: qweb.render('bi_view_editor.JoinNodeDialog', {
|
||||
'choices': choices,
|
||||
dialogClass: "oe_act_window",
|
||||
$content: qweb.render("bi_view_editor.JoinNodeDialog", {
|
||||
choices: choices,
|
||||
}),
|
||||
buttons: [{
|
||||
text: _t("Cancel"),
|
||||
classes: "btn-default o_form_button_cancel",
|
||||
close: true,
|
||||
}],
|
||||
buttons: [
|
||||
{
|
||||
text: _t("Cancel"),
|
||||
classes: "btn-default o_form_button_cancel",
|
||||
close: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
this._super(parent, defaults);
|
||||
},
|
||||
choiceClicked: function (e) {
|
||||
this.trigger('chosen', {
|
||||
choice: this.choices[$(e.currentTarget).attr('data-index')],
|
||||
choiceClicked: function(e) {
|
||||
this.trigger("chosen", {
|
||||
choice: this.choices[$(e.currentTarget).attr("data-index")],
|
||||
});
|
||||
this.close();
|
||||
},
|
||||
|
||||
@@ -1,87 +1,92 @@
|
||||
/* Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define('bi_view_editor.ModelList', function (require) {
|
||||
odoo.define("bi_view_editor.ModelList", function(require) {
|
||||
"use strict";
|
||||
|
||||
var Widget = require('web.Widget');
|
||||
var core = require('web.core');
|
||||
var Widget = require("web.Widget");
|
||||
var core = require("web.core");
|
||||
var qweb = core.qweb;
|
||||
|
||||
var ModelList = Widget.extend({
|
||||
template: 'bi_view_editor.ModelList',
|
||||
template: "bi_view_editor.ModelList",
|
||||
events: {
|
||||
'keyup .search-bar > input': 'filterChanged',
|
||||
"keyup .search-bar > input": "filterChanged",
|
||||
},
|
||||
init: function (parent) {
|
||||
init: function(parent) {
|
||||
var res = this._super(parent);
|
||||
this.active_models = [];
|
||||
this.cache_fields = {};
|
||||
this.current_filter = '';
|
||||
this.current_filter = "";
|
||||
this.mode = null;
|
||||
return res;
|
||||
},
|
||||
setMode: function (mode) {
|
||||
if (mode === 'readonly') {
|
||||
this.$el.find('.search-bar').attr('disabled', true);
|
||||
this.$el.find('.class-list, .class').addClass('readonly');
|
||||
setMode: function(mode) {
|
||||
if (mode === "readonly") {
|
||||
this.$el.find(".search-bar").attr("disabled", true);
|
||||
this.$el.find(".class-list, .class").addClass("readonly");
|
||||
} else {
|
||||
this.$el.find('.search-bar').attr('disabled', false);
|
||||
this.$el.find('.class-list, .class').removeClass('readonly');
|
||||
this.$el.find(".search-bar").attr("disabled", false);
|
||||
this.$el.find(".class-list, .class").removeClass("readonly");
|
||||
}
|
||||
this.mode = mode;
|
||||
},
|
||||
isActive: function (id) {
|
||||
isActive: function(id) {
|
||||
return this.active_models.indexOf(id) !== -1;
|
||||
},
|
||||
removeAsActive: function (id) {
|
||||
removeAsActive: function(id) {
|
||||
var i = this.active_models.indexOf(id);
|
||||
this.active_models.splice(i, 1);
|
||||
},
|
||||
addAsActive: function (id) {
|
||||
addAsActive: function(id) {
|
||||
this.active_models.push(id);
|
||||
},
|
||||
loadModels: function (model_ids) {
|
||||
loadModels: function(model_ids) {
|
||||
return this._rpc({
|
||||
model: 'ir.model',
|
||||
method: 'get_models',
|
||||
model: "ir.model",
|
||||
method: "get_models",
|
||||
args: model_ids ? [model_ids] : [],
|
||||
});
|
||||
},
|
||||
loadFields: function (model_id) {
|
||||
loadFields: function(model_id) {
|
||||
if (!(model_id in this.cache_fields)) {
|
||||
var deferred = this._rpc({
|
||||
model: 'ir.model',
|
||||
method: 'get_fields',
|
||||
model: "ir.model",
|
||||
method: "get_fields",
|
||||
args: [model_id],
|
||||
});
|
||||
this.cache_fields[model_id] = deferred;
|
||||
}
|
||||
return this.cache_fields[model_id];
|
||||
},
|
||||
populateModels: function (models) {
|
||||
populateModels: function(models) {
|
||||
var self = this;
|
||||
this.$el.find(".class-list").html('');
|
||||
this.$el.find(".class-list").html("");
|
||||
|
||||
_.each(models, function (model) {
|
||||
var $html = $(qweb.render('bi_view_editor.ModelListItem', {
|
||||
'id': model.id,
|
||||
'model': model.model,
|
||||
'name': model.name,
|
||||
}));
|
||||
$html.find('.class').data('model', model).click(function () {
|
||||
self.modelClicked($(this));
|
||||
});
|
||||
_.each(models, function(model) {
|
||||
var $html = $(
|
||||
qweb.render("bi_view_editor.ModelListItem", {
|
||||
id: model.id,
|
||||
model: model.model,
|
||||
name: model.name,
|
||||
})
|
||||
);
|
||||
$html
|
||||
.find(".class")
|
||||
.data("model", model)
|
||||
.click(function() {
|
||||
self.modelClicked($(this));
|
||||
});
|
||||
self.$el.find(".class-list").append($html);
|
||||
|
||||
if (self.isActive(model.id)) {
|
||||
self.loadFields(model.id).done(function (fields) {
|
||||
self.loadFields(model.id).done(function(fields) {
|
||||
self.populateFields(fields, model.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
populateFields: function (fields, model_id) {
|
||||
populateFields: function(fields, model_id) {
|
||||
var self = this;
|
||||
if (!model_id && fields.length === 0) {
|
||||
return;
|
||||
@@ -91,59 +96,72 @@ odoo.define('bi_view_editor.ModelList', function (require) {
|
||||
data_model_id = fields[0].model_id;
|
||||
}
|
||||
var $model_item = this.$el.find(".class[data-id='" + data_model_id + "']");
|
||||
_.each(fields, function (field) {
|
||||
var $field = $(qweb.render('bi_view_editor.ModelListFieldItem', {
|
||||
name: field.name,
|
||||
description: field.description,
|
||||
})).data('field', field).click(function () {
|
||||
self.fieldClicked($(this));
|
||||
}).draggable({
|
||||
'revert': 'invalid',
|
||||
'scroll': false,
|
||||
'helper': 'clone',
|
||||
'appendTo': 'body',
|
||||
'containment': 'window',
|
||||
});
|
||||
_.each(fields, function(field) {
|
||||
var $field = $(
|
||||
qweb.render("bi_view_editor.ModelListFieldItem", {
|
||||
name: field.name,
|
||||
description: field.description,
|
||||
})
|
||||
)
|
||||
.data("field", field)
|
||||
.click(function() {
|
||||
self.fieldClicked($(this));
|
||||
})
|
||||
.draggable({
|
||||
revert: "invalid",
|
||||
scroll: false,
|
||||
helper: "clone",
|
||||
appendTo: "body",
|
||||
containment: "window",
|
||||
});
|
||||
$model_item.after($field);
|
||||
|
||||
});
|
||||
},
|
||||
modelClicked: function ($el) {
|
||||
if (this.mode === 'readonly') {
|
||||
modelClicked: function($el) {
|
||||
if (this.mode === "readonly") {
|
||||
return;
|
||||
}
|
||||
var model = $el.data('model');
|
||||
$el.parent().find('.field').remove();
|
||||
var model = $el.data("model");
|
||||
$el.parent()
|
||||
.find(".field")
|
||||
.remove();
|
||||
if (this.isActive(model.id)) {
|
||||
this.removeAsActive(model.id);
|
||||
} else {
|
||||
this.addAsActive(model.id);
|
||||
this.loadFields(model.id).done(function (fields) {
|
||||
this.populateFields(fields, model.id);
|
||||
}.bind(this));
|
||||
this.loadFields(model.id).done(
|
||||
function(fields) {
|
||||
this.populateFields(fields, model.id);
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
},
|
||||
fieldClicked: function ($el) {
|
||||
if (this.mode === 'readonly') {
|
||||
fieldClicked: function($el) {
|
||||
if (this.mode === "readonly") {
|
||||
return;
|
||||
}
|
||||
this.trigger('field_clicked', $el.data('field'));
|
||||
this.trigger("field_clicked", $el.data("field"));
|
||||
},
|
||||
filterChanged: function (e) {
|
||||
filterChanged: function(e) {
|
||||
var $input = $(e.target);
|
||||
this.filter($input.val());
|
||||
},
|
||||
filter: function (value) {
|
||||
filter: function(value) {
|
||||
this.active_models = [];
|
||||
this.$el.find('.field').remove();
|
||||
var val = typeof value === 'undefined' ? this.current_filter : value.toLowerCase();
|
||||
this.$el.find(".class").each(function () {
|
||||
var data = $(this).data('model');
|
||||
if (data.name.toLowerCase().indexOf(val) === -1 &&
|
||||
data.model.toLowerCase().indexOf(val) === -1) {
|
||||
$(this).addClass('d-none');
|
||||
this.$el.find(".field").remove();
|
||||
var val =
|
||||
typeof value === "undefined"
|
||||
? this.current_filter
|
||||
: value.toLowerCase();
|
||||
this.$el.find(".class").each(function() {
|
||||
var data = $(this).data("model");
|
||||
if (
|
||||
data.name.toLowerCase().indexOf(val) === -1 &&
|
||||
data.model.toLowerCase().indexOf(val) === -1
|
||||
) {
|
||||
$(this).addClass("d-none");
|
||||
} else {
|
||||
$(this).removeClass('d-none');
|
||||
$(this).removeClass("d-none");
|
||||
}
|
||||
});
|
||||
this.current_filter = val;
|
||||
@@ -151,5 +169,4 @@ odoo.define('bi_view_editor.ModelList', function (require) {
|
||||
});
|
||||
|
||||
return ModelList;
|
||||
|
||||
});
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
/* Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
|
||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define('bi_view_editor', function (require) {
|
||||
odoo.define("bi_view_editor", function(require) {
|
||||
"use strict";
|
||||
|
||||
var JoinNodeDialog = require('bi_view_editor.JoinNodeDialog');
|
||||
var ModelList = require('bi_view_editor.ModelList');
|
||||
var FieldList = require('bi_view_editor.FieldList').FieldList;
|
||||
var JoinNodeDialog = require("bi_view_editor.JoinNodeDialog");
|
||||
var ModelList = require("bi_view_editor.ModelList");
|
||||
var FieldList = require("bi_view_editor.FieldList").FieldList;
|
||||
|
||||
var AbstractField = require('web.AbstractField');
|
||||
var Data = require('web.data');
|
||||
var field_registry = require('web.field_registry');
|
||||
var AbstractField = require("web.AbstractField");
|
||||
var Data = require("web.data");
|
||||
var field_registry = require("web.field_registry");
|
||||
|
||||
var BiViewEditor = AbstractField.extend({
|
||||
template: "bi_view_editor.Frame",
|
||||
events: {
|
||||
"click .clear-btn": "clear",
|
||||
},
|
||||
start: function () {
|
||||
start: function() {
|
||||
var self = this;
|
||||
var res = this._super.apply(this, arguments);
|
||||
|
||||
// Init ModelList
|
||||
this.model_list = new ModelList(this);
|
||||
this.model_list.appendTo(this.$(".body > .left"));
|
||||
this.model_list.on('field_clicked', this, function (field) {
|
||||
this.model_list.on("field_clicked", this, function(field) {
|
||||
self.addField(_.extend({}, field));
|
||||
});
|
||||
|
||||
// Init FieldList
|
||||
this.field_list = new FieldList(this);
|
||||
this.field_list.appendTo(this.$(".body > .right"));
|
||||
this.field_list.on('removed', this, this.fieldListRemoved);
|
||||
this.field_list.on('updated', this, this.fieldListChanged);
|
||||
this.field_list.on("removed", this, this.fieldListRemoved);
|
||||
this.field_list.on("updated", this, this.fieldListChanged);
|
||||
|
||||
this.$el.find(".body > .right").droppable({
|
||||
accept: "div.class-list div.field",
|
||||
drop: function (event, ui) {
|
||||
self.addField(_.extend({}, ui.draggable.data('field')));
|
||||
ui.draggable.draggable('option', 'revert', false);
|
||||
drop: function(event, ui) {
|
||||
self.addField(_.extend({}, ui.draggable.data("field")));
|
||||
ui.draggable.draggable("option", "revert", false);
|
||||
},
|
||||
});
|
||||
|
||||
this.on("change:effective_readonly", this, function () {
|
||||
this.on("change:effective_readonly", this, function() {
|
||||
this.updateMode();
|
||||
});
|
||||
this.renderValue();
|
||||
@@ -50,61 +50,65 @@ odoo.define('bi_view_editor', function (require) {
|
||||
this.updateMode();
|
||||
return res;
|
||||
},
|
||||
clear: function () {
|
||||
if (this.mode !== 'readonly') {
|
||||
clear: function() {
|
||||
if (this.mode !== "readonly") {
|
||||
this.field_list.set([]);
|
||||
this.loadAndPopulateModelList();
|
||||
this._setValue(this.field_list.get());
|
||||
}
|
||||
},
|
||||
fieldListChanged: function () {
|
||||
fieldListChanged: function() {
|
||||
this._setValue(this.field_list.get());
|
||||
},
|
||||
fieldListRemoved: function () {
|
||||
fieldListRemoved: function() {
|
||||
console.log(this.field_list.get());
|
||||
this._setValue(this.field_list.get());
|
||||
var model = new Data.DataSet(this, "bve.view");
|
||||
model.call('get_clean_list', [this.value]).then(function (result) {
|
||||
this.field_list.set(JSON.parse(result));
|
||||
this._setValue(this.field_list.get());
|
||||
}.bind(this));
|
||||
model.call("get_clean_list", [this.value]).then(
|
||||
function(result) {
|
||||
this.field_list.set(JSON.parse(result));
|
||||
this._setValue(this.field_list.get());
|
||||
}.bind(this)
|
||||
);
|
||||
this.loadAndPopulateModelList();
|
||||
},
|
||||
renderValue: function () {
|
||||
renderValue: function() {
|
||||
this.field_list.set(JSON.parse(this.value));
|
||||
},
|
||||
updateMode: function () {
|
||||
if (this.mode === 'readonly') {
|
||||
this.$el.find('.clear-btn').addClass('d-none');
|
||||
updateMode: function() {
|
||||
if (this.mode === "readonly") {
|
||||
this.$el.find(".clear-btn").addClass("d-none");
|
||||
this.$el.find(".body .right").droppable("option", "disabled", true);
|
||||
} else {
|
||||
this.$el.find('.clear-btn').removeClass('d-none');
|
||||
this.$el.find('.body .right').droppable('option', 'disabled', false);
|
||||
this.$el.find(".clear-btn").removeClass("d-none");
|
||||
this.$el.find(".body .right").droppable("option", "disabled", false);
|
||||
}
|
||||
this.field_list.setMode(this.mode);
|
||||
this.model_list.setMode(this.mode);
|
||||
},
|
||||
loadAndPopulateModelList: function () {
|
||||
loadAndPopulateModelList: function() {
|
||||
var model_ids = null;
|
||||
if (this.field_list.get().length > 0) {
|
||||
model_ids = this.field_list.getModelIds();
|
||||
}
|
||||
this.model_list.loadModels(model_ids).done(function (models) {
|
||||
this.model_list.populateModels(models);
|
||||
}.bind(this));
|
||||
this.model_list.loadModels(model_ids).done(
|
||||
function(models) {
|
||||
this.model_list.populateModels(models);
|
||||
}.bind(this)
|
||||
);
|
||||
},
|
||||
getTableAlias: function (field) {
|
||||
if (typeof field.table_alias === 'undefined') {
|
||||
getTableAlias: function(field) {
|
||||
if (typeof field.table_alias === "undefined") {
|
||||
var model_ids = this.field_list.getModelIds();
|
||||
var n = 1;
|
||||
while (typeof model_ids["t" + n] !== 'undefined') {
|
||||
while (typeof model_ids["t" + n] !== "undefined") {
|
||||
n++;
|
||||
}
|
||||
return "t" + n;
|
||||
}
|
||||
return field.table_alias;
|
||||
},
|
||||
addFieldAndJoinNode: function (field, join_node) {
|
||||
addFieldAndJoinNode: function(field, join_node) {
|
||||
if (join_node.join_node === -1 || join_node.table_alias === -1) {
|
||||
field.table_alias = this.getTableAlias(field);
|
||||
if (join_node.join_node === -1) {
|
||||
@@ -121,31 +125,37 @@ odoo.define('bi_view_editor', function (require) {
|
||||
this.loadAndPopulateModelList();
|
||||
this._setValue(this.field_list.get());
|
||||
},
|
||||
addField: function (field) {
|
||||
addField: function(field) {
|
||||
var data = _.extend({}, field);
|
||||
var model = new Data.DataSet(this, "ir.model");
|
||||
var field_data = this.field_list.get();
|
||||
model.call('get_join_nodes', [field_data, data]).then(function (result) {
|
||||
if (result.length === 1) {
|
||||
this.addFieldAndJoinNode(data, result[0]);
|
||||
} else if (result.length > 1) {
|
||||
var dialog = new JoinNodeDialog(this, {}, result, this.field_list.getModelData());
|
||||
dialog.open().on('chosen', this, function (e) {
|
||||
this.addFieldAndJoinNode(data, e.choice);
|
||||
});
|
||||
} else {
|
||||
data.table_alias = this.getTableAlias(data);
|
||||
this.field_list.add(data);
|
||||
this.loadAndPopulateModelList();
|
||||
this._setValue(this.field_list.get());
|
||||
}
|
||||
}.bind(this));
|
||||
model.call("get_join_nodes", [field_data, data]).then(
|
||||
function(result) {
|
||||
if (result.length === 1) {
|
||||
this.addFieldAndJoinNode(data, result[0]);
|
||||
} else if (result.length > 1) {
|
||||
var dialog = new JoinNodeDialog(
|
||||
this,
|
||||
{},
|
||||
result,
|
||||
this.field_list.getModelData()
|
||||
);
|
||||
dialog.open().on("chosen", this, function(e) {
|
||||
this.addFieldAndJoinNode(data, e.choice);
|
||||
});
|
||||
} else {
|
||||
data.table_alias = this.getTableAlias(data);
|
||||
this.field_list.add(data);
|
||||
this.loadAndPopulateModelList();
|
||||
this._setValue(this.field_list.get());
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
},
|
||||
_parseValue: function (value) {
|
||||
_parseValue: function(value) {
|
||||
return JSON.stringify(value);
|
||||
},
|
||||
});
|
||||
|
||||
field_registry.add('BVEEditor', BiViewEditor);
|
||||
|
||||
field_registry.add("BVEEditor", BiViewEditor);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user