1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2008 Georgia Public Library Service
3 * Bill Erickson <erickson@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
19 * Create a new menu that can be used as a grid column picker. This version
20 * takes advantage of Dojo's 1.2 headerMenu attribute for selecting which
21 * columns to display. As columns are chosen, they are updated on the server
25 if(!dojo._hasResource['openils.widget.GridColumnPicker']) {
26 dojo.provide('openils.widget.GridColumnPicker');
27 dojo.require('dijit.Menu');
28 dojo.require('dojox.widget.PlaceholderMenuItem');
29 dojo.require('fieldmapper.Fieldmapper');
30 dojo.require('openils.Util');
33 'openils.widget.GridColumnPicker',
37 USER_PERSIST_SETTING : 'ui.grid_columns',
40 * Load the fields from the grid and map them to the MenuItem's.
41 * Load settings from server
43 init : function(args) {
45 this.grid = args.grid;
46 this.persistPrefix = args.prefix;
47 this.authtoken = args.authtoken;
48 this.cells = this.grid.structure[0].cells[0];
51 dojo.style(this.grid.domNode.id, 'visibility', 'hidden');
53 dojo.forEach(this.getChildren(),
55 for(var i in self.cells) {
56 var name = self.cells[i].name;
57 if(name == child.attr('label')) {
58 child.field = {label:name, ident:self.cells[i].field};
67 onClose : function() {
68 this.inherited('onClose',arguments);
73 * Save new settings on the server
75 persist : function() {
78 dojo.forEach(this.getChildren(),
81 selected.push(child.field.ident)
86 setting[this.USER_PERSIST_SETTING+'.'+this.persistPrefix] = {'columns':selected, 'auto':autoFields};
87 fieldmapper.standardRequest(
88 ['open-ils.actor', 'open-ils.actor.patron.settings.update'],
90 params: [this.authtoken, null, setting],
91 oncomplete: function(r) {
92 openils.Util.readResponse(r);
99 * Load existing settings from the server
103 fieldmapper.standardRequest(
104 ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve'],
106 params: [this.authtoken, null, this.USER_PERSIST_SETTING+'.'+this.persistPrefix],
107 oncomplete: function(r) { self._loadCallback(r); }
112 _loadCallback : function(r) {
113 dojo.style(this.grid.domNode.id, 'visibility', 'visible');
114 if(settings = openils.Util.readResponse(r)) {
115 dojo.forEach(this.getChildren(),
118 if(!openils.Util.arrayContains(settings.columns, child.field.ident)) {
119 child.attr("checked", false);
120 child.onChange(child.checked);