otsdaq_utilities  v2_05_02_indev
accessor.js
1 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2 
3 /* Tabulator v4.5.3 (c) Oliver Folkerd */
4 
5 var Accessor = function Accessor(table) {
6  this.table = table; //hold Tabulator object
7  this.allowedTypes = ["", "data", "download", "clipboard"]; //list of accessor types
8 };
9 
10 //initialize column accessor
11 Accessor.prototype.initializeColumn = function (column) {
12  var self = this,
13  match = false,
14  config = {};
15 
16  this.allowedTypes.forEach(function (type) {
17  var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
18  accessor;
19 
20  if (column.definition[key]) {
21  accessor = self.lookupAccessor(column.definition[key]);
22 
23  if (accessor) {
24  match = true;
25 
26  config[key] = {
27  accessor: accessor,
28  params: column.definition[key + "Params"] || {}
29  };
30  }
31  }
32  });
33 
34  if (match) {
35  column.modules.accessor = config;
36  }
37 }, Accessor.prototype.lookupAccessor = function (value) {
38  var accessor = false;
39 
40  //set column accessor
41  switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
42  case "string":
43  if (this.accessors[value]) {
44  accessor = this.accessors[value];
45  } else {
46  console.warn("Accessor Error - No such accessor found, ignoring: ", value);
47  }
48  break;
49 
50  case "function":
51  accessor = value;
52  break;
53  }
54 
55  return accessor;
56 };
57 
58 //apply accessor to row
59 Accessor.prototype.transformRow = function (dataIn, type) {
60  var self = this,
61  key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1));
62 
63  //clone data object with deep copy to isolate internal data from returned result
64  var data = Tabulator.prototype.helpers.deepClone(dataIn || {});
65 
66  self.table.columnManager.traverse(function (column) {
67  var value, accessor, params, component;
68 
69  if (column.modules.accessor) {
70 
71  accessor = column.modules.accessor[key] || column.modules.accessor.accessor || false;
72 
73  if (accessor) {
74  value = column.getFieldValue(data);
75 
76  if (value != "undefined") {
77  component = column.getComponent();
78  params = typeof accessor.params === "function" ? accessor.params(value, data, type, component) : accessor.params;
79  column.setFieldValue(data, accessor.accessor(value, data, type, params, component));
80  }
81  }
82  }
83  });
84 
85  return data;
86 },
87 
88 //default accessors
89 Accessor.prototype.accessors = {};
90 
91 Tabulator.prototype.registerModule("accessor", Accessor);