# all files / clique/view/LinkInfo/ index.js

40.74% Statements 11/27
50% Branches 4/8
16.67% Functions 1/6
27.27% Lines 6/22
1 branch Ignored

    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
    471×
    1×

    1×

    1×

    1×

     import _ from 'underscore';
    import Backbone from 'backbone';

    import linkInfo from './linkInfo.jade';

    const LinkInfo = Backbone.View.extend({
      initialize: function (options) {
        var debRender;

        options = options || {};
        this.graph = options.graph;

        debRender = _.debounce(this.render, 100);

        this.listenTo(this.model, 'focused', debRender);
        this.listenTo(this.model, 'focused', debRender);
      },

      render: function () {
        const doRender = _.bind(function (link) {
          this.$el.html(linkInfo({
            link: link
          }));

          this.$('a.prev').on('click', _.bind(function () {
            this.model.focusLeft();
          }, this));

          this.$('a.next').on('click', _.bind(function () {
            this.model.focusRight();
          }, this));
        }, this);

        let key = this.model.focused();
        if (!key) {
          doRender(undefined);
        } else {
          this.graph.adapter.findLink({
            key: key
          }).then(doRender);
        }
      }
    });

    export default LinkInfo;