[CLOSED] Re-write Ext.preg call as Ext.define - Extjs5 migration

  1. #1

    [CLOSED] Re-write Ext.preg call as Ext.define - Extjs5 migration

    We use many plugins and have traditionally used this method to register them:
        if (typeof Ext !== 'undefined') {
        var AutomatedTesting = Ext.extend(Object, {
            constructor: function (config) {
                config = config || {};
                Ext.apply(this, config);
            },
            init: function (parent) {
                var parentFn = parent.view.getRowClass || Ext.emptyFn;
     
                parent.view.getRowClass = function (record, rowIndex, rp, ds) {
                    var cls = ' qa-row-' + record.id;
                    var parentCls = parentFn(record, rowIndex, rp, ds);
                    if (parentCls != undefined) {
                        cls += ' ' + parentCls;
                    }
                    return cls;
                };
            }
        });
        Ext.preg('AutomatedTesting', AutomatedTesting);
    };
    On my Ext3 pages I am now getting the js error:
    "Ext.preg is not a function"
    According to the Extjs migration page,http://www.manilaforwarders.com/asse...migration.html, I should be using Ext.define(...), but I have not found any clear examples that would apply, to the type of code above, using define().
    Can you give me some guidance?
    Last edited by Daniil; Apr 10, 2015 at 2:04 PM. Reason: [CLOSED]
  2. #2

    Possible solution

    if (typeof Ext !== 'undefined') {
        vms.extVer = parseFloat(Ext.version || Ext.getVersion().version);
        if (vms.extVer < 4){
            var AutomatedTesting = Ext.extend(Object, {
                constructor: function(config){
                    config = config || {};
                    Ext.apply(this, config);
                },
                init: function(parent){
                    var parentFn = parent.view.getRowClass || Ext.emptyFn;
     
                    parent.view.getRowClass = function(record, rowIndex, rp, ds){
                        var cls = ' qa-row-' + record.id;
                        var parentCls = parentFn(record, rowIndex, rp, ds);
                        if (parentCls != undefined){
                            cls += ' ' + parentCls;
                        }
                        return cls;
                    };
                }
            });
            Ext.preg('AutomatedTesting', AutomatedTesting);
        } else{
            Ext.define('vms.AutomatedTesting', {
                extend: "Object",
                alias: "AutomatedTesting",
                constructor: function(config){
                    config = config || {};
                    Ext.apply(this, config);
                },
                init: function (parent) {
                    var parentFn = parent.view.getRowClass || Ext.emptyFn;
     
                    parent.view.getRowClass = function (record, rowIndex, rp, ds) {
                        var cls = ' qa-row-' + record.id;
                        var parentCls = parentFn(record, rowIndex, rp, ds);
                        if (parentCls != undefined) {
                            cls += ' ' + parentCls;
                        }
                        return cls;
                    };
                }
            });
        };
    };
  3. #3
    Hi @betamax,

    Your solution appears to be fine.
  4. #4
    hi Danill,

    Should I need to leave the original .preg for backwards compat to Ext v1.8, or will the .define work for both version 1.x and v3.x?
    Remember I am running multiple versions of Ext.
  5. #5
    I would expect that Ext.define() should work with v1. Does it work for you? As for Ext.preg(), I think it might be still required for v1. So, I would try to leave Ext.define() for both versions, but call Ext.preg() additionally for v1.

    It is theoretically. I have not tested.

Similar Threads

  1. Migration from 1.x to 2.5.3
    By srikanthn27 in forum 2.x Help
    Replies: 1
    Last Post: Mar 13, 2015, 8:28 AM
  2. Replies: 10
    Last Post: Feb 20, 2015, 5:17 AM
  3. Replies: 1
    Last Post: Jul 15, 2014, 1:10 PM
  4. Migration from ext 1.0 to 2.0
    By speedstepmem4 in forum 1.x Help
    Replies: 1
    Last Post: Jun 11, 2013, 9:14 AM
  5. Replies: 5
    Last Post: May 04, 2011, 9:24 AM

Tags for this Thread

Posting Permissions