[open-ils-commits] r13913 - trunk/Open-ILS/web/js/dojo/openils/widget (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Aug 21 11:33:05 EDT 2009
Author: erickson
Date: 2009-08-21 11:33:02 -0400 (Fri, 21 Aug 2009)
New Revision: 13913
Modified:
trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
trunk/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js
Log:
more work on pcrud filter dialog. added filter option to autogrid. repaired faulty linked object caching in autogrid. with caching repaired, made linked grid cell data fetching synchronous to prevent excessive network requests (1st instance of an object is cached)
Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js 2009-08-21 12:38:47 UTC (rev 13912)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js 2009-08-21 15:33:02 UTC (rev 13913)
@@ -9,8 +9,6 @@
dojo.declare('openils.widget.AutoFieldWidget', null, {
async : false,
- cache : {},
- cacheSingle : {},
/**
* args:
@@ -48,9 +46,10 @@
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 || {};
},
/**
@@ -217,8 +216,8 @@
// 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:
@@ -230,11 +229,13 @@
}
// 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;
@@ -242,10 +243,13 @@
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();
}
@@ -306,15 +310,15 @@
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 {
@@ -452,5 +456,6 @@
});
openils.widget.AutoFieldWidget.localeStrings = dojo.i18n.getLocalization("openils.widget", "AutoFieldWidget");
+ openils.widget.AutoFieldWidget.cache = {};
}
Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js 2009-08-21 12:38:47 UTC (rev 13912)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoGrid.js 2009-08-21 15:33:02 UTC (rev 13913)
@@ -26,6 +26,7 @@
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 */
@@ -78,7 +79,7 @@
var back = dojo.create('a', {
- innerHTML : 'Back',
+ innerHTML : 'Back', // TODO i18n
style : 'padding-right:6px;',
href : 'javascript:void(0);',
onclick : function() {
@@ -92,7 +93,7 @@
});
var forw = dojo.create('a', {
- innerHTML : 'Next',
+ innerHTML : 'Next', // TODO i18n
style : 'padding-right:6px;',
href : 'javascript:void(0);',
onclick : function() {
@@ -108,8 +109,31 @@
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);
@@ -540,18 +564,25 @@
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();
}
Modified: trunk/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js 2009-08-21 12:38:47 UTC (rev 13912)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js 2009-08-21 15:33:02 UTC (rev 13913)
@@ -3,6 +3,7 @@
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');
@@ -19,6 +20,8 @@
constructor : function(args) {
for(var k in args)
this[k] = args[k];
+ this.widgetIndex = 0;
+ this.widgetCache = {};
},
/**
@@ -26,6 +29,7 @@
* Values are dijit's, when values set
*/
startup : function() {
+ var self = this;
this.inherited(arguments);
this.initAutoEnv();
var realFieldList = this.sortedFieldList.filter(
@@ -41,13 +45,34 @@
)
}
});
-
- 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();
@@ -60,19 +85,42 @@
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;
}
}
);
More information about the open-ils-commits
mailing list