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.

162 lines
5.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. MultiLangDemo = function() {
  16. // get the selected language code parameter from url (if exists)
  17. var params = Ext.urlDecode(window.location.search.substring(1));
  18. Ext.form.Field.prototype.msgTarget = 'side';
  19. return {
  20. init: function() {
  21. Ext.QuickTips.init();
  22. /* Language chooser combobox */
  23. var store = new Ext.data.ArrayStore({
  24. fields: ['code', 'language', 'charset'],
  25. data : Ext.exampledata.languages // from languages.js
  26. });
  27. var combo = new Ext.form.ComboBox({
  28. renderTo: 'languages',
  29. store: store,
  30. displayField:'language',
  31. typeAhead: true,
  32. mode: 'local',
  33. triggerAction: 'all',
  34. emptyText: 'Select a language...',
  35. selectOnFocus: true,
  36. onSelect: function(record) {
  37. window.location.search = Ext.urlEncode({"lang":record.get("code"),"charset":record.get("charset")});
  38. }
  39. });
  40. if (params.lang) {
  41. // check if there's really a language with that language code
  42. record = store.data.find(function(item, key){
  43. if (item.data.code == params.lang) {
  44. return true;
  45. }
  46. return false;
  47. });
  48. // if language was found in store assign it as current value in combobox
  49. if (record) {
  50. combo.setValue(record.data.language);
  51. }
  52. }
  53. if (params.lang) {
  54. var url = String.format("../../src/locale/ext-lang-{0}.js", params.lang);
  55. Ext.Ajax.request({
  56. url: url,
  57. success: this.onSuccess,
  58. failure: this.onFailure,
  59. scope: this
  60. });
  61. } else {
  62. this.setupDemo();
  63. }
  64. },
  65. onSuccess: function(response, opts) {
  66. eval(response.responseText);
  67. this.setupDemo();
  68. },
  69. onFailure: function() {
  70. Ext.Msg.alert('Failure', 'Failed to load locale file.');
  71. this.setupDemo();
  72. },
  73. setupDemo: function() {
  74. /* Email field */
  75. var emailfield = new Ext.FormPanel({
  76. renderTo: 'emailfield',
  77. labelWidth: 100, // label settings here cascade unless overridden
  78. frame: true,
  79. title: 'Email Field',
  80. bodyStyle: 'padding:5px 5px 0',
  81. width: 360,
  82. defaults: {width: 220},
  83. defaultType: 'textfield',
  84. items: [{
  85. fieldLabel: 'Email',
  86. name: 'email',
  87. vtype: 'email'
  88. }]
  89. });
  90. /* Datepicker */
  91. var datefield = new Ext.FormPanel({
  92. renderTo: 'datefield',
  93. labelWidth: 100, // label settings here cascade unless overridden
  94. frame: true,
  95. title: 'Datepicker',
  96. bodyStyle: 'padding:5px 5px 0',
  97. width: 360,
  98. defaults: {width: 220},
  99. defaultType: 'datefield',
  100. items: [{
  101. fieldLabel: 'Date',
  102. name: 'date'
  103. }]
  104. });
  105. // shorthand alias
  106. var fm = Ext.form, Ed = Ext.grid.GridEditor;
  107. var monthArray = Date.monthNames.map(function (e) { return [e]; });
  108. var ds = new Ext.data.Store({
  109. proxy: new Ext.ux.data.PagingMemoryProxy(monthArray),
  110. reader: new Ext.data.ArrayReader({}, [
  111. {name: 'month'}
  112. ])
  113. });
  114. var cm = new Ext.grid.ColumnModel([{
  115. header: "Months of the year",
  116. dataIndex: 'month',
  117. editor: new Ed(new fm.TextField({
  118. allowBlank: false
  119. })),
  120. width: 240,
  121. defaultSortable: true
  122. }]);
  123. var grid = new Ext.grid.GridPanel({
  124. renderTo: 'grid',
  125. width: 360,
  126. height: 203,
  127. title:'Month Browser',
  128. store: ds,
  129. cm: cm,
  130. sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
  131. bbar: new Ext.PagingToolbar({
  132. pageSize: 6,
  133. store: ds,
  134. displayInfo: true
  135. })
  136. });
  137. // trigger the data store load
  138. ds.load({params:{start:0, limit:6}});
  139. }
  140. };
  141. }();
  142. Ext.onReady(MultiLangDemo.init, MultiLangDemo);