3 * @extends Ext.util.Observable
6 Ext.define('Ext.App', {
7 extend: 'Ext.util.Observable',
10 * response status codes.
12 STATUS_EXCEPTION : 'exception',
13 STATUS_VALIDATION_ERROR : "validation",
14 STATUS_ERROR: "error",
15 STATUS_NOTICE: "notice",
21 * remoting api. should be defined in your own config js.
29 // private, ref to message-box Element.
32 constructor: function(config) {
35 this.initStateProvider();
37 Ext.apply(this, config);
39 if (!this.api.actions) {
40 this.api.actions = {};
43 Ext.onReady(this.onReady, this);
45 Ext.App.superclass.constructor.apply(this, arguments);
48 // @protected, onReady, executes when Ext.onReady fires.
49 onReady : function() {
50 // create the msgBox container. used for App.setAlert
51 this.msgCt = Ext.core.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
52 this.msgCt.setStyle('position', 'absolute');
53 this.msgCt.setStyle('z-index', 9999);
54 this.msgCt.setWidth(300);
57 initStateProvider : function() {
59 * set days to be however long you think cookies should last
61 var days = ''; // expires when browser closes
63 var date = new Date();
64 date.setTime(date.getTime()+(days*24*60*60*1000));
65 var exptime = "; expires="+date.toGMTString();
70 // register provider with state manager.
71 Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', {
81 * register an application view component.
82 * @param {Object} view
84 registerView : function(view) {
85 this.views.push(view);
90 * return list of registered views
92 getViews : function() {
98 * registers new actions for API
99 * @param {Object} actions
101 registerActions : function(actions) {
102 Ext.apply(this.api.actions, actions);
107 * return Ext Remoting api
109 getAPI : function() {
115 * show the message box. Aliased to addMessage
116 * @param {String} msg
117 * @param {Bool} status
119 setAlert : function(status, msg) {
120 this.addMessage(status, msg);
124 * adds a message to queue.
125 * @param {String} msg
126 * @param {Bool} status
128 addMessage : function(status, msg) {
129 var delay = 3; // <-- default delay of msg box is 1 second.
130 if (status == false) {
131 delay = 5; // <-- when status is error, msg box delay is 3 seconds.
133 // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
134 delay = msg.length / 13.3;
138 else if (delay > 9) {
142 this.msgCt.alignTo(document, 't-t');
143 Ext.core.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});
149 buildMessageBox : function(title, msg) {
152 title = this.STATUS_OK;
155 title = this.STATUS_ERROR;
159 '<div class="app-msg">',
160 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
161 '<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>',
162 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
169 * @param {Object} status
171 decodeStatusIcon : function(status) {
176 iconCls = this.ICON_OK;
178 case this.STATUS_NOTICE:
179 iconCls = this.ICON_NOTICE;
182 case this.STATUS_ERROR:
183 iconCls = this.ICON_ERROR;
185 case this.STATUS_HELP:
186 iconCls = this.ICON_HELP;
193 * setViewState, alias for Ext.state.Manager.set
194 * @param {Object} key
195 * @param {Object} value
197 setViewState : function(key, value) {
198 Ext.state.Manager.set(key, value);
202 * getViewState, aliaz for Ext.state.Manager.get
203 * @param {Object} cmd
205 getViewState : function(key) {
206 return Ext.state.Manager.get(key);
211 * translation function. needs to be implemented. simply echos supplied word back currently.
212 * @param {String} to translate
213 * @return {String} translated.
215 t : function(words) {
219 handleResponse : function(res) {
220 if (res.type == this.STATUS_EXCEPTION) {
221 return this.handleException(res);
223 if (res.message.length > 0) {
224 this.setAlert(res.status, res.message);
228 handleException : function(res) {
229 Ext.MessageBox.alert(res.type.toUpperCase(), res.message);