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