text: /**
   * Shopware 5
   * Copyright (c) shopware AG
   *
   * According to our dual licensing model, this program can be used either
   * under the terms of the GNU Affero General Public License, version 3,
   * or under a proprietary license.
   *
   * The texts of the GNU Affero General Public License with an additional
   * permission and of our proprietary license can be found at and
   * in the LICENSE file you have received along with this program.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Affero General Public License for more details.
   *
   * "Shopware" is a registered trademark of shopware AG.
   * The licensing of the program under the AGPLv3 does not imply a
   * trademark license. Therefore any rights, title and interest in
   * our trademarks remain entirely with us.
   *
   * @category   Shopware
   * @package    Customer
   * @subpackage Controller
   * @version    $Id$
   * @author shopware AG
   */
  
  // {namespace name=backend/customer/view/main}
  // {block name="backend/customer/view/customer_stream/assignment"}
  
  Ext.define('Shopware.apps.Customer.view.customer_stream.Assignment', {
  
      extend: 'Shopware.form.field.CustomerGrid',
      xtype: 'widget.customer-stream-assignment',
      isFormField: false,
      supportText: '{s name="assigned_customers_help"}{/s}',
      fieldLabel: '{s name="assigned_customers"}{/s}',
      fieldLabelConfig: 'as_empty_text',
      allowSorting: false,
      animateAddItem: false,
  
      initComponent: function() {
          var me = this;
  
          var factory = Ext.create('Shopware.attribute.SelectionFactory');
  
          me.searchStore = factory.createEntitySearchStore("Shopware\\Models\\Customer\\Customer");
  
          me.callParent(arguments);
  
          me.store.load();
      },
  
      createGrid: function() {
          var me = this;
  
          me.pagingbar = Ext.create('Ext.toolbar.Paging', {
              store: me.store,
              dock: 'bottom'
          });
  
          return Ext.create('Ext.grid.Panel', {
              columns: me.createColumns(),
              store: me.store,
              border: false,
              flex: 1,
              dockedItems: [me.pagingbar],
              hideHeaders: true
          });
      },
  
      initializeStore: function() {
          var me = this;
          var factory = Ext.create('Shopware.attribute.SelectionFactory');
  
          me.store = factory.createEntitySearchStore("Shopware\\Models\\Customer\\Customer");
          me.store.getProxy().extraParams.streamId = me.record.get('id');
          me.store.pageSize = 20;
          return me.store;
      },
  
      addItem: function(record) {
          var me = this;
          var success = me.callParent(arguments);
  
          if (success) {
              me.addCustomerToStream(me.record.get('id'), record.get('id'))
          }
          return success;
      },
  
      removeItem: function(record) {
          var me = this,
              customerId = record.get('id'),
              streamId = me.record.get('id');
  
          me.callParent(arguments);
          me.removeCustomerFromStream(streamId, customerId);
      },
  
      removeCustomerFromStream: function(streamId, customerId) {
          Ext.Ajax.request({
              url: '{url controller=CustomerStream action=removeCustomerFromStream}',
              params: {
                  streamId: streamId,
                  customerId: customerId
              }
          });
      },
  
      addCustomerToStream: function(streamId, customerId) {
          Ext.Ajax.request({
              url: '{url controller=CustomerStream action=addCustomerToStream}',
              params: {
                  streamId: streamId,
                  customerId: customerId
              }
          });
      }
  });
  
  //{/block}
  