Test Failed
Push — master ( f1c8a7...a1d14d )
by
unknown
35:26 queued 18:32
created

client/zarafa/hierarchy/dialogs/FolderPropertiesPermissionTab.js   F

Complexity

Total Complexity 60
Complexity/F 2.31

Size

Lines of Code 757
Function Count 26

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 455
c 0
b 0
f 0
dl 0
loc 757
rs 3.6
wmc 60
mnd 34
bc 34
fnc 26
bpm 1.3076
cpm 2.3076
noi 6

How to fix   Complexity   

Complexity

Complex classes like client/zarafa/hierarchy/dialogs/FolderPropertiesPermissionTab.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
Ext.namespace('Zarafa.hierarchy.dialogs');
2
3
/**
4
 * @class Zarafa.hierarchy.dialogs.FolderPropertiesPermissionTab
5
 * @extends Ext.Panel
6
 * @xtype zarafa.folderpropertiespermissiontab
7
 *
8
 * Permissions tab in the {@link Zarafa.hierarchy.dialogs.FolderPropertiesContentPanel}
9
 * that is used to set permissions on folder for other users.
10
 */
11
Zarafa.hierarchy.dialogs.FolderPropertiesPermissionTab = Ext.extend(Ext.Panel, {
12
	/**
13
	 * @constructor
14
	 * @param {Object} config
15
	 */
16
17
	constructor: function(config)
18
	{
19
		config = config || {};
20
21
		config.plugins = Ext.value(config.plugins, []);
22
		config.plugins.push('zarafa.recordcomponentupdaterplugin');
23
		var emptyText = Ext.isDefined(config.emptyText) ? config.emptyText : _('No permissions granted');
24
		var isAppointmentDialog = Ext.isDefined(config.isAppointmentDialog) ? config.isAppointmentDialog : false;
25
26
		Ext.applyIf(config, {
27
			xtype: 'zarafa.folderpropertiespermissiontab',
28
			cls: 'tab-permissions',
29
			layout: {
30
				type: 'vbox',
31
				align: 'stretch'
32
			},
33
			border: false,
34
			items: [
35
				this.createUserListPanel(emptyText),
36
				this.createProfilePanel(isAppointmentDialog),
37
				this.createPermissionPanel(isAppointmentDialog)
38
			]
39
		});
40
41
		Zarafa.hierarchy.dialogs.FolderPropertiesPermissionTab.superclass.constructor.call(this, config);
42
	},
43
44
	/**
45
	 * @param {String} emptyText The string which shows in grid when grid is empty.
46
	 * @return {Object} Configuration object for the panel which shows users to which permissions are set
47
	 * @private
48
	 */
49
	createUserListPanel: function(emptyText)
50
	{
51
		return {
52
			xtype: 'panel',
53
			cls: 'userlist-panel',
54
			layout: 'fit',
55
			flex: 1,
56
			border: false,
57
			items: [{
58
				xtype: 'grid',
59
				ref: '../userView',
60
				store: new Zarafa.hierarchy.data.MAPIFolderPermissionsSubStore(),
61
				hideHeaders: true,
62
				enableHdMenu: false,
63
				border: true,
64
				viewConfig: {
65
					forceFit: true,
66
					deferEmptyText: false,
67
					emptyText: '<div class="emptytext">' + emptyText + '</div>'
68
				},
69
				sm: new Ext.grid.RowSelectionModel({
70
					singleSelect: true,
71
					listeners: {
72
						selectionchange: this.onUserSelectionChange,
73
						scope: this
74
					}
75
				}),
76
				columns: [{
77
					dataIndex: 'display_name',
78
					header: '&#160;',
79
					renderer: Ext.util.Format.htmlEncode
80
				}],
81
				listeners: {
82
					viewready: this.onViewReady,
83
					scope: this
84
				}
85
			}],
86
			buttons: [{
87
				cls: 'zarafa-normal',
88
				text: _('Add'),
89
				ref: '../../addUserBtn',
90
				handler: this.onUserAdd,
91
				scope: this,
92
				autoWidth: false
93
			},{
94
				text: _('Remove'),
95
				ref: '../../removeUserBtn',
96
				handler: this.onUserRemove,
97
				scope: this,
98
				autoWidth: false
99
			}]
100
		};
101
	},
102
103
	/**
104
	 * @return {Object} Configuration object for the panel for permissions
105
	 * @private
106
	 */
107
	createProfilePanel: function(isAppointmentDialog)
108
	{
109
		var profileStore = {
110
			xtype: 'jsonstore',
111
			fields: ['name', 'value'],
112
			data: isAppointmentDialog ? Zarafa.hierarchy.data.PermissionProfilesCalendar : Zarafa.hierarchy.data.PermissionProfiles
113
		};
114
115
		return {
116
			xtype: 'panel',
117
			layout: 'fit',
118
			cls: 'profile-panel',
119
			autoHeight: true,
120
			border: false,
121
			items: {
122
				xtype: 'container',
123
				autoHeight: true,
124
				items: [{
125
					xtype: 'form',
126
					layout: {
127
						type: 'table',
128
						columns: 2
129
					},
130
					border: false,
131
					ref: '../profileForm',
132
					items: [{
133
						xtype: 'label',
134
						autoWidth: true,
135
						autoHeight: true,
136
						forId: 'profile-combo',
137
						hideLabel: false,
138
						text: _('Profile') + ':',
139
						ref: '../../profileLabel'
140
					},{
141
						xtype: 'combo',
142
						ref: '../../../profileCombo',
143
						width: 250,
144
						flex: 1,
145
						id: 'profile-combo',
146
						fieldLabel: _('Profile'),
147
						labelWidth: undefined,
148
						labelStyle: 'width: auto',
149
						hideLabel: true,
150
						autoHeight: true,
151
						store: profileStore,
152
						mode: 'local',
153
						triggerAction: 'all',
154
						displayField: 'name',
155
						valueField: 'value',
156
						lazyInit: false,
157
						autoSelect: true,
158
						forceSelection: true,
159
						editable: false,
160
						defaultValue: Zarafa.core.mapi.Rights.RIGHTS_NO_RIGHTS,
161
						listeners: {
162
							select: this.onProfileSelect,
163
							scope: this
164
						}
165
					}]
166
				}]
167
			}
168
		};
169
	},
170
171
	/**
172
	 * @return {Object} Configuration object for the panel for permissions
173
	 * @private
174
	 */
175
	createPermissionPanel: function(isAppointmentDialog)
176
	{
177
		const readRadioGroupItems = isAppointmentDialog ? [{
178
			name: 'allowread',
179
			boxLabel: _('None'),
180
			hideLabel: true,
181
			rightsValue: Zarafa.core.mapi.Rights.RIGHTS_NO_RIGHTS
182
		},{
183
			name: 'allowread',
184
			boxLabel: _('Free/Busy time'),
185
			hideLabel: true,
186
			rightsValue: Zarafa.core.mapi.Rights.RIGHTS_CAL_FBSIMPLE
187
		},{
188
			name: 'allowread',
189
			boxLabel: _('Free/Busy time, subject, location'),
190
			hideLabel: true,
191
			rightsValue: Zarafa.core.mapi.Rights.RIGHTS_CAL_FBSIMPLE | Zarafa.core.mapi.Rights.RIGHTS_CAL_FBDETAILED
192
		},{
193
			name: 'allowread',
194
			boxLabel: _('Full Details'),
195
			hideLabel: true,
196
			rightsValue: Zarafa.core.mapi.Rights.RIGHTS_READ_ANY | Zarafa.core.mapi.Rights.RIGHTS_CAL_FBSIMPLE | Zarafa.core.mapi.Rights.RIGHTS_CAL_FBDETAILED | Zarafa.core.mapi.Rights.RIGHTS_FOLDER_VISIBLE
197
		}] : [{
198
				name: 'allowread',
199
				boxLabel: _('None'),
200
				hideLabel: true,
201
				rightsValue: Zarafa.core.mapi.Rights.RIGHTS_NO_RIGHTS
202
			},{
203
				name: 'allowread',
204
				boxLabel: _('Full Details'),
205
				hideLabel: true,
206
				rightsValue: Zarafa.core.mapi.Rights.RIGHTS_READ_ANY | Zarafa.core.mapi.Rights.RIGHTS_FOLDER_VISIBLE
207
			},
208
		];
209
		return {
210
			xtype: 'form',
211
			layout: 'fit',
212
			cls: 'permissions-panel',
213
			autoHeight: true,
214
			columnWidth: 1,
215
			border: false,
216
			ref: 'permissionsForm',
217
			items: [{
218
				xtype: 'fieldset',
219
				autoHeight: true,
220
				autoSizeColumn: true,
221
				cls: 'zarafa-fieldset',
222
				items: [{
223
					xtype: 'container',
224
					layout: 'column',
225
					autoSizeColumn: true,
226
					columnWidth: 1,
227
					items: [{
228
						xtype: 'fieldset',
229
						columnWidth: 0.49,
230
						cls: 'zarafa-fieldset',
231
						title: _('Read'),
232
						items: [{
233
							xtype: 'radiogroup',
234
							style: 'margin-right: 2px;',
235
							hideLabel: true,
236
							columns: 1,
237
							items: readRadioGroupItems,
238
							listeners: {
239
								change: this.onPermissionChecked,
240
								scope: this
241
							}
242
						}]
243
					},{
244
						xtype: 'fieldset',
245
						columnWidth: 0.49,
246
						cls: 'zarafa-fieldset',
247
						title: _('Write'),
248
						items: [{
249
							xtype: 'checkboxgroup',
250
							style: 'margin-left: 2px;',
251
							hideLabel: true,
252
							columns: 1,
253
							items: [{
254
								xtype: 'checkbox',
255
								boxLabel: _('Create items'),
256
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_CREATE
257
							},{
258
								xtype: 'checkbox',
259
								boxLabel: _('Create subfolders'),
260
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_CREATE_SUBFOLDER
261
							},{
262
								xtype: 'checkbox',
263
								boxLabel: _('Edit own'),
264
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_EDIT_OWNED
265
							},{
266
								xtype: 'checkbox',
267
								boxLabel: _('Edit all'),
268
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_EDIT_OWNED | Zarafa.core.mapi.Rights.RIGHTS_EDIT_ANY
269
							}],
270
							listeners: {
271
								change: this.onPermissionChecked,
272
								scope: this
273
							}
274
						}]
275
					}]
276
				},{
277
					xtype: 'container',
278
					style: 'margin-top: 2px;',
279
					columnWidth: 1,
280
					autoSizeColumn: true,
281
					layout: 'column',
282
					items: [{
283
						xtype: 'fieldset',
284
						columnWidth: 0.49,
285
						cls: 'zarafa-fieldset',
286
						title: _('Delete items'),
287
						items: [{
288
							xtype: 'radiogroup',
289
							columns: 1,
290
							hideLabel: true,
291
							items: [{
292
								name: 'allowdelete',
293
								boxLabel: _('None'),
294
								hideLabel: true,
295
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_NONE
296
							},{
297
								name: 'allowdelete',
298
								boxLabel: _('Own'),
299
								hideLabel: true,
300
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_DELETE_OWNED
301
							},{
302
								name: 'allowdelete',
303
								boxLabel: _('All'),
304
								hideLabel: true,
305
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_DELETE_ANY | Zarafa.core.mapi.Rights.RIGHTS_DELETE_OWNED
306
							}],
307
							listeners: {
308
								change: this.onPermissionChecked,
309
								scope: this
310
							}
311
						}]
312
					},{
313
						xtype: 'fieldset',
314
						columnWidth: 0.49,
315
						cls: 'zarafa-fieldset',
316
						title: _('Other'),
317
						items: [{
318
							xtype: 'checkboxgroup',
319
							style: 'margin-left: 2px;',
320
							hideLabel: true,
321
							columns: 1,
322
							items: [{
323
								xtype: 'checkbox',
324
								boxLabel: _('Folder owner'),
325
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_CREATE_FOLDER | Zarafa.core.mapi.Rights.RIGHTS_FOLDER_CONTACT | Zarafa.core.mapi.Rights.RIGHTS_FOLDER_VISIBLE
326
							},{
327
								xtype: 'checkbox',
328
								boxLabel: _('Folder contact'),
329
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_FOLDER_CONTACT
330
							},{
331
								xtype: 'checkbox',
332
								boxLabel: _('Folder visible'),
333
								rightsValue: Zarafa.core.mapi.Rights.RIGHTS_FOLDER_VISIBLE
334
							}],
335
							listeners: {
336
								change: this.onPermissionChecked,
337
								scope: this
338
							}
339
						}]
340
					}]
341
				},{
342
					xtype: "checkbox",
343
					style: 'margin-top: 8px;',
344
					name: 'recursive',
345
					boxLabel: _('Apply (copy) changed permissions recursively'),
346
					handler: this.onFolderFieldChange,
347
					scope: this,
348
					ref: 'recursivePermissionsCheckbox'
349
				}]
350
			}]
351
		};
352
	},
353
354
	/**
355
	 * Event handler which is fired when the user presses the "Add" button to add a new
356
	 * user to the permission store. This will call {@link Zarafa.common.Actions#openABUserSelectionContent}
357
	 * to open the addressbook selection content panel.
358
	 * @private
359
	 */
360
	onUserAdd: function()
361
	{
362
		Zarafa.common.Actions.openABUserSelectionContent({
363
			callback: this.onUserSelected,
364
			scope: this,
365
			hideContactsFolders: true,
366
			listRestriction: {
367
				hide_users: [ 'non_security' ],
368
				hide_groups: [ 'non_security' ],
369
				hide_companies: [ 'non_security' ]
370
			}
371
		});
372
	},
373
374
		/**
375
	 * Event handler which is fired when a field has been changed.
376
	 * This will update the corresponding field inside the {@link Zarafa.core.data.IPMRecord record}.
377
	 * @param {Ext.form.Field} field The field which has changed
378
	 * @param {Mixed} newValue The new value for the field
379
	 * @param {Mixed} oldValue The original value for the field
380
	 * @private
381
	 */
382
		onFolderFieldChange: function(field, newValue, oldValue)
383
		{
384
			this.record.set(field.getName(), newValue);
385
		},
386
387
	/**
388
	 * Event handler for the {@link Zarafa.common.Actions#openABUserSelectionContent} function,
389
	 * which is used to select a user to be added to the permissions store.
390
	 * @param {Zarafa.addressbook.AddressBookRecord} record The selected user/group
391
	 * @private
392
	 */
393
	onUserSelected: function(record)
394
	{
395
		var store = this.userView.getStore();
396
		var permission = record.convertToUserPermission();
397
398
		if (store.findExact('entryid', permission.get('entryid')) < 0) {
399
			store.add(permission);
400
			this.userView.getSelectionModel().selectRecords([permission]);
401
		} else {
402
			var msg;
403
			if (permission.get('object_type') === Zarafa.core.mapi.ObjectType.MAPI_MAILUSER) {
404
				msg = _('User already exists');
405
			} else {
406
				msg = _('Group already exists');
407
			}
408
			container.getNotifier().notify('error.permissions', _('Error'), msg, {
409
				container: this.getEl()
410
			});
411
		}
412
	},
413
414
	/**
415
	 * Event handler which is fired when the user presses the "Remove' button. This will
416
	 * remove the currently selected user from the permissions store.
417
	 * @private
418
	 */
419
	onUserRemove: function()
420
	{
421
		var store = this.userView.getStore();
422
		var selection = this.userView.getSelectionModel().getSelected();
423
424
		if (this.selectedUser === selection) {
425
			this.clearPermissionsForm();
426
		}
427
		store.remove(selection);
428
	},
429
430
	/**
431
	 * Check if the given permissions masks can be represented by a
432
	 * {@link Zarafa.hierarchy.data.PermissionProfiles profile}. If it doesn't
433
	 * match anyting the 'Other' profile will be displayed in the profile combobox.
434
	 * @param {Number} permissions The permissions to load
435
	 * @private
436
	 */
437
	updateProfileCombo: function(permissions)
438
	{
439
		var store = this.profileCombo.store;
440
441
		// Check if the given permissions mask is set on one
442
		// of the profiles in the combobox. If that is the case,
443
		// then we enable that profile, and otherwise we apply
444
		// 'null' to ensure that the 'Other' profile is selected.
445
		var index = store.findExact('value', permissions);
446
		if (index >= 0) {
447
			this.profileCombo.setValue(permissions);
448
		} else {
449
			this.profileCombo.setValue(null);
450
		}
451
	},
452
453
	/**
454
	 * Load a permissions mask into the {@link Ext.form.CheckboxGroup} or {@Link Ext.form.RadioGroup}.
455
	 * This will toggle all radios and checkboxes to ensure they reflect the given permission mask.
456
	 * @param {Ext.form.CheckboxGroup} group The group to update
457
	 * @param {Number} permissions The permission mask to load into the group
458
	 * @private
459
	 */
460
	loadPermissionToGroup: function(group, permissions)
461
	{
462
		var items = group.items;
463
464
		group.suspendEvents(false);
465
		if (group instanceof Ext.form.RadioGroup) {
466
			// If in calendar dialog
467
			if(items.get(3)){
468
				var none = items.get(0);
469
				var fb = items.get(1);
470
				var fbdetailed = items.get(2);
471
				var all = items.get(3);
472
473
				if ((permissions & all.rightsValue) === all.rightsValue) {
474
					none.setValue(false);
475
					fb.setValue(false);
476
					fbdetailed.setValue(false);
477
					all.setValue(true);
478
				} else if ((permissions & fbdetailed.rightsValue) === fbdetailed.rightsValue) {
479
					none.setValue(false);
480
					fb.setValue(false);
481
					all.setValue(false);
482
					fbdetailed.setValue(true);
483
				} else if ((permissions & fb.rightsValue) === fb.rightsValue) {
484
					none.setValue(false);
485
					fbdetailed.setValue(false);
486
					all.setValue(false);
487
					fb.setValue(true);
488
				} else {
489
					fb.setValue(false);
490
					fbdetailed.setValue(false);
491
					all.setValue(false);
492
					none.setValue(true);
493
				}
494
				// If in other dialog
495
			} else if (items.get(2)){
496
				var none = items.get(0);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable none already seems to be declared on line 468. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
497
				var own = items.get(1);
498
				var all = items.get(2);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable all already seems to be declared on line 471. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
499
500
				if ((permissions & all.rightsValue) === all.rightsValue) {
501
					none.setValue(false);
502
					own.setValue(false);
503
					all.setValue(true);
504
				} else if ((permissions & own.rightsValue) === own.rightsValue) {
505
					none.setValue(false);
506
					all.setValue(false);
507
					own.setValue(true);
508
				} else {
509
					own.setValue(false);
510
					all.setValue(false);
511
					none.setValue(true);
512
				}
513
			} else {
514
				var none = items.get(0);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable none already seems to be declared on line 468. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
515
				var all = items.get(1);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable all already seems to be declared on line 471. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
516
517
				if ((permissions & all.rightsValue) === all.rightsValue) {
518
					none.setValue(false);
519
					all.setValue(true);
520
				} else {
521
					all.setValue(false);
522
					none.setValue(true);
523
				}
524
			}
525
		} else {
526
			for (var i = 0, len = items.getCount(); i < len; i++) {
527
				var option = items.get(i);
528
				if (Ext.isDefined(option.rightsValue)) {
529
					var enabled = (permissions & option.rightsValue) === option.rightsValue;
530
					option.setValue(enabled);
531
				}
532
			}
533
		}
534
		group.resumeEvents();
535
	},
536
537
	/**
538
	 * Read a {@link Ext.form.CheckboxGroup} or {@Link Ext.form.RadioGroup} to detect which
539
	 * permissions have been enabled in the group. This will be applied to the given
540
	 * permissions argument
541
	 * @param {Ext.form.CheckboxGroup} group The group to read
542
	 * @param {Number} permissions The current permissions value which must be updated by this group
543
	 * @return {Number} The updated permissions value
544
	 * @private
545
	 */
546
	updatePermissionFromGroup: function(group, permissions)
547
	{
548
		var mask = 0;
549
		var flag = 0;
550
		var items = group.items;
551
		items.each(function(item) {
552
			if (Ext.isDefined(item.rightsValue)) {
553
				mask |= item.rightsValue;
554
				if (item.checked) {
555
					flag |= item.rightsValue;
556
					// If "Edit all" is checked, check "Edit own"
557
					if(item.rightsValue === 40) {
558
						var option = items.get(2)
559
						option.setValue(true);
560
					}
561
					// If "Folder owner" is checked, check other folder permissions
562
					if(item.rightsValue === 1792) {
563
						var option = items.get(1)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable option already seems to be declared on line 558. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
564
						option.setValue(true);
565
						var option = items.get(2)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable option already seems to be declared on line 558. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
566
						option.setValue(true);
567
					}
568
				}
569
			}
570
		});
571
572
		return (permissions & ~mask) | flag;
573
	},
574
575
	/**
576
	 * Load the given {@link Zarafa.core.mapi.Rights permissions mask} into the UI.
577
	 * This will detect which profile must be enabled, and toggle all required
578
	 * {@link Ext.form.CheckBox checkboxes} and {@link Ext.form.Radio radios}.
579
	 * @param {Number} permissions Mask of {@link Zarafa.core.mapi.Rights rights values}.
580
	 * @private
581
	 */
582
	loadPermissionValue: function(permissions)
583
	{
584
		this.updateProfileCombo(permissions);
585
586
		// Search for all checkbox and radiogroups,
587
		// and start toggle the appropriate components
588
		// based on the given mask.
589
		this.permissionsForm.cascade(function(item) {
590
			if (item instanceof Ext.form.CheckboxGroup) {
591
				this.loadPermissionToGroup(item, permissions);
592
			}
593
		}, this);
594
	},
595
596
	/**
597
	 * Read the UI to determine the {@link Zarafa.core.mapi.Rights permissions mask}
598
	 * which is currently enabled. This will read if a predefined profile is selected,
599
	 * or will otherwise read all the {@link Ext.form.CheckBox checkboxes} and
600
	 * {@link Ext.form.Radio radios} to generate the value.
601
	 * @returns {Number} Mask of {@link Zarafa.core.mapi.Rights rights values}.
602
	 * @private
603
	 */
604
	updatePermissionValue: function()
605
	{
606
		var permissions = 0;
607
608
		// Search for all checkbox and radiogroups,
609
		// and apply the value to the permissions mask
610
		// from the toggled components
611
		this.permissionsForm.cascade(function(item) {
612
			if (item instanceof Ext.form.CheckboxGroup) {
613
				permissions = this.updatePermissionFromGroup(item, permissions);
614
			}
615
		}, this);
616
617
		return permissions;
618
	},
619
620
	/**
621
	 * Update the {@link #selectedUser} and update the contents
622
	 * of the entire permissions form
623
	 * @param {Zarafa.hierarchy.data.UserPermissionRecord} user The user to load into the form
624
	 * @private
625
	 */
626
	loadPermissionsForm: function(user)
627
	{
628
		this.selectedUser = user;
629
		this.removeUserBtn.enable();
630
		this.permissionsForm.getForm().items.each(function(item) { item.enable(); });
631
		this.loadPermissionValue(user.get('rights'));
632
	},
633
634
	/**
635
	 * Clear the {@link #selectedUser} and clear the contents
636
	 * of the entire permissions form
637
	 * @private
638
	 */
639
	clearPermissionsForm: function()
640
	{
641
		this.selectedUser = undefined;
642
		this.loadPermissionValue(this.profileCombo.defaultValue);
643
		this.removeUserBtn.disable();
644
		this.permissionsForm.getForm().items.each(function(item) { item.disable(); });
645
	},
646
647
	/**
648
	 * Event fired when the Permissions {@link Ext.grid.GridPanel grid} fires the
649
	 * {@link Ext.grid.GridPanel#viewready viewready} event. This will check a
650
	 * {@link #record} has been set, and if so it will select the first
651
	 * record on the 'folders' substore.
652
	 * @private
653
	 */
654
	onViewReady: function()
655
	{
656
		if (this.record && this.record.isOpened()) {
657
			var store = this.record.getSubStore('permissions');
658
			if (store.getCount() > 0) {
659
				this.userView.getSelectionModel().selectFirstRow();
660
			}
661
		}
662
	},
663
664
	/**
665
	 * Event handler which is fired when the user selects a user/group
666
	 * from the userlist.
667
	 * @param {Ext.grid.RowSelectionModel} selectionmodel The selectionmodel which fired the event
668
	 * @private
669
	 */
670
	onUserSelectionChange: function(selectionModel)
671
	{
672
		var record = selectionModel.getSelected();
673
674
		if (!Ext.isEmpty(record)) {
675
			this.loadPermissionsForm(record);
676
		} else {
677
			this.clearPermissionsForm();
678
		}
679
	},
680
681
	/**
682
	 * Event handler which is fired when the user selects a profile from
683
	 * the dropdown box.
684
	 * @param {Ext.form.ComboBox} combo The combobox which fired the event
685
	 * @param {Ext.data.Record} record The record which was selected
686
	 * @param {Number} index The selected index
687
	 * @private
688
	 */
689
	onProfileSelect: function(combo, record, index)
690
	{
691
		var permissions = record.get('value');
692
		if (permissions !== null) {
693
			this.loadPermissionValue(permissions);
694
			if (this.selectedUser) {
695
				this.selectedUser.set('rights', permissions);
696
			}
697
		}
698
	},
699
700
	/**
701
	 * Event handler which is fired when a {@link Ext.form.CheckBox} or {@link Ext.form.Radio}
702
	 * has been toggled. This will update the rights property inside the {@link #selectedUser}
703
	 * and check if the new permissions match a profile in the combobox.
704
	 * @param {Ext.form.CheckboxGroup} group The group to which the checkbox or radio belongs
705
	 * @param {Boolean} True if the checkbox is enabled or not
706
	 * @private
707
	 */
708
	onPermissionChecked: function(group, checked)
709
	{
710
		var permissions;
711
		if (this.selectedUser) {
712
			permissions = this.selectedUser.get('rights');
713
			permissions = this.updatePermissionFromGroup(group, permissions);
714
715
			this.selectedUser.set('rights', permissions);
716
			this.updateProfileCombo(permissions);
717
		} else {
718
			permissions = this.updatePermissionValue();
719
			this.updateProfileCombo(permissions);
720
		}
721
	},
722
723
	/**
724
	 * Update the {@link Ext.Panel Panel} with the given {@link Zarafa.core.data.IPMRecord IPMRecord}
725
	 * @param {Zarafa.core.data.IPMRecord} record The record to update the panel with
726
	 * @param {Boolean} contentReset force the component to perform a full update of the data.
727
	 */
728
	update: function(record, contentReset)
729
	{
730
		this.record = record;
731
732
		if (contentReset && record.isOpened()) {
733
734
			var store = record.getSubStore('permissions');
735
			this.userView.reconfigure(store, this.userView.getColumnModel());
736
			if (store.getCount() > 0) {
737
				this.userView.getSelectionModel().selectFirstRow();
738
			} else {
739
				this.clearPermissionsForm();
740
			}
741
		}
742
	},
743
744
	/**
745
	 * Update the {@link Zarafa.core.data.IPMRecord IPMRecord} with the data from the {@link Ext.Panel Panel}.
746
	 * @param {Zarafa.core.data.IPMRecord} record The record which has to be updated
747
	 */
748
	updateRecord: function(record)
749
	{
750
		if (this.selectedUser) {
751
			var permissions = this.updatePermissionValue();
752
			this.selectedUser.set('rights', permissions);
753
		}
754
	}
755
});
756
757
Ext.reg('zarafa.folderpropertiespermissiontab', Zarafa.hierarchy.dialogs.FolderPropertiesPermissionTab);
758