// Generated by CoffeeScript 1.11.1
Ext.define('FM.view.grids.IPBlockList', {
  extend: 'Ext.grid.Panel',
  alias: 'widget.ip-block-list',
  cls: 'fm-ip-block-list',
  columns: [],
  stateful: true,
  multiSelect: true,
  enableColumnHide: false,
  enableColumnMove: false,
  tbar: {
    xtype: 'ip-block-list-top-toolbar'
  },
  viewConfig: {
    stripeRows: false
  },
  requires: ['FM.view.toolbars.IPBlockListTopToolbar', 'FM.model.IP'],
  initComponent: function() {
    var plugin;
    FM.Logger.log('FM.view.grids.IPBlockList init');
    plugin = Ext.create("Ext.ux.grid.plugin.RowEditing", {
      clicksToMoveEditor: 1,
      autoCancel: false
    });
    this.plugins = [plugin];
    this.callParent(arguments);
    this.initGridConfig();
    this.initHandlers();
    return this.initGridStore();
  },
  initHandlers: function() {
    var panel;
    panel = this;
    return (function(panel) {
      var selection, toolbar;
      selection = panel.getView().getSelectionModel();
      toolbar = Ext.ComponentQuery.query('ip-block-list-top-toolbar', panel)[0];
      return selection.on({
        selectionchange: function(view, records) {
          FM.Logger.debug('FileList selectionchange() called', panel, arguments);
          if (records.length > 0) {
            Ext.ComponentQuery.query('button[cls="fm-ip-remove"]', toolbar)[0].setDisabled(false);
            return Ext.ComponentQuery.query('button[cls="fm-ip-edit"]', toolbar)[0].setDisabled(false);
          } else {
            Ext.ComponentQuery.query('button[cls="fm-ip-remove"]', toolbar)[0].setDisabled(true);
            return Ext.ComponentQuery.query('button[cls="fm-ip-edit"]', toolbar)[0].setDisabled(true);
          }
        }
      });
    })(panel);
  },
  initGridConfig: function() {
    return this.setConfig({
      columns: [
        {
          header: t("IP"),
          dataIndex: "ip",
          flex: true,
          editor: {
            allowBlank: false,
            regex: /^([\d]{0,3}[\.]?)?([\d]{0,3}[\.]?)?([\d]{0,3}[\.]?)?([\d]{0,3}[\.]?)?[\/]?([\d]{0,3}[\.]?)?([\d]{0,3}[\.]?)?([\d]{0,3}[\.]?)?([\d]{0,3})?$/,
            regexText: t("Incorrect ip value"),
            maxLength: 255
          }
        }, {
          header: t("Comment"),
          dataIndex: "comment",
          flex: true,
          editor: {
            allowBlank: true,
            maxLength: 255
          }
        }
      ]
    });
  },
  initGridStore: function() {
    var store;
    store = Ext.create("Ext.data.Store", {
      sortOnLoad: true,
      model: 'FM.model.IP'
    });
    return this.setStore(store);
  }
});
