|
Lines 199-494
export default {
Link Here
|
| 199 |
} |
199 |
} |
| 200 |
this.$refs.table.redraw(this.table_url()) |
200 |
this.$refs.table.redraw(this.table_url()) |
| 201 |
}, |
201 |
}, |
| 202 |
build_datatable: function () { |
|
|
| 203 |
let show_agreement = this.show_agreement |
| 204 |
let edit_agreement = this.edit_agreement |
| 205 |
let delete_agreement = this.delete_agreement |
| 206 |
let select_agreement = this.select_agreement |
| 207 |
let get_lib_from_av = this.get_lib_from_av |
| 208 |
let map_av_dt_filter = this.map_av_dt_filter |
| 209 |
let datatable_url = this.datatable_url |
| 210 |
let default_search = this.$route.query.q |
| 211 |
let actions = this.before_route_entered ? "edit_delete" : "select" |
| 212 |
let table_id = this.table_id |
| 213 |
|
| 214 |
window["vendors"] = this.vendors.map(e => { |
| 215 |
e["_id"] = e["id"] |
| 216 |
e["_str"] = e["name"] |
| 217 |
return e |
| 218 |
}) |
| 219 |
let vendors_map = this.vendors.reduce((map, e) => { |
| 220 |
map[e.id] = e |
| 221 |
return map |
| 222 |
}, {}) |
| 223 |
let avs = [ |
| 224 |
"av_agreement_statuses", |
| 225 |
"av_agreement_closure_reasons", |
| 226 |
"av_agreement_renewal_priorities", |
| 227 |
] |
| 228 |
avs.forEach(function (av_cat) { |
| 229 |
window[av_cat] = map_av_dt_filter(av_cat) |
| 230 |
}) |
| 231 |
|
| 232 |
window["av_agreement_is_perpetual"] = [ |
| 233 |
{ _id: 0, _str: _("No") }, |
| 234 |
{ _id: 1, _str: _("Yes") }, |
| 235 |
] |
| 236 |
|
| 237 |
const table = $("#" + table_id).kohaTable( |
| 238 |
{ |
| 239 |
ajax: { |
| 240 |
url: datatable_url, |
| 241 |
}, |
| 242 |
order: [[0, "asc"]], |
| 243 |
autoWidth: false, |
| 244 |
search: { search: default_search }, |
| 245 |
columnDefs: [ |
| 246 |
{ |
| 247 |
targets: [0, 2], |
| 248 |
render: function (data, type, row, meta) { |
| 249 |
if (type == "display") { |
| 250 |
return escape_str(data) |
| 251 |
} |
| 252 |
return data |
| 253 |
}, |
| 254 |
}, |
| 255 |
], |
| 256 |
columns: [ |
| 257 |
{ |
| 258 |
title: __("Name"), |
| 259 |
data: "me.agreement_id:me.name", |
| 260 |
searchable: true, |
| 261 |
orderable: true, |
| 262 |
render: function (data, type, row, meta) { |
| 263 |
// Rendering done in drawCallback |
| 264 |
return "" |
| 265 |
}, |
| 266 |
}, |
| 267 |
{ |
| 268 |
title: __("Vendor"), |
| 269 |
data: "vendor_id", |
| 270 |
searchable: true, |
| 271 |
orderable: true, |
| 272 |
render: function (data, type, row, meta) { |
| 273 |
return row.vendor_id != undefined |
| 274 |
? escape_str( |
| 275 |
vendors_map[row.vendor_id].name |
| 276 |
) |
| 277 |
: "" |
| 278 |
}, |
| 279 |
}, |
| 280 |
{ |
| 281 |
title: __("Description"), |
| 282 |
data: "description", |
| 283 |
searchable: true, |
| 284 |
orderable: true, |
| 285 |
}, |
| 286 |
{ |
| 287 |
title: __("Status"), |
| 288 |
data: "status", |
| 289 |
searchable: true, |
| 290 |
orderable: true, |
| 291 |
render: function (data, type, row, meta) { |
| 292 |
return escape_str( |
| 293 |
get_lib_from_av( |
| 294 |
"av_agreement_statuses", |
| 295 |
row.status |
| 296 |
) |
| 297 |
) |
| 298 |
}, |
| 299 |
}, |
| 300 |
{ |
| 301 |
title: __("Closure reason"), |
| 302 |
data: "closure_reason", |
| 303 |
searchable: true, |
| 304 |
orderable: true, |
| 305 |
render: function (data, type, row, meta) { |
| 306 |
return escape_str( |
| 307 |
get_lib_from_av( |
| 308 |
"av_agreement_closure_reasons", |
| 309 |
row.closure_reason |
| 310 |
) |
| 311 |
) |
| 312 |
}, |
| 313 |
}, |
| 314 |
{ |
| 315 |
title: __("Is perpetual"), |
| 316 |
data: "is_perpetual", |
| 317 |
searchable: true, |
| 318 |
orderable: true, |
| 319 |
render: function (data, type, row, meta) { |
| 320 |
return escape_str( |
| 321 |
row.is_perpetual ? _("Yes") : _("No") |
| 322 |
) |
| 323 |
}, |
| 324 |
}, |
| 325 |
{ |
| 326 |
title: __("Renewal priority"), |
| 327 |
data: "renewal_priority", |
| 328 |
searchable: true, |
| 329 |
orderable: true, |
| 330 |
render: function (data, type, row, meta) { |
| 331 |
return escape_str( |
| 332 |
get_lib_from_av( |
| 333 |
"av_agreement_renewal_priorities", |
| 334 |
row.renewal_priority |
| 335 |
) |
| 336 |
) |
| 337 |
}, |
| 338 |
}, |
| 339 |
{ |
| 340 |
title: __("Actions"), |
| 341 |
data: function (row, type, val, meta) { |
| 342 |
return '<div class="actions"></div>' |
| 343 |
}, |
| 344 |
className: "actions noExport", |
| 345 |
searchable: false, |
| 346 |
orderable: false, |
| 347 |
}, |
| 348 |
], |
| 349 |
drawCallback: function (settings) { |
| 350 |
var api = new $.fn.dataTable.Api(settings) |
| 351 |
|
| 352 |
if (actions == "edit_delete") { |
| 353 |
$.each( |
| 354 |
$(this).find("td .actions"), |
| 355 |
function (index, e) { |
| 356 |
let tr = $(this).parent().parent() |
| 357 |
let agreement_id = api |
| 358 |
.row(tr) |
| 359 |
.data().agreement_id |
| 360 |
let agreement_name = api.row(tr).data().name |
| 361 |
let editButton = createVNode( |
| 362 |
"a", |
| 363 |
{ |
| 364 |
class: "btn btn-default btn-xs", |
| 365 |
role: "button", |
| 366 |
onClick: () => { |
| 367 |
edit_agreement(agreement_id) |
| 368 |
}, |
| 369 |
}, |
| 370 |
[ |
| 371 |
createVNode("i", { |
| 372 |
class: "fa fa-pencil", |
| 373 |
"aria-hidden": "true", |
| 374 |
}), |
| 375 |
__("Edit"), |
| 376 |
] |
| 377 |
) |
| 378 |
|
| 379 |
let deleteButton = createVNode( |
| 380 |
"a", |
| 381 |
{ |
| 382 |
class: "btn btn-default btn-xs", |
| 383 |
role: "button", |
| 384 |
onClick: () => { |
| 385 |
delete_agreement( |
| 386 |
agreement_id, |
| 387 |
agreement_name |
| 388 |
) |
| 389 |
}, |
| 390 |
}, |
| 391 |
[ |
| 392 |
createVNode("i", { |
| 393 |
class: "fa fa-trash", |
| 394 |
"aria-hidden": "true", |
| 395 |
}), |
| 396 |
__("Delete"), |
| 397 |
] |
| 398 |
) |
| 399 |
|
| 400 |
let n = createVNode("span", {}, [ |
| 401 |
editButton, |
| 402 |
" ", |
| 403 |
deleteButton, |
| 404 |
]) |
| 405 |
render(n, e) |
| 406 |
} |
| 407 |
) |
| 408 |
} else { |
| 409 |
$.each( |
| 410 |
$(this).find("td .actions"), |
| 411 |
function (index, e) { |
| 412 |
let tr = $(this).parent().parent() |
| 413 |
let agreement_id = api |
| 414 |
.row(tr) |
| 415 |
.data().agreement_id |
| 416 |
let selectButton = createVNode( |
| 417 |
"a", |
| 418 |
{ |
| 419 |
class: "btn btn-default btn-xs", |
| 420 |
role: "button", |
| 421 |
onClick: () => { |
| 422 |
select_agreement(agreement_id) |
| 423 |
}, |
| 424 |
}, |
| 425 |
[ |
| 426 |
createVNode("i", { |
| 427 |
class: "fa fa-check", |
| 428 |
"aria-hidden": "true", |
| 429 |
}), |
| 430 |
__("Select"), |
| 431 |
] |
| 432 |
) |
| 433 |
|
| 434 |
let n = createVNode("span", {}, [ |
| 435 |
selectButton, |
| 436 |
]) |
| 437 |
render(n, e) |
| 438 |
} |
| 439 |
) |
| 440 |
} |
| 441 |
|
| 442 |
$.each( |
| 443 |
$(this).find("tbody tr td:first-child"), |
| 444 |
function (index, e) { |
| 445 |
let tr = $(this).parent() |
| 446 |
let row = api.row(tr).data() |
| 447 |
if (!row) return // Happen if the table is empty |
| 448 |
let n = createVNode( |
| 449 |
"a", |
| 450 |
{ |
| 451 |
role: "button", |
| 452 |
onClick: () => { |
| 453 |
show_agreement(row.agreement_id) |
| 454 |
}, |
| 455 |
}, |
| 456 |
`${row.name} (#${row.agreement_id})` |
| 457 |
) |
| 458 |
render(n, e) |
| 459 |
} |
| 460 |
) |
| 461 |
}, |
| 462 |
preDrawCallback: function (settings) { |
| 463 |
$("#" + table_id) |
| 464 |
.find("thead th") |
| 465 |
.eq(1) |
| 466 |
.attr("data-filter", "vendors") |
| 467 |
$("#" + table_id) |
| 468 |
.find("thead th") |
| 469 |
.eq(3) |
| 470 |
.attr("data-filter", "av_agreement_statuses") |
| 471 |
$("#" + table_id) |
| 472 |
.find("thead th") |
| 473 |
.eq(4) |
| 474 |
.attr("data-filter", "av_agreement_closure_reasons") |
| 475 |
$("#" + table_id) |
| 476 |
.find("thead th") |
| 477 |
.eq(5) |
| 478 |
.attr("data-filter", "av_agreement_is_perpetual") |
| 479 |
$("#" + table_id) |
| 480 |
.find("thead th") |
| 481 |
.eq(6) |
| 482 |
.attr( |
| 483 |
"data-filter", |
| 484 |
"av_agreement_renewal_priorities" |
| 485 |
) |
| 486 |
}, |
| 487 |
}, |
| 488 |
agreement_table_settings, |
| 489 |
1 |
| 490 |
) |
| 491 |
}, |
| 492 |
getTableColumns: function () { |
202 |
getTableColumns: function () { |
| 493 |
let get_lib_from_av = this.get_lib_from_av |
203 |
let get_lib_from_av = this.get_lib_from_av |
| 494 |
let escape_str = this.escape_str |
204 |
let escape_str = this.escape_str |
| 495 |
- |
|
|