]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('KitchenSink.view.ProfileSwitcher', {\r |
2 | extend: 'Ext.Component',\r | |
3 | xtype: 'profileSwitcher',\r | |
4 | cls: 'ks-profile-switcher',\r | |
5 | \r | |
6 | readProfileInfo: function() {\r | |
7 | var profile = location.href.match(/profile=([\w\-]+)/),\r | |
8 | locale = location.href.match(/locale=([\w\-]+)/);\r | |
9 | \r | |
10 | profile = (profile && profile[1]) || (Ext.platformTags.phone ? 'modern-neptune' : 'triton');\r | |
11 | locale = locale && locale[1] || 'en';\r | |
12 | \r | |
13 | if (!Ext.profileName && !!profile) {\r | |
14 | var m = profile.match(/^([\w\-]+)-(?:he)$/);\r | |
15 | Ext.profileName = m ? m[1] : profile;\r | |
16 | }\r | |
17 | \r | |
18 | this.profile = profile;\r | |
19 | this.locale = locale;\r | |
20 | },\r | |
21 | \r | |
22 | setQueryParam: function(name, value, preserveHash) {\r | |
23 | var query = Ext.Object.fromQueryString(location.search),\r | |
24 | queryString;\r | |
25 | \r | |
26 | query[name] = value;\r | |
27 | \r | |
28 | queryString = Ext.Object.toQueryString(query);\r | |
29 | if (preserveHash) {\r | |
30 | location.search = queryString;\r | |
31 | } else {\r | |
32 | window.location = location.pathname + '?' + queryString;\r | |
33 | }\r | |
34 | },\r | |
35 | \r | |
36 | initComponent: function() {\r | |
37 | var me = this,\r | |
38 | menuItems = [],\r | |
39 | classicProfiles = {\r | |
40 | triton: 'Triton',\r | |
41 | neptune: 'Neptune',\r | |
42 | 'neptune-touch': 'Neptune Touch',\r | |
43 | crisp: 'Crisp',\r | |
44 | 'crisp-touch': 'Crisp Touch',\r | |
45 | classic: 'Classic',\r | |
46 | gray: 'Gray'\r | |
47 | },\r | |
48 | modernProfiles = {\r | |
49 | 'modern-triton': 'Modern Triton',\r | |
50 | 'modern-neptune': 'Modern Neptune',\r | |
51 | blackberry: 'Blackberry',\r | |
52 | cupertino: 'Cupertino',\r | |
53 | mountainview: 'Mountain View',\r | |
54 | windows: 'Windows'\r | |
55 | },\r | |
56 | menu, profileId;\r | |
57 | \r | |
58 | me.readProfileInfo();\r | |
59 | \r | |
60 | function makeItem(value, text, paramName) {\r | |
61 | paramName = paramName || "profile";\r | |
62 | \r | |
63 | var checked = value === (paramName === "profile" ? me.profile : me.locale);\r | |
64 | \r | |
65 | return {\r | |
66 | text: text,\r | |
67 | group: (paramName === 'profile' ? 'profilegroup' : 'localegroup'),\r | |
68 | checked: checked,\r | |
69 | handler: function () {\r | |
70 | if (!checked) {\r | |
71 | if(paramName === 'profile') {\r | |
72 | me.setQueryParam('profile', value, value in classicProfiles);\r | |
73 | } else {\r | |
74 | me.setQueryParam('locale', value);\r | |
75 | }\r | |
76 | }\r | |
77 | }\r | |
78 | };\r | |
79 | }\r | |
80 | \r | |
81 | for (profileId in classicProfiles) {\r | |
82 | menuItems.push(makeItem(profileId, classicProfiles[profileId]));\r | |
83 | }\r | |
84 | \r | |
85 | menuItems.push('-');\r | |
86 | \r | |
87 | for (profileId in modernProfiles) {\r | |
88 | menuItems.push(makeItem(profileId, modernProfiles[profileId]));\r | |
89 | }\r | |
90 | \r | |
91 | menuItems.push('-');\r | |
92 | \r | |
93 | menuItems.push(makeItem('en', 'English', 'locale'));\r | |
94 | menuItems.push(makeItem('he', 'Hebrew', 'locale'));\r | |
95 | \r | |
96 | menu = new Ext.menu.Menu({\r | |
97 | items: menuItems\r | |
98 | });\r | |
99 | \r | |
100 | this.on({\r | |
101 | scope: this,\r | |
102 | click: function (e) {\r | |
103 | menu.showBy(this);\r | |
104 | },\r | |
105 | element: 'el'\r | |
106 | });\r | |
107 | \r | |
108 | this.callParent();\r | |
109 | }\r | |
110 | });\r |