Project

General

Profile

Download (7.28 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / flarecast / workspace / client-user-3.0 / app / Application.js @ master

1
/*******************************************************************************
2
 * Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify it under the
7
 * terms of the GNU General Public License as published by the Free Software
8
 * Foundation, either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful, but WITHOUT ANY
12
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along with
16
 * SITools2. If not, see <http://www.gnu.org/licenses/>.
17
 ******************************************************************************/
18
/*global Ext, i18n, loadUrl, getDesktop, sitools, SitoolsDesk */
19
Ext.define('sitools.user.Application', {
20
    name: 'sitools.user',
21

    
22
    requires: ['Ext.container.Viewport',
23

    
24
        /* CORE */
25
        'sitools.public.utils.LoginDef',
26
        'sitools.user.utils.Def',
27
        'sitools.user.core.Project',
28
        'sitools.user.core.Desktop',
29

    
30
        /* UTILS PUBLIC */
31
        'sitools.public.widget.vtype',
32
        'sitools.public.widget.datasets.columnRenderer.BehaviorEnum',
33
        'sitools.public.utils.reference',
34
        'sitools.public.utils.i18n',
35
        'sitools.public.utils.loadUrl',
36
        'sitools.public.utils.sql2ext',
37
        'sitools.public.utils.Locale',
38
        'sitools.public.utils.LoginUtils',
39
        'sitools.public.crypto.Base64',
40
        'sitools.public.utils.UserStorage',
41
        'sitools.public.utils.PublicStorage',
42
        'sitools.public.utils.PopupMessage',
43
        'sitools.public.version.Version',
44
        'sitools.user.utils.I18nRegistry',
45
        'sitools.user.utils.ScriptLoader',
46

    
47
        /* UTILS USER */
48
        'sitools.user.utils.FormUtils',
49
        'sitools.user.utils.ServerServiceUtils',
50
        'sitools.user.utils.DataviewUtils',
51
        'sitools.user.utils.ModuleUtils',
52
        'sitools.user.core.Module',
53

    
54

    
55
        /* MODULE LOADER, uncomment if all plugins have to be loaded at startup*/
56
//                 'sitools.user.utils.PluginDependenciesLoader'
57
    ],
58

    
59
    extend: 'Ext.app.Application',
60

    
61
    controllers: ['core.SitoolsController',
62
        'DesktopController',
63
        'header.HeaderController',
64
        'footer.FooterController',
65
        'core.NavigationModeFactory',
66
        'component.personal.UserPersonalController',
67
        'component.personal.TaskController',
68
        'sitools.user.controller.component.personal.OrderController'
69
    ],
70
    isReady: false,
71
    modules: null,
72
    useQuickTips: true,
73

    
74
    config: {
75
        ready: false,
76
        loaded: false
77
    },
78

    
79
    init: function () {
80
        var me = this, desktopCfg;
81
        this.addMask();
82
        if (me.useQuickTips) {
83
            Ext.tip.QuickTipManager.init(true, {
84
                anchor : 'bottom',
85
                showDelay : 20,
86
                hideDelay : 50
87
            });
88
        }
89

    
90
        if (!Ext.isEmpty(Ext.util.Cookies.get('userLogin'))) {
91
            var auth = Ext.util.Cookies.get('hashCode');
92

    
93
            Ext.Ajax.defaultHeaders = {
94
                "Authorization": auth,
95
                "Accept": "application/json",
96
                "X-User-Agent": "Sitools"
97
            };
98
            taskCheckSessionExpired.delay(COOKIE_DURATION * 60 * 1000);
99

    
100
        } else {
101
            Ext.Ajax.defaultHeaders = {
102
                "Accept": "application/json",
103
                "X-User-Agent": "Sitools"
104
            };
105
        }
106

    
107
        if (Ext.isEmpty(Ext.util.Cookies.get('showDesktopHelp'))) {
108
            Ext.util.Cookies.set('showDesktopHelp', true, sitools.user.utils.Def.getInfiniteCookieDuration());
109
        }
110

    
111
        Desktop.init();
112
        Desktop.setApplication(this);
113
        this.initSiteMap();
114
    },
115

    
116
    // 1
117
    initSiteMap: function () {
118
        loadUrl.load('/sitools/client-user/siteMap', this.initLanguages, this);
119
    },
120

    
121
    // 2
122
    initLanguages: function () {
123
        locale.initLocale();
124
        locale.load(loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL') + '/res/statics/langues.json', this.initi18n, this);
125
    },
126

    
127
    // 3
128
    initi18n: function () {
129
        i18n.load(
130
            loadUrl.get("APP_URL") + loadUrl.get("APP_CLIENT_PUBLIC_URL") + '/res/i18n/' + locale.getLocale() + '/gui.properties',
131
            function () {
132
                if(!checkCookieDuration()){
133
                    Ext.Msg.show({
134
                        title: i18n.get('label.warning'),
135
                        msg : i18n.get("label.wrongcookieduration.configuration")
136
                    });
137
                    this.removeMask();
138
                    return;
139
                }
140
                //def.js
141
                initLocalisedVariables();
142
                this.initSql2ext();
143
            }
144
            , this);
145
    },
146

    
147
    // 4
148
    initSql2ext: function () {
149
        this.updateMaskText();
150
        sql2ext.load(loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL') + '/conf/sql2ext.properties', this.initUser, this);
151
    },
152

    
153
    // 5
154
    initUser: function () {
155
        var storeUser = Ext.create('sitools.user.store.UserStore', {
156
            storeId: 'UserStore'
157
        });
158

    
159
        storeUser.setCustomUrl(loadUrl.get('APP_URL') + loadUrl.get('APP_USER_ROLE_URL'));
160

    
161
//        var url = sitools.user.utils.Project.getSitoolsAttachementForUsers();
162
//        storeUser.setCustomUrl(loadUrl.get('APP_URL') + loadUrl.get('APP_USER_ROLE_URL'));
163
        storeUser.load({
164
            scope: this,
165
            callback: function (records, operation, success) {
166
                if (Ext.isEmpty(records)) {
167
                    storeUser.add({
168
                        firstName: "public",
169
                        identifier: "public",
170
                        email: "&nbsp;"
171
                    });
172
                }
173
                this.initProject();
174
            }
175
        });
176
    },
177

    
178
    // 6
179
    initProject: function () {
180
        sitools.user.core.Project.init(this.projectInitialized, this);
181
    },
182

    
183
    // 7
184
    projectInitialized: function () {
185
        this.setReady(true);
186
        this.fireEvent('projectInitialized'); // listened by SitoolsController
187
    },
188

    
189
    // 11
190
    noticeProjectLoaded: function () {
191
        this.setLoaded(true);
192
        this.fireEvent('projectLoaded');
193
        this.removeMask();
194

    
195
        this.showDesktopHelp();
196
    },
197

    
198
    addMask: function () {
199
        this.splashScreen = Ext.getBody().mask('', 'splashscreen sitoolsLoadingWhite');
200
        this.splashScreen.addCls('splashscreen');
201
        Ext.DomHelper.insertFirst(Ext.query('.x-mask-msg')[0], {
202
            cls: 'x-splash-icon'
203
        });
204
    },
205

    
206
    updateMaskText: function () {
207
        Ext.dom.Query.selectNode('.x-mask-msg-text').innerHTML = i18n.get("label.loadingSitools");
208
    },
209

    
210
    removeMask: function () {
211
        this.splashScreen.fadeOut({
212
            duration: 1000,
213
            remove: true
214
        });
215

    
216
        this.splashScreen.next().fadeOut({
217
            duration: 1000,
218
            remove: true
219
        });
220
    },
221

    
222
    showDesktopHelp : function () {
223
        if (Ext.util.Cookies.get('showDesktopHelp') == "false") {
224
            return;
225
        }
226

    
227
        var desktopHelpView = Ext.create('sitools.user.view.desktop.DesktopHelpView');
228
        desktopHelpView.show();
229
    }
230

    
231
});