sao-base/src/view.js

90 lines
2.9 KiB
JavaScript
Raw Permalink 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.View = Sao.class_(Object, {
init: function(screen, xml) {
this.screen = screen;
this.view_type = null;
this.el = null;
this.view_id = null;
2013-03-04 19:08:16 +01:00
this.fields = {};
2015-03-27 10:39:52 +01:00
var attributes = xml.children()[0].attributes;
this.attributes = {};
for (var i = 0, len = attributes.length; i < len; i++) {
var attribute = attributes[i];
this.attributes[attribute.name] = attribute.value;
}
screen.set_on_write(this.attributes.on_write);
2013-03-04 19:08:16 +01:00
},
set_value: function() {
},
get_fields: function() {
return Object.keys(this.fields);
},
selected_records: function() {
return [];
},
get_buttons: function() {
return [];
2013-01-04 21:29:48 +01:00
}
});
2012-11-29 11:32:58 +01:00
Sao.View.idpath2path = function(tree, idpath) {
var path = [];
var child_path;
if (!idpath) {
return [];
}
for (var i = 0, len = tree.rows.length; i < len; i++) {
if (tree.rows[i].record.id == idpath[0]) {
path.push(i);
child_path = Sao.View.idpath2path(tree.rows[i],
idpath.slice(1, idpath.length));
path = path.concat(child_path);
break;
}
}
return path;
};
2013-01-04 21:29:48 +01:00
Sao.View.parse = function(screen, xml, children_field) {
switch (xml.children().prop('tagName')) {
case 'tree':
return new Sao.View.Tree(screen, xml, children_field);
case 'form':
return new Sao.View.Form(screen, xml);
2015-05-29 18:44:24 +02:00
case 'graph':
return new Sao.View.Graph(screen, xml);
2015-10-11 13:56:11 +02:00
case 'calendar':
return new Sao.View.Calendar(screen, xml);
2013-01-04 21:29:48 +01:00
}
};
2012-11-29 11:32:58 +01:00
Sao.View.resize = function(el) {
// Let the browser compute the table size with the fixed layout
// then set this size to the treeview to allow scroll on overflow
// and set the table layout to auto to get the width from the content.
if (!el) {
el = jQuery(document);
}
el.find('.treeview').each(function() {
var treeview = jQuery(this);
treeview.css('width', '100%');
treeview.children('.tree').css('table-layout', 'fixed');
});
el.find('.treeview').each(function() {
var treeview = jQuery(this);
if (treeview.width()) {
treeview.css('width', treeview.width());
treeview.children('.tree').css('table-layout', 'auto');
}
});
};
jQuery(window).resize(function() {
Sao.View.resize();
});
2013-01-04 21:29:48 +01:00
}());