ExtJs minify Gets ignored
Asked Answered
C

1

15

We have a CMS so I don't have access to the header of the HTML page which gets rendered for our extjs implementation. So I had to make a workaround which is like this:

 Ext.local = {};
    var lang = {
        initLang: function (revisionNr) {
            var local = localStorage.getItem('localLang')
            if (!local) {
                AjaxHandlerByClass('ajax/lang/webuser/init', {}, this.loadLangRemote);
            } else {
                local = JSON.parse(local);
                if (local.revisionNr == config.revisionNr && local.lang == config.lang) {
                    console.log('loading local lang variables');
                    if (local.date < new Date().getTime() - (24 * 60 * 60 * 1000) * 2) {//2 day caching time before retry
                        delete window.localStorage.localLangBackup;
                    }
                    this.loadLangLocal(local);
                } else {
                    delete window.localStorage.localLang;
                    AjaxHandlerByClass('ajax/lang/webuser/init', {}, this.loadLangRemote);
                }
            }
        },
        loadLangRemote: function (data) {
            data.revisionNr = config.revisionNr;
            data.lang = config.lang;
            data.date = new Date().getTime();
            lang.loadLangLocal(data);
            localStorage.setItem('localLang', JSON.stringify(data));
        },
        loadLangLocal: function (data) {
            var jsElm = document.createElement("script");
            jsElm.type = "application/javascript";
            jsElm.src = 'js/freetext-deploy.min.js?rev={/literal}{$revisionNr}{literal}';

            document.getElementsByTagName('head')[0].appendChild(jsElm);

            Ext.Date.defaultFormat = 'd-m-Y';
            if (!debug) {
                Ext.Loader.config.disableCaching = true;
            }


            Ext.application({
                name: 'freetextOrder',
                appFolder: 'modules/extjs/freetextOrder/app',
                controllers: [
                    'Main'
                ],
                launch: function () {
                    
                    var freetextOrder = Ext.create('Ext.container.Container', {
                        renderTo: Ext.get('freetextOrderDiv'),
                        layout: 'fit',
                        id: 'catalogAdministrationDiv_ext',
                        height: 800,
                        cls: 'x-dig-override',
                        items: [Ext.create('freetextOrder.view.base.MainView', {})],
                        layout:'fit'
                    });
                }
            });
            Ext.local = data;
        }
    };
    lang.initLang();

The problem I'm having is that the minified version gets ignored completely. I see it load on the http request but extjs ignores them.... even though I can see the objects are being created after include (via console log)

Anyone any idea how I can achieve this?

Curtal answered 26/8, 2015 at 13:44 Comment(0)
C
4

as i see none found the answer so i post my own here wich i came up with.

Since i could for the love of god not load the damn thing i refactored the loader and exported it into a Js. file. wich i reqired and called later on in code.

exported lang.js file:

Ext.define('Lang', {
    singleton: true,
    ApplicationConf: null,
    Launch: function (launchConfig) {

        this.ApplicationConf = launchConfig;

        var local = localStorage.getItem('localLang');
        var me = this;

        this.loadLangRemote = function (data) {
            debugger;
            data.revisionNr = config.revisionNr;
            data.lang = config.lang;
            data.date = new Date().getTime();
            me.loadLangLocal(data);
            localStorage.setItem('localLang', JSON.stringify(data));
        };
        this.loadLangLocal = function (data) {
            Ext.local = data;
            Ext.lang = function (langId) {
                if (Ext.local[langId]) {
                    return Ext.local[langId];
                }

                delete window.localStorage.localLang;
                localStorage.setItem('localLangBackup', true);
                return langId;
            }
            Ext.application(me.ApplicationConf);
        };

        if (!local) {
            Ext.Ajax.request({
                url: 'ajax/lang/webuser/init',
                params: {
                    sid: sid,
                },
                success: function (data) {
                    debugger;
                    me.loadLangRemote(Ext.JSON.decode(data.responseText));
                }

            })
        } else {
            local = JSON.parse(local);
            if (local.revisionNr == config.revisionNr && local.lang == config.lang) {
                console.log('loading local lang variables');
                if (local.date < new Date().getTime() - (24 * 60 * 60 * 1000) * 2) {//2 day caching time before retry
                    delete window.localStorage.localLangBackup;
                }
                debugger;
                me.loadLangLocal(local);
            } else {
                delete window.localStorage.localLang;
                Ext.Ajax.request({
                    url: 'ajax/lang/webuser/init',
                    params: {
                        sid: sid,
                    },
                    success: function (data) {
                        me.loadLangRemote(Ext.JSON.decode(data.responseText));
                    }
                })
            }
        }

    },
})

And IMPORTANT was to add the

  Ext.onReady(function () {
           Lang.Launch({
                name: 'catalogAdministration',
                appFold....

To the call of the Launch function in code, bacause it would have been not defined at run time. i added the file to the minified file first and call the Lang.Launch instead Ext.Application.

Hope somone has use of my solution :)

Curtal answered 7/9, 2015 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.