[% WRAPPER base.tt2 %]
[% ctx.page_title = 'Flattener Test' %]
<script type="text/javascript">
+ dojo.require("dijit.form.Button");
dojo.require("openils.widget.FlattenerGrid");
dojo.require("dojo.data.ItemFileReadStore");
+ /*
+ var gridData = <esc>:r ~/grid-data
+ */
var gridData = {
"data":{
"identifier":"part_num",
{"part_num":7,"min_temp":0,"max_temp":32,"type":"ice","thick":5},
{"part_num":8,"min_temp":-10,"max_temp":22,"type":"ice_1","thick":6},
{"part_num":9,"min_temp":-20,"max_temp":12,"type":"ice_2","thick":7},
+ {"part_num":10,"min_temp":-30,"max_temp":2,"type":"ice_3","thick":8},
+ {"part_num":11,"min_temp":-40,"max_temp":-8,"type":"ice_4","thick":9},
+ {"part_num":12,"min_temp":-50,"max_temp":-18,"type":"ice_5","thick":10},
+ {"part_num":13,"min_temp":-60,"max_temp":-28,"type":"ice_6","thick":11},
+ {"part_num":14,"min_temp":-70,"max_temp":-38,"type":"ice_7","thick":12},
+ {"part_num":15,"min_temp":-80,"max_temp":-48,"type":"ice_8","thick":13},
+ {"part_num":16,"min_temp":-90,"max_temp":-58,"type":"ice_9","thick":14},
+ {"part_num":17,"min_temp":-100,"max_temp":-68,"type":"ice_10","thick":15},
+ {"part_num":18,"min_temp":-110,"max_temp":-78,"type":"ice_11","thick":16},
+ {"part_num":19,"min_temp":-120,"max_temp":-88,"type":"ice_12","thick":17},
+ {"part_num":20,"min_temp":-130,"max_temp":-98,"type":"ice_13","thick":18},
+ {"part_num":21,"min_temp":-140,"max_temp":-108,"type":"ice_14","thick":19},
+ {"part_num":22,"min_temp":-150,"max_temp":-118,"type":"ice_15","thick":20},
+ {"part_num":23,"min_temp":-160,"max_temp":-128,"type":"ice_16","thick":21},
+ {"part_num":24,"min_temp":-170,"max_temp":-138,"type":"ice_17","thick":22},
+ {"part_num":25,"min_temp":-180,"max_temp":-148,"type":"ice_18","thick":23},
+ {"part_num":26,"min_temp":-190,"max_temp":-158,"type":"ice_19","thick":24},
+ {"part_num":27,"min_temp":-200,"max_temp":-168,"type":"ice_20","thick":25},
+ {"part_num":28,"min_temp":-210,"max_temp":-178,"type":"ice_21","thick":26},
+ {"part_num":29,"min_temp":-220,"max_temp":-188,"type":"ice_22","thick":27},
+ {"part_num":30,"min_temp":-230,"max_temp":-198,"type":"ice_23","thick":28},
+ {"part_num":31,"min_temp":-240,"max_temp":-208,"type":"ice_24","thick":29},
+ {"part_num":32,"min_temp":-250,"max_temp":-218,"type":"ice_25","thick":30},
+ {"part_num":33,"min_temp":-260,"max_temp":-228,"type":"ice_26","thick":31},
+ {"part_num":34,"min_temp":-270,"max_temp":-238,"type":"ice_27","thick":32},
+ {"part_num":35,"min_temp":-280,"max_temp":-248,"type":"ice_28","thick":33},
+ {"part_num":36,"min_temp":-290,"max_temp":-258,"type":"ice_29","thick":34}
]
}
};
+ var gridStore = new dojo.data.ItemFileReadStore(gridData);
+ console.log("gridStore built");
- var gridStore = new dojo.data.ItemFileReadStore(gridData);
-
- console.log("gridStore built");
+ /* mapClause="{ 'barcode': 'barcode', 'circ_lib_name': 'circ_lib.name', 'circ_lib': 'circ_lib.shortname', 'call_number': { 'path': 'call_number.label', 'sort': true, 'display': true }, 'id': 'id', 'tcn': { 'path': 'call_number.record.tcn_value', 'filter': true, 'sort': true } }" */
+ /* query="{tcn: {'>': 100, circ_lib: 'BR1'}}" */
</script>
<table
id="gridNode"
jsid="grid"
dojoType="openils.widget.FlattenerGrid"
+ fmClass="acp"
autoHeight="10"
- query="{part_num: '*'}" store="gridStore">
+ query="{__id: '*'}"
+ >
<thead>
<tr>
- <th field="part_num">Part Number</th>
- <th field="min_temp" width="100px">Minimum Temperature</th>
- <th field="max_temp" width="100px">Maximum Temperature</th>
- <th field="type" width="100px">Type</th>
- <th field="thick" width="5em">Thickness</th>
+ <th field="barcode" fpath="barcode">Barcode</th>
+ <th field="circ_lib" fpath="circ_lib.name" width="100px">Circulation Library Name</th>
+ <th field="circ_lib_name" fpath="circ_lib.shortname" width="100px">Circulation Library</th>
+ <th field="call_number" fpath="call_number.label" fsort="true" width="100px">Call Number</th>
+ <th field="tcn" fpath="call_number.record.tcn_value" ffilter="true" width="5em">TCN</th>
</tr>
</thead>
</table>
-if (!dojo._hasResource["openils.widget.FlatGrid"]) {
+if (!dojo._hasResource["openils.widget.FlattenerGrid"]) {
dojo.provide("openils.widget.FlattenerGrid");
- dojo.require("dijit.form.Button");
- dojo.require("dijit.layout.ContentPane");
dojo.require("dojox.grid.DataGrid");
+ dojo.require("openils.FlattenerStore");
dojo.declare(
"openils.widget.FlattenerGrid",
[dojox.grid.DataGrid], {
- "nothing": null
+ "columnReordering": true,
+
+ "_generate_map": function() {
+ var map = this.mapClause = {};
+ var fields = this.structure[0].cells[0];
+ /* XXX TODO remove column from grid (or hide? or what?)
+ * when display is false */
+ dojo.forEach(
+ fields,
+ function(field) {
+ if (field.fpath) {
+ if ("fdisplay" in field ||
+ "fsort" in field ||
+ "ffilter" in field) {
+ map[field.field] = {
+ "display": (field.fdisplay || false),
+ "filter": (field.ffilter || false),
+ "sort": (field.fsort || false)
+ };
+ } else {
+ map[field.field] = {
+ "path": field.fpath,
+ "sort": true,
+ "filter": true,
+ "display": true
+ };
+ }
+ }
+ }
+ );
+
+ return map;
+ },
+
+ "startup": function() {
+ if (!this.store) {
+ this.store = new openils.FlattenerStore({
+ "fmClass": this.fmClass,
+ "mapClause": (this.mapClause || this._generate_map())
+ });
+ }
+ }
}
);
+
+ /* monkey patch so we can get more attributes from each column in the
+ * markup that specifies grid columns (table->thead->tr->[td,...])
+ */
+ (function() {
+ var b = dojox.grid.cells._Base;
+ var orig_mf = b.markupFactory;
+
+ b.markupFactory = function(node, cellDef) {
+ orig_mf(node, cellDef);
+
+ dojo.forEach(
+ ["fpath", "fdisplay", "fsort", "ffilter"],
+ function(a) {
+ var value = dojo.attr(node, a);
+ if (value)
+ cellDef[a] = value;
+ }
+ );
+ };
+ })();
+
+ /* the secret to successfully subclassing dojox.grid.DataGrid */
+ openils.widget.FlattenerGrid.markupFactory =
+ dojox.grid.DataGrid.markupFactory;
}