dojo.declare('openils.widget.AutoFieldWidget', null, {
async : false,
- cache : {},
- cacheSingle : {},
/**
* args:
this.fmClass + ' fmField=' + this.fmField + ' fmObject=' + js2JSON(this.fmObject));
this.auth = openils.User.authtoken;
- if(!this.cache[this.auth]) {
- this.cache[this.auth] = {};
- }
+ this.cache = openils.widget.AutoFieldWidget.cache;
+ this.cache[this.auth] = this.cache[this.auth] || {};
+ this.cache[this.auth].single = this.cache[this.auth].single || {};
+ this.cache[this.auth].list = this.cache[this.auth].list || {};
},
/**
// first try the store cache
var self = this;
- if(this.cache[this.auth][lclass]) {
- var store = this.cache[this.auth][lclass];
+ if(this.cache[this.auth].list[lclass]) {
+ var store = this.cache[this.auth].list[lclass];
var query = {};
query[linkInfo.vfield.name] = ''+this.widgetValue;
store.fetch({query:query, onComplete:
}
// then try the single object cache
- if(this.cacheSingle[lclass] && this.cacheSingle[lclass][this.widgetValue]) {
- this.widgetValue = this.cacheSingle[lclass][this.widgetValue];
+ if(this.cache[this.auth].single[lclass] && this.cache[this.auth].single[lclass][this.widgetValue]) {
+ this.widgetValue = this.cache[this.auth].single[lclass][this.widgetValue];
return;
}
+ console.log("Fetching sync object " + lclass + " : " + this.widgetValue);
+
// if those fail, fetch the linked object
this.async = true;
var self = this;
async : !this.forceSync,
oncomplete : function(r) {
var item = openils.Util.readResponse(r);
- if(!self.cacheSingle[lclass])
- self.cacheSingle[lclass] = {};
- self.widgetValue = item[linkInfo.vfield.selector]();
- self.cacheSingle[lclass][self.widgetValue] = item;
+ var newvalue = item[linkInfo.vfield.selector]();
+
+ if(!self.cache[self.auth].single[lclass])
+ self.cache[self.auth].single[lclass] = {};
+ self.cache[self.auth].single[lclass][self.widgetValue] = newvalue;
+
+ self.widgetValue = newvalue;
self.widget.startup();
self._widgetLoaded();
}
if(list) {
self.widget.store =
new dojo.data.ItemFileReadStore({data:fieldmapper[linkClass].toStoreData(list)});
- self.cache[self.auth][linkClass] = self.widget.store;
+ self.cache[self.auth].list[linkClass] = self.widget.store;
} else {
- self.widget.store = self.cache[self.auth][linkClass];
+ self.widget.store = self.cache[self.auth].list[linkClass];
}
self.widget.startup();
self._widgetLoaded();
};
- if(this.cache[self.auth][linkClass]) {
+ if(this.cache[self.auth].list[linkClass]) {
oncomplete();
} else {
});
openils.widget.AutoFieldWidget.localeStrings = dojo.i18n.getLocalization("openils.widget", "AutoFieldWidget");
+ openils.widget.AutoFieldWidget.cache = {};
}
displayLimit : 15,
displayOffset : 0,
showPaginator : false,
+ showLoadFilter : false,
suppressLinkedFields : null, // list of fields whose linked display data should not be fetched from the server
/* by default, don't show auto-generated (sequence) fields */
var back = dojo.create('a', {
- innerHTML : 'Back',
+ innerHTML : 'Back', // TODO i18n
style : 'padding-right:6px;',
href : 'javascript:void(0);',
onclick : function() {
});
var forw = dojo.create('a', {
- innerHTML : 'Next',
+ innerHTML : 'Next', // TODO i18n
style : 'padding-right:6px;',
href : 'javascript:void(0);',
onclick : function() {
dojo.place(this.paginator.domNode, this.domNode, 'before');
dojo.place(back, this.paginator.domNode);
dojo.place(forw, this.paginator.domNode);
+
+ if(this.showLoadFilter) {
+ dojo.require('openils.widget.PCrudFilterDialog');
+ dojo.place(
+ dojo.create('a', {
+ innerHTML : 'Filter', // TODO i18n
+ style : 'padding-right:6px;',
+ href : 'javascript:void(0);',
+ onclick : function() {
+ var dialog = new openils.widget.PCrudFilterDialog({fmClass:self.fmClass})
+ dialog.onApply = function(filter) {
+ self.resetStore();
+ self.loadAll(self.cachedQueryOpts, filter);
+ };
+ dialog.startup();
+ dialog.show();
+ }
+ }),
+ this.paginator.domNode
+ );
+ }
+
+ // progress image
this.loadProgressIndicator = dojo.create('img', {
- src:'/opac/images/progressbar_green.gif',
+ src:'/opac/images/progressbar_green.gif', // TODO configured path
style:'height:16px;width:16px;'
});
dojo.place(this.loadProgressIndicator, this.paginator.domNode);
fmField: this.field,
widgetValue : val,
readOnly : true,
+ forceSync : true, // prevents many simultaneous requests for the same data
suppressLinkedFields : this.grid.suppressLinkedFields
});
+ autoWidget.build();
+
+ /*
+ // With proper caching, this should not be necessary to prevent grid render flickering
var _this = this;
autoWidget.build(
function(w, ww) {
- var node = _this.grid.getCell(_this.index).view.getCellNode(rowIndex, _this.index);
- if(node) {
- node.innerHTML = ww.getDisplayString();
- }
+ try {
+ var node = _this.grid.getCell(_this.index).view.getCellNode(rowIndex, _this.index);
+ if(node)
+ node.innerHTML = ww.getDisplayString();
+ } catch(E) {}
}
);
+ */
return autoWidget.getDisplayString();
}
dojo.provide('openils.widget.PCrudFilterDialog');
dojo.require('openils.widget.AutoFieldWidget');
dojo.require('dijit.form.FilteringSelect');
+ dojo.require('dijit.form.Button');
dojo.require('dojo.data.ItemFileReadStore');
dojo.require('dijit.Dialog');
dojo.require('openils.Util');
constructor : function(args) {
for(var k in args)
this[k] = args[k];
+ this.widgetIndex = 0;
+ this.widgetCache = {};
},
/**
* Values are dijit's, when values set
*/
startup : function() {
+ var self = this;
this.inherited(arguments);
this.initAutoEnv();
var realFieldList = this.sortedFieldList.filter(
)
}
});
-
- dojo.place( // TODO i18n/CSS
+
+ // TODO i18n/CSS
+ dojo.place(
dojo.create(
'div',
{innerHTML:'Filter Selector', style:'text-align:center;width:100%;padding:10px;'}
), this.domNode);
+ dojo.place(
+ new dijit.form.Button({
+ label:"Apply",
+ onClick : function() {
+ if(self.onApply)
+ self.onApply(self.compileFilter());
+ self.hide();
+ }
+ }).domNode, this.domNode);
+
+ dojo.place(
+ new dijit.form.Button({
+ label:"Cancel",
+ onClick : function() {
+ if(self.onCancel)
+ self.onCancel();
+ self.hide();
+ }
+ }).domNode, this.domNode);
+
this.table = dojo.place(dojo.create('table'), this.domNode);
openils.Util.addCSSClass(this.table, 'oils-fm-edit-dialog');
this.insertFieldSelector();
var valueTd = dojo.place(dojo.create('td'), row);
dojo.place(selector.domNode, selectorTd);
+ // dummy text box
+ dojo.place(new dijit.form.TextBox().domNode, valueTd);
+
+ // when a field is selected, update the value widget
var self = this;
dojo.connect(selector, 'onChange',
function(value) {
+
if(valueTd.childNodes[0])
valueTd.removeChild(valueTd.childNodes[0]);
+
var widget = new openils.widget.AutoFieldWidget({
fmClass : self.fmClass,
fmField : value,
parentNode : dojo.place(dojo.create('div'), valueTd)
});
widget.build();
+
+ if(self.widgetCache[selector.widgetIndex]) {
+ self.widgetCache[selector.widgetIndex].widget.destroy();
+ delete self.widgetCache[selector.widgetIndex];
+ }
+
+ selector.widgetIndex = this.widgetIndex;
+ self.widgetCache[self.widgetIndex++] = widget;
}
);
+ },
+
+ compileFilter : function() {
+ var filter = {};
+ for(var i in this.widgetCache) {
+ var widget = this.widgetCache[i];
+ filter[widget.fmField] = widget.getFormattedValue();
+ }
+ return filter;
}
}
);