},
startup : function() {
+ var _this = this;
this.selectionMode = 'single';
this.sequence = openils.widget.AutoGrid.sequence++;
openils.widget.AutoGrid.gridCache[this.sequence] = this;
this.setStore(this.buildAutoStore());
this.cachedQueryOpts = {};
this._showing_create_pane = false;
-
- if(this.showColumnPicker) {
- if(!this.columnPersistKey) {
- console.error("No columnPersistKey defined");
- } else {
- var picker = new openils.widget.GridColumnPicker(
- openils.User.authtoken, this.columnPersistKey, this);
- if(openils.User.authtoken) {
- picker.load();
- } else {
- openils.Util.addOnLoad(function() { picker.load() });
- }
- }
- }
-
this.overrideEditWidgets = {};
this.overrideEditWidgetClass = {};
this.overrideWidgetArgs = {};
href : 'javascript:void(0);',
onclick : function() {
if (!self.filterDialog) {
- self.filterDialog = new openils.widget.PCrudFilterDialog({fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields})
+ self.filterDialog = new openils.widget.PCrudFilterDialog(
+ {fmClass:self.fmClass, suppressFilterFields:self.suppressFilterFields})
self.filterDialog.onApply = function(filter) {
- self.resetStore();
- self.loadAll(self.cachedQueryOpts, filter);
+ self.refresh(self.cachedQueryOpts, filter);
};
self.filterDialog.startup();
}
this.setStore(this.buildAutoStore());
},
- refresh : function() {
+ refresh : function(opts, search) {
+ opts = opts || this.cachedQueryOpts;
+ search = search || this.cachedQuerySearch;
this.resetStore();
if (this.dataLoader)
this.dataLoader()
else
- this.loadAll(this.cachedQueryOpts, this.cachedQuerySearch);
+ this._loadAll(opts, search);
+ },
+
+ // called after a sort change occurs within the column picker
+ cpSortHandler : function(fields) {
+ console.log("AutoGrod cpSortHandler(): " + fields);
+ // user-defined sort handler
+ if (this.onSortChange) {
+ this.onSortChange(fields)
+
+ // default sort handler
+ } else {
+ if (!this.cachedQueryOpts)
+ this.cachedQueryOpts = {};
+ this.cachedQueryOpts.order_by = {};
+ this.cachedQueryOpts.order_by[this.fmClass] = fields.join(',');
+ this.refresh();
+ }
},
loadAll : function(opts, search) {
+ var _this = this;
+
+ // first we have to load the column picker to determine the sort fields.
+
+ if(this.showColumnPicker && !this.columnPicker) {
+ if(!this.columnPersistKey) {
+ console.error("No columnPersistKey defined");
+ this.columnPicker = {};
+ } else {
+ this.columnPicker = new openils.widget.GridColumnPicker(
+ openils.User.authtoken, this.columnPersistKey, this);
+ this.columnPicker.onSortChange = function(fields) {_this.cpSortHandler(fields)};
+ this.columnPicker.onLoad = function(cpOpts) {
+ _this.cachedQueryOpts = opts;
+ _this.cachedQuerySearch = search;
+ _this.cpSortHandler(cpOpts.sortFields); // calls refresh() -> _loadAll()
+ };
+ this.columnPicker.load();
+ return;
+ }
+ }
+
+ // column picker not wanted or already loaded
+ this._loadAll(opts, search);
+ },
+
+ _loadAll : function(opts, search) {
+ var self = this;
+
dojo.require('openils.PermaCrud');
if(this.loadProgressIndicator)
dojo.style(this.loadProgressIndicator, 'visibility', 'visible');
- var self = this;
opts = dojo.mixin(
{limit : this.displayLimit, offset : this.displayOffset},
opts || {}