summaryrefslogtreecommitdiff
path: root/web-ui/app/js/mixins/with_enable_disable_on_event.js
blob: fa574a973824d2a39e6d140d38486754c8f24f78 (plain)
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
/*global Smail */
/*global _ */

define([],
  function () {
    'use strict';

    function withEnableDisableOnEvent(ev) {
      return function () {
        this.disableElement = function () {
          this.$node.attr('disabled', 'disabled');
        };

        this.enableElement = function () {
          this.$node.removeAttr('disabled');
        };

        this.toggleEnabled = function (ev, enable) {
          if (enable) {
            this.enableElement();
          } else {
            this.disableElement();
          }
        };

        this.after('initialize', function () {
          this.on(document, ev, this.toggleEnabled);
        });
      };
    }

    return withEnableDisableOnEvent;
  }
);