Sencha nav diagram overlays home list

I am using sencha navigation view in sencha app. my error script I have a list view with images on the home screen the first time it loads 20 entries and then the scroll down to the entry will be incremented by 20 each time I scroll when I click on any image and redirect to another view like image or profile view, and return to home when the return button is pressed, all images overlap.

please help, I am trying to solve this error up to 10 days but not getting success: - before overlapping

1) I am using a navigation view that it extends with "Ext.dataview.DataView" and useComponents: true, defaultType: 'productlistitem'

2) In "productlistitem" expand with "Ext.dataview.component.DataItem". In this view, I use an update method that sets the data for the image and other components, and a dynamic method for the width and height of the image.

below you can check the code of all views

A) Home.js

Ext.define('demo.view.home.Home', {

    extend: 'Ext.dataview.DataView',

    requires: [
        'demo.view.product.ListItem',
        'demo.view.layout.ColumnLayout'
    ],

    xtype: 'home',

    config: {

        scrollable: true,
        plugins: {
            xclass: 'demo.plugin.DataViewPaging', // Reference plugin by class
            autoPaging: true
        },

        autoDestroy: true,

        store: 'LookStore',

        margin:'2 0',

        useComponents: true,

        defaultType: 'productlistitem',

        cls: 'wow-home',

        layout: {
            type: 'column',
            columnCount: 2,
            columnWidth: 160
        }
    }
});

      

B) ListItem.js

var listItemData=[];
Ext.define('demo.view.product.ListItem', {

    extend: 'Ext.dataview.component.DataItem',

    requires: ['demo.view.product.Item'],

    xtype: 'productlistitem',

    config: {
        padding: 2,
        zIndex:999,
        items: [{
            xtype: 'item'
        }]
    },

    initialize: function() {
        console.log('initing the list item  ');
        var me = this;
        me.callParent(arguments);
        this.on('heightchange', 'recalculateHeight', me, {
            delegate: '> item'
        });
    },

    recalculateHeight: function() {
        var me = this;
        me.setHeight(me.innerElement.getHeight());
    },

    updateRecord: function(record) {
        if (!record) {
            return;
        }
        var me = this,
            item = me.down('item');
        me.callParent(arguments);
        if (item) {
            item.updateRecord(record, me.getDataview());
        }
        listItemData.push(item.id);
    }
});

      

c) Item.js

