3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @extends Ext.util.Observable
20 Ext.define('Ext.App', {
21 extend: 'Ext.util.Observable',
24 * response status codes.
26 STATUS_EXCEPTION : 'exception',
27 STATUS_VALIDATION_ERROR : "validation",
28 STATUS_ERROR: "error",
29 STATUS_NOTICE: "notice",
35 * remoting api. should be defined in your own config js.
43 // private, ref to message-box Element.
46 constructor: function(config) {
49 this.initStateProvider();
51 Ext.apply(this, config);
53 if (!this.api.actions) {
54 this.api.actions = {};
57 Ext.onReady(this.onReady, this);
59 Ext.App.superclass.constructor.apply(this, arguments);
62 // @protected, onReady, executes when Ext.onReady fires.
63 onReady : function() {
64 // create the msgBox container. used for App.setAlert
65 this.msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
66 this.msgCt.setStyle('position', 'absolute');
67 this.msgCt.setStyle('z-index', 9999);
68 this.msgCt.setWidth(300);
71 initStateProvider : function() {
73 * set days to be however long you think cookies should last
75 var days = ''; // expires when browser closes
77 var date = new Date();
78 date.setTime(date.getTime()+(days*24*60*60*1000));
79 var exptime = "; expires="+date.toGMTString();
84 // register provider with state manager.
85 Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', {
95 * register an application view component.
96 * @param {Object} view
98 registerView : function(view) {
99 this.views.push(view);
104 * return list of registered views
106 getViews : function() {
112 * registers new actions for API
113 * @param {Object} actions
115 registerActions : function(actions) {
116 Ext.apply(this.api.actions, actions);
121 * return Ext Remoting api
123 getAPI : function() {
129 * show the message box. Aliased to addMessage
130 * @param {String} msg
131 * @param {Bool} status
133 setAlert : function(status, msg) {
134 this.addMessage(status, msg);
138 * adds a message to queue.
139 * @param {String} msg
140 * @param {Bool} status
142 addMessage : function(status, msg) {
143 var delay = 3; // <-- default delay of msg box is 1 second.
144 if (status == false) {
145 delay = 5; // <-- when status is error, msg box delay is 3 seconds.
147 // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
148 delay = msg.length / 13.3;
152 else if (delay > 9) {
156 this.msgCt.alignTo(document, 't-t');
157 Ext.DomHelper.append(this.msgCt, {html:this.buildMessageBox(status, String.format.apply(String, Array.prototype.slice.call(arguments, 1)))}, true).slideIn('t').pause(delay).ghost("t", {remove:true});
163 buildMessageBox : function(title, msg) {
166 title = this.STATUS_OK;
169 title = this.STATUS_ERROR;
173 '<div class="app-msg">',
174 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
175 '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3 class="x-icon-text icon-status-' + title + '">', title, '</h3>', msg, '</div></div></div>',
176 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
183 * @param {Object} status
185 decodeStatusIcon : function(status) {
190 iconCls = this.ICON_OK;
192 case this.STATUS_NOTICE:
193 iconCls = this.ICON_NOTICE;
196 case this.STATUS_ERROR:
197 iconCls = this.ICON_ERROR;
199 case this.STATUS_HELP:
200 iconCls = this.ICON_HELP;
207 * setViewState, alias for Ext.state.Manager.set
208 * @param {Object} key
209 * @param {Object} value
211 setViewState : function(key, value) {
212 Ext.state.Manager.set(key, value);
216 * getViewState, aliaz for Ext.state.Manager.get
217 * @param {Object} cmd
219 getViewState : function(key) {
220 return Ext.state.Manager.get(key);
225 * translation function. needs to be implemented. simply echos supplied word back currently.
226 * @param {String} to translate
227 * @return {String} translated.
229 t : function(words) {
233 handleResponse : function(res) {
234 if (res.type == this.STATUS_EXCEPTION) {
235 return this.handleException(res);
237 if (res.message.length > 0) {
238 this.setAlert(res.status, res.message);
242 handleException : function(res) {
243 Ext.MessageBox.alert(res.type.toUpperCase(), res.message);