Add creatable attribute on tree and form views
issue10929 review370201002
This commit is contained in:
@@ -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
|
||||
|
||||
+15
-25
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+5
-2
@@ -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 {
|
||||
|
||||
@@ -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('<ul/>', {
|
||||
|
||||
+12
-1
@@ -281,6 +281,17 @@
|
||||
return (parseInt(this.attributes.editable || 0, 10) &&
|
||||
!this.screen.attributes.readonly);
|
||||
},
|
||||
get creatable() {
|
||||
if (this.editable) {
|
||||
if (this.attributes.creatable) {
|
||||
return Boolean(parseInt(this.attributes.creatable, 10));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
unfold: function() {
|
||||
if (!this.expander) {
|
||||
return;
|
||||
@@ -2016,7 +2027,7 @@
|
||||
this.tree.screen.model_name);
|
||||
var limit = ((this.tree.screen.size_limit !== null) &&
|
||||
(model.length >= this.tree.screen.size_limit));
|
||||
if (access.create && !limit) {
|
||||
if (this.tree.creatable && access.create && !limit) {
|
||||
prm.then(function() {
|
||||
return this.tree.screen.new_();
|
||||
}.bind(this))
|
||||
|
||||
Reference in New Issue
Block a user