diff --git a/CHANGELOG b/CHANGELOG index 64d95a80f3..f9f6ebbc8b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add support of expand attribute on group tag * Add the context model name in the screen context * Add sum of records on list view * Add shortcuts to Date and DateTime widgets diff --git a/src/view/form.js b/src/view/form.js index 588fe7b49a..63111e02b1 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -26,6 +26,8 @@ function eval_pyson(value){ this.state_widgets = []; this.containers = []; this.notebooks = []; + this.expandables = []; + var root = xml.children()[0]; var container = this.parse(screen.model, root); this.el.append(container.el); @@ -261,10 +263,19 @@ function eval_pyson(value){ } }); } - var group = new Sao.View.Form.Group(attributes); - group.add(this.parse(model, node)); - this.state_widgets.push(group); - container.add(attributes, group); + + var widget; + if (attributes.expandable !== undefined) { + widget = new Sao.View.Form.Expander(attributes); + widget.set_expanded(attributes.expandable === '1'); + this.expandables.push(widget); + } else { + widget = new Sao.View.Form.Group(attributes); + } + widget.add(this.parse(model, node)); + + this.state_widgets.push(widget); + container.add(attributes, widget); }, _parse_paned: function(model, node, container, attributes, orientation) { @@ -385,7 +396,7 @@ function eval_pyson(value){ }, set_cursor: function(new_, reset_view) { var i, name, j; - var focus_el, notebook, child; + var focus_el, notebook, child, group; var widgets, error_el, pages, is_ancestor; var currently_focused = jQuery(document.activeElement); @@ -448,6 +459,14 @@ function eval_pyson(value){ } } } + for (i = 0; i < this.expandables.length; i++) { + group = this.expandables[i]; + is_ancestor = ( + jQuery(focus_el).closest(group.el).length > 0); + if (is_ancestor) { + group.set_expanded(true); + } + } jQuery(focus_el).find('input,select,textarea') .addBack(focus_el).focus(); } @@ -830,6 +849,59 @@ function eval_pyson(value){ } }); + Sao.View.Form.Expander = Sao.class_(Sao.View.Form.StateWidget, { + class_: 'form-group-expandable', + init: function(attributes) { + Sao.View.Form.Expander._super.init.call(this, attributes); + this.el = jQuery('
', { + 'class': 'panel panel-default ' + this.class_ + }); + var heading = jQuery('
', { + 'class': 'panel-heading', + }).appendTo(this.el); + heading.uniqueId(); + + this.collapsible = jQuery('
', { + 'class': 'panel-collapse collapse', + 'aria-labelledby': heading.attr('id'), + }).appendTo(this.el); + this.collapsible.uniqueId(); + this.body = jQuery('
', { + 'class': 'panel-body', + }).appendTo(this.collapsible); + + var title = jQuery('