Test Failed
Pull Request — master (#9)
by
unknown
09:58
created

client/zarafa/task/TaskContext.js   B

Complexity

Total Complexity 47
Complexity/F 1.88

Size

Lines of Code 641
Function Count 25

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 335
c 0
b 0
f 0
dl 0
loc 641
rs 8.64
wmc 47
mnd 22
bc 22
fnc 25
bpm 0.88
cpm 1.88
noi 1

How to fix   Complexity   

Complexity

Complex classes like client/zarafa/task/TaskContext.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
/*
2
 * #dependsFile client/zarafa/task/TaskContextModel.js
3
 */
4
Ext.namespace('Zarafa.task');
5
6
/**
7
 * @class Zarafa.task.TaskContext
8
 * @extends Zarafa.core.Context
9
 *
10
 * Context that displays tasks. This context has only one view ie. grid view
11
 */
12
Zarafa.task.TaskContext = Ext.extend(Zarafa.core.Context, {
13
	// Insertion points for this class
14
	/**
15
	 * @insert main.maintoolbar.view.task
16
	 * Insertion point for populating the main toolbar with a View button. This item is only visible
17
	 * when this context is active.
18
	 * @param {Zarafa.mail.TaskContext} context This context
19
	 */
20
21
	/**
22
	 * When searching, this property marks the {@link Zarafa.core.Context#getCurrentView view}
23
	 * which was used before {@link #onSearchStart searching started} the view was switched to
24
	 * {@link Zarafa.task.data.Views#SEARCH}.
25
	 * @property
26
	 * @type Mixed
27
	 * @private
28
	 */
29
	oldView: undefined,
30
31
	/**
32
	 * When searching, this property marks the {@link Zarafa.core.Context#getCurrentViewMode viewmode}
33
	 * which was used before {@link #onSearchStart searching started} the viewmode was switched to
34
	 * {@link Zarafa.task.data.ViewModes#SEARCH}.
35
	 * @property
36
	 * @type Mixed
37
	 * @private
38
	 */
39
	oldViewMode: undefined,
40
41
	/**
42
	 * @constructor
43
	 * @param config
44
	 */
45
	constructor: function(config)
46
	{
47
		config = config || {};
48
		Ext.applyIf(config, {
49
			current_view: Zarafa.task.data.Views.LIST,
50
			current_view_mode: Zarafa.task.data.ViewModes.SIMPLE,
51
			current_data_mode: Zarafa.task.data.DataModes.ALL
52
		});
53
54
		// The tab in the top tabbar
55
		this.registerInsertionPoint('main.maintabbar.left', this.createMainTab, this);
56
57
		//The task filter buttons
58
		this.registerInsertionPoint('context.mainpaneltoolbar.item', this.createFilterButtons, this);
59
60
		// The "New task" button which is available in all contexts
61
		this.registerInsertionPoint('main.maintoolbar.new.item', this.createToolbarNewTaskButton, this);
62
		// The "New task request" button which is available in all contexts
63
		this.registerInsertionPoint('main.maintoolbar.new.item', this.createToolbarNewTaskRequestButton, this);
64
65
		this.registerInsertionPoint('previewpanel.toolbar.left', this.createTaskRequestToolbarButtons, this);
66
67
		Zarafa.task.TaskContext.superclass.constructor.call(this, config);
68
69
		// Add a tree control showing a list of task folders to the navigation panel.
70
		// The control will be shown when the user selects the task context from the button panel.
71
		this.registerInsertionPoint('navigation.center', this.createTaskNavigationPanel, this);
72
73
		// Adds convert mail to task contextmenu item in the mail contextmenu.
74
		this.registerInsertionPoint('context.mail.contextmenu.topoptions', this.convertToTask, this);
75
76
		// Register task specific dialog types
77
		Zarafa.core.data.SharedComponentType.addProperty('task.dialogs.sendtaskrequestconfirmation');
78
		Zarafa.core.data.SharedComponentType.addProperty('task.dialogs.sendtaskrequestcancellation');
79
		Zarafa.core.data.SharedComponentType.addProperty('task.contextmenu.flags');
80
	},
81
82
	/**
83
	 * @return Zarafa.task.TaskContextModel the task context model
84
	 */
85
	getModel: function()
86
	{	if (!Ext.isDefined(this.model)) {
87
			this.model = new Zarafa.task.TaskContextModel();
88
			this.model.on({
89
				'searchstart': this.onModelSearchStart,
90
				'searchstop': this.onModelSearchStop,
91
				scope: this
92
			});
93
		}
94
		return this.model;
95
	},
96
97
	/**
98
	 * Event handler for the {@link #model}#{@link Zarafa.core.ContextModel#searchstart searchstart} event.
99
	 * This will {@link #switchView switch the view} to {@link Zarafa.task.data.Views#SEARCH search mode}.
100
	 * The previously active {@link #getCurrentView view} will be stored in the {@link #oldView} and will
101
	 * be recovered when the {@link #onModelSearchStop search is stopped}.
102
	 * @param {Zarafa.core.ContextModel} model The model which fired the event
103
	 * @private
104
	 */
105
	onModelSearchStart: function(model)
106
	{
107
		if(this.getCurrentView() !== Zarafa.task.data.Views.SEARCH && this.getCurrentViewMode() !== Zarafa.task.data.ViewModes.SEARCH){
108
			this.oldView = this.getCurrentView();
109
			this.oldViewMode = this.getCurrentViewMode();
110
			this.switchView(Zarafa.task.data.Views.SEARCH, Zarafa.task.data.ViewModes.SEARCH);
111
		}
112
	},
113
114
	/**
115
	 * Event handler for the {@link #model}#{@link Zarafa.core.ContextModel#searchstop searchstop} event.
116
	 * This will {@link #switchView switch the view} to the {@link #oldView previous view}.
117
	 * @param {Zarafa.core.ContextModel} model The model which fired the event
118
	 * @private
119
	 */
120
	onModelSearchStop: function(model)
121
	{
122
		this.switchView(this.oldView, this.oldViewMode);
123
		delete this.oldView;
124
		delete this.oldViewMode;
125
	},
126
127
	/**
128
	 * Bid on task folders.
129
	 * @param {Zarafa.Folder} folder which contains task items.
130
	 * @return {Number} return 1 if specified folder contains items of type IPF.Task else -1
131
	 * @method
132
	 */
133
	bid: function(folder)
134
	{
135
136
		// the folder contains items of type IPF.Task, return 1
137
		if (folder.isContainerClass('IPF.Task', true)) {
138
			return 1;
139
		}
140
141
		// return -1, don't handle this content type
142
		return -1;
143
144
	},
145
146
	/**
147
	 * Bid for the type of shared component and the given record.
148
	 * @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for.
149
	 * @param {Ext.data.Record} record Optionally passed record.
150
	 * @return {Number} The bid for the shared component
151
	 */
152
	bidSharedComponent: function(type, record)
153
	{
154
		var bid = -1;
155
156
		if (Array.isArray(record)) {
157
			record = record[0];
158
		}
159
160
		switch (type) {
161
			case Zarafa.core.data.SharedComponentType['common.create']:
162
			case Zarafa.core.data.SharedComponentType['common.view']:
163
			case Zarafa.core.data.SharedComponentType['common.preview']:
164
				if (record instanceof Zarafa.core.data.IPMRecord && record.isMessageClass('IPM.Task', true)) {
165
					bid = 1;
166
				}
167
				break;
168
			case Zarafa.core.data.SharedComponentType['task.dialogs.sendtaskrequestconfirmation']:
169
			case Zarafa.core.data.SharedComponentType['task.dialogs.sendtaskrequestcancellation']:
170
				if (record instanceof Zarafa.core.data.IPMRecord && record.get('object_type') == Zarafa.core.mapi.ObjectType.MAPI_MESSAGE) {
171
					if (record.isMessageClass('IPM.Task', true)) {
172
						bid = 1;
173
					}
174
				}
175
				break;
176
			case Zarafa.core.data.SharedComponentType['common.contextmenu']:
177
				if (record instanceof Zarafa.core.data.IPMRecord) {
178
					if(this.model.getDefaultFolder().isTodoListFolder()) {
179
						bid = 2;
180
					} else if(record.isMessageClass('IPM.Task', true)) {
181
						bid = 1;
182
					}
183
				}
184
				break;
185
			case Zarafa.core.data.SharedComponentType['common.printer.renderer']:
186
				if (record instanceof Zarafa.core.data.IPMRecord && record.get('object_type') === Zarafa.core.mapi.ObjectType.MAPI_MESSAGE) {
187
					if (record.isMessageClass([ 'IPM.Task' ], true)) {
188
						bid = 1;
189
					}
190
				} else if (record instanceof Zarafa.task.TaskContext) {
191
					bid = 1;
192
				}
193
				break;
194
			case Zarafa.core.data.SharedComponentType['common.attachment.dialog.attachitem.columnmodel']:
195
				if (record instanceof Zarafa.hierarchy.data.MAPIFolderRecord) {
196
					if (record.isContainerClass('IPF.Task', true)) {
197
						bid = 1;
198
					}
199
				}
200
				break;
201
			case Zarafa.core.data.SharedComponentType['common.attachment.dialog.attachitem.textrenderer']:
202
				if (record instanceof Zarafa.core.data.IPMRecord && record.get('object_type') === Zarafa.core.mapi.ObjectType.MAPI_MESSAGE) {
203
					if (record.isMessageClass('IPM.Task', true)) {
204
						bid = 1;
205
					}
206
				}
207
				break;
208
			case Zarafa.core.data.SharedComponentType['task.contextmenu.flags']:
209
				bid = 1;
210
				break;
211
		}
212
		return bid;
213
	},
214
215
	/**
216
	 * Will return the reference to the shared component.
217
	 * Based on the type of component requested a component is returned.
218
	 * @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for.
219
	 * @param {Ext.data.Record} record Optionally passed record.
220
	 * @return {Ext.Component} Component
221
	 */
222
	getSharedComponent: function(type, record)
223
	{
224
		var component;
225
		switch (type) {
226
			case Zarafa.core.data.SharedComponentType['common.create']:
227
			case Zarafa.core.data.SharedComponentType['common.view']:
228
				component = Zarafa.task.dialogs.TaskEditContentPanel;
229
				break;
230
			case Zarafa.core.data.SharedComponentType['common.preview']:
231
				component = Zarafa.task.ui.TaskPreviewPanel;
232
				break;
233
			case Zarafa.core.data.SharedComponentType['task.dialogs.sendtaskrequestconfirmation']:
234
			case Zarafa.core.data.SharedComponentType['task.dialogs.sendtaskrequestcancellation']:
235
				component = Zarafa.task.dialogs.SendTaskRequestConfirmationContentPanel;
236
				break;
237
			case Zarafa.core.data.SharedComponentType['common.contextmenu']:
238
		 		component = Zarafa.task.ui.TaskContextMenu;
239
				break;
240
			case Zarafa.core.data.SharedComponentType['task.contextmenu.flags']:
241
		 		component = Zarafa.task.ui.TaskFlagsMenu;
242
				break;
243
			case Zarafa.core.data.SharedComponentType['common.printer.renderer']:
244
				if (record instanceof Zarafa.core.data.IPMRecord && record.get('object_type') === Zarafa.core.mapi.ObjectType.MAPI_MESSAGE) {
245
					component = Zarafa.task.printer.TaskRenderer;
246
				} else {
247
					component = Zarafa.task.printer.TaskListViewRenderer;
248
				}
249
				break;
250
			case Zarafa.core.data.SharedComponentType['common.attachment.dialog.attachitem.columnmodel']:
251
				component = Zarafa.task.attachitem.AttachTaskColumnModel;
252
				break;
253
			case Zarafa.core.data.SharedComponentType['common.attachment.dialog.attachitem.textrenderer']:
254
				component = Zarafa.task.attachitem.AttachTaskRenderer;
255
				break;
256
		}
257
		return component;
258
	},
259
260
	/**
261
	 * Creates the task tree that is shown when the user selects the task context from the
262
	 * button panel. It shows a tree of available task folders that can be checked and unchecked.
263
	 * @private
264
	 */
265
	createTaskNavigationPanel: function()
266
	{
267
		return {
268
			xtype: 'zarafa.contextnavigation',
269
			context: this,
270
			items: [{
271
				xtype: 'panel',
272
				id: 'zarafa-navigationpanel-tasks-navigation',
273
				cls: 'zarafa-context-navigation-block',
274
				layout: 'fit',
275
				items: [{
276
					xtype: 'zarafa.hierarchytreepanel',
277
					id: 'zarafa-navigationpanel-tasks-navigation-tree',
278
					model: this.getModel(),
279
					IPMFilter: 'IPF.Task',
280
					hideDeletedFolders: true,
281
					enableDD: true,
282
					enableItemDrop: true,
283
					deferredLoading: true,
284
					bbarConfig: {
285
						defaultSelectedSharedFolderType: Zarafa.hierarchy.data.SharedFolderTypes['TASK'],
286
						buttonText: _('Open Shared Tasks')
287
					}
288
				}]
289
			}]
290
		};
291
	},
292
293
	/**
294
	 * Obtain the {@link Zarafa.task.ui.taskPanel taskpanel} object
295
	 *
296
	 * @return {Zarafa.task.ui.taskPanel} The main panel which should
297
	 * be used within the {@link Zarafa.core.Context context}
298
	 */
299
	createContentPanel: function()
300
	{
301
		return {
302
			xtype: 'zarafa.taskmainpanel',
303
			id: 'zarafa-mainpanel-contentpanel-tasks',
304
			context: this
305
		};
306
	},
307
308
	/**
309
	 * Returns the buttons for the dropdown list of the VIEW-button in the main toolbar. It will use the
310
	 * main.maintoolbar.view.task insertion point to allow other plugins to add their items at the end.
311
	 *
312
	 * @return {Ext.Component[]} an array of components
313
	 */
314
	getMainToolbarViewButtons: function()
315
	{
316
		var items = container.populateInsertionPoint('main.maintoolbar.view.task', this) || [];
317
318
		var defaultItems = [{
319
			id: 'zarafa-maintoolbar-view-tasks-simple',
320
			text: _('Simple view'),
321
			overflowText: _('Simple view'),
322
			iconCls: 'icon_task_simple',
323
			valueView: Zarafa.task.data.Views.LIST,
324
			valueViewMode: Zarafa.task.data.ViewModes.SIMPLE,
325
			handler: this.onContextSelectView,
326
			scope: this
327
		},{
328
			id: 'zarafa-maintoolbar-view-tasks-detailed',
329
			text: _('Detailed view'),
330
			overflowText: _('Detailed view'),
331
			iconCls: 'icon_task_detailed',
332
			valueView: Zarafa.task.data.Views.LIST,
333
			valueViewMode: Zarafa.task.data.ViewModes.DETAILED,
334
			handler: this.onContextSelectView,
335
			scope: this
336
		}];
337
338
		return defaultItems.concat(items);
339
	},
340
341
	/**
342
	 * Event handler which is fired when one of the View buttons
343
	 * has been pressed. This will call {@link Zarafa.task.TaskContext#setView setView}
344
	 * to update the view.
345
	 * @param {Ext.Button} button The button which was pressed
346
	 * @private
347
	 */
348
	onContextSelectView: function(button)
349
	{
350
		var model = this.getModel();
351
		model.setDataMode(model.getCurrentDataMode());
352
		this.switchView(button.valueView, button.valueViewMode);
353
	},
354
355
	/**
356
	 * Create "New Task" {@link Ext.menu.MenuItem item} for the "New item"
357
	 * {@link Ext.menu.Menu menu} in the {@link Zarafa.core.ui.MainToolbar MainToolbar}.
358
	 * This button should be shown in all {@link Zarafa.core.Context contexts} and
359
	 * is used to create a new task.
360
	 *
361
	 * @return {Object} The menu item for creating a new task item
362
	 * @static
363
	 */
364
	createToolbarNewTaskButton: function()
365
	{
366
		//create new task buttton.
367
		return {
368
369
			xtype	: 'menuitem',
370
			id: 'zarafa-maintoolbar-newitem-task',
371
			tooltip: _('Task')+' (Ctrl + Alt + K)',
372
			plugins: 'zarafa.menuitemtooltipplugin',
373
			text	: _('Task'),
374
			handler	: function(){
375
				Zarafa.task.Actions.openCreateTaskContent(this.getModel());
376
			},
377
			iconCls		: 'icon_new_task',
378
			newMenuIndex: 4,
379
			context: 'task',
380
			scope: this
381
		};
382
	},
383
384
	/**
385
	 * Create "New Task Request" {@link Ext.menu.MenuItem item} for the "New item"
386
	 * {@link Ext.menu.Menu menu} in the {@link Zarafa.core.ui.MainToolbar MainToolbar}.
387
	 * This button should be shown in all {@link Zarafa.core.Context contexts} and
388
	 * is used to create a new task request.
389
	 *
390
	 * @return {Object} The menu item for creating a new task request item
391
	 * @static
392
	 */
393
	createToolbarNewTaskRequestButton: function()
394
	{
395
		return {
396
			xtype: 'menuitem',
397
			id: 'zarafa-maintoolbar-newitem-task-request',
398
			tooltip: _('Task request'),
399
			plugins: 'zarafa.menuitemtooltipplugin',
400
			text: _('Task request'),
401
			handler: function(){
402
				Zarafa.task.Actions.openCreateTaskRequestContent(this.getModel());
403
			},
404
			iconCls: 'icon_new-task_request',
405
			newMenuIndex: 4,
406
			context: 'task',
407
			scope: this
408
		};
409
	},
410
411
	/**
412
	 * Populates the Print button in the main toolbar
413
	 * @return {Array} items The menu items available for printing in this context
414
	 */
415
	getMainToolbarPrintButtons: function()
416
	{
417
		var items = container.populateInsertionPoint('main.toolbar.print.task', this) || [];
418
419
		var defaultItems = [{
420
			xtype: 'zarafa.conditionalitem',
421
			id: 'zarafa-maintoolbar-print-selectedtask',
422
			overflowText: _('Print selected task'),
423
			iconCls: 'icon_print_task',
424
			tooltip: _('Print selected task') + ' (Ctrl + P)',
425
			plugins: 'zarafa.menuitemtooltipplugin',
426
			text: _('Print selected task'),
427
			hideOnDisabled: false,
428
			singleSelectOnly: true,
429
			handler: this.onPrintSelected.createDelegate(this, [_('No task selected')], 2),
430
			scope: this
431
		},{
432
			overflowText: _('Print task list'),
433
			id: 'zarafa-maintoolbar-print-tasklist',
434
			iconCls: 'icon_print',
435
			tooltip: _('Print task list') + ' (Ctrl + Alt + P)',
436
			plugins: 'zarafa.menuitemtooltipplugin',
437
			text: _('Print task list'),
438
			handler: this.onPrintList,
439
			scope: this
440
		}];
441
442
		return defaultItems.concat(items);
443
	},
444
445
	/**
446
	 * Handler for printing all {@link Zarafa.core.data.MAPIRecord} records in the current view.
447
	 * Calls {@link Zarafa.common.Actions.openPrintDialog} openPrintDialog with the current context.
448
	 * @private
449
	 */
450
	onPrintList: function(item)
451
	{
452
		Zarafa.common.Actions.openPrintDialog(this);
453
	},
454
455
	/**
456
	 * Adds a button to the top tab bar for this context.
457
	 * @return {Object} The button for the top tabbar
458
	 * @private
459
	 */
460
	createMainTab: function()
461
	{
462
		return {
463
			text: this.getDisplayName(),
464
			tabOrderIndex: 5,
465
			context: this.getName(),
466
			id: 'mainmenu-button-tasks'
467
		};
468
	},
469
470
	/**
471
	 * Adds a new contextmenu item in the mail context, which converts an email to a task
472
	 * @return {Zarafa.core.ui.menu.ConditionalItem[]} The Action context menu item
473
	 * @private
474
	 */
475
	convertToTask: function()
476
	{
477
		return {
478
			xtype: 'zarafa.conditionalitem',
479
			text: _('Create task'),
480
			iconCls: 'icon_new_task',
481
			singleSelectOnly: true,
482
			hidden: true,
483
			handler: this.onContextItemCreateTask,
484
			scope: this
485
		};
486
	},
487
488
	/**
489
	 * @param {Ext.Component} component The component to which the buttons will be added
490
	 * @return {Array} Array of configuration objects containing a Buttons which should be
491
	 * added in the {@link Ext.Toolbar Toolbar}.
492
	 * @private
493
	 */
494
	createTaskRequestToolbarButtons: function(component)
495
	{
496
		return [{
497
			xtype: 'zarafa.taskrequestbutton',
498
			name: Zarafa.task.data.TaskRequestButtonNames.ACCEPT,
499
			text: _('Accept'),
500
			iconCls: 'icon_calendar_appt_accept',
501
			responseStatus: Zarafa.core.mapi.TaskMode.ACCEPT
502
503
		},{
504
			xtype: 'zarafa.taskrequestbutton',
505
			name: Zarafa.task.data.TaskRequestButtonNames.DECLINE,
506
			text: _('Decline'),
507
			iconCls: 'icon_calendar_appt_cancelled',
508
			responseStatus: Zarafa.core.mapi.TaskMode.DECLINE
509
		}];
510
	},
511
512
	/**
513
	 * Event Handler triggered when {@link #convertToTask convert to task} context menu item is click.
514
	 * function is used to convert email to task record
515
	 *
516
	 * @param {Zarafa.core.ui.menu.ConditionalItem} item context menu item
517
	 * @param {Ext.EventObject} event The event information
518
	 * @private
519
	 */
520
	onContextItemCreateTask: function(menuItem, event)
521
	{
522
		var records = menuItem.getRecords();
523
		Zarafa.task.Actions.createTaskFromMail(records, this.getModel());
524
	},
525
526
	/**
527
	 * Create task filter buttons in {@link Zarafa.common.ui.ContextMainPanelToolbar ContextMainPanelToolbar}
528
	 *
529
	 * @param {String} insertionPoint The insertionPoint text.
530
	 * @param {Zarafa.core.Context} currentContext The current context in which this
531
	 * insertion point triggered.
532
	 * @return {Object} configuration object to create task filter buttons.
533
	 */
534
	createFilterButtons: function(insertionPoint, currentContext) {
535
		var hidden = currentContext?.getName() !== 'task';
536
537
		return [{
538
				xtype: 'button',
539
				cls: 'k-filter-options-btn',
540
				text: '<span>' + _('Active') + '</span>',
541
				overflowText: _('Active'),
542
				iconCls: 'icon_task_active',
543
				model: this.getModel(),
544
				hidden: hidden,
545
				valueDataMode: Zarafa.task.data.DataModes.ACTIVE,
546
				enableToggle: true,
547
				toggleGroup: 'taskFilters',
548
				toggleHandler: this.onClickToggleHandler,
549
				listeners: {
550
					afterrender: this.onAfterRenderFilterButtons,
551
					scope: this
552
				},
553
				scope: this
554
			}, {
555
				xtype: 'button',
556
				cls: 'k-filter-options-btn',
557
				text: '<span>' + _('Upcoming') + '</span>',
558
				overflowText: _('Upcoming'),
559
				iconCls: 'icon_calendar',
560
				model: this.getModel(),
561
				hidden: hidden,
562
				valueDataMode: Zarafa.task.data.DataModes.NEXT_7_DAYS,
563
				enableToggle: true,
564
				toggleGroup: 'taskFilters',
565
				toggleHandler: this.onClickToggleHandler,
566
				listeners: {
567
					afterrender: this.onAfterRenderFilterButtons,
568
					scope: this
569
				},
570
				scope: this
571
			}, {
572
				xtype: 'button',
573
				cls: 'k-filter-options-btn',
574
				text: '<span>' + _('Complete') + '</span>',
575
				overflowText: _('Complete'),
576
				iconCls: 'icon_task_complete',
577
				hidden: hidden,
578
				model: this.getModel(),
579
				valueDataMode: Zarafa.task.data.DataModes.COMPLETED,
580
				enableToggle: true,
581
				toggleGroup: 'taskFilters',
582
				toggleHandler: this.onClickToggleHandler,
583
				listeners: {
584
					afterrender: this.onAfterRenderFilterButtons,
585
					scope: this
586
				},
587
				scope: this
588
			}, {
589
				xtype: 'button',
590
				cls: 'k-filter-options-btn',
591
				text: '<span>' + _('Overdue') + '</span>',
592
				overflowText: _('Overdue'),
593
				iconCls: 'icon_calendar_appt_newtime',
594
				model: this.getModel(),
595
				hidden: hidden,
596
				valueDataMode: Zarafa.task.data.DataModes.OVERDUE,
597
				enableToggle: true,
598
				toggleGroup: 'taskFilters',
599
				toggleHandler: this.onClickToggleHandler,
600
				listeners: {
601
					afterrender: this.onAfterRenderFilterButtons,
602
					scope: this
603
				},
604
				scope: this
605
			}];
606
	},
607
608
	/**
609
	 * Function sets selection on the button which has the current data mode.
610
	 *
611
	 * @param {Object} button The filter button to be selected.
612
	 */
613
	onAfterRenderFilterButtons: function (button)
614
	{
615
		if (this.getModel().getCurrentDataMode() === button.valueDataMode) {
616
			button.btnEl.addClass('k-selection');
617
			button.pressed = true;
618
		}
619
	},
620
621
	/**
622
	 * The function handles the toggling of the filter button. If already pressed,
623
	 * it resets the {@link Zarafa.task.data.DataModes datamode} and clears the restriction.
624
	 *
625
	 * @param {Object} button The filter button pressed by user.
626
	 * @param {Boolean} state The state of the button, true if pressed.
627
	 */
628
	onClickToggleHandler: function (button, state)
629
	{
630
		var model = this.getModel();
631
		button.btnEl.toggleClass('k-selection');
632
		model.getStore().hasFilterApplied = state;
633
		model.setDataMode(state ? button.valueDataMode : Zarafa.task.data.DataModes.ALL);
634
	}
635
});
636
637
Zarafa.onReady(function() {
638
	container.registerContext(new Zarafa.core.ContextMetaData({
639
		name: 'task',
640
		displayName: _('Tasks'),
641
		allowUserVisible: false,
642
		pluginConstructor: Zarafa.task.TaskContext
643
	}));
644
});
645