PageRenderTime 39ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/ext-4.1.0_b3/examples/direct/direct.js

https://bitbucket.org/srogerf/javascript
JavaScript | 109 lines | 101 code | 8 blank | 0 comment | 4 complexity | e695d955c6560b23ac97ded9b838581a MD5 | raw file
  1. Ext.require([
  2. 'Ext.direct.*',
  3. 'Ext.panel.Panel',
  4. 'Ext.form.field.Text',
  5. 'Ext.toolbar.TextItem'
  6. ]);
  7. Ext.onReady(function(){
  8. function doEcho(field){
  9. TestAction.doEcho(field.getValue(), function(result, event){
  10. var transaction = event.getTransaction(),
  11. content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
  12. transaction.action, transaction.method, Ext.encode(result));
  13. updateMain(content);
  14. field.reset();
  15. });
  16. }
  17. function doMultiply(field){
  18. TestAction.multiply(field.getValue(), function(result, event){
  19. var transaction = event.getTransaction(),
  20. content;
  21. if (event.status) {
  22. content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
  23. transaction.action, transaction.method, Ext.encode(result));
  24. } else {
  25. content = Ext.String.format('<b>Call to {0}.{1} failed with message:</b><pre>{2}</pre>',
  26. transaction.action, transaction.method, event.message);
  27. }
  28. updateMain(content);
  29. field.reset();
  30. });
  31. }
  32. function updateMain(content){
  33. main.update({
  34. data: content
  35. });
  36. main.body.scroll('b', 100000, true);
  37. }
  38. Ext.direct.Manager.addProvider(Ext.app.REMOTING_API, {
  39. type:'polling',
  40. url: 'php/poll.php',
  41. listeners: {
  42. data: function(provider, event){
  43. updateMain('<i>' + event.data + '</i>');
  44. }
  45. }
  46. });
  47. var main = Ext.create('Ext.panel.Panel', {
  48. id: 'logger',
  49. title: 'Remote Call Log',
  50. renderTo: document.body,
  51. width: 600,
  52. height: 300,
  53. tpl: '<p>{data}</p>',
  54. tplWriteMode: 'append',
  55. autoScroll: true,
  56. bodyStyle: 'padding: 5px;',
  57. dockedItems: [{
  58. dock: 'bottom',
  59. xtype: 'toolbar',
  60. items: [{
  61. hideLabel: true,
  62. itemId: 'echoText',
  63. xtype: 'textfield',
  64. width: 300,
  65. emptyText: 'Echo input',
  66. listeners: {
  67. specialkey: function(field, event){
  68. if (event.getKey() === event.ENTER) {
  69. doEcho(field);
  70. }
  71. }
  72. }
  73. }, {
  74. itemId: 'echo',
  75. text: 'Echo',
  76. handler: function(){
  77. doEcho(main.down('#echoText'));
  78. }
  79. }, '-', {
  80. hideLabel: true,
  81. itemId: 'multiplyText',
  82. xtype: 'textfield',
  83. width: 80,
  84. emptyText: 'Multiply x 8',
  85. listeners: {
  86. specialkey: function(field, event){
  87. if (event.getKey() === event.ENTER) {
  88. doMultiply(field);
  89. }
  90. }
  91. }
  92. }, {
  93. itemId: 'multiply',
  94. text: 'Multiply',
  95. handler: function(){
  96. doMultiply(main.down('#multiplyText'));
  97. }
  98. }]
  99. }]
  100. });
  101. });