File: completer.js

package info (click to toggle)
graphite-web 1.1.4-3%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,416 kB
  • sloc: python: 11,275; sh: 61; makefile: 53
file content (63 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// From Ext library
/*global Ext*/

var MetricCompleter;

MetricCompleter = Ext.extend(Ext.form.ComboBox, {
  displayField: 'path',
  listEmptyText: 'No matching metrics',
  mode: 'remote',
  hideTrigger: true,
  queryDelay: 100,
  queryParam: 'query',
  typeAhead: false,
  minChars: 1,

  initComponent: function () {
    var _this = this;

    var store = new Ext.data.JsonStore({
      url: document.body.dataset.baseUrl + 'metrics/find/',
      root: 'metrics',
      fields: ['path', 'name'],
      baseParams: {format: 'completer'}
    });

    var config = {store: store};

    Ext.apply(this, config);
    Ext.apply(this.initialConfig, config);

    MetricCompleter.superclass.initComponent.call(this);

    this.addListener('beforequery', this.prepareQuery.createDelegate(this));
    this.addListener('specialkey', this.onSpecialKey.createDelegate(this));
    this.addListener('afterrender',
      function () {
        _this.getEl().addListener('specialkey',
          function (el, e) {
            _this.onSpecialKey(_this.getEl(), e);
          }
        );
      }
    );
  },

  prepareQuery: function (queryEvent) {
    if (queryEvent.query.substr(-1) != '*') {
      queryEvent.query += '*';
    }
  },

  onSpecialKey: function (field, e) {
    if (e.getKey() == e.TAB) { // This was a pain in the ass to actually get it working right
      field.getEl().blur();
      field.getEl().focus(50);
      field.doQuery( field.getValue() );
      e.stopEvent();
      return false;
    }
  }
});

Ext.reg('metriccompleter', MetricCompleter);