Ext.define('demo.view.product.Item', {

    extend: 'Ext.Container',

    xtype: 'item',

    requires: [
        'Ext.Carousel',
        'demo.view.product.ItemImage',
        'demo.view.product.UserInfo',
        'demo.view.product.InfoLabel'
    ],

    config: {
        record: null,

        baseCls: 'wow-item',
        showDescription: false,
        items: [{
                xtype: 'itemimage',
                width: '100%'
            }, {
                xtype: 'userinfo',
                height: 40,
                listeners: {
                    painted: function() {
                        if (!this.element.hasListener('tap')) {
                            this.element.on('tap', function(e) {
                                e.stopPropagation();
                                var record = this.scope.up('item').getRecord();
                                if (!this.scope.getHandleListeners()) {
                                    if(Ext.ComponentQuery.query('main')[0].getActiveItem().xtype === "wardrobedrawer")
                                        demo.app.getController('ProductController').openProductDetail('', '', '', record);
                                    return;
                                }
                                if (record && !Ext.isEmpty(record.raw.product_id) && !Ext.isEmpty(record.raw.importer)) {
                                    var brandMerchantProducts = this.scope.up('brandmerchantproducts');
                                    if (brandMerchantProducts) {
                                        var currentTitle = demo.app.getController('HomeController').getMain().getActiveItem().config.title;
                                        var currentItem = this.scope.element.dom.textContent;
                                        if (currentTitle.toUpperCase() !== currentItem.toUpperCase()) {
                                            demo.app.getController('ProductController').showMerchantProducts(record);
                                        }
                                        return;
                                    }
                                    demo.app.getController('ProductController').showMerchantProducts(record);
                                } else {

                                    var list = this.scope.up('list');

                                    demo.app.getController('ProfileController').goToOtherUserProfile(list, null, null, record.get('merchantId'), e);
                                }
                            }, {
                                scope: this
                            });
                        }
                    }
                }
            },

            {
                xtype: 'container',
                height: 40,
                margin:'1 0 0 0',
                name: 'infoContainer',
                layout:'hbox',
                defaults: {
                    xtype: 'infolabel',
                    flex: 1
                },
                items: [{
                    iconCls: 'icon-diamond',
                    text: '09',
                    itemId: 'wows',
                    listeners: {
                        painted: function() {
                            if (!this.element.hasListener('tap')) {
                                this.element.on('tap', function(e) {
                                    e.stopPropagation();
                                    var record = this.scope.up('item').getRecord();
                                    if (record.get('type') == 'product') {
                                        demo.app.getController('ProductController').wowOrUnwowHomeProduct(record, this.scope.up('item'));
                                    }
                                    if (record.get('type') === 'look') {
                                        demo.app.getController('ProductController').wowOrUnwowHomeLook(record, this.scope.up('item'));
                                    }

                                }, {
                                    scope: this
                                });
                            }
                        }
                    }
                }, {
                    iconCls: 'icon-drawer',
                    text: '11',
                    itemId: 'lookOrAdd',
                    listeners: {
                        painted: function() {
                            if (!this.element.hasListener('tap')) {
                                this.element.on('tap', function(e) {
                                    e.stopPropagation();
                                    var record = this.scope.up('item').getRecord();
                                    if (record.get('type') == 'product') {
                                        demo.addedProductItem = this.scope.up('item');
                                        demo.app.getController('ProductController').addProduct(record);
                                    }
                                    if (record.get('type') === 'look') {
                                        demo.app.getController('ProductController').addHomeLook(record, this.scope.up('item'));
                                    }

                                }, {
                                    scope: this
                                });
                            }
                        }
                    }
                }]
            }
        ]

    },

    initialize: function() {
        var me = this;
        me.callParent(arguments);
        me.on('load', 'imageLoaded', me, {
            delegate: 'itemimage'
        });
    },

    imageLoaded: function() {
        var me = this;
        me.setHeight(me.element.getHeight());
    },

    updateRecord: function(item, dataview) {
        if (!item) {
            return;
        }
        if (dataview && dataview.config.showDescription) {

            this.setShowDescription(true);

        }
        var me = this;

        me.setRecord(item); 
        if (item) {

            var itemImage = this.down('itemimage'),
                images = item.get('images'),
                wows = item.get('wows') + '',
                adds = item.get('adds') + '',
                userInfo = this.down('userinfo');
            if (images && images.length) {
                itemImage.setSrc(images[0].original);
            }

            var type = item.get('type');
            var lookOrProduct = me.down('#lookOrAdd');
            var added = item.get('added');
            var icon;

            if (type === 'product') { 
                icon = 'icon-add-drawer';
                lookOrProduct.setIconCls(icon);
            } else {
                icon = added ? 'icon-counterlook' : 'icon-addlookbook';
                lookOrProduct.setIconCls(icon);
            } 
            if (!Ext.isEmpty(item.raw.product_id)) {
                userInfo.setAvatar('');
            } else { // USER

                var importer = item.get('importer');
                if (importer) {

                    var avatar = importer.avatar;
                    if (avatar) {
                        userInfo.setAvatar(avatar);
                    } else {
                        userInfo.setAvatar('resources/images/default/default_avatar.jpg');
                    }
                }
            } 
            me.down('#wows').setText(wows);

            if (!item.get('wowed')) {
                me.down('#wows').addCls('grayedout-cls');
            } else {
                me.down('#wows').removeCls('grayedout-cls');
            } 
            lookOrProduct.setText(adds);
            if (!item.get('added')) {
                lookOrProduct.addCls('grayedout-cls');
            } else {
                lookOrProduct.removeCls('grayedout-cls');
            }
            var infoContainer = this.down('container[name=infoContainer]');
            if (infoContainer && infoContainer.isHidden()) {
                infoContainer.show();
            } 
            var title = Ext.ComponentQuery.query('main')[0].getActiveItem().title;
            var storeId = this._record.stores[0].getStoreId();
            if (type === 'product' && !Ext.isDefined(title) && storeId !== 'WowedStore' && storeId !== 'SearchStore' && storeId !== 'BrandMerchatProducts') {
                var homeUrl = this._record.stores[0].getProxy().getUrl();
                if ((homeUrl === demo.model.Config.apiServerPath('home')) || (homeUrl === demo.model.Config.apiServerPath('home'))) {
                    var noOfProducts = Ext.ComponentQuery.query('#productsInTheListId').length;
                    if (noOfProducts === 1) {
                        userInfo.setUsername(item);

                        if (me.getShowDescription()) {
                            infoContainer.hide();
                            userInfo.setAvatar('');
                            userInfo.setUsername(item);
                            userInfo.setHandleListeners(false);
                        }
                    } else {
                        userInfo.setUsername(item.get('author'));

                        if (me.getShowDescription()) {
                            infoContainer.hide();
                            userInfo.setAvatar('');
                            userInfo.setUsername(item.get('description'));
                            userInfo.setHandleListeners(false);
                        }
                    }
                } else {
                    userInfo.setUsername(item);

                    if (me.getShowDescription()) {
                        infoContainer.hide();
                        userInfo.setAvatar('');
                        userInfo.setUsername(item);
                        userInfo.setHandleListeners(false);
                    }
                }
            } else {
                userInfo.setUsername(item.get('author'));
                if (me.getShowDescription()) {
                    infoContainer.hide();
                    userInfo.setAvatar('');
                    userInfo.setUsername(item.get('description'));
                    userInfo.setHandleListeners(false);
                }
            }
        }
    },

    updateColorOfItem: function(item) {

        var me = this,
            lookOrProduct = me.down('#lookOrAdd');
        if (!item.get('wowed')) {
            me.down('#wows').addCls('grayedout-cls');
        } else {
            me.down('#wows').removeCls('grayedout-cls');
        }

        if (!item.get('added')) {
            lookOrProduct.addCls('grayedout-cls');
        } else {
            lookOrProduct.removeCls('grayedout-cls');
        }
    }
}); 

      

