multi-lang.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. Ext.Loader.setConfig({enabled: true});
  2. Ext.Loader.setPath('Ext.ux', '../ux/');
  3. Ext.require([
  4. 'Ext.data.*',
  5. 'Ext.tip.QuickTipManager',
  6. 'Ext.form.*',
  7. 'Ext.ux.data.PagingMemoryProxy',
  8. 'Ext.grid.Panel'
  9. ]);
  10. Ext.onReady(function(){
  11. MultiLangDemo = (function() {
  12. // get the selected language code parameter from url (if exists)
  13. var params = Ext.urlDecode(window.location.search.substring(1));
  14. //Ext.form.Field.prototype.msgTarget = 'side';
  15. return {
  16. init: function() {
  17. Ext.tip.QuickTipManager.init();
  18. /* Language chooser combobox */
  19. var store = Ext.create('Ext.data.ArrayStore', {
  20. fields: ['code', 'language', 'charset'],
  21. data : Ext.exampledata.languages // from languages.js
  22. });
  23. var combo = Ext.create('Ext.form.field.ComboBox', {
  24. renderTo: 'languages',
  25. store: store,
  26. displayField:'language',
  27. queryMode: 'local',
  28. emptyText: 'Select a language...',
  29. hideLabel: true,
  30. listeners: {
  31. select: {
  32. fn: function(cb, records) {
  33. var record = records[0];
  34. window.location.search = Ext.urlEncode({"lang":record.get("code"),"charset":record.get("charset")});
  35. },
  36. scope: this
  37. }
  38. }
  39. });
  40. if (params.lang) {
  41. // check if there's really a language with that language code
  42. var record = store.findRecord('code', params.lang, null, null, null, true);
  43. // if language was found in store assign it as current value in combobox
  44. if (record) {
  45. combo.setValue(record.data.language);
  46. }
  47. }
  48. if (params.lang) {
  49. var record = store.findRecord('code', params.lang, null, null, null, true),
  50. url = Ext.util.Format.format("../../locale/ext-lang-{0}.js", params.lang);
  51. Ext.Loader.injectScriptElement(
  52. url,
  53. this.onSuccess,
  54. this.onFailure,
  55. this,
  56. params.charset);
  57. } else {
  58. this.setupDemo();
  59. }
  60. },
  61. onSuccess: function() {
  62. this.setupDemo();
  63. },
  64. onFailure: function() {
  65. Ext.Msg.alert('Failure', 'Failed to load locale file.');
  66. this.setupDemo();
  67. },
  68. setupDemo: function() {
  69. // Grid needs to be this wide to handle the largest language case for the toolbar.
  70. // In this case, it's Russian.
  71. var width = 500;
  72. /* Email field */
  73. Ext.create('Ext.FormPanel', {
  74. renderTo: 'emailfield',
  75. labelWidth: 100, // label settings here cascade unless overridden
  76. frame: true,
  77. title: 'Email Field',
  78. bodyStyle: 'padding:5px 5px 0',
  79. width: width,
  80. defaults: {
  81. msgTarget: 'side',
  82. width: width - 40
  83. },
  84. defaultType: 'textfield',
  85. items: [{
  86. fieldLabel: 'Email',
  87. name: 'email',
  88. vtype: 'email'
  89. }]
  90. });
  91. /* Datepicker */
  92. Ext.create('Ext.FormPanel', {
  93. renderTo: 'datefield',
  94. labelWidth: 100, // label settings here cascade unless overridden
  95. frame: true,
  96. title: 'Datepicker',
  97. bodyStyle: 'padding:5px 5px 0',
  98. width: width,
  99. defaults: {
  100. msgTarget: 'side',
  101. width: width - 40
  102. },
  103. defaultType: 'datefield',
  104. items: [{
  105. fieldLabel: 'Date',
  106. name: 'date'
  107. }]
  108. });
  109. // shorthand alias
  110. var monthArray = Ext.Array.map(Ext.Date.monthNames, function (e) { return [e]; });
  111. var ds = Ext.create('Ext.data.Store', {
  112. fields: ['month'],
  113. remoteSort: true,
  114. pageSize: 6,
  115. proxy: {
  116. type: 'pagingmemory',
  117. data: monthArray,
  118. reader: {
  119. type: 'array'
  120. }
  121. }
  122. });
  123. Ext.create('Ext.grid.Panel', {
  124. renderTo: 'grid',
  125. width: width,
  126. height: 203,
  127. title:'Month Browser',
  128. columns:[{
  129. text: 'Month of the year',
  130. dataIndex: 'month',
  131. width: 240
  132. }],
  133. store: ds,
  134. bbar: Ext.create('Ext.toolbar.Paging', {
  135. pageSize: 6,
  136. store: ds,
  137. displayInfo: true
  138. })
  139. });
  140. // trigger the data store load
  141. ds.load();
  142. }
  143. };
  144. })();
  145. MultiLangDemo.init();
  146. });