Add "More" button on tree view and implement next/previous

review1058002
This commit is contained in:
C?dric Krier 2013-09-13 10:35:11 +02:00
parent 54e203b14b
commit 809e14e070
5 changed files with 109 additions and 33 deletions

View File

@ -414,7 +414,7 @@
var context = jQuery.extend({}, this.get_context());
if (loading == 'eager') {
var limit = 1000; // TODO use config
var limit = Sao.config.limit;
if (!this.group.parent) {
// If not a children no need to load too much
limit = parseInt(limit / fnames_to_fetch.length, 10);
@ -487,7 +487,7 @@
record.set(value);
}
}
};
}.bind(this);
var failed = function() {
var failed_values = [];
var default_values;

View File

@ -37,6 +37,7 @@ var Sao = {};
Sao.config = {};
Sao.config.limit = 1000;
Sao.config.display_size = 20;
Sao.login = function() {
var dfd = jQuery.Deferred();

View File

@ -139,7 +139,7 @@
this.new_group();
this.current_view = null;
this.current_record = null;
this.limit = attributes.limit || 80;
this.limit = attributes.limit || Sao.config.limit;
this.offset = 0;
this.search_count = 0;
this.screen_container = new Sao.ScreenContainer(
@ -322,10 +322,58 @@
}
},
display_next: function() {
// TODO
var view = this.current_view;
view.set_value();
// TODO set cursor
if (~['tree', '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) {
var index = group.indexOf(record);
if (index < group.length - 1) {
record = group[index + 1];
break;
} else if (group.parent) {
record = group.parent;
group = group.parent.group;
} else {
break;
}
}
this.set_current_record(record);
} else {
this.set_current_record(this.group[0]);
}
// TODO set cursor
view.display();
},
display_previous: function() {
// TODO
var view = this.current_view;
view.set_value();
// TODO set cursor
if (~['tree', '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) {
var index = group.indexOf(record);
if (index > 0) {
record = group[index - 1];
break;
} else if (group.parent) {
record = group.parent;
group = group.parent.group;
} else {
break;
}
}
this.set_current_record(record);
} else {
this.set_current_record(this.group[0]);
}
// TODO set cursor
view.display();
},
default_row_activate: function() {
if ((this.current_view.view_type == 'tree') &&

View File

@ -226,6 +226,20 @@
// TODO activate_save
}.bind(this));
},
previous: function() {
if (!this.modified_save()) {
return;
}
this.screen.display_previous();
// TODO message and activate_save
},
next: function() {
if (!this.modified_save()) {
return;
}
this.screen.display_next();
// TODO message and activate_save
},
attach: function() {
var record = this.screen.current_record;
if (!record || (record.id < 0)) {

View File

@ -100,32 +100,18 @@
this.tbody = jQuery('<tbody/>');
this.table.append(this.tbody);
// Footer with pagination stuff
// Footer for more
var footer = jQuery('<div/>', {
'class': 'treefooter'
});
this.previous_button = jQuery('<button/>').button({
'disabled': true,
'icons': {
primary: 'ui-icon-triangle-1-w'
},
'text': false,
'label': 'Previous' //TODO translation
});
footer.append(this.previous_button);
this.pagination = jQuery('<span/>', {
text: '0 / 0'
});
footer.append(this.pagination);
this.next_button = jQuery('<button/>').button({
'disabled': true,
'icons': {
primary: 'ui-icon-triangle-1-e'
},
'text': false,
'label': 'Next' //TODO translation
});
this.pagination.append(this.next_button);
this.more = jQuery('<button/>').button({
'label': 'More' // TODO translation
}).click(function() {
this.display_size += Sao.config.display_size;
this.display();
}.bind(this));
footer.append(this.more);
this.display_size = Sao.config.display_size;
this.el.append(footer);
},
create_columns: function(model, xml) {
@ -202,6 +188,10 @@
},
display: function() {
var selected = this.selected_records();
var current_record = this.screen.current_record;
if (current_record && !~selected.indexOf(current_record)) {
selected = [current_record];
}
this.rows = [];
this.tbody.empty();
var add_row = function(record, pos, group) {
@ -209,7 +199,12 @@
this.rows.push(tree_row);
tree_row.display(selected);
};
this.screen.group.forEach(add_row.bind(this));
this.screen.group.slice(0, this.display_size).forEach(add_row.bind(this));
if (this.display_size >= this.screen.group.length) {
this.more.hide();
} else {
this.more.show();
}
},
switch_: function(path) {
this.screen.row_activate();
@ -228,6 +223,13 @@
row.rows.forEach(add_record);
};
this.rows.forEach(add_record);
if (this.selection.prop('checked') &&
!this.selection.prop('indeterminate')) {
this.screen.group.slice(this.rows.length)
.forEach(function(record) {
records.push(record);
});
}
return records;
},
selection_changed: function() {
@ -244,11 +246,16 @@
}
},
update_selection: function() {
if (this.selection.prop('checked')) {
return;
}
var selected_records = this.selected_records();
this.selection.prop('indeterminate', false);
if (jQuery.isEmptyObject(selected_records)) {
this.selection.prop('checked', false);
} else if (selected_records.length == this.tbody.children().length) {
} else if (selected_records.length ==
this.tbody.children().length &&
this.display_size >= this.screen.group.length) {
this.selection.prop('checked', true);
} else {
this.selection.prop('indeterminate', true);
@ -398,13 +405,19 @@
},
set_selection: function(value) {
this.selection.prop('checked', value);
if (value) {
this.el.addClass('ui-state-highlight');
} else {
this.tree.selection.prop('checked', false);
this.el.removeClass('ui-state-highlight');
}
},
selection_changed: function() {
if (this.is_selected()) {
this.el.addClass('ui-state-highlight');
var is_selected = this.is_selected();
this.set_selection(is_selected);
if (is_selected) {
this.tree.select_changed(this.record);
} else {
this.el.removeClass('ui-state-highlight');
this.tree.select_changed(
this.tree.selected_records()[0] || null);
}