-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjtox-kit.js
817 lines (683 loc) · 24.4 KB
/
jtox-kit.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/** jToxKit - chem-informatics multi-tool-kit.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
// Define this as a main object to put everything in
var jToxKit = { version: "2.4.3" };
(function (jT, a$, Solr) {
// Now import all the actual skills ...
// ATTENTION: Kepp them in the beginning of the line - this is how smash expects them.
/** jToxKit - chem-informatics multi toolkit.
* Generic tools
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2017, IDEAConsult Ltd. All rights reserved.
*/
jT = a$.extend(jT, {
templateRegExp: /\{\{([^}]+)\}\}/,
/* formats a string, replacing {{number | property}} in it with the corresponding value in the arguments
*/
formatString: function (str, info, def) {
var pieces = str.split(jT.templateRegExp),
pl = pieces.length,
out = "";
for (var i = 0;; ++i) {
out += pieces[i++];
if (i >= pl)
break;
var f = _.get(info, _.trim(pieces[i]), null);
if (f != null) // i.e. we've found it.
out += f;
else if (typeof def === 'function') // not found, but we have default function.
out += def(pieces[i]);
else if (typeof def === 'string') // not found, but default string.
out += def;
else // we have nothing, so - put nothing.
out += "";
}
return out;
},
nicifyNumber: function (num, prec) {
if (num == null)
return "";
var maxPrec = Math.pow(10, prec || 9),
rounded, prec;
for (prec = 10; prec < maxPrec; prec *= 10) {
rounded = Math.round(num * prec);
if (Math.abs(rounded - num * prec) < .1)
break;
}
return parseInt(rounded) / prec;
},
formatUnits: function (str) {
// change the exponential
return !str ? '' : str.toString()
.replace(/(^|\W)u(\w)/g, '$1µ$2')
.replace(/\^\(?([\-\d]+)\)?/g, '<sup>$1</sup>')
.replace(/ /g, " ")
},
valueAndUnits: function (val, unit, prec) {
var out = '';
if (val != null) {
val = typeof val === 'string' ? _.trim(val) : jT.nicifyNumber(val, prec).toString();
out += val.replace(/ /g, " ");
out += jT.formatUnits(unit);
}
return out;
},
addParameter: function (url, param) {
return url + (("&?".indexOf(url.charAt(url.length - 1)) == -1) ? (url.indexOf('?') > 0 ? "&" : "?") : '') + param;
},
removeParameter: function (url, param) {
return url.replace(new RegExp('(.*\?.*)(' + param + '=[^\&\s$]*\&?)(.*)'), '$1$3');
},
parseURL: function (url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':', ''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function () {
var ret = {},
seg = a.search.replace(/^\?/, '').split('&'),
len = seg.length,
i = 0,
s, v, arr;
for (; i < len; i++) {
if (!seg[i]) {
continue;
}
s = seg[i].split('=');
v = (s.length > 1) ? decodeURIComponent(s[1].replace(/\+/g, " ")) : '';
if (s[0].indexOf('[]') == s[0].length - 2) {
arr = ret[s[0].slice(0, -2)];
if (arr === undefined)
ret[s[0].slice(0, -2)] = [v];
else
arr.push(v);
} else
ret[s[0]] = v;
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
hash: a.hash.replace('#', ''),
path: a.pathname.replace(/^([^\/])/, '/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
segments: a.pathname.replace(/^\//, '').split('/')
};
},
modifyURL: function (url, name, value) {
var a = document.createElement('a'),
str = !!value ? name + "=" + encodeURIComponent(value) : "",
mbs, q;
a.href = url;
q = a.search;
mbs = q.match(new RegExp(name + "=[\\S^&]+"))
if (!!mbs)
q = q.replace(mbs[0], str);
else if (!str)
return;
else if (q.charAt(0) == '?')
q = "?" + str;
else
q += (q.slice(-1) == "&" ? "" : "&") + str;
a.search = q;
return a.href;
},
/* Fix the baseUrl - ensure it has trailing slash
*/
fixBaseUrl: function (url) {
if (url && url.charAt(url.length - 1) != '/')
url += '/';
return url;
},
// form the "default" baseUrl if no other is supplied
formBaseUrl: function (url) {
var burl = url.match(/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:\d+)?(\/\w+)/);
if (burl)
burl = burl[0] + '/';
console.log("Deduced base URL: " + burl + " (from: " + url + ")");
return burl;
},
copyToClipboard: function (text, prompt) {
if (!prompt) {
prompt = "Press Ctrl-C (Command-C) to copy and then Enter.";
}
window.prompt(prompt, text);
},
fireCallback: function (callback, self) {
if (!$.isArray(callback))
callback = [callback];
var ret = true;
for (var i = 0, cl = callback.length; i < cl; ++i) {
var callone = callback[i];
if (typeof callone != 'function')
callone = window[callone];
ret = (typeof callone == 'function') ? (callone.apply((self !== undefined && self != null) ? self : document, Array.prototype.slice.call(arguments, 2))) : undefined;
}
return ret;
},
validateForm: function (form, cb) {
cb = cb || function () {
if ('checkValidity' in this)
return this.checkValidity();
else {
var valid = (this.value.length > 0);
if (!valid)
this.placeholder = 'You need to fill this box';
return valid;
}
};
var ok = true;
$('input,textarea,select', form).each(function () {
ok = ok && (!!cb.call(this));
});
return ok;
},
activateDownload: function (aEl, blob, destName, autoRemove) {
var url = URL.createObjectURL(blob),
selfClick = false;
if (!aEl) {
aEl = document.createElement('a');
selfClick = autoRemove = true;
} else
aEl.style.visibility = "visible";
aEl.href = url;
aEl.download = destName;
if (autoRemove === true)
aEl.addEventListener('click', function () {
setTimeout(function () {
if (aEl.parentElement)
aEl.parentElement.removeChild(aEl);
window.URL.revokeObjectURL(url);
}, 0);
});
if (selfClick)
aEl.click();
},
promiseXHR: function (ajax) {
var keySetter = function (xhr, aux) {
aux && Object.keys(aux).forEach(function (key) {
xhr[key] = aux[key];
});
};
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(ajax.method || "GET", ajax.url, true);
Object.keys(ajax.headers || {}).forEach(function (key) {
xhr.setRequestHeader(key, ajax.headers[key]);
});
if (typeof ajax.dataType === 'string')
xhr.setRequestHeader('Content-Type', ajax.dataType);
keySetter(xhr, ajax.settings);
keySetter(xhr, ajax.xhrFields);
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4)
return;
// Process the response
if ((xhr.status == 0 && !!xhr.response) || (xhr.status >= 200 && xhr.status < 300))
resolve(xhr.response, xhr.statusText, xhr);
else
reject(xhr, xhr.statusText, xhr.responseText);
};
xhr.send(ajax.body || ajax.data);
});
},
blobFromBase64: function (data64, mimeType) {
return new Blob([data64], {
type: mimeType
});
}
});
/** jToxKit - chem-informatics multi toolkit.
* Data translation basic skills.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
/***
* The rationale behind this skill-set is that any data transformation that could be needed from the raw response
* to the data expected by the widgets should happen only once. If we have each widget directly being notified
* upon query's response, then each widget should transform the data by itself, which could potentially be
* time consuming.
* With this skill-set encapsulation we provide the mechanism for widget(s) to listen to `data ready` notification.
* The actual data transformation, of course, is going to be done by another skill set, which will provide the only
* expected method - `translateResponse`.
*
* Consumers are registered pretty much the same way each listener is.
* There two methods that are expected to be present - `init` and `afterTranslation`.
* The first one is optional and is invoked once, when the Translation-enabled entity
* is initialized itself.
* The other method - `afterTranslation` is invoked on every successfull response.
*/
/**
* Data translation skills, aimed a generic binding link between translators and parties
* interested in pre-formatted data.
*
*/
jT.Translation = function (settings) {
a$.extend(true, this, settings);
}
jT.Translation.prototype = {
__expects: [ "translateResponse" ],
/**
* Methods, that are going to be invoked by the manager.
*/
init: function () {
// Let the other initializers, like the Management, for example
a$.pass(this, jT.Translation, "init");
},
parseResponse: function (response, scope) {
a$.pass(this, jT.Translation, "parseResponse");
var data = this.translateResponse(response, scope),
self = this;
a$.each(this.listeners, function (c) {
a$.act(c, c.afterTranslation, data, scope, self);
});
},
};
/** jToxKit - chem-informatics multi toolkit.
* Raw SOLR translation
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
/**
* Raw, non-nested Solr data translation.
*/
jT.RawSolrTranslation = function (settings) {
a$.extend(true, this, a$.common(settings, this));
}
jT.RawSolrTranslation.prototype = {
collapseRules: {
"study": { fields: /topcategory[_sh]*|endpointcategory[_sh]*|guidance[_sh]*|reference[_sh]*|reference_owner[_sh]*|reference_year[_sh]*|guidance[_sh]*/ },
"composition": { fields: /CORE|COATING|CONSTITUENT|ADDITIVE|IMPURITY|FUNCTIONALISATION|DOPING/ }
},
init: function (manager) {
// Let the other initializers, like the Management, for example
a$.pass(this, jT.RawSolrTranslation, "init");
},
translateResponse: function (response, scope) {
var docs = [],
self = this,
filterProps = function (dout, din) {
a$.each(self.collapseRules, function (r, type) {
var subdoc = {};
a$.each(din, function (v, k) {
if (!k.match(r.fields))
return;
delete din[k];
// smash these annoying multi-arrays.
if (Array.isArray(v) && v.length == 1)
v = v[0];
subdoc[k] = v;
});
// now add this.
if (dout._extended_ === undefined)
dout._extended_ = {};
if (dout._extended_[type] === undefined)
dout._extended_[type] = [ subdoc ];
else
dout._extended_[type].push(subdoc);
});
// now process the remaining fields too
a$.each(din, function (v, k) {
// smash these annoying multi-arrays.
if (Array.isArray(v) && v.length == 1)
v = v[0];
dout[k] = v;
});
};
for (var i = 0, dl = response.response.docs.length; i < dl; ++i) {
var din = response.response.docs[i],
ein = response.expanded[din.s_uuid],
dout = {};
filterProps(dout, din);
for (var j = 0, edl = ein.docs.length; j < edl; ++j)
filterProps(dout, ein.docs[j]);
docs.push(dout);
}
return {
'entries': docs,
'stats': a$.extend({}, response.stats, response.responseHeader),
'facets': a$.extend({}, response.facet_counts.facet_fields || response.facets, response.facet_counts.facet_pivot),
'paging': {
'start': response.response.start,
'count': response.response.docs.length,
'total': response.response.numFound,
'pageSize': parseInt(response.responseHeader.params.rows)
}
};
}
};
// TODO: Potentially add other, higher level methods for constructing a query.
/** jToxKit - chem-informatics multi toolkit.
* Nested docs SOLR translation
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2017, IDEAConsult Ltd. All rights reserved.
*/
/**
* The nested documents Solr data translation.
*/
jT.NestedSolrTranslation = function (settings) {
this.nestingField = settings && settings.nestingField || "type_s";
}
jT.NestedSolrTranslation.prototype = {
init: function (manager) {
// Let the other initializers, like the Management, for example
a$.pass(this, jT.NestedSolrTranslation, "init");
},
translateResponse: function (response, scope) {
var docs = response.response.docs;
for (var i = 0, dl = docs.length; i < dl; ++i) {
var d = docs[i],
ext = {};
if (!d._childDocuments_)
continue;
for (var j = 0, cl = d._childDocuments_.length; j < cl; ++j) {
var c = d._childDocuments_[j],
type = c[this.nestingField];
if (ext[type] === undefined)
ext[type] = [];
ext[type].push(c);
}
delete d._childDocuments_;
d._extended_ = ext;
}
return {
'entries': docs,
'stats': a$.extend({}, response.stats, response.responseHeader),
'facets': response.facets,
'paging': {
'start': response.response.start,
'count': response.response.docs.length,
'total': response.response.numFound,
'pageSize': parseInt(response.responseHeader.params.rows)
}
};
}
};
// TODO: Potentially add other, higher level methods for constructing a query.
/** jToxKit - chem-informatics multi-tool-kit.
* A model running skill, based on AMBIT API.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016-2017, IDEAConsult Ltd. All rights reserved.
*/
jT.ModelRunning = function (settings) {
a$.extend(true, this, settings);
this.models = null;
}
jT.ModelRunning.prototype = {
__expects: [ 'pollTask' ],
algorithms: false, // ask for algorithms, not models.
forceCreate: false, // upon creating a model from algorithm - whether to attempt getting a prepared one, or always create it new.
loadOnInit: false, // whether to make a (blank) request upon loading.
listFilter: null, // What needle to use when obtaining model/algorithm list.
onLoaded: null, // callback to be called when data has arrived.
init: function (manager) {
// Let the other initializers.
a$.pass(this, jT.ModelRunning, "init", manager);
this.manager = manager;
if (this.loadOnInit)
this.queryList();
},
/* List all models provided from the server
*/
listModels: function () {
var self = this;
self.manager.doRequest('model', function (result, jhr) {
if (result && result.model)
self.models = result.model;
else if (jhr.status == 200)
result = { model: [] }; // empty one. The self.model is already in this state.
a$.act(self, self.onLoaded, result);
});
},
/* List algorithms that contain given 'needle' in their name
*/
listAlgorithms: function (needle) {
var self = this,
servlet = 'algorithm';
if (!!needle)
servlet += '?search=' + needle;
self.manager.doRequest(servlet, function (result, jhr) {
if (result && result.algorithm)
self.algorithm = result.algorithm;
else if (jhr.status == 200)
result = { algorithm: [] }; // empty one
a$.act(self, self.onLoaded, result, jhr);
});
},
/**
* Get a runnable model for the given algorithm
*/
getModel: function (algoUri, callback) {
var self = this,
reportIt = function (task, jhr) { return callback(task && task.completed > -1 ? task.result : null, jhr); };
if (self.forceCreate)
self.pollTask({url: algoUri, method: 'POST'}, reportIt);
else
self.manager.doRequest('model?algorithm=' + encodeURIComponent(algoUri), function (result, jhr) {
if (!result && jhr.status != 404) // Some kind of error.
callback(null, jhr);
else if (!result || result.model.length == 0) // Ok, we need to create it.
self.pollTask({ url: algoUri, method: 'POST' }, reportIt);
else // Bingo - we've got it!
callback(result.model[0].URI, jhr);
});
},
/**
* Run a prediction on a created/obtained model
*/
runPrediction: function (datasetUri, modelUri, callback) {
var self = this,
createAttempted = false,
obtainResults = null,
createIt = function (jhr) {
if (createAttempted) {
callback(null, jhr);
return;
}
self.pollTask({
url: modelUri,
method: "POST",
data: { dataset_uri: datasetUri },
}, function (task, jhr) {
createAttempted = true;
if (task && task.completed > -1)
obtainResults(task.result);
});
};
obtainResults = function (uri) {
self.manager.connector.ajax({
url: uri,
method: 'GET',
dataType: 'json',
error: function (jhr) { callback(null, jhr); },
success: function (result, jhr) {
if (result && result.dataEntry && result.dataEntry.length > 0) {
var empty = true;
for (var i = 0, rl = result.dataEntry.length; i < rl; ++i)
if (a$.weight(result.dataEntry[i].values) > 0) {
empty = false;
break;
}
if (empty)
createIt(jhr);
else
callback(result, jhr);
}
else
createIt(jhr);
}
});
};
if (self.forceCreate)
createIt();
else
obtainResults(jT.addParameter(datasetUri, 'feature_uris[]=' + encodeURIComponent(modelUri + '/predicted')));
},
/**
* Query the list of algorithms or models on the server
*/
queryList: function (needle) {
if (this.algorithms)
this.listAlgorithms(this.listFilter = (needle || this.listFilter));
else
this.listModels(this.modelUri);
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* The simple skill of polling for a task - based on the AMBIT API.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016-2017, IDEAConsult Ltd. All rights reserved.
*/
jT.TaskPolling = function (settings) {
a$.extend(true, this, settings);
this.models = null;
}
jT.TaskPolling.prototype = {
pollDelay: 250, // how often to check for task completion. In milliseconds.
pollTimeout: 15000, // after how many milliseconds to give up.
init: function (manager) {
a$.pass(this, jT.TaskPolling, "init", manager);
this.manager = manager;
},
/**
* Poll on a task, until it is finished. Pay attention to the fact that the taskUri could be URI
* of any service that _returns_ task definition.
*/
pollTask : function(taskUri, callback) {
var self = this, proceedOnTask, queryTask, taskStart = null;
queryTask = function (settings) {
if (typeof settings === 'string')
settings = { url: settings, method: 'GET' };
settings.error = function (jhr) { callback( null, jhr ); };
settings.success = proceedOnTask;
settings.dataType = "json";
self.manager.connector.ajax(settings);
}
proceedOnTask = function (task, jhr) {
if (task == null || task.task == null || task.task.length < 1) {
callback(task, jhr);
return;
}
task = task.task[0];
if (task.completed > -1 || !!task.error) // i.e. - we're ready or we're in trouble.
callback(task, jhr);
else if (taskStart == null) { // first round
taskStart = Date.now();
setTimeout(function() { queryTask(task.result); }, self.pollDelay);
}
else if (Date.now() - taskStart > self.poolTimeout) // timedout
callback(task, jhr);
else
setTimeout(function() { queryTask(task.result); }, self.pollDelay); // normal round.
}
// Initiate the cycle.
queryTask(taskUri);
}
};
/** jToxKit - chem-informatics multi-tool-kit.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2019, IDEAConsult Ltd. All rights reserved.
*/
function Exporting(settings) {
a$.extend(true, this, a$.common(settings, this));
this.manager = null;
};
Exporting.prototype = {
__expects: [ "addParameter", "prepareQuery" ],
useJson: false, // whether we're in JSON mode or URL string one.
expectJson: false, // what is the provided manager's mode.
servlet: null, // the servlet to be used. Defaults to manager's one.
manualFilter: false, // Handles the `fq` parameter manually.
exportDefinition: { // Definition of additional parameters
extraParams: [],
defaultFilter: null,
inheritDomain: true, // Whether to inherit the domain from original query.
domain: "",
fieldsRegExp: null,
idField: 'id', // The field to be considered ID when provided with id list.
},
init: function (manager) {
a$.pass(this, Exporting, "init", manager);
this.manager = manager;
this.servlet = this.servlet || manager.servlet || "select";
this.fqName = this.useJson ? "json.filter" : "fq";
},
transformParameter: function (par, name) {
var np = {
value: par.value,
name: name || par.name
};
// Check if we have a different level and the field in the filter is subject to parenting.
if (this.exportDefinition.inheritDomain && par.domain && par.domain.type == 'parent') {
if (!this.exportDefinition.domain)
np.domain = par.domain;
else if (!par.value || !!par.value.match(this.exportDefinition.fieldsRegExp))
np.domain = this.exportDefinition.domain;
}
return np;
},
prepareFilters: function () {
var innerParams = [],
fqPar = this.manager.getParameter(this.expectJson ? "json.filter" : "fq");
for (var i = 0, vl = fqPar.length; i < vl; i++) {
var par = fqPar[i];
if (!this.manualFilter)
this.addParameter(this.transformParameter(par, this.fqName));
innerParams.push(Solr.stringifyValue(par));
}
return innerParams;
},
prepareExport: function(auxParams, selectedIds, keepFilters) {
var innerParams = !selectedIds || keepFilters ? this.prepareFilters() : [],
inFilter = innerParams.length > 0
? innerParams.join(' AND ')
: this.exportDefinition.defaultFilter || "",
escapedInFilter = inFilter.replace(/"|\\/g, "\\$&");
if (!!selectedIds)
this.addParameter(this.fqName, this.exportDefinition.idField + ":(" + selectedIds.join(" ") + ")");
this.addParameter(this.transformParameter(this.manager.getParameter('q')));
auxParams = (auxParams || []).concat(this.exportDefinition.extraParams || []);
for (var i = 0, pl = auxParams.length; i < pl; ++i) {
var np = this.transformParameter(auxParams[i]);
if (typeof np.value === 'string')
np.value = np.value
.replace("{{filter}}", inFilter)
.replace("{{filter-escaped}}", escapedInFilter)
.replace(/\(\s*\)\s+OR\s+/, '')
this.addParameter(np);
}
return this; // For chaining.
},
getAjax: function (serverUrl, ajaxSettings) {
var urlPrefix = serverUrl + this.servlet,
settings = a$.extend({}, this.manager.ajaxSettings, ajaxSettings, this.prepareQuery());
if (urlPrefix.indexOf('?') > 0 && settings.url && settings.url.startsWith('?'))
settings.url = '&' + settings.url.substr(1);
settings.url = urlPrefix + (settings.url || "");
return settings;
}
};
jT.Exporting = Exporting;
/** ... and finish with some module / export definition for according platforms
*/
if ( typeof module === "object" && module && typeof module.exports === "object" )
module.exports = jToxKit;
else {
this.jToxKit = this.jT = a$.extend({}, this.jToxKit, jToxKit);
if ( typeof define === "function" && define.amd )
define(jToxKit);
}
})(jToxKit, asSys, Solr);