-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom.viewGridTasks.js
152 lines (140 loc) · 5.89 KB
/
custom.viewGridTasks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* global _, $, app, localizationHelper, session */
/*
* Custom View Grid Tasks Config
*/
(function () {
'use strict';
if (!_.isUndefined(app.storage.custom) && app.storage.custom.get('DEBUG_ENABLED')) {
app.custom.utils.log('custom.viewGridTasks:define');
}
/**
* Populate the grid tasks of the first Kendo Grid found.
*/
function populateViewGridTasks() {
if (!_.isUndefined(app.storage.custom) && app.storage.custom.get('DEBUG_ENABLED')) {
app.custom.utils.log('custom.viewGridTasks:populateViewGridTasks');
}
// Find first kendoGrid on page.
var gridData = $('.k-grid').filter('[data-role="grid"]:first').data('kendoGrid');
if (!_.isUndefined(gridData)) {
app.custom.gridTasks
// Adding background colors to the Priority column based on value.
.add(gridData, {
field: 'Priority',
type: 'class',
template: "#= 'ra-grid-priority-' + Priority #",
})
// Adding custom internal and external links to the Title column with dynamic template and no callback.
.add(gridData, {
field: 'Title',
type: 'task',
name: 'TitleLinks',
/**
* Custom Title Links task template generated using Underscore templating
*
* @param {object} column - Kendo grid column object.
* @param {object} task - gridTask object.
* @returns {string} Kendo column template.
*/
template: function template(column, task) {
var template =
'# var url = app.gridUtils.getLinkUrl(data, "***");' +
'if ((!_.isUndefined(WorkItemType) && WorkItemType.indexOf("Activity") != -1)) {' +
'var approvalUrl = app.gridUtils.getApprovalLinkUrl(data); #' +
'<%= app.custom.gridTasks.buildTemplate("link", field, taskName, actLinkSettings) %>' +
'# } #' +
'<%= app.custom.gridTasks.buildTemplate("link", field, taskName, wiLinkSettings) %>' +
'<%= app.custom.gridTasks.buildTemplate("link", field, taskName, defaultLinkSettings) %>';
template = _.template(template, {
field: column.field,
taskName: task.name,
wiLinkSettings: {
href: '#= url #',
},
actLinkSettings: {
href: '#= approvalUrl #',
icon: 'fa-check',
},
defaultLinkSettings: {
href: '#= url #',
icon: 'fa-arrow-right',
bClickPropagation: true,
className: 'ra-highlight-default-icon',
target: '',
},
});
return template;
},
});
// If user is an analyst then add 'AssignToAnalystByGroup' grid task to AssignedUser column.
if (session.user.Analyst === 1) {
// Check if page includes the 'analystByGroup' button before adding task.
var assignToAnalystByGroupButton = $('.drawer-task-menu li').filter('[data-bind*="click: analystByGroup"]').eq(0);
if (assignToAnalystByGroupButton.length > 0) {
app.custom.gridTasks
// Adding grid task to trigger AssignToAnalystByGroup with dynamic template and custom callback
.add(gridData, {
field: 'AssignedUser',
type: 'task',
name: 'AssignToAnalystByGroup',
/**
* Custom AssignToAnalystByGroup task template.
*
* @param {object} column - Kendo grid column object.
* @param {object} task - gridTask object.
* @returns {string} Kendo column template.
*/
template: function template(column, task) {
var template =
'# var analystByGroupTypes = ["System.WorkItem.Incident", "System.WorkItem.ServiceRequest"];' +
'if (!_.isUndefined(WorkItemType) && analystByGroupTypes.indexOf(WorkItemType) > -1) { #' +
'<%= app.custom.gridTasks.buildTemplate("task", field, taskName, taskLinkSettings) %>' +
'# } #';
template = _.template(template, {
field: column.field,
taskName: task.name,
taskLinkSettings: {
icon: 'fa-pencil',
bClickPropagation: false,
title: localizationHelper.localize(task.name, 'Assign To Analyst By Group'),
},
});
return template;
},
/**
* Custom callback function.
*
* @param {object} data - Grid data object including dataItem and related data.
*/
callback: function (data) {
app.custom.utils.log('AssignToAnalystByGroup:callback', data);
data.gridData.clearSelection();
data.gridData.select(data.itemRowEle);
assignToAnalystByGroupButton.click();
},
});
}
}
// Update grid with pending grid task changes.
app.custom.gridTasks.apply(gridData);
}
}
/**
* Initialize Custom View grid tasks.
*/
function initViewGridTasks() {
if (!_.isUndefined(app.storage.custom) && app.storage.custom.get('DEBUG_ENABLED')) {
app.custom.utils.log('custom.viewGridTasks:initViewGridTasks');
}
// Immediately attempt to populate View grid tasks.
populateViewGridTasks();
// Subscribe to queryBuilderGridReady events to populate dynamics grids.
app.events.subscribe('queryBuilderGridReady', populateViewGridTasks);
}
if (typeof app.custom.gridTasks !== 'undefined') {
app.custom.gridTasks.ready(initViewGridTasks);
} else {
// Subscribe initViewGridTasks to gridTasks.Ready event once.
$(app.events).one('gridTasks.Ready', initViewGridTasks);
}
}());