# Code coverage report for slap/lib/ui/BaseForm.js

## Statements: 86.05% (37 / 43) Branches: 52.38% (11 / 21) Functions: 81.82% (9 / 11) Lines: 100% (29 / 29) Ignored: none

All files » slap/lib/ui/ » BaseForm.js

    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
    531
    1

    1
    1

    1

    1
    4

    4

    4

    4

    1

    1
    1
    1
    4
    4
    11
    1

    4
    4
    1
    1

    4
    4
    4
    4

    4

    1

    1
     var blessed = require('blessed');
    var _ = require('lazy.js');

    var Slap = require('./Slap');
    var BaseElement = require('./BaseElement');

    var util = require('../util');

    function BaseForm (opts) {
      var self = this;

      Iif (!(self instanceof blessed.Node)) return new BaseForm(opts);

      BaseElement.call(self, _({
          hidden: true,
          height: 1,
          left: 0,
          right: 0,
          bottom: 0
        })
        .merge(Slap.global.options.form || {})
        .merge(opts || {})
        .toObject());
      Eif (self.parent instanceof Pane) self.pane.forms.push(self);
    }
    BaseForm.prototype.__proto__ = BaseElement.prototype;

    BaseForm.prototype.cancel = function () { this.emit('cancel'); };
    BaseForm.prototype.submit = function () { this.emit('submit'); };
    BaseForm.prototype._initHandlers = function () {
      var self = this;
      self.on('element keypress', function (el, ch, key) {
        switch (util.getBinding(self.options.bindings, key)) {
          case 'cancel': self.cancel(); return false;
        };
      });
      self.on('show', function () { self.focus(); });
      self.on('hide', function () {
        self.slap._stopKeyPropagation();
        Eif (self.screen.focused.hasAncestor(self.pane) && !self.screen.focused.visible) self.pane.focus();
      });
      self.on('element blur', function (el) { Iif (self.visible && !self.hasFocus(true)) self.cancel(); });
      self.on('element submit', function (el) { if (el !== self) self.submit(); });
      self.on('element cancel', function (el) { Iif (el !== self) self.cancel(); });
      self.on('cancel', function () { self.hide(); });

      return BaseElement.prototype._initHandlers.apply(self, arguments);
    };

    module.exports = BaseForm;

    var Pane = require('./Pane'); // circular import