3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
9 * @extends Ext.util.Observable
12 Ext.App = function(config) {
14 // set up StateProvider
15 this.initStateProvider();
20 Ext.apply(this, config);
21 if (!this.api.actions) { this.api.actions = {}; }
23 // init when onReady fires.
24 Ext.onReady(this.onReady, this);
26 Ext.App.superclass.constructor.apply(this, arguments);
28 Ext.extend(Ext.App, Ext.util.Observable, {
31 * response status codes.
33 STATUS_EXCEPTION : 'exception',
34 STATUS_VALIDATION_ERROR : "validation",
35 STATUS_ERROR: "error",
36 STATUS_NOTICE: "notice",
42 * remoting api. should be defined in your own config js.
50 // private, ref to message-box Element.
53 // @protected, onReady, executes when Ext.onReady fires.
54 onReady : function() {
55 // create the msgBox container. used for App.setAlert
56 this.msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
57 this.msgCt.setStyle('position', 'absolute');
58 this.msgCt.setStyle('z-index', 9999);
59 this.msgCt.setWidth(300);
62 initStateProvider : function() {
64 * set days to be however long you think cookies should last
66 var days = ''; // expires when browser closes
68 var date = new Date();
69 date.setTime(date.getTime()+(days*24*60*60*1000));
70 var exptime = "; expires="+date.toGMTString();
75 // register provider with state manager.
76 Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
86 * register an application view component.
87 * @param {Object} view
89 registerView : function(view) {
90 this.views.push(view);
95 * return list of registered views
97 getViews : function() {
103 * registers new actions for API
104 * @param {Object} actions
106 registerActions : function(actions) {
107 Ext.apply(this.api.actions, actions);
112 * return Ext Remoting api
114 getAPI : function() {
120 * show the message box. Aliased to addMessage
121 * @param {String} msg
122 * @param {Bool} status
124 setAlert : function(status, msg) {
125 this.addMessage(status, msg);
129 * adds a message to queue.
130 * @param {String} msg
131 * @param {Bool} status
133 addMessage : function(status, msg) {
134 var delay = 3; // <-- default delay of msg box is 1 second.
135 if (status == false) {
136 delay = 5; // <-- when status is error, msg box delay is 3 seconds.
138 // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
139 delay = msg.length / 13.3;
143 else if (delay > 9) {
147 this.msgCt.alignTo(document, 't-t');
148 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});
154 buildMessageBox : function(title, msg) {
157 title = this.STATUS_OK;
160 title = this.STATUS_ERROR;
164 '<div class="app-msg">',
165 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
166 '<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>',
167 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
174 * @param {Object} status
176 decodeStatusIcon : function(status) {
181 iconCls = this.ICON_OK;
183 case this.STATUS_NOTICE:
184 iconCls = this.ICON_NOTICE;
187 case this.STATUS_ERROR:
188 iconCls = this.ICON_ERROR;
190 case this.STATUS_HELP:
191 iconCls = this.ICON_HELP;
198 * setViewState, alias for Ext.state.Manager.set
199 * @param {Object} key
200 * @param {Object} value
202 setViewState : function(key, value) {
203 Ext.state.Manager.set(key, value);
207 * getViewState, aliaz for Ext.state.Manager.get
208 * @param {Object} cmd
210 getViewState : function(key) {
211 return Ext.state.Manager.get(key);
216 * translation function. needs to be implemented. simply echos supplied word back currently.
217 * @param {String} to translate
218 * @return {String} translated.
220 t : function(words) {
224 handleResponse : function(res) {
225 if (res.type == this.STATUS_EXCEPTION) {
226 return this.handleException(res);
228 if (res.message.length > 0) {
229 this.setAlert(res.status, res.message);
233 handleException : function(res) {
234 Ext.MessageBox.alert(res.type.toUpperCase(), res.message);