msg-box.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Ext.require([
  2. 'Ext.window.MessageBox',
  3. 'Ext.tip.*'
  4. ]);
  5. Ext.onReady(function(){
  6. Ext.get('mb1').on('click', function(e){
  7. Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?', showResult);
  8. });
  9. Ext.get('mb2').on('click', function(e){
  10. Ext.MessageBox.prompt('Name', 'Please enter your name:', showResultText);
  11. });
  12. Ext.get('mb3').on('click', function(e){
  13. Ext.MessageBox.show({
  14. title: 'Address',
  15. msg: 'Please enter your address:',
  16. width:300,
  17. buttons: Ext.MessageBox.OKCANCEL,
  18. multiline: true,
  19. fn: showResultText,
  20. animateTarget: 'mb3'
  21. });
  22. });
  23. Ext.get('mb4').on('click', function(e){
  24. Ext.MessageBox.show({
  25. title:'Save Changes?',
  26. msg: 'You are closing a tab that has unsaved changes. <br />Would you like to save your changes?',
  27. buttons: Ext.MessageBox.YESNOCANCEL,
  28. fn: showResult,
  29. animateTarget: 'mb4',
  30. icon: Ext.MessageBox.QUESTION
  31. });
  32. });
  33. Ext.get('mb6').on('click', function(){
  34. Ext.MessageBox.show({
  35. title: 'Please wait',
  36. msg: 'Loading items...',
  37. progressText: 'Initializing...',
  38. width:300,
  39. progress:true,
  40. closable:false,
  41. animateTarget: 'mb6'
  42. });
  43. // this hideous block creates the bogus progress
  44. var f = function(v){
  45. return function(){
  46. if(v == 12){
  47. Ext.MessageBox.hide();
  48. Ext.example.msg('Done', 'Your fake items were loaded!');
  49. }else{
  50. var i = v/11;
  51. Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% completed');
  52. }
  53. };
  54. };
  55. for(var i = 1; i < 13; i++){
  56. setTimeout(f(i), i*500);
  57. }
  58. });
  59. Ext.get('mb7').on('click', function(){
  60. Ext.MessageBox.show({
  61. msg: 'Saving your data, please wait...',
  62. progressText: 'Saving...',
  63. width:300,
  64. wait:true,
  65. waitConfig: {interval:200},
  66. icon:'ext-mb-download', //custom class in msg-box.html
  67. animateTarget: 'mb7'
  68. });
  69. setTimeout(function(){
  70. //This simulates a long-running operation like a database save or XHR call.
  71. //In real code, this would be in a callback function.
  72. Ext.MessageBox.hide();
  73. Ext.example.msg('Done', 'Your fake data was saved!');
  74. }, 8000);
  75. });
  76. Ext.get('mb8').on('click', function(){
  77. Ext.MessageBox.alert('Status', 'Changes saved successfully.', showResult);
  78. });
  79. //Add these values dynamically so they aren't hard-coded in the html
  80. Ext.fly('info').dom.value = Ext.MessageBox.INFO;
  81. Ext.fly('question').dom.value = Ext.MessageBox.QUESTION;
  82. Ext.fly('warning').dom.value = Ext.MessageBox.WARNING;
  83. Ext.fly('error').dom.value = Ext.MessageBox.ERROR;
  84. Ext.get('mb9').on('click', function(){
  85. Ext.MessageBox.show({
  86. title: 'Icon Support',
  87. msg: 'Here is a message with an icon!',
  88. buttons: Ext.MessageBox.OK,
  89. animateTarget: 'mb9',
  90. fn: showResult,
  91. icon: Ext.get('icons').dom.value
  92. });
  93. });
  94. Ext.get('mb10').on('click', function(){
  95. Ext.MessageBox.show({
  96. title: 'What, really?',
  97. msg: 'Are you sure?',
  98. buttons: Ext.MessageBox.YESNO,
  99. buttonText:{
  100. yes: "Definitely!",
  101. no: "No chance!"
  102. },
  103. fn: showResult
  104. });
  105. });
  106. function showResult(btn){
  107. Ext.example.msg('Button Click', 'You clicked the {0} button', btn);
  108. };
  109. function showResultText(btn, text){
  110. Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text "{1}".', btn, text);
  111. };
  112. });