9f29d1fce471fa7bac58aba7e082063c2d15ef90.svn-base 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.MessageBox = function() {
  7. var R, B, N, Q;
  8. var G, J, P, A, K, M, H, F;
  9. var O, S, L, C = "";
  10. var D = function(U) {
  11. R.hide();
  12. Ext.callback(B.fn, B.scope || window, [U, S.dom.value], 1)
  13. };
  14. var T = function() {
  15. if (B && B.cls) {
  16. R.el.removeClass(B.cls)
  17. }
  18. K.reset()
  19. };
  20. var E = function(W, U, V) {
  21. if (B && B.closable !== false) {
  22. R.hide()
  23. }
  24. if (V) {
  25. V.stopEvent()
  26. }
  27. };
  28. var I = function(U) {
  29. var W = 0;
  30. if (!U) {
  31. O["ok"].hide();
  32. O["cancel"].hide();
  33. O["yes"].hide();
  34. O["no"].hide();
  35. return W
  36. }
  37. R.footer.dom.style.display = "";
  38. for (var V in O) {
  39. if (typeof O[V] != "function") {
  40. if (U[V]) {
  41. O[V].show();
  42. O[V].setText(typeof U[V] == "string"
  43. ? U[V]
  44. : Ext.MessageBox.buttonText[V]);
  45. W += O[V].el.getWidth() + 15
  46. } else {
  47. O[V].hide()
  48. }
  49. }
  50. }
  51. return W
  52. };
  53. return {
  54. getDialog : function(U) {
  55. if (!R) {
  56. R = new Ext.Window({
  57. autoCreate : true,
  58. title : U,
  59. resizable : false,
  60. constrain : true,
  61. constrainHeader : true,
  62. minimizable : false,
  63. maximizable : false,
  64. stateful : false,
  65. modal : true,
  66. shim : true,
  67. buttonAlign : "center",
  68. width : 400,
  69. height : 100,
  70. minHeight : 80,
  71. plain : true,
  72. footer : true,
  73. closable : true,
  74. close : function() {
  75. if (B && B.buttons && B.buttons.no && !B.buttons.cancel) {
  76. D("no")
  77. } else {
  78. D("cancel")
  79. }
  80. }
  81. });
  82. O = {};
  83. var V = this.buttonText;
  84. O["ok"] = R.addButton(V["ok"], D.createCallback("ok"));
  85. O["yes"] = R.addButton(V["yes"], D.createCallback("yes"));
  86. O["no"] = R.addButton(V["no"], D.createCallback("no"));
  87. O["cancel"] = R.addButton(V["cancel"], D
  88. .createCallback("cancel"));
  89. O["ok"].hideMode = O["yes"].hideMode = O["no"].hideMode = O["cancel"].hideMode = "offsets";
  90. R.render(document.body);
  91. R.getEl().addClass("x-window-dlg");
  92. N = R.mask;
  93. G = R.body.createChild({
  94. html : "<div class=\"ext-mb-icon\"></div><div class=\"ext-mb-content\"><span class=\"ext-mb-text\"></span><br /><input type=\"text\" class=\"ext-mb-input\" /><textarea class=\"ext-mb-textarea\"></textarea></div>"
  95. });
  96. H = Ext.get(G.dom.firstChild);
  97. var W = G.dom.childNodes[1];
  98. J = Ext.get(W.firstChild);
  99. P = Ext.get(W.childNodes[2]);
  100. P.enableDisplayMode();
  101. P.addKeyListener([10, 13], function() {
  102. if (R.isVisible() && B && B.buttons) {
  103. if (B.buttons.ok) {
  104. D("ok")
  105. } else {
  106. if (B.buttons.yes) {
  107. D("yes")
  108. }
  109. }
  110. }
  111. });
  112. A = Ext.get(W.childNodes[3]);
  113. A.enableDisplayMode();
  114. K = new Ext.ProgressBar({
  115. renderTo : G
  116. });
  117. G.createChild({
  118. cls : "x-clear"
  119. })
  120. }
  121. return R
  122. },
  123. updateText : function(X) {
  124. if (!R.isVisible() && !B.width) {
  125. R.setSize(this.maxWidth, 100)
  126. }
  127. J.update(X || "&#160;");
  128. var V = C != "" ? (H.getWidth() + H.getMargins("lr")) : 0;
  129. var Z = J.getWidth() + J.getMargins("lr");
  130. var W = R.getFrameWidth("lr");
  131. var Y = R.body.getFrameWidth("lr");
  132. if (Ext.isIE && V > 0) {
  133. V += 3
  134. }
  135. var U = Math.max(Math.min(B.width || V + Z + W + Y, this.maxWidth),
  136. Math.max(B.minWidth || this.minWidth, L || 0));
  137. if (B.prompt === true) {
  138. S.setWidth(U - V - W - Y)
  139. }
  140. if (B.progress === true || B.wait === true) {
  141. K.setSize(U - V - W - Y)
  142. }
  143. R.setSize(U, "auto").center();
  144. return this
  145. },
  146. updateProgress : function(V, U, W) {
  147. K.updateProgress(V, U);
  148. if (W) {
  149. this.updateText(W)
  150. }
  151. return this
  152. },
  153. isVisible : function() {
  154. return R && R.isVisible()
  155. },
  156. hide : function() {
  157. if (this.isVisible()) {
  158. R.hide();
  159. T()
  160. }
  161. return this
  162. },
  163. show : function(X) {
  164. if (this.isVisible()) {
  165. this.hide()
  166. }
  167. B = X;
  168. var Y = this.getDialog(B.title || "&#160;");
  169. Y.setTitle(B.title || "&#160;");
  170. var U = (B.closable !== false && B.progress !== true && B.wait !== true);
  171. Y.tools.close.setDisplayed(U);
  172. S = P;
  173. B.prompt = B.prompt || (B.multiline ? true : false);
  174. if (B.prompt) {
  175. if (B.multiline) {
  176. P.hide();
  177. A.show();
  178. A.setHeight(typeof B.multiline == "number"
  179. ? B.multiline
  180. : this.defaultTextHeight);
  181. S = A
  182. } else {
  183. P.show();
  184. A.hide()
  185. }
  186. } else {
  187. P.hide();
  188. A.hide()
  189. }
  190. S.dom.value = B.value || "";
  191. if (B.prompt) {
  192. Y.focusEl = S
  193. } else {
  194. var W = B.buttons;
  195. var V = null;
  196. if (W && W.ok) {
  197. V = O["ok"]
  198. } else {
  199. if (W && W.yes) {
  200. V = O["yes"]
  201. }
  202. }
  203. if (V) {
  204. Y.focusEl = V
  205. }
  206. }
  207. this.setIcon(B.icon);
  208. L = I(B.buttons);
  209. K.setVisible(B.progress === true || B.wait === true);
  210. this.updateProgress(0, B.progressText);
  211. this.updateText(B.msg);
  212. if (B.cls) {
  213. Y.el.addClass(B.cls)
  214. }
  215. Y.proxyDrag = B.proxyDrag === true;
  216. Y.modal = B.modal !== false;
  217. Y.mask = B.modal !== false ? N : false;
  218. if (!Y.isVisible()) {
  219. document.body.appendChild(R.el.dom);
  220. Y.setAnimateTarget(B.animEl);
  221. Y.show(B.animEl)
  222. }
  223. Y.on("show", function() {
  224. if (U === true) {
  225. Y.keyMap.enable()
  226. } else {
  227. Y.keyMap.disable()
  228. }
  229. });
  230. if (B.wait === true) {
  231. K.wait(B.waitConfig)
  232. }
  233. return this
  234. },
  235. setIcon : function(U) {
  236. if (U && U != "") {
  237. H.removeClass("x-hidden");
  238. H.replaceClass(C, U);
  239. C = U
  240. } else {
  241. H.replaceClass(C, "x-hidden");
  242. C = ""
  243. }
  244. return this
  245. },
  246. progress : function(W, V, U) {
  247. this.show({
  248. title : W,
  249. msg : V,
  250. buttons : false,
  251. progress : true,
  252. closable : false,
  253. minWidth : this.minProgressWidth,
  254. progressText : U
  255. });
  256. return this
  257. },
  258. wait : function(W, V, U) {
  259. this.show({
  260. title : V,
  261. msg : W,
  262. buttons : false,
  263. closable : false,
  264. wait : true,
  265. modal : true,
  266. minWidth : this.minProgressWidth,
  267. waitConfig : U
  268. });
  269. return this
  270. },
  271. alert : function(X, W, V, U) {
  272. this.show({
  273. title : X,
  274. msg : W,
  275. buttons : this.OK,
  276. fn : V,
  277. scope : U
  278. });
  279. return this
  280. },
  281. confirm : function(X, W, V, U) {
  282. this.show({
  283. title : X,
  284. msg : W,
  285. buttons : this.YESNO,
  286. fn : V,
  287. scope : U,
  288. icon : this.QUESTION
  289. });
  290. return this
  291. },
  292. prompt : function(Y, X, W, V, U) {
  293. this.show({
  294. title : Y,
  295. msg : X,
  296. buttons : this.OKCANCEL,
  297. fn : W,
  298. minWidth : 250,
  299. scope : V,
  300. prompt : true,
  301. multiline : U
  302. });
  303. return this
  304. },
  305. OK : {
  306. ok : true
  307. },
  308. CANCEL : {
  309. cancel : true
  310. },
  311. OKCANCEL : {
  312. ok : true,
  313. cancel : true
  314. },
  315. YESNO : {
  316. yes : true,
  317. no : true
  318. },
  319. YESNOCANCEL : {
  320. yes : true,
  321. no : true,
  322. cancel : true
  323. },
  324. INFO : "ext-mb-info",
  325. WARNING : "ext-mb-warning",
  326. QUESTION : "ext-mb-question",
  327. ERROR : "ext-mb-error",
  328. defaultTextHeight : 75,
  329. maxWidth : 600,
  330. minWidth : 100,
  331. minProgressWidth : 250,
  332. buttonText : {
  333. ok : "OK",
  334. cancel : "Cancel",
  335. yes : "Yes",
  336. no : "No"
  337. }
  338. }
  339. }();
  340. Ext.Msg = Ext.MessageBox;