-
Notifications
You must be signed in to change notification settings - Fork 0
/
ess_pro_userscript.js
233 lines (196 loc) · 6.51 KB
/
ess_pro_userscript.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// ==UserScript==
// @name ETS Recherche de stages PRO
// @namespace https://gist.github.com/sm-Fifteen/762e564694db40a8477ae9e32496f51b
// @version 0.1
// @description Pour rendre la recherche de stage moins pénible sur le site du SEE.
// @author Nicolas Roy-Renaud <[email protected]>
// @include https://see.etsmtl.ca/Postes/Affichages
// @require https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js
// @resource jsgrid_css https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css
// @resource jsgrid_theme_css https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
function loadCSS() {
var gridcss = GM_getResourceText("jsgrid_css");
var gridcss2 = GM_getResourceText("jsgrid_theme_css");
GM_addStyle(gridcss);
GM_addStyle(gridcss2);
GM_addStyle(".cellIcon img { width: 20px }");
GM_addStyle(".jsgrid-cell { white-space: pre-wrap; overflow-x: hidden; }");
GM_addStyle("a {color: inherit;}");
}
function replaceGrid(jsgridData) {
$("#grid1").removeData('igGrid');
$("#ConteneurListes").empty();
$("#ConteneurListes").append( "<div id='grid1'></div>" );
$("#grid1").jsGrid(jsgridData);
}
function declareCustomFields() {
var PosteField = function(config) {
jsGrid.Field.call(this, config);
};
PosteField.prototype = new jsGrid.Field({
itemTemplate: function(value) {
return value.title;
},
sorter: function(val1, val2) {
return new val1.title.localeCompare(val2.title);
},
});
jsGrid.fields.posteField = PosteField;
}
function gridDataToJSGrid(ogDataSourceSettings) {
var jsGridParams = {
width: "100%",
inserting: false,
editing: false,
sorting: true,
filtering: true,
autoload: true,
};
// While I could have used the rowClick callback, I've never been fond of using JS to handle links
jsGridParams.rowRenderer = function(item, itemIndex) {
var rowObj = $("<tr>");
var cellClass = this.cellClass;
this.fields.forEach(function(rowField){
if (rowField.visible) {
var content = $("<a>").append(rowField.itemTemplate(item[rowField.name]));
content.attr("href", item.pageURL);
var cell = $("<td>").append(content);
cell.css("width", rowField.width);
cell.addClass(cellClass);
cell.addClass(rowField.css);
cell.addClass(rowField.align ? ("jsgrid-align-" + rowField.align) : "");
rowObj.append(cell);
}
});
return rowObj;
};
jsGridParams.controller = {
loadData: function(filter) {
return $.grep(jsGridParams.data, function(record) {
return (!filter.Nopost || record.Nopost.toUpperCase().indexOf(filter.Nopost.toUpperCase()) > -1) &&
(!filter.Lieupost || record.Lieupost === filter.Lieupost) &&
(!filter.Nmemp || record.Nmemp === filter.Nmemp) &&
(filter.IsNouveau === undefined || record.IsNouveau === filter.IsNouveau) &&
(filter.IsFavori === undefined || record.IsFavori === filter.IsFavori) &&
(filter.IsPostulee === undefined || record.IsPostulee === filter.IsPostulee);
});
},
};
var parsedData = parseOGGridData(ogDataSourceSettings.dataSource.Records);
jsGridParams.data = parsedData.data;
var fields = ogDataSourceSettings.schema.fields;
function iconCheckboxTemplate(iconUrl, value) {
var templ = $("<img>");
if (value) templ.attr("src", iconUrl);
return templ;
}
fields.forEach(function(field) {
field.width = "auto";
switch(field.name) {
case "GuidString":
case "FinAffichage":
case "DureePoste":
field.visible = false;
break;
case "IsPostulee":
field.type = "checkbox";
field.itemTemplate = iconCheckboxTemplate.bind(this, "/images/okvert.png");
field.title = "";
field.css = "cellIcon";
field.width = "32px";
break;
case "IsFavori":
field.type = "checkbox";
field.itemTemplate = iconCheckboxTemplate.bind(this, "/images/star.png");
field.title = "";
field.css = "cellIcon";
field.width = "32px";
break;
case "IsNouveau":
field.type = "checkbox";
field.itemTemplate = iconCheckboxTemplate.bind(this, "/images/nouveau.png");
field.title = "";
field.css = "cellIcon";
field.width = "32px";
break;
case "tempsRestant":
field.width = "60px";
field.title = "Reste";
break;
case "Nopost":
field.width = "10em";
field.type = "text";
field.title = "No. poste";
break;
case "Lieupost":
field.type = "select";
field.autosearch = true;
field.selectedIndex = -1;
field.items = parsedData.lieux;
field.width = "10em";
break;
case "Nmemp":
field.type = "select";
field.autosearch = true;
field.selectedIndex = -1;
field.items = parsedData.employeurs;
break;
case "Titpost":
field.name = "poste";
field.type = "posteField";
break;
}
});
jsGridParams.fields = fields;
return jsGridParams;
}
function parseOGGridData(gridData) {
var listLieupost = [""];
var listEnrt = [""];
var returnDict = {};
gridData.forEach(function(record){
record.pageURL = "/Poste/" + record.GuidString;
//record.FinAffichage = new Date(1507150800000);
record.IsFavori = (record.IsFavori !== "transparent");
record.IsPostulee = (record.IsPostulee !== "transparent");
record.IsNouveau = (record.IsNouveau !== "transparent");
record.Nmemp = record.Nmemp.toUpperCase();
if (record.Lieupost.length === 0) { record.Lieupost = "<null>"; }
if (record.Nmemp.length === 0) { record.Nmemp = "<null>"; }
var idxLieu = listLieupost.indexOf(record.Lieupost);
var idxEntr = listEnrt.indexOf(record.Nmemp);
if (idxLieu < 0) {
idxLieu = listLieupost.length;
listLieupost.push(record.Lieupost);
}
if (idxEntr < 0) {
idxEntr = listEnrt.length;
listEnrt.push(record.Nmemp);
}
record.Lieupost = idxLieu;
record.Nmemp = idxEntr;
// Stored on a per-extension basis
var storedPoste = GM_getValue(record.GuidString, undefined);
if(storedPoste) {
record.poste = JSON.parse(storedPoste);
} else {
record.poste = {"title": record.Titpost};
}
});
returnDict.data = gridData;
returnDict.lieux = listLieupost;
returnDict.employeurs = listEnrt;
return returnDict;
}
loadCSS();
declareCustomFields();
var jsGridParams = gridDataToJSGrid($("#grid1").data("igGrid").dataSource.settings);
replaceGrid(jsGridParams);
})();