wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
listbox.js.php
Go to the documentation of this file.
1 /**
2  * @class Listbox. Build on Ext.form.ComboBox
3  */
4 Listbox = function() {};
5 
6 Listbox.prototype = {
7  // the displayed type
8  type:null,
9  // the custom parameters
10  customParams:null,
11  // the Ext.data.Store instance
12  ds:null,
13 
14  /**
15  * Initialize a grid that displays entities
16  * @param id The html container id
17  * @param name The name submitted to the server
18  * @param type The entity type to display
19  * @param value The selected value (aka 'key')
20  * @param display The displayed value (aka 'value')
21  * @param filter A filter string to be used to filter the entities (see StringQuery), maybe obfuscated using Obfuscator
22  * @param config An associative array with the following keys: none defined yet
23  * @param customParams An assoziative array of additional values passed to the controller [optional]
24  */
25  init: function(id, name, type, value, display, filter, config, customParams) {
26  this.type = type;
27  this.customParams = customParams;
28 
29  // create the Data Store
30  this.ds = new Ext.data.Store({
31  proxy:new Ext.data.HttpProxy({
32  url:'<?php echo $APP_URL; ?>'
33  }),
34 
35  baseParams:{type:type, controller:'<?php echo $controller; ?>', context:'<?php echo $context; ?>', usr_action:'listbox', response_format:'JSON', sid:'<?php echo session_id() ?>', filter:filter},
36 
37  reader:new Ext.data.JsonReader({
38  root:'objects',
39  totalProperty:'totalCount',
40  id:'key'
41  }, [{name:'key'}, {name:'val'}]),
42 
43  // turn on remote sorting
44  remoteSort:true
45  });
46 
47  // add custom parameters to baseParams
48  if (customParams)
49  for (var i in customParams)
50  this.ds.baseParams[i] = customParams[i];
51 
52  // create the combo box
53  var self = this;
54  var combo = new Ext.form.ComboBox({
55  store:this.ds,
56  applyTo:id,
57  displayField:'val',
58  valueField:'key',
59  hiddenName:name,
60  mode:'remote',
61  triggerAction:'all',
62  emptyText:'',
63  editable:true,
64  forceSelection:false,
65  typeAhead:false,
66  selectOnFocus:true,
67  listeners: {
68  beforequery: function(queryEvent) {
69  self.ds.baseParams.displayFilter = "^"+queryEvent.query;
70  }
71  }
72  });
73  if (value && display) {
74  // add the given record and set it
75  RecType = Ext.data.Record.create([{name:'key'}, {name:'val'}]);
76  var record = new RecType({key:value, val:display});
77  this.ds.add(record);
78  combo.setValue(value);
79  }
80  }
81 };