Settings.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*!
  2. * Ext JS Library 4.0
  3. * Copyright(c) 2006-2011 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.define('MyDesktop.Settings', {
  8. extend: 'Ext.window.Window',
  9. uses: [
  10. 'Ext.tree.Panel',
  11. 'Ext.tree.View',
  12. 'Ext.form.field.Checkbox',
  13. 'Ext.layout.container.Anchor',
  14. 'Ext.layout.container.Border',
  15. 'Ext.ux.desktop.Wallpaper',
  16. 'MyDesktop.WallpaperModel'
  17. ],
  18. layout: 'anchor',
  19. title: 'Change Settings',
  20. modal: true,
  21. width: 640,
  22. height: 480,
  23. border: false,
  24. initComponent: function () {
  25. var me = this;
  26. me.selected = me.desktop.getWallpaper();
  27. me.stretch = me.desktop.wallpaper.stretch;
  28. me.preview = Ext.create('widget.wallpaper');
  29. me.preview.setWallpaper(me.selected);
  30. me.tree = me.createTree();
  31. me.buttons = [
  32. { text: 'OK', handler: me.onOK, scope: me },
  33. { text: 'Cancel', handler: me.close, scope: me }
  34. ];
  35. me.items = [
  36. {
  37. anchor: '0 -30',
  38. border: false,
  39. layout: 'border',
  40. items: [
  41. me.tree,
  42. {
  43. xtype: 'panel',
  44. title: 'Preview',
  45. region: 'center',
  46. layout: 'fit',
  47. items: [ me.preview ]
  48. }
  49. ]
  50. },
  51. {
  52. xtype: 'checkbox',
  53. boxLabel: 'Stretch to fit',
  54. checked: me.stretch,
  55. listeners: {
  56. change: function (comp) {
  57. me.stretch = comp.checked;
  58. }
  59. }
  60. }
  61. ];
  62. me.callParent();
  63. },
  64. createTree : function() {
  65. var me = this;
  66. function child (img) {
  67. return { img: img, text: me.getTextOfWallpaper(img), iconCls: '', leaf: true };
  68. }
  69. var tree = new Ext.tree.Panel({
  70. title: 'Desktop Background',
  71. rootVisible: false,
  72. lines: false,
  73. autoScroll: true,
  74. width: 150,
  75. region: 'west',
  76. split: true,
  77. minWidth: 100,
  78. listeners: {
  79. afterrender: { fn: this.setInitialSelection, delay: 100 },
  80. select: this.onSelect,
  81. scope: this
  82. },
  83. store: new Ext.data.TreeStore({
  84. model: 'MyDesktop.WallpaperModel',
  85. root: {
  86. text:'Wallpaper',
  87. expanded: true,
  88. children:[
  89. { text: "None", iconCls: '', leaf: true },
  90. child('Blue-Sencha.jpg'),
  91. child('Dark-Sencha.jpg'),
  92. child('Wood-Sencha.jpg'),
  93. child('blue.jpg'),
  94. child('desk.jpg'),
  95. child('desktop.jpg'),
  96. child('desktop2.jpg'),
  97. child('sky.jpg')
  98. ]
  99. }
  100. })
  101. });
  102. return tree;
  103. },
  104. getTextOfWallpaper: function (path) {
  105. var text = path, slash = path.lastIndexOf('/');
  106. if (slash >= 0) {
  107. text = text.substring(slash+1);
  108. }
  109. var dot = text.lastIndexOf('.');
  110. text = Ext.String.capitalize(text.substring(0, dot));
  111. text = text.replace(/[-]/g, ' ');
  112. return text;
  113. },
  114. onOK: function () {
  115. var me = this;
  116. if (me.selected) {
  117. me.desktop.setWallpaper(me.selected, me.stretch);
  118. }
  119. me.destroy();
  120. },
  121. onSelect: function (tree, record) {
  122. var me = this;
  123. if (record.data.img) {
  124. me.selected = 'wallpapers/' + record.data.img;
  125. } else {
  126. me.selected = Ext.BLANK_IMAGE_URL;
  127. }
  128. me.preview.setWallpaper(me.selected);
  129. },
  130. setInitialSelection: function () {
  131. var s = this.desktop.getWallpaper();
  132. if (s) {
  133. var path = '/Wallpaper/' + this.getTextOfWallpaper(s);
  134. this.tree.selectPath(path, 'text');
  135. }
  136. }
  137. });