Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
6.1 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * Ext.App
  9. * @extends Ext.util.Observable
  10. * @author Chris Scott
  11. */
  12. Ext.App = function(config) {
  13. this.views = [];
  14. this.initStateProvider();
  15. Ext.apply(this, config);
  16. if (!this.api.actions) {
  17. this.api.actions = {};
  18. }
  19. Ext.onReady(this.onReady, this);
  20. Ext.App.superclass.constructor.apply(this, arguments);
  21. };
  22. Ext.extend(Ext.App, Ext.util.Observable, {
  23. /***
  24. * response status codes.
  25. */
  26. STATUS_EXCEPTION : 'exception',
  27. STATUS_VALIDATION_ERROR : "validation",
  28. STATUS_ERROR: "error",
  29. STATUS_NOTICE: "notice",
  30. STATUS_OK: "ok",
  31. STATUS_HELP: "help",
  32. /**
  33. * @cfg {Object} api
  34. * remoting api. should be defined in your own config js.
  35. */
  36. api: {
  37. url: null,
  38. type: null,
  39. actions: {}
  40. },
  41. // private, ref to message-box Element.
  42. msgCt : null,
  43. // @protected, onReady, executes when Ext.onReady fires.
  44. onReady : function() {
  45. // create the msgBox container. used for App.setAlert
  46. this.msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
  47. this.msgCt.setStyle('position', 'absolute');
  48. this.msgCt.setStyle('z-index', 9999);
  49. this.msgCt.setWidth(300);
  50. },
  51. initStateProvider : function() {
  52. /*
  53. * set days to be however long you think cookies should last
  54. */
  55. var days = ''; // expires when browser closes
  56. if(days){
  57. var date = new Date();
  58. date.setTime(date.getTime()+(days*24*60*60*1000));
  59. var exptime = "; expires="+date.toGMTString();
  60. } else {
  61. var exptime = null;
  62. }
  63. // register provider with state manager.
  64. Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
  65. path: '/',
  66. expires: exptime,
  67. domain: null,
  68. secure: false
  69. }));
  70. },
  71. /**
  72. * registerView
  73. * register an application view component.
  74. * @param {Object} view
  75. */
  76. registerView : function(view) {
  77. this.views.push(view);
  78. },
  79. /**
  80. * getViews
  81. * return list of registered views
  82. */
  83. getViews : function() {
  84. return this.views;
  85. },
  86. /**
  87. * registerActions
  88. * registers new actions for API
  89. * @param {Object} actions
  90. */
  91. registerActions : function(actions) {
  92. Ext.apply(this.api.actions, actions);
  93. },
  94. /**
  95. * getAPI
  96. * return Ext Remoting api
  97. */
  98. getAPI : function() {
  99. return this.api;
  100. },
  101. /***
  102. * setAlert
  103. * show the message box. Aliased to addMessage
  104. * @param {String} msg
  105. * @param {Bool} status
  106. */
  107. setAlert : function(status, msg) {
  108. this.addMessage(status, msg);
  109. },
  110. /***
  111. * adds a message to queue.
  112. * @param {String} msg
  113. * @param {Bool} status
  114. */
  115. addMessage : function(status, msg) {
  116. var delay = 3; // <-- default delay of msg box is 1 second.
  117. if (status == false) {
  118. delay = 5; // <-- when status is error, msg box delay is 3 seconds.
  119. }
  120. // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
  121. delay = msg.length / 13.3;
  122. if (delay < 3) {
  123. delay = 3;
  124. }
  125. else if (delay > 9) {
  126. delay = 9;
  127. }
  128. this.msgCt.alignTo(document, 't-t');
  129. 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});
  130. },
  131. /***
  132. * buildMessageBox
  133. */
  134. buildMessageBox : function(title, msg) {
  135. switch (title) {
  136. case true:
  137. title = this.STATUS_OK;
  138. break;
  139. case false:
  140. title = this.STATUS_ERROR;
  141. break;
  142. }
  143. return [
  144. '<div class="app-msg">',
  145. '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
  146. '<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>',
  147. '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
  148. '</div>'
  149. ].join('');
  150. },
  151. /**
  152. * decodeStatusIcon
  153. * @param {Object} status
  154. */
  155. decodeStatusIcon : function(status) {
  156. iconCls = '';
  157. switch (status) {
  158. case true:
  159. case this.STATUS_OK:
  160. iconCls = this.ICON_OK;
  161. break;
  162. case this.STATUS_NOTICE:
  163. iconCls = this.ICON_NOTICE;
  164. break;
  165. case false:
  166. case this.STATUS_ERROR:
  167. iconCls = this.ICON_ERROR;
  168. break;
  169. case this.STATUS_HELP:
  170. iconCls = this.ICON_HELP;
  171. break;
  172. }
  173. return iconCls;
  174. },
  175. /***
  176. * setViewState, alias for Ext.state.Manager.set
  177. * @param {Object} key
  178. * @param {Object} value
  179. */
  180. setViewState : function(key, value) {
  181. Ext.state.Manager.set(key, value);
  182. },
  183. /***
  184. * getViewState, aliaz for Ext.state.Manager.get
  185. * @param {Object} cmd
  186. */
  187. getViewState : function(key) {
  188. return Ext.state.Manager.get(key);
  189. },
  190. /**
  191. * t
  192. * translation function. needs to be implemented. simply echos supplied word back currently.
  193. * @param {String} to translate
  194. * @return {String} translated.
  195. */
  196. t : function(words) {
  197. return words;
  198. },
  199. handleResponse : function(res) {
  200. if (res.type == this.STATUS_EXCEPTION) {
  201. return this.handleException(res);
  202. }
  203. if (res.message.length > 0) {
  204. this.setAlert(res.status, res.message);
  205. }
  206. },
  207. handleException : function(res) {
  208. Ext.MessageBox.alert(res.type.toUpperCase(), res.message);
  209. }
  210. });