3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="method-App.user.FormPanel-App"></div>/**
10 * @extends Ext.util.Observable
13 Ext.App = function(config) {
15 // set up StateProvider
16 this.initStateProvider();
21 Ext.apply(this, config);
22 if (!this.api.actions) { this.api.actions = {}; }
24 // init when onReady fires.
25 Ext.onReady(this.onReady, this);
27 Ext.App.superclass.constructor.apply(this, arguments);
29 Ext.extend(Ext.App, Ext.util.Observable, {
31 <div id="prop-App.user.FormPanel-STATUS_EXCEPTION"></div>/***
32 * response status codes.
34 STATUS_EXCEPTION : 'exception',
35 STATUS_VALIDATION_ERROR : "validation",
36 STATUS_ERROR: "error",
37 STATUS_NOTICE: "notice",
41 <div id="cfg-App.user.FormPanel-api"></div>/**
43 * remoting api. should be defined in your own config js.
51 // private, ref to message-box Element.
54 // @protected, onReady, executes when Ext.onReady fires.
55 onReady : function() {
56 // create the msgBox container. used for App.setAlert
57 this.msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
58 this.msgCt.setStyle('position', 'absolute');
59 this.msgCt.setStyle('z-index', 9999);
60 this.msgCt.setWidth(300);
63 initStateProvider : function() {
65 * set days to be however long you think cookies should last
67 var days = ''; // expires when browser closes
69 var date = new Date();
70 date.setTime(date.getTime()+(days*24*60*60*1000));
71 var exptime = "; expires="+date.toGMTString();
76 // register provider with state manager.
77 Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
85 <div id="method-App.user.FormPanel-registerView"></div>/**
87 * register an application view component.
88 * @param {Object} view
90 registerView : function(view) {
91 this.views.push(view);
94 <div id="method-App.user.FormPanel-getViews"></div>/**
96 * return list of registered views
98 getViews : function() {
102 <div id="method-App.user.FormPanel-registerActions"></div>/**
104 * registers new actions for API
105 * @param {Object} actions
107 registerActions : function(actions) {
108 Ext.apply(this.api.actions, actions);
111 <div id="method-App.user.FormPanel-getAPI"></div>/**
113 * return Ext Remoting api
115 getAPI : function() {
119 <div id="method-App.user.FormPanel-setAlert"></div>/***
121 * show the message box. Aliased to addMessage
122 * @param {String} msg
123 * @param {Bool} status
125 setAlert : function(status, msg) {
126 this.addMessage(status, msg);
129 <div id="method-App.user.FormPanel-addMessage"></div>/***
130 * adds a message to queue.
131 * @param {String} msg
132 * @param {Bool} status
134 addMessage : function(status, msg) {
135 var delay = 3; // <-- default delay of msg box is 1 second.
136 if (status == false) {
137 delay = 5; // <-- when status is error, msg box delay is 3 seconds.
139 // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
140 delay = msg.length / 13.3;
144 else if (delay > 9) {
148 this.msgCt.alignTo(document, 't-t');
149 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});
152 <div id="method-App.user.FormPanel-buildMessageBox"></div>/***
155 buildMessageBox : function(title, msg) {
158 title = this.STATUS_OK;
161 title = this.STATUS_ERROR;
165 '<div class="app-msg">',
166 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
167 '<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>',
168 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
173 <div id="method-App.user.FormPanel-decodeStatusIcon"></div>/**
175 * @param {Object} status
177 decodeStatusIcon : function(status) {
182 iconCls = this.ICON_OK;
184 case this.STATUS_NOTICE:
185 iconCls = this.ICON_NOTICE;
188 case this.STATUS_ERROR:
189 iconCls = this.ICON_ERROR;
191 case this.STATUS_HELP:
192 iconCls = this.ICON_HELP;
198 <div id="method-App.user.FormPanel-setViewState"></div>/***
199 * setViewState, alias for Ext.state.Manager.set
200 * @param {Object} key
201 * @param {Object} value
203 setViewState : function(key, value) {
204 Ext.state.Manager.set(key, value);
207 <div id="method-App.user.FormPanel-getViewState"></div>/***
208 * getViewState, aliaz for Ext.state.Manager.get
209 * @param {Object} cmd
211 getViewState : function(key) {
212 return Ext.state.Manager.get(key);
215 <div id="method-App.user.FormPanel-t"></div>/**
217 * translation function. needs to be implemented. simply echos supplied word back currently.
218 * @param {String} to translate
219 * @return {String} translated.
221 t : function(words) {
225 handleResponse : function(res) {
226 if (res.type == this.STATUS_EXCEPTION) {
227 return this.handleException(res);
229 if (res.message.length > 0) {
230 this.setAlert(res.status, res.message);
234 handleException : function(res) {
235 Ext.MessageBox.alert(res.type.toUpperCase(), res.message);