]> git.proxmox.com Git - pmg-gui.git/blob - js/Utils.js
improving oclass formatter
[pmg-gui.git] / js / Utils.js
1 Ext.ns('PMG');
2
3 console.log("Starting PMG Manager");
4
5
6 Ext.define('PMG.Utils', {
7 singleton: true,
8
9 // this singleton contains miscellaneous utilities
10
11 senderText: gettext('Sender'),
12 receiverText: gettext('Receiver'),
13
14 oclass_text: {
15 who: gettext('Who Objects'),
16 what: gettext('What Objects'),
17 when: gettext('When Objects'),
18 action: gettext('Action Objects'),
19 from: gettext('From'),
20 to: gettext('To')
21 },
22
23 oclass_icon: {
24 who: '<span class="fa fa-fw fa-user-circle"></span> ',
25 what: '<span class="fa fa-fw fa-cube"></span> ',
26 when: '<span class="fa fa-fw fa-clock-o"></span> ',
27 action: '<span class="fa fa-fw fa-flag"></span> ',
28 from: '<span class="fa fa-fw fa-user-circle"></span> ',
29 to: '<span class="fa fa-fw fa-user-circle"></span> ',
30 },
31
32 format_oclass: function(oclass) {
33 var icon = PMG.Utils.oclass_icon[oclass] || '';
34 var text = PMG.Utils.oclass_text[oclass] || oclass;
35 return icon + text;
36 },
37
38 rule_direction_text: {
39 0: gettext('In'),
40 1: gettext('Out'),
41 2: gettext('In & Out')
42 },
43
44 format_rule_direction: function(dir) {
45 return PMG.Utils.rule_direction_text[dir] || dir;
46 },
47
48 format_otype: function(otype) {
49 var editor = PMG.Utils.object_editors[otype];
50 if (editor) {
51 return editor.subject;
52 }
53 return 'unknown';
54 },
55
56 format_ldap_protocol: function(p) {
57 if (p === undefined) return 'LDAP';
58 if (p === 'ldap') return 'LDAP';
59 if (p === 'ldaps') return 'LDAPS';
60 return 'unknown';
61 },
62
63 object_editors: {
64 1000: {
65 xtype: 'proxmoxWindowEdit',
66 subdir: 'regex',
67 subject: gettext("Regular Expression"),
68 width: 400,
69 items: [
70 {
71 xtype: 'textfield',
72 name: 'regex',
73 labelWidth: 150,
74 fieldLabel: gettext("Regular Expression")
75 }
76 ]
77 },
78 1005: {
79 xtype: 'pmgLDAPGroupEditor',
80 subdir: 'ldap',
81 subject: gettext("LDAP Group")
82 },
83 1006: {
84 xtype: 'pmgLDAPUserEditor',
85 subdir: 'ldapuser',
86 subject: gettext("LDAP User")
87 },
88 1009: {
89 xtype: 'proxmoxWindowEdit',
90 subdir: 'receiver_regex',
91 subject: gettext("Regular Expression"),
92 receivertest: true,
93 width: 400,
94 items: [
95 {
96 xtype: 'textfield',
97 name: 'regex',
98 labelWidth: 150,
99 fieldLabel: gettext("Regular Expression")
100 }
101 ]
102 },
103 1001: {
104 xtype: 'proxmoxWindowEdit',
105 subdir: 'email',
106 subject: gettext("Email"),
107 width: 400,
108 items: [
109 {
110 xtype: 'textfield',
111 name: 'email',
112 fieldLabel: gettext("Email")
113 }
114 ]
115 },
116 1007: {
117 xtype: 'proxmoxWindowEdit',
118 subdir: 'receiver',
119 subject: gettext("Email"),
120 receivertest: true,
121 width: 400,
122 items: [
123 {
124 xtype: 'textfield',
125 name: 'email',
126 fieldLabel: gettext("Email")
127 }
128 ]
129 },
130 1002: {
131 xtype: 'proxmoxWindowEdit',
132 subdir: 'domain',
133 subject: gettext("Domain"),
134 width: 400,
135 items: [
136 {
137 xtype: 'textfield',
138 name: 'domain',
139 fieldLabel: gettext("Domain")
140 }
141 ]
142 },
143 1008: {
144 xtype: 'proxmoxWindowEdit',
145 subdir: 'receiver_domain',
146 subject: gettext("Domain"),
147 receivertest: true,
148 width: 400,
149 items: [
150 {
151 xtype: 'textfield',
152 name: 'domain',
153 fieldLabel: gettext("Domain")
154 }
155 ]
156 },
157 1003: {
158 xtype: 'proxmoxWindowEdit',
159 subdir: 'ip',
160 subject: gettext("IP Address"),
161 width: 400,
162 items: [
163 {
164 xtype: 'textfield',
165 name: 'ip',
166 fieldLabel: gettext("IP Address")
167 }
168 ]
169 },
170 1004: {
171 xtype: 'proxmoxWindowEdit',
172 subdir: 'network',
173 subject: gettext("IP Network"),
174 width: 400,
175 items: [
176 {
177 xtype: 'textfield',
178 name: 'cidr',
179 fieldLabel: gettext("IP Network")
180 }
181 ]
182 },
183 2000: {
184 xtype: 'proxmoxWindowEdit',
185 subdir: 'timeframe',
186 subject: gettext("TimeFrame"),
187 items: [
188 {
189 xtype: 'timefield',
190 name: 'start',
191 format: 'H:i',
192 fieldLabel: gettext("Start Time")
193 },
194 {
195 xtype: 'timefield',
196 name: 'end',
197 format: 'H:i',
198 fieldLabel: gettext("End Time")
199 }
200 ]
201 },
202 4005: {
203 xtype: 'proxmoxWindowEdit',
204 subdir: 'bcc',
205 subject: gettext('BCC'),
206 width: 400,
207 items: [
208 {
209 xtype: 'textfield',
210 name: 'name',
211 allowBlank: false,
212 fieldLabel: gettext('Name')
213 },
214 {
215 xtype: 'textareafield',
216 name: 'info',
217 fieldLabel: gettext("Description")
218 },
219 {
220 xtype: 'textfield',
221 name: 'target',
222 allowBlank: false,
223 fieldLabel: gettext("Target")
224 },
225 {
226 xtype: 'proxmoxcheckbox',
227 checked: true,
228 name: 'original',
229 fieldLabel: gettext("send orig. Mail")
230 }
231 ]
232
233 }
234 },
235
236 openVNCViewer: function(consoletype, nodename) {
237 var url = Ext.urlEncode({
238 console: consoletype, // upgrade or shell
239 novnc: 1,
240 node: nodename
241 });
242 var nw = window.open("?" + url, '_blank',
243 "innerWidth=745,innerheight=427");
244 nw.focus();
245 },
246
247 updateLoginData: function(data) {
248 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
249 Proxmox.UserName = data.username;
250 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
251 },
252
253 constructor: function() {
254 var me = this;
255
256 // do whatever you want here
257 }
258 });