From f70fa8e80d521b01b37ebf4c02c6fb8cc0c0f296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 16 Dec 2021 22:26:04 +0100 Subject: [PATCH] Add creatable attribute on tree and form views issue10929 review370201002 --- CHANGELOG | 2 ++ src/screen.js | 40 +++++++++++++++------------------------- src/view.js | 1 + src/view/calendar.js | 1 + src/view/form.js | 7 +++++-- src/view/list_form.js | 7 +++++-- src/view/tree.js | 13 ++++++++++++- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 813abd1138..b2b3367124 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Manage creatable attribute of view + Version 6.2.0 - 2021-11-01 * Bug fixes (see mercurial logs for details) * Support grouping attribute diff --git a/src/screen.js b/src/screen.js index f388773dee..9b979d4bfe 100644 --- a/src/screen.js +++ b/src/screen.js @@ -941,7 +941,7 @@ get number_of_views() { return this.views.length + this.view_to_load.length; }, - switch_view: function(view_type, view_id, display) { + switch_view: function(view_type, view_id, creatable, display) { display = display === undefined ? true : display; if ((view_id !== undefined) && (view_id !== null)) { view_id = Number(view_id); @@ -969,14 +969,17 @@ if (!this.current_view) { return false; } - else if (!view_type && (view_id === null)) { - return false; + var result = true; + if ((view_type !== undefined) && (view_type !== null)) { + result &= this.current_view.view_type == view_type; } - else if (view_id !== null) { - return this.current_view.view_id == view_id; - } else { - return this.current_view.view_type == view_type; + if ((view_id !== undefined) && (view_id !== null)) { + result &= this.current_view.view_id == view_id; } + if ((creatable !== undefined) && (creatable !== null)) { + result &= this.current_view.creatable == creatable; + } + return result; }.bind(this); var _switch = function() { var set_container = function() { @@ -995,21 +998,12 @@ } }.bind(this)); }.bind(this); - var continue_loop = function() { - if (!view_type && (view_id === null)) { - return false; - } - if (view_type && !view_id && !this.view_to_load.length) { - return false; - } - return true; - }.bind(this); var set_current_view = function() { this.current_view = this.views[this.views.length - 1]; }.bind(this); var switch_current_view = (function() { set_current_view(); - if (continue_loop()) { + if (!found()) { return _switch(); } else { return set_container(); @@ -1019,7 +1013,7 @@ return view.view_id == view_id; }; - while (!found()) { + for (var n = 0; n < this.views.length + this.view_to_load.length; n++) { if (this.view_to_load.length) { return this.load_next_view().then(switch_current_view); } else if ((view_id !== null) && @@ -1031,7 +1025,7 @@ this.current_view = this.views[ (i + 1) % this.views.length]; } - if (!continue_loop()) { + if (found()) { break; } } @@ -1461,13 +1455,9 @@ var prm = jQuery.when(); if (this.current_view.view_type == 'calendar') { var selected_date = this.current_view.get_selected_date(); - prm = this.switch_view('form', undefined, false); } - if (this.current_view && - ((this.current_view.view_type == 'tree' && - !this.current_view.editable) || - this.current_view.view_type == 'graph')) { - prm = this.switch_view('form', undefined, false); + if (this.current_view && !this.current_view.creatable) { + prm = this.switch_view('form', undefined, true, false); } return prm.then(function() { if (!this.current_view.editable) { diff --git a/src/view.js b/src/view.js index 1c59324d55..80740d01e2 100644 --- a/src/view.js +++ b/src/view.js @@ -10,6 +10,7 @@ view_id: null, modified: null, editable: null, + creatable: null, children_field: null, xml_parser: null, init: function(view_id, screen, xml) { diff --git a/src/view/calendar.js b/src/view/calendar.js index 51ae25784b..c179120808 100644 --- a/src/view/calendar.js +++ b/src/view/calendar.js @@ -83,6 +83,7 @@ /* Fullcalendar works with utc date, the default week start day depends on the user language, the events dates are handled by moment object. */ editable: false, + creatable: false, view_type: 'calendar', xml_parser: Sao.View.CalendarXMLViewParser, init: function(view_id, screen, xml) { diff --git a/src/view/form.js b/src/view/form.js index e451002494..c8febfd5c8 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -275,6 +275,7 @@ function eval_pyson(value){ Sao.View.Form = Sao.class_(Sao.View, { editable: true, + creatable: true, view_type: 'form', xml_parser: Sao.View.FormXMLViewParser, init: function(view_id, screen, xml) { @@ -286,6 +287,9 @@ function eval_pyson(value){ this.containers = []; this.widget_id = 0; Sao.View.Form._super.init.call(this, view_id, screen, xml); + if (this.attributes.creatable) { + this.creatable = Boolean(parseInt(this.attributes.creatable, 10)); + } }, get_fields: function() { return Object.keys(this.widgets); @@ -3456,8 +3460,7 @@ function eval_pyson(value){ sequence, this.screen.new_position); } }.bind(this); - if (this.screen.current_view.type == 'form' || - this.screen.current_view.editable) { + if (this.screen.current_view.creatable) { this.screen.new_().then(update_sequence); this.screen.current_view.el.prop('disabled', false); } else { diff --git a/src/view/list_form.js b/src/view/list_form.js index eb5eeef7a1..bfd45b1c71 100644 --- a/src/view/list_form.js +++ b/src/view/list_form.js @@ -4,7 +4,6 @@ 'use strict'; Sao.View.ListGroupViewForm = Sao.class_(Sao.View.Form, { - editable: true, get record() { return this._record; }, @@ -14,10 +13,14 @@ }); Sao.View.ListForm = Sao.class_(Sao.View, { + editable: true, + creatable: true, view_type: 'list-form', init: function(view_id, screen, xml) { Sao.View.ListForm._super.init.call(this, view_id, screen, xml); - this.editable = true; + if (this.attributes.creatable) { + this.creatable = Boolean(parseInt(this.attributes.creatable, 10)); + } this.form_xml = xml; this.el = jQuery('