Add reload toolbar function

This commit is contained in:
Cédric Krier committed 2013-03-22 16:56:41 +01:00
1 parent e03c62a063
commit f18e378be1
4 files changed
+128 -2

No files matched your search

+43 -1
View File
@@ -41,7 +41,7 @@
},
delete_: function(records) {
if (jQuery.isEmptyObject(records)) {
return;
return jQuery.when();
}
var record = records[0];
var root_group = record.group.root_group;
@@ -151,6 +151,44 @@
this.changed();
return record;
};
array.remove = function(record, remove, modified, force_remove) {
if (modified === undefined) {
modified = true;
}
var idx = this.indexOf(record);
if (record.id >= 0) {
if (remove) {
if (record in this.record_deleted) {
this.record_deleted.splice(
this.record_deleted.indexOf(record), 1);
}
this.record_removed.push(record);
} else {
if (record in this.record_removed) {
this.record_removed.splice(
this.record_removed.indexOf(record), 1);
}
this.record_deleted.push(record);
}
}
if (record.parent) {
record.parent._changed.id = true;
}
if (modified) {
record._changed.id = true;
}
if (!(record.parent) || (record.id < 0) || force_remove) {
this._remove(record);
}
record.group.changed();
record.group.root_group().screens.forEach(function(screen) {
screen.display();
});
};
array._remove = function(record) {
var idx = this.indexOf(record);
this.splice(idx, 1);
};
array.changed = function() {
if (!this.parent) {
return;
@@ -483,6 +521,10 @@
var result = true;
// TODO
return result;
},
cancel: function() {
this._loaded = {};
this._changed = {};
}
});
+58
View File
@@ -179,6 +179,16 @@
// TODO editable
return position;
},
cancel_current: function() {
var prms = [];
if (this.current_record) {
this.current_record.cancel();
if (this.current_record.id < 0) {
prms.push(this.remove());
}
}
return jQuery.when(prms);
},
save_current: function() {
if (!this.current_record) {
if ((this.current_view.view_type == 'tree') &&
@@ -225,6 +235,54 @@
}
// TODO test view modified
return false;
},
remove: function(delete_, remove, force_remove) {
var result = jQuery.Deferred();
var records = null;
if ((this.current_view.view_type == 'form') &&
this.current_record) {
records = [this.current_record];
} else if (this.current_view.view_type == 'tree') {
records = this.current_view.selected_records();
}
if (jQuery.isEmptyObject(records)) {
return;
}
var prm = jQuery.when();
if (delete_) {
// TODO delete children before parent
prm = this.model.delete_(records);
}
prm.done(function() {
records.forEach(function(record) {
record.group.remove(record, remove, true, force_remove);
});
var prms = [];
if (delete_) {
records.forEach(function(record) {
if (record.parent) {
prms.push(record.parent.save());
}
if (record in record.group.record_deleted) {
record.group.record_deleted.splice(
record.group.record_deleted.indexOf(record), 1);
}
if (record in record.group.record_removed) {
record.group.record_removed.splice(
record.group.record_removed.indexOf(record), 1);
}
// TODO destroy
});
}
// TODO set current_record
this.current_record = null;
// TODO set_cursor
jQuery.when(prms).done(function() {
this.display();
result.resolve();
}.bind(this));
}.bind(this));
return result;
}
});
}());
+14
View File
@@ -194,6 +194,20 @@
switch_: function() {
// TODO modified
this.screen.switch_view();
},
reload: function(test_modified) {
if (test_modified && this.screen.modified()) {
// TODO popup
}
this.screen.cancel_current().done(function() {
if (this.screen.current_view.view_type != 'form') {
this.screen.search_filter(); // TODO set search text
// TODO set current_record
}
this.screen.display();
// TODO message
// TODO activate_save
}.bind(this));
}
});
}());
+13 -1
View File
@@ -181,6 +181,15 @@
this.screen.current_record = record;
// TODO validate if editable
// TODO update_children
},
selected_records: function() {
var records = [];
this.columns.forEach(function(column) {
if (column.is_selected()) {
records.push(column.record);
}
});
return records;
}
});
@@ -277,11 +286,14 @@
},
select_row: function() {
this.el.toggleClass('ui-state-highlight');
if (this.el.hasClass('ui-state-highlight')) {
if (this.is_selected()) {
this.tree.select_changed(this.record);
} else {
this.tree.select_changed(null);
}
},
is_selected: function() {
return this.el.hasClass('ui-state-highlight');
}
});