D) ItemImage.js

Ext.define('demo.view.product.ItemImage', {

    extend: 'Ext.Img',

    xtype: 'itemimage',

    config: {

    },

    onLoad: function(event) { 
        var me = this,
            width = me.getParent().element.getWidth(), // me.element.getWidth() should work but I have found that sometimes it gives a width of 0. Now I go with a width of the parent.
            imageObject = me.imageObject,
            naturalWidth = imageObject.width,
            naturalHeight = imageObject.height,
            naturalRatio = naturalHeight / naturalWidth,
            newHeight = naturalRatio * width;
        me.setHeight(newHeight);
        //Ext.ComponentQuery.query('productlistitem')[0].setHeight(newHeight+84);
        me.callParent(event);
    }

});

      

E) UserInfo.js

Ext.define('demo.view.product.UserInfo', {

    extend: 'Ext.Container',

    requires: ['Ext.Img'],

    xtype: 'userinfo',

    config: {
        avatar: null,
        username: null,
        baseCls: 'wow-user-info',
        handleListeners: true

    },

    applyAvatar: function(avatar) {

        if (Ext.isEmpty(avatar)) {
            return null;
        }
        return Ext.factory({
            src: avatar,
            cls: 'wow-avatar',
            docked: 'left'
        }, 'Ext.Img');
    },

    updateAvatar: function(newAvatar, oldAvatar) {

        if (newAvatar) {
            this.add(newAvatar);
        }
        if (oldAvatar) {
            oldAvatar.destroy();
        }
    },

    applyUsername: function(item) {
        if (Ext.isObject(item)) {
            var price_value = "",
                price_currency = "",
                itemName = "";

            if (Ext.isDefined(item.raw.price)) {
                if (Ext.isDefined(item.raw.price.value)) {
                    price_value = item.raw.price.value.toString();
                }
            }
            if (Ext.isDefined(item.raw.price)) {
                if (Ext.isDefined(item.raw.price.currency)) {
                    price_currency = item.raw.price.symbol;
                }
            }
            if (item.raw.description === null) {
                var item = item.data.author;
            } else {
                var item = item.raw.description;
            }
            item = item.toLowerCase();
            itemName = item.charAt(0).toUpperCase() + item.slice(1);
            if (Ext.isDefined(price_currency) && Ext.isDefined(price_value) && (price_currency !== "") && (price_value !== "")) {
                itemName = '<div class="itemNames"><span style="font-size:0.9em" >' + price_currency.bold() + ' ' + price_value.bold() + '</span>' + " " + '<span style=" font-size:0.8em" class="itemName">' + itemName + '</span>' + '</div>';

            } else {
                itemName = '<div class="itemNames"><span style=" font-size:0.8em" class="itemName">' + itemName + '</span></div>';
            }
            return Ext.factory({
                html: itemName,
                xtype: 'component',
                cls: 'wow-username-product'
            });
        } else {
            return Ext.factory({
                html: item,
                xtype: 'component',
                cls: 'wow-username'
            });
        }
    },

    updateUsername: function(newUsername, oldUsername) {
        if (newUsername) {
            this.add(newUsername);
        }
        if (oldUsername) {
            oldUsername.destroy();
        }
    }

});

      

F) InfoLabel.js

Ext.define('demo.view.product.InfoLabel', {

    extend: 'Ext.Button',

    xtype: 'infolabel',

    config: {
        iconAlign: 'left',
        cls: 'wow-info-label'
    },
    initialize: function() {

        // Do nothing stopping unnecessary event listeners being added.
    }
});

      

+3


source to share





All Articles