Test if current view is defined on screen before using it
Closes #13178 (grafted from 6f0ae4c7719fbf129ffd0221aa9b1fa008df23e2) --HG-- branch : 7.0
This commit is contained in:
1 parent
3c67364ddd
commit
3d976ba795
2 files changed
+127
-73
No files matched your search
+70
-38
@@ -1317,13 +1317,15 @@
|
||||
},
|
||||
load: function(ids, set_cursor=true, modified=false, position=-1) {
|
||||
this.group.load(ids, modified, position);
|
||||
this.current_view.reset();
|
||||
if (this.current_view) {
|
||||
this.current_view.reset();
|
||||
}
|
||||
this.current_record = null;
|
||||
return this.display(set_cursor);
|
||||
},
|
||||
display: function(set_cursor) {
|
||||
var deferreds = [];
|
||||
if (this.views) {
|
||||
if (this.views && this.current_view) {
|
||||
var search_prm = this.search_active(
|
||||
~['tree', 'graph', 'calendar'].indexOf(
|
||||
this.current_view.view_type));
|
||||
@@ -1359,8 +1361,9 @@
|
||||
},
|
||||
_get_next_record: function() {
|
||||
var view = this.current_view;
|
||||
if (~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
|
||||
this.current_record && this.current_record.group) {
|
||||
if (view &&
|
||||
~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
|
||||
this.current_record && this.current_record.group) {
|
||||
var group = this.current_record.group;
|
||||
var record = this.current_record;
|
||||
while (group) {
|
||||
@@ -1389,16 +1392,19 @@
|
||||
},
|
||||
display_next: function() {
|
||||
var view = this.current_view;
|
||||
view.set_value();
|
||||
if (view) {
|
||||
view.set_value();
|
||||
}
|
||||
this.set_cursor(false, false);
|
||||
this.current_record = this._get_next_record();
|
||||
this.set_cursor(false, false);
|
||||
return view.display();
|
||||
return view ? view.display() : jQuery.when();
|
||||
},
|
||||
_get_previous_record: function() {
|
||||
var view = this.current_view;
|
||||
if (~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
|
||||
this.current_record && this.current_record.group) {
|
||||
if (view &&
|
||||
~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
|
||||
this.current_record && this.current_record.group) {
|
||||
var group = this.current_record.group;
|
||||
var record = this.current_record;
|
||||
while (group) {
|
||||
@@ -1427,11 +1433,13 @@
|
||||
},
|
||||
display_previous: function() {
|
||||
var view = this.current_view;
|
||||
view.set_value();
|
||||
if (view) {
|
||||
view.set_value();
|
||||
}
|
||||
this.set_cursor(false, false);
|
||||
this.current_record = this._get_previous_record();
|
||||
this.set_cursor(false, false);
|
||||
return view.display();
|
||||
return view ? view.display() : jQuery.when();
|
||||
},
|
||||
get selected_records() {
|
||||
if (this.current_view) {
|
||||
@@ -1469,8 +1477,9 @@
|
||||
});
|
||||
},
|
||||
default_row_activate: function() {
|
||||
if ((this.current_view.view_type == 'tree') &&
|
||||
(this.current_view.attributes.keyword_open == 1)) {
|
||||
if (this.current_view &&
|
||||
(this.current_view.view_type == 'tree') &&
|
||||
(this.current_view.attributes.keyword_open == 1)) {
|
||||
const id = this.get_id();
|
||||
if (id) {
|
||||
Sao.Action.exec_keyword('tree_open', {
|
||||
@@ -1493,14 +1502,15 @@
|
||||
new_: function(default_=true, defaults=null) {
|
||||
var previous_view = this.current_view;
|
||||
var prm = jQuery.when();
|
||||
if (this.current_view.view_type == 'calendar') {
|
||||
if (this.current_view &&
|
||||
this.current_view.view_type == 'calendar') {
|
||||
var selected_date = this.current_view.get_selected_date();
|
||||
}
|
||||
if (this.current_view && !this.current_view.creatable) {
|
||||
prm = this.switch_view('form', undefined, true, false);
|
||||
}
|
||||
return prm.then(() => {
|
||||
if (!this.current_view.editable) {
|
||||
if (!this.current_view || !this.current_view.editable) {
|
||||
return;
|
||||
}
|
||||
var group;
|
||||
@@ -1581,23 +1591,26 @@
|
||||
save_current: function() {
|
||||
var current_record = this.current_record;
|
||||
if (!current_record) {
|
||||
if ((this.current_view.view_type == 'tree') &&
|
||||
this.group && this.group.length) {
|
||||
if (this.current_view &&
|
||||
(this.current_view.view_type == 'tree') &&
|
||||
this.group && this.group.length) {
|
||||
this.current_record = this.group[0];
|
||||
current_record = this.current_record;
|
||||
} else {
|
||||
return jQuery.when();
|
||||
}
|
||||
}
|
||||
this.current_view.set_value();
|
||||
var fields = this.current_view.get_fields();
|
||||
if (this.current_view) {
|
||||
this.current_view.set_value();
|
||||
var fields = this.current_view.get_fields();
|
||||
}
|
||||
var path = current_record.get_path(this.group);
|
||||
var prm = jQuery.Deferred();
|
||||
if (this.current_view.view_type == 'tree') {
|
||||
if (this.current_view && (this.current_view.view_type == 'tree')) {
|
||||
prm = this.group.save().then(() => this.current_record);
|
||||
} else if (current_record.validate(fields, null, null, true)) {
|
||||
prm = current_record.save().then(() => current_record);
|
||||
} else {
|
||||
} else if (this.current_view) {
|
||||
return this.current_view.display().then(() => {
|
||||
this.set_cursor();
|
||||
return jQuery.Deferred().reject();
|
||||
@@ -1631,7 +1644,7 @@
|
||||
var test = function(record) {
|
||||
return (record.modified || record.id < 0);
|
||||
};
|
||||
if (this.current_view.view_type != 'tree') {
|
||||
if (this.current_view && (this.current_view.view_type != 'tree')) {
|
||||
if (this.current_record) {
|
||||
if (test(this.current_record)) {
|
||||
return true;
|
||||
@@ -1642,20 +1655,24 @@
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.current_view.modified) {
|
||||
if (this.current_view && this.current_view.modified) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
unremove: function() {
|
||||
var records = this.current_view.selected_records;
|
||||
for (const record of records) {
|
||||
record.group.unremove(record);
|
||||
if (this.current_view) {
|
||||
var records = this.current_view.selected_records;
|
||||
for (const record of records) {
|
||||
record.group.unremove(record);
|
||||
}
|
||||
}
|
||||
},
|
||||
remove: function(delete_, remove, force_remove, records) {
|
||||
var prm = jQuery.when();
|
||||
records = records || this.current_view.selected_records;
|
||||
if (!records && this.current_view) {
|
||||
records = this.current_view.selected_records;
|
||||
}
|
||||
if (jQuery.isEmptyObject(records)) {
|
||||
return prm;
|
||||
}
|
||||
@@ -1696,7 +1713,8 @@
|
||||
},
|
||||
copy: function() {
|
||||
var dfd = jQuery.Deferred();
|
||||
var records = this.current_view.selected_records;
|
||||
var records = (
|
||||
this.current_view ? this.current_view.selected_records : []);
|
||||
this.model.copy(records, this.context)
|
||||
.then(new_ids => {
|
||||
this.group.load(new_ids, false, this.new_position);
|
||||
@@ -1877,14 +1895,18 @@
|
||||
if (!this.current_record) {
|
||||
return null;
|
||||
}
|
||||
this.current_view.set_value();
|
||||
if (this.current_view) {
|
||||
this.current_view.set_value();
|
||||
}
|
||||
return this.current_record.get();
|
||||
},
|
||||
get_on_change_value: function() {
|
||||
if (!this.current_record) {
|
||||
return null;
|
||||
}
|
||||
this.current_view.set_value();
|
||||
if (this.current_view) {
|
||||
this.current_view.set_value();
|
||||
}
|
||||
return this.current_record.get_on_change_value();
|
||||
},
|
||||
reload: function(ids, written) {
|
||||
@@ -1901,11 +1923,13 @@
|
||||
});
|
||||
},
|
||||
get_buttons: function() {
|
||||
var selected_records = this.current_view.selected_records;
|
||||
var selected_records = (
|
||||
this.current_view ? this.current_view.selected_records : []);
|
||||
if (jQuery.isEmptyObject(selected_records)) {
|
||||
return [];
|
||||
}
|
||||
var buttons = this.current_view.get_buttons();
|
||||
var buttons = (
|
||||
this.current_view ? this.current_view.get_buttons() : []);
|
||||
for (const record of selected_records) {
|
||||
buttons = buttons.filter(function(button) {
|
||||
if (button.attributes.type === 'instance') {
|
||||
@@ -1935,9 +1959,11 @@
|
||||
});
|
||||
};
|
||||
|
||||
var selected_records = this.current_view.selected_records;
|
||||
this.current_view.set_value();
|
||||
var fields = this.current_view.get_fields();
|
||||
if (this.current_view) {
|
||||
var selected_records = this.current_view.selected_records;
|
||||
this.current_view.set_value();
|
||||
var fields = this.current_view.get_fields();
|
||||
}
|
||||
|
||||
var prms = [];
|
||||
const reset_state = record => {
|
||||
@@ -2029,7 +2055,8 @@
|
||||
} else if (action.startsWith('switch')) {
|
||||
this.switch_view.apply(this, action.split(' ', 3).slice(1));
|
||||
} else if (action == 'reload') {
|
||||
if (~['tree', 'graph', 'calendar'].indexOf(this.current_view.view_type) &&
|
||||
if (this.current_view &&
|
||||
~['tree', 'graph', 'calendar'].indexOf(this.current_view.view_type) &&
|
||||
!this.group.parent) {
|
||||
this.search_filter();
|
||||
}
|
||||
@@ -2068,7 +2095,7 @@
|
||||
var path = ['model', this.model_name];
|
||||
var view_ids = this.views.map(
|
||||
function(v) {return v.view_id;}).concat(this.view_ids);
|
||||
if (this.current_view.view_type != 'form') {
|
||||
if (this.current_view && (this.current_view.view_type != 'form')) {
|
||||
var search_value;
|
||||
if (this.attributes.search_value) {
|
||||
search_value = this.attributes.search_value;
|
||||
@@ -2081,8 +2108,10 @@
|
||||
}
|
||||
} else if (this.current_record && (this.current_record.id > -1)) {
|
||||
path.push(this.current_record.id);
|
||||
var i = view_ids.indexOf(this.current_view.view_id);
|
||||
view_ids = view_ids.slice(i).concat(view_ids.slice(0, i));
|
||||
if (this.current_view) {
|
||||
var i = view_ids.indexOf(this.current_view.view_id);
|
||||
view_ids = view_ids.slice(i).concat(view_ids.slice(0, i));
|
||||
}
|
||||
}
|
||||
if (!jQuery.isEmptyObject(view_ids)) {
|
||||
query_string.push(['views', dumps(view_ids)]);
|
||||
@@ -2176,6 +2205,9 @@
|
||||
set_tree_state: function() {
|
||||
var parent_, state, state_prm, tree_state_model;
|
||||
var view = this.current_view;
|
||||
if (!view) {
|
||||
return jQuery.when();
|
||||
}
|
||||
if (!~['tree', 'form', 'list-form'].indexOf(view.view_type)) {
|
||||
return jQuery.when();
|
||||
}
|
||||
|
||||
@@ -116,11 +116,10 @@ class Screen:
|
||||
return child
|
||||
|
||||
# Remove first level Viewport and ScrolledWindow to fill the Vbox
|
||||
for widget in [
|
||||
self.context_screen.screen_container.viewport,
|
||||
self.context_screen.current_view.widget.get_children()[0],
|
||||
]:
|
||||
remove_bin(widget)
|
||||
remove_bin(self.context_screen.screen_container.viewport)
|
||||
if self.context_screen.current_view:
|
||||
remove_bin(
|
||||
self.context_screen.current_view.widget.get_children()[0])
|
||||
|
||||
self.screen_container.filter_vbox.pack_start(
|
||||
context_widget, expand=False, fill=True, padding=0)
|
||||
@@ -520,7 +519,8 @@ class Screen:
|
||||
self.group.destroy()
|
||||
|
||||
def default_row_activate(self):
|
||||
if (self.current_view.view_type == 'tree'
|
||||
if (self.current_view
|
||||
and self.current_view.view_type == 'tree'
|
||||
and int(self.current_view.attributes.get('keyword_open', 0))):
|
||||
return Action.exec_keyword('tree_open', {
|
||||
'model': self.model_name,
|
||||
@@ -642,7 +642,7 @@ class Screen:
|
||||
|
||||
def new(self, default=True, defaults=None):
|
||||
previous_view = self.current_view
|
||||
if self.current_view.view_type == 'calendar':
|
||||
if self.current_view and self.current_view.view_type == 'calendar':
|
||||
selected_date = self.current_view.get_selected_date()
|
||||
if self.current_view and not self.current_view.creatable:
|
||||
self.switch_view(creatable=True)
|
||||
@@ -695,16 +695,19 @@ class Screen:
|
||||
|
||||
def save_current(self):
|
||||
if not self.current_record:
|
||||
if self.current_view.view_type == 'tree' and len(self.group):
|
||||
if (self.current_view
|
||||
and self.current_view.view_type == 'tree'
|
||||
and len(self.group)):
|
||||
self.current_record = self.group[0]
|
||||
else:
|
||||
return True
|
||||
self.current_view.set_value()
|
||||
saved = False
|
||||
record_id = None
|
||||
fields = self.current_view.get_fields()
|
||||
if self.current_view:
|
||||
self.current_view.set_value()
|
||||
fields = self.current_view.get_fields()
|
||||
path = self.current_record.get_path(self.group)
|
||||
if self.current_view.view_type == 'tree':
|
||||
if self.current_view and self.current_view.view_type == 'tree':
|
||||
# False value must be not saved
|
||||
saved = all((
|
||||
x is not False and x >= 0
|
||||
@@ -714,7 +717,7 @@ class Screen:
|
||||
record_id = self.current_record.save(force_reload=True)
|
||||
# False value must be not saved
|
||||
saved = record_id is not False and record_id >= 0
|
||||
else:
|
||||
elif self.current_view:
|
||||
self.set_cursor()
|
||||
self.current_view.display()
|
||||
return False
|
||||
@@ -742,17 +745,19 @@ class Screen:
|
||||
def get(self):
|
||||
if not self.current_record:
|
||||
return None
|
||||
self.current_view.set_value()
|
||||
if self.current_view:
|
||||
self.current_view.set_value()
|
||||
return self.current_record.get()
|
||||
|
||||
def get_on_change_value(self):
|
||||
if not self.current_record:
|
||||
return None
|
||||
self.current_view.set_value()
|
||||
if self.current_view:
|
||||
self.current_view.set_value()
|
||||
return self.current_record.get_on_change_value()
|
||||
|
||||
def modified(self):
|
||||
if self.current_view.view_type != 'tree':
|
||||
if self.current_view and self.current_view.view_type != 'tree':
|
||||
if self.current_record:
|
||||
if self.current_record.modified or self.current_record.id < 0:
|
||||
return True
|
||||
@@ -760,7 +765,7 @@ class Screen:
|
||||
for record in self.group:
|
||||
if record.modified or record.id < 0:
|
||||
return True
|
||||
if self.current_view.modified:
|
||||
if self.current_view and self.current_view.modified:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -829,6 +834,8 @@ class Screen:
|
||||
|
||||
def set_tree_state(self):
|
||||
view = self.current_view
|
||||
if not view:
|
||||
return
|
||||
if view.view_type not in {'tree', 'form', 'list-form'}:
|
||||
return
|
||||
if id(view) in self.tree_states_done:
|
||||
@@ -938,12 +945,13 @@ class Screen:
|
||||
|
||||
def load(self, ids, set_cursor=True, modified=False, position=-1):
|
||||
self.group.load(ids, modified=modified, position=position)
|
||||
self.current_view.reset()
|
||||
if self.current_view:
|
||||
self.current_view.reset()
|
||||
self.current_record = None
|
||||
self.display(set_cursor=set_cursor)
|
||||
|
||||
def display(self, set_cursor=False):
|
||||
if self.views:
|
||||
if self.views and self.current_view:
|
||||
self.search_active(self.current_view.view_type
|
||||
in ('tree', 'graph', 'calendar'))
|
||||
for view in self.views:
|
||||
@@ -975,7 +983,8 @@ class Screen:
|
||||
|
||||
def _get_next_record(self, test=False):
|
||||
view = self.current_view
|
||||
if (view.view_type in {'tree', 'form'}
|
||||
if (view
|
||||
and view.view_type in {'tree', 'form'}
|
||||
and self.current_record
|
||||
and self.current_record.group):
|
||||
group = self.current_record.group
|
||||
@@ -1003,12 +1012,14 @@ class Screen:
|
||||
record = next
|
||||
break
|
||||
return record
|
||||
elif (view.view_type == 'list-form' and len(self.group)
|
||||
elif (view
|
||||
and view.view_type == 'list-form'
|
||||
and len(self.group)
|
||||
and self.current_record in self.group):
|
||||
idx = self.group.index(self.current_record)
|
||||
if 0 <= idx < len(self.group) - 1:
|
||||
return self.group[idx + 1]
|
||||
elif view.view_type == 'calendar':
|
||||
elif view and view.view_type == 'calendar':
|
||||
record = self.current_record
|
||||
goocalendar = view.widgets.get('goocalendar')
|
||||
if goocalendar:
|
||||
@@ -1042,15 +1053,18 @@ class Screen:
|
||||
|
||||
def display_next(self):
|
||||
view = self.current_view
|
||||
view.set_value()
|
||||
if view:
|
||||
view.set_value()
|
||||
self.set_cursor(reset_view=False)
|
||||
self.current_record = self._get_next_record()
|
||||
self.set_cursor(reset_view=False)
|
||||
view.display()
|
||||
if view:
|
||||
view.display()
|
||||
|
||||
def _get_prev_record(self, test=False):
|
||||
view = self.current_view
|
||||
if (view.view_type in {'tree', 'form'}
|
||||
if (view
|
||||
and view.view_type in {'tree', 'form'}
|
||||
and self.current_record
|
||||
and self.current_record.group):
|
||||
group = self.current_record.group
|
||||
@@ -1068,7 +1082,7 @@ class Screen:
|
||||
if parent and record.model_name == parent.model_name:
|
||||
record = parent
|
||||
return record
|
||||
elif view.view_type == 'calendar':
|
||||
elif view and view.view_type == 'calendar':
|
||||
record = self.current_record
|
||||
goocalendar = view.widgets.get('goocalendar')
|
||||
if goocalendar:
|
||||
@@ -1093,7 +1107,9 @@ class Screen:
|
||||
if prev_id >= 0:
|
||||
return events[prev_id].record
|
||||
break
|
||||
elif (view.view_type == 'list-form' and len(self.group)
|
||||
elif (view
|
||||
and view.view_type == 'list-form'
|
||||
and len(self.group)
|
||||
and self.current_record in self.group):
|
||||
idx = self.group.index(self.current_record)
|
||||
if 0 < idx <= len(self.group) - 1:
|
||||
@@ -1107,11 +1123,13 @@ class Screen:
|
||||
|
||||
def display_prev(self):
|
||||
view = self.current_view
|
||||
view.set_value()
|
||||
if view:
|
||||
view.set_value()
|
||||
self.set_cursor(reset_view=False)
|
||||
self.current_record = self._get_prev_record()
|
||||
self.set_cursor(reset_view=False)
|
||||
view.display()
|
||||
if view:
|
||||
view.display()
|
||||
|
||||
def invalid_message(self, record=None):
|
||||
if record is None:
|
||||
@@ -1184,7 +1202,7 @@ class Screen:
|
||||
if not self.selected_records:
|
||||
return []
|
||||
|
||||
buttons = self.current_view.get_buttons()
|
||||
buttons = self.current_view.get_buttons() if self.current_view else []
|
||||
|
||||
for record in self.selected_records:
|
||||
buttons = [b for b in buttons if is_active(record, b)]
|
||||
@@ -1194,8 +1212,9 @@ class Screen:
|
||||
|
||||
def button(self, button):
|
||||
'Execute button on the selected records'
|
||||
self.current_view.set_value()
|
||||
fields = self.current_view.get_fields()
|
||||
if self.current_view:
|
||||
self.current_view.set_value()
|
||||
fields = self.current_view.get_fields()
|
||||
for record in self.selected_records:
|
||||
domain = record.expr_eval(
|
||||
button.get('states', {})).get('pre_validate', [])
|
||||
@@ -1276,7 +1295,9 @@ class Screen:
|
||||
elif action.startswith('switch'):
|
||||
self.switch_view(*action.split(None, 2)[1:])
|
||||
elif action == 'reload':
|
||||
if (self.current_view.view_type in ['tree', 'graph', 'calendar']
|
||||
if (self.current_view
|
||||
and self.current_view.view_type in [
|
||||
'tree', 'graph', 'calendar']
|
||||
and not self.parent):
|
||||
self.search_filter()
|
||||
elif action == 'reload menu':
|
||||
@@ -1306,7 +1327,7 @@ class Screen:
|
||||
cls=JSONEncoder, separators=(',', ':'))))
|
||||
path = [CONFIG['login.db'], 'model', self.model_name]
|
||||
view_ids = [v.view_id for v in self.views] + self.view_ids
|
||||
if self.current_view.view_type != 'form':
|
||||
if self.current_view and self.current_view.view_type != 'form':
|
||||
if self.search_value:
|
||||
search_value = self.search_value
|
||||
else:
|
||||
@@ -1318,8 +1339,9 @@ class Screen:
|
||||
separators=(',', ':'))))
|
||||
elif self.current_record and self.current_record.id > -1:
|
||||
path.append(str(self.current_record.id))
|
||||
i = view_ids.index(self.current_view.view_id)
|
||||
view_ids = view_ids[i:] + view_ids[:i]
|
||||
if self.current_view:
|
||||
i = view_ids.index(self.current_view.view_id)
|
||||
view_ids = view_ids[i:] + view_ids[:i]
|
||||
if view_ids:
|
||||
query_string.append(('views', json.dumps(
|
||||
view_ids, separators=(',', ':'))))
|
||||
|
||||
Reference in new issue
Block a user