-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjtox-kit.widgets.js
1595 lines (1345 loc) · 51.3 KB
/
jtox-kit.widgets.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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** jToxKit - chem-informatics multi-tool-kit.
* Base for widgets and UI-related stuff
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016-2020, IDEAConsult Ltd. All rights reserved.
*/
(function (jT, a$, $) {
// Define more tools here
jT.ui = $.extend(jT.ui, {
templates: {},
bakeTemplate: function (html, info, def) {
var all$ = $(html);
$('*', all$[0]).each(function (i, el) {
var liveEl = null,
liveData = {};
var allAttrs = el.attributes;
for (var i = 0;i < allAttrs.length; ++i) {
if (allAttrs[i].specified && allAttrs[i].value.match(jT.templateRegExp)) {
liveData[allAttrs[i].name] = allAttrs[i].value;
allAttrs[i].value = jT.formatString(allAttrs[i].value, info, def);
}
}
if (el.childNodes.length == 1 && el.childNodes[0].nodeType === Node.TEXT_NODE) {
el = el.childNodes[0];
if (el.textContent.match(jT.templateRegExp)) {
liveEl = $(el).parent();
liveData[''] = el.textContent;
el.textContent = jT.formatString(el.textContent, info, def);
}
}
if (liveEl != null)
liveEl.addClass('jtox-live-data').data('jtox-live-data', liveData);
});
return all$;
},
putTemplate: function (id, info, root) {
var html = jT.ui.bakeTemplate(jT.ui.templates[id], info);
return !root ? html : $(root).append(html);
},
updateTree: function (root, info, def) {
$('.jtox-live-data', root).each(function (i, el) {
$.each($(el).data('jtox-live-data'), function (k, v) {
v = jT.formatString(v, info, def)
if (k === '')
el.innerHTML = v;
else
el.attributes[k] = v;
});
});
},
fillHtml: function (id, info, def) {
return jT.formatString(jT.ui.templates[id], info, def);
},
getTemplate: function (id, info, def) {
return $(jT.ui.fillHtml(id, info, def));
},
updateCounter: function (str, count, total) {
var re = null;
var add = '';
if (count == null)
count = 0;
if (total == null) {
re = /\(([\d\?]+)\)$/;
add = '' + count;
} else {
re = /\(([\d\?]+\/[\d\?\+-]+)\)$/;
add = '' + count + '/' + total;
}
// now the addition
if (!str.match(re))
str += ' (' + add + ')';
else
str = str.replace(re, "(" + add + ")");
return str;
},
enterBlur: function (e) {
if (e.keyCode == 13)
this.blur();
},
shortenedData: function (content, message, data) {
var res = '';
if (data == null)
data = content;
if (data.toString().length <= 5) {
res += content;
} else {
res += '<div class="shortened"><span>' + content + '</div><i class="icon fa fa-copy"';
if (message != null)
res += ' title="' + message + '"';
res += ' data-uuid="' + data + '"></i>';
}
return res;
},
linkedData: function (content, message, data) {
var res = '';
if (data == null)
data = content;
if (data.toString().length <= 5)
res += content;
else {
if (message != null) {
res += res += '<div title="' + message + '">' + content + '</div>';
} else res += '<div >' + content + '</div>';
}
return res;
},
changeTabsIds: function (root, suffix) {
$('ul li a', root).each(function () {
var id = $(this).attr('href').substr(1),
el = document.getElementById(id);
id += suffix;
el.id = id;
$(this).attr('href', '#' + id);
})
},
addTab: function (root, name, id, content) {
// first try to see if there is same already...
if (document.getElementById(id) != null)
return;
// first, create and add li/a element
var a$ = $('<a>', { href: '#' + id }).html(name);
$('ul', root[0]).append($('<li>').append(a$));
// then proceed with the panel, itself...
if (typeof content === 'function')
content = $(content(root[0]));
else if (typeof content === 'string')
content = $(content);
content.attr('id', id);
root.append(content).tabs('refresh');
return { tab: a$, content: content };
},
renderRange: function (data, unit, type, prefix) {
var out = "";
if (typeof data == 'string' || typeof data == 'number') {
out += (type != 'display') ? data : ((!!prefix ? prefix + " = " : '') + jT.valueAndUnits(data, unit));
} else if (typeof data == 'object' && data != null) {
var loValue = _.trim(data.loValue),
upValue = _.trim(data.upValue);
if (String(loValue) != '' && String(upValue) != '' && !!data.upQualifier && data.loQualifier != '=') {
if (!!prefix) {
out += prefix + " = ";
}
out += (data.loQualifier == ">=") ? "[" : "(";
out += loValue + ", " + upValue;
out += (data.upQualifier == "<=") ? "]" : ") ";
} else { // either of them is non-undefined
var fnFormat = function (p, q, v) {
var o = '';
if (!!p) {
o += p + ' ';
}
if (!!q) {
o += (!!p || q != '=') ? (q + ' ') : '';
}
return o + v;
};
if (String(loValue) != '') {
out += fnFormat(prefix, data.loQualifier || '=', loValue);
} else if (String(upValue) != '') {
out += fnFormat(prefix, data.upQualifier || '=', upValue);
} else {
if (!!prefix) {
out += prefix;
} else {
out += type == 'display' ? '-' : '';
}
}
}
out = out.replace(/ /g, " ");
if (type == 'display') {
unit = _.trim(data.unit || unit);
if (!!unit) {
out += ' <span class="units">' + unit.replace(/ /g, " ") + '</span>';
}
}
} else {
out += '-';
}
return out;
},
putInfo: function (href, title) {
return '<sup class="helper"><a target="_blank" href="' + (href || '#') + '" title="' + (title || href) + '"><span class="ui-icon ui-icon-info"></span></a></sup>';
},
renderRelation: function (data, type, full) {
if (type != 'display')
return _.map(data, 'relation').join(',');
var res = '';
for (var i = 0, il = data.length; i < il; ++i)
res += '<span>' + data[i].relation.substring(4).toLowerCase() + '</span>' + jT.ui.putInfo(full.URI + '/composition', data[i].compositionName + '(' + data[i].compositionUUID + ')');
return res;
}
});
// 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-tool-kit.
* Base for widgets and UI-related stuff
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2017, IDEAConsult Ltd. All rights reserved.
*/
jT.ui = a$.extend(jT.ui, {
rootSettings: {}, // These can be modified from the URL string itself.
kitsMap: {}, // all found kits are put here.
templateRoot: null,
callId: 0,
// initializes one kit, based on the kit name passed, either as params, or found within data-XXX parameters of the element
initKit: function(element) {
var self = this,
dataParams = element.data(),
kit = dataParams.kit,
topSettings = $.extend(true, {}, self.rootSettings),
parent = null;
// we need to traverse up, to collect some parent's settings...
a$.each(element.parents('.jtox-kit,.jtox-widget').toArray().reverse(), function(el) {
parent = self.kit(el);
if (parent != null)
topSettings = $.extend(true, topSettings, parent);
});
// make us ultimate parent of all
if (!parent)
parent = self;
dataParams = $.extend(true, topSettings, dataParams);
dataParams.baseUrl = jT.fixBaseUrl(dataParams.baseUrl);
dataParams.target = element;
if (dataParams.id === undefined)
dataParams.id = element.attr('id');
// the real initialization function
var realInit = function (params, element) {
if (!kit)
return null;
// add jTox if it is missing AND there is not existing object/function with passed name. We can initialize ketcher and others like this too.
var fn = window[kit];
if (typeof fn !== 'function') {
kit = kit.charAt(0).toUpperCase() + kit.slice(1);
fn = jT.ui[kit] || jT[kit];
}
var obj = null;
if (typeof fn == 'function')
obj = new fn(params);
else if (typeof fn == "object" && typeof fn.init == "function")
obj = fn.init(params);
if (obj != null) {
if (fn.prototype.__kits === undefined)
fn.prototype.__kits = [];
fn.prototype.__kits.push(obj);
obj.parentKit = parent;
if (dataParams.id !== null)
self.kitsMap[dataParams.id] = obj;
}
else
console.log("jToxError: trying to initialize unexistent jTox kit: " + kit);
return obj;
};
// first, get the configuration, if such is passed
if (dataParams.configFile != null) {
// we'll use a trick here so the baseUrl parameters set so far to take account... thus passing 'fake' kit instance
// as the first parameter of jT.ambit.call();
$.ajax({ settings: "GET", url: dataParams.configFile }, function(config){
if (!!config)
$.extend(true, dataParams, config);
element.data('jtKit', realInit(dataParams));
});
}
else {
var config = dataParams.configuration;
if (typeof config === 'string')
config = window[config];
if (typeof config === 'function')
config = config.call(kit, dataParams, kit);
if (typeof config === 'object')
$.extend(true, dataParams, config);
delete dataParams.configuration;
var kitObj = realInit(dataParams, element);
element.data('jtKit', kitObj);
return kitObj;
}
},
// the jToxKit initialization routine, which scans all elements, marked as 'jtox-kit' and initializes them
initialize: function(root) {
var self = this;
if (!root) {
// make this handler for UUID copying. Once here - it's live, so it works for all tables in the future
$(document).on('click', '.jtox-kit div.shortened + .icon', function () { jT.copyToClipboard($(this).data('uuid')); return false;});
// install the click handler for fold / unfold
$(document).on('click', '.jtox-foldable>.title', function(e) { $(this).parent().toggleClass('folded'); });
// install diagram zooming handlers
$(document).on('click', '.jtox-diagram .icon', function () {
$(this).toggleClass('fa-search-plus fa-search-minus');
$('img', this.parentNode).toggleClass('jtox-smalldiagram');
});
// scan the query parameter for settings
var url = jT.parseURL(document.location),
queryParams = url.params;
if (!self.rootSettings.baseUrl)
queryParams.baseUrl = jT.formBaseUrl(document.location.href);
else if (!!queryParams.baseUrl)
queryParams.baseUrl = jT.fixBaseUrl(queryParams.baseUrl);
self.rootSettings = $.extend(true, self.rootSettings, queryParams); // merge with defaults
self.fullUrl = url;
root = document;
}
// now scan all insertion divs
var fnInit = function() { if (!$(this).data('manualInit')) self.initKit($(this)); };
$('.jtox-kit', root).each(fnInit);
$('.jtox-widget', root).each(fnInit);
},
kit: function (element) {
if (typeof element !== "string")
return $(element).data('jtKit');
else if (this.kitsMap[element] !== undefined)
return this.kitsMap[element];
else
return $("#" + element).data('jtKit');
},
attachKit: function (element, kit) {
return $(element).data('jtKit', kit);
},
parentKit: function(name, element) {
var self = this;
var query = null;
if (typeof name == 'string')
name = window[name];
$(element).parents('.jtox-kit').each(function() {
var kit = self.kit(this);
if (!kit || !!query)
return;
if (!name || kit instanceof name)
query = kit;
});
return query;
},
insertTool: function (name, root) {
var html = this.tools[name];
if (html != null) {
root.innerHTML = html;
this.init(root); // since we're pasting as HTML - we need to make re-traverse and initiazaltion of possible jTox kits.
}
return root;
}
});
/** jToxKit - chem-informatics multi-tool-kit.
* A generic widget for list management
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
jT.ListWidget = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
this.length = 0;
this.clearItems();
};
jT.ListWidget.prototype = {
itemId: "id",
populate: function (docs, callback) {
this.items = docs;
this.length = docs.length;
this.target.empty().hide(); // Hiding for performnance improvements.
for (var i = 0, l = docs.length; i < l; i++)
this.target.append(this.renderItem(typeof callback === "function" ? callback(docs[i]) : docs[i]));
this.target.show();
},
addItem: function (doc) {
this.items.push(doc);
++this.length;
return this.renderItem(doc);
},
clearItems: function () {
this.target.empty();
this.items = [];
this.length = 0;
},
findItem: function (id) {
var self = this;
return a$.findIndex(this.items, typeof id !== "string" ? id : function (doc) { return doc[self.itemId] === id; });
},
eraseItem: function (id) {
var i = this.findItem(id),
r = (i >= 0) ? this.items.splice(i, 1)[0] : false;
this.length = this.items.length;
return r;
},
enumerateItems: function (callback) {
var els = this.target.children();
for (var i = 0, l = this.items.length; i < l; ++i)
callback.call(els[i], this.items[i]);
}
}
/** jToxKit - chem-informatics multi-tool-kit.
* A generic widget for box of tag management.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
jT.TagWidget = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
if (!!this.subtarget)
this.target = this.target.find(this.subtarget).eq(0);
this.id = settings.id;
this.color = this.color || this.target.data("color");
if (!!this.color)
this.target.addClass(this.color);
};
jT.TagWidget.prototype = {
__expects: [ "hasValue", "clickHandler" ],
color: null,
renderItem: null,
onUpdated: null,
subtarget: null,
init: function (manager) {
a$.pass(this, jT.TagWidget, "init", manager);
this.manager = manager;
},
populate: function (objectedItems, preserve) {
var self = this,
item = null,
total = 0,
el, selected, value;
if (objectedItems.length == null || objectedItems.length == 0) {
if (!preserve)
this.target.html("No items found in this selection").addClass("jt-no-tags");
}
else {
this.target.removeClass("jt-no-tags");
objectedItems.sort(function (a, b) {
return (a.value || a.val) < (b.value || b.val) ? -1 : 1;
});
if (!preserve)
this.target.empty();
this.target.hide(); // Hiding for performance improvement
for (var i = 0, l = objectedItems.length; i < l; i++) {
item = objectedItems[i];
value = item.value || item.val;
selected = this.exclusion && this.hasValue(value);
total += item.count;
item.title = value.toString();
if (typeof this.modifyTag === 'function')
item = this.modifyTag(item);
if (!selected)
item.onMain = self.clickHandler(value);
this.target.append(el = this.renderItem(item));
if (selected)
el.addClass("selected");
}
this.target.show();
}
a$.act(this, this.onUpdated, total);
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* A generic widget for autocomplete box management.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*
*/
jT.AutocompleteWidget = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
this.lookupMap = settings.lookupMap || {};
};
jT.AutocompleteWidget.prototype = {
__expects: [ "doRequest" ],
tokenMode: true,
initialState: 'enabled',
init: function (manager) {
var self = this;
// now configure the "accept value" behavior
this.findBox = this.target.find('input').addBack('input').on("change", function (e) {
if (!self._inChange && self.onChange) {
var thi$ = $(this);
self.onChange(thi$.val()) && thi$.blur();
}
});
// configure the auto-complete box.
var boxOpts = {
'minLength': 0,
'source': function (request, callback) {
self.reportCallback = callback;
self.doRequest(request.term);
},
'select': function(event, ui) {
if (!ui.item)
return;
self.onSelect && self.onSelect(ui.item);
self.onAdded && self.onAdded(ui.item);
self.onChange && self.onChange(ui.item);
},
'focus': function (event, ui) {
// Make sure the label is shown, not the value.
event.preventDefault();
$(this).val(ui.item.label);
}
};
if (!this.tokenMode)
this.findBox.autocomplete(boxOpts);
else
this.findBox
.on('tokenfield:removedtoken', function (e) {
self.onRemoved && self.onRemoved(e.attrs.value);
})
.tokenfield({ autocomplete: boxOpts });
if (this.initialState === 'disabled')
this.findBox[this.tokenMode ? 'tokenfield' : 'autocomplete']("disable");
a$.pass(this, jT.AutocompleteWidget, "init", manager);
},
resetValue: function(val) {
this._inChange = true;
if (this.tokenMode)
this.findBox.tokenfield('enable').tokenfield('setTokens', val);
else
this.findBox.autocomplete('enable').val(val);
this._inChange = false;
},
onFound: function (list) {
this.findBox[this.tokenMode ? 'tokenfield' : 'autocomplete']("enable");
this.reportCallback && this.reportCallback(list);
this.reportCallback = null;
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* A very simple, template rendering Item Widget. Suitable for
* both ListWidget and TagWidgets
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016, IDEAConsult Ltd. All rights reserved.
*/
jT.SimpleItemWidget = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
};
jT.SimpleItemWidget.prototype = {
template: null,
classes: null,
renderItem: function (info) {
return jT.ui.getTemplate(template, info).addClass(this.classes);
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* An expansion builder for existing Accordion widget
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2017, IDEAConsult Ltd. All rights reserved.
*/
jT.AccordionExpansion = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
this.header = null;
this.id = settings.id;
// We're resetting the target, so the rest of skills get a true one.
if (this.automatic)
settings.target = this.makeExpansion();
};
jT.AccordionExpansion.prototype = {
automatic: true,
title: null,
classes: null,
expansionTemplate: null,
before: null,
renderExpansion: function (info) {
return jT.ui.getTemplate(this.expansionTemplate, info).addClass(this.classes);
},
makeExpansion: function (before, info) {
// Check if we've already made the expansion
if (!!this.header)
return;
if (!info)
info = this;
if (!before)
before = this.before;
var el$ = this.renderExpansion(info);
this.accordion = this.target;
if (!before)
this.accordion.append(el$);
else if (typeof before === "number")
this.accordion.children().eq(before).before(el$);
else if (typeof before === "string")
$(before, this.accordion[0]).before(el$);
else
$(before).before(el$);
this.refresh();
this.header = $("#" + this.id + "_header");
return this.target = $("#" + this.id); // ATTENTION: This presumes we've put that ID to the content part!
},
getHeaderText: function () {
return this.header.contents().filter(function () { return this.nodeType == 3; })[0];
},
refresh: function () {
this.accordion.accordion("refresh");
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* A generic slider (or range) widget
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2017, IDEAConsult Ltd. All rights reserved.
*/
jT.SliderWidget = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = $(settings.target);
this.prepareLimits(settings.limits);
if (this.initial == null)
this.initial = this.isRange ? [ this.limits[0], this.limits[1] ] : (this.limits[0] + this.limits[1]) / 2;
this.target.val(Array.isArray(this.initial) ? this.initial.join(",") : this.initial);
if (!!this.automatic)
this.makeSlider();
};
jT.SliderWidget.prototype = {
__expects: [ "updateHandler" ],
limits: null, // The overall range limit.
units: null, // The units of the values.
initial: null, // The initial value of the sliders.
title: null, // The name of the slier.
width: null, // The width of the whole slider.
automatic: true, // Whether to automatically made the slider in constructor.
isRange: true, // Is this a range slider(s) or a single one?
showScale: true, // Whether to show the scale
format: "%s {{units}}", // The format for value output.
prepareLimits: function (limits) {
this.limits = typeof limits === "string" ? limits.split(",") : limits;
this.limits[0] = parseFloat(this.limits[0]);
this.limits[1] = parseFloat(this.limits[1]);
this.precision = Math.pow(10, parseInt(Math.min(1, Math.floor(Math.log10(this.limits[1] - this.limits[0] + 1) - 3))));
if (this.precision < 1 && this.precision > .01)
this.precison = .01;
},
updateSlider: function (value, limits) {
if (Array.isArray(value))
value = value.join(",");
if (limits != null) {
this.prepareLimits(limits);
this.target.jRange('updateRange', this.limits, value);
}
else
this.target.jRange('setValue', value);
},
makeSlider: function () {
var self = this,
enabled = this.limits[1] > this.limits[0],
scale = [
jT.nicifyNumber(this.limits[0], this.precision),
this.title + (enabled || !this.units ? "" : " (" + this.units + ")"),
jT.nicifyNumber(this.limits[1], this.precision)
],
updateHandler = self.updateHandler(),
settings = {
from: this.limits[0],
to: this.limits[1],
step: this.precision,
scale: scale,
showScale: this.showScale,
showLabels: enabled,
disable: !enabled,
isRange: this.isRange,
width: this.width,
format: jT.formatString(this.format, this) || ""
};
if (this.color != null)
settings.theme = "theme-" + this.color;
settings.ondragend = function (value) {
if (typeof value === "string" && self.isRange)
value = value.split(",");
value = Array.isArray(value) ? value.map(function (v) { return parseFloat(v); }) : parseFloat(value);
return updateHandler(value);
};
return this.target.jRange(settings);
}
};
/** jToxKit - chem-informatics multi-tool-kit.
* A generic widget for managing current search results
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2020, IDEAConsult Ltd. All rights reserved.
*
*/
CurrentSearchWidgeting = function (settings) {
a$.extend(true, this, a$.common(settings, this));
this.target = settings.target;
this.id = settings.id;
this.manager = null;
this.facetWidgets = {};
this.fqName = this.useJson ? "json.filter" : "fq";
};
CurrentSearchWidgeting.prototype = {
useJson: false,
renderItem: null,
init: function (manager) {
a$.pass(this, CurrentSearchWidgeting, "init", manager);
this.manager = manager;
},
registerWidget: function (widget, pivot) {
this.facetWidgets[widget.id] = pivot;
},
afterTranslation: function (data) {
var self = this,
links = [],
q = this.manager.getParameter('q'),
fq = this.manager.getAllValues(this.fqName);
// add the free text search as a tag
if (!!q.value && !q.value.match(/^(\*:)?\*$/)) {
links.push(self.renderItem({ title: q.value, count: "x", onMain: function () {
q.value = "";
self.manager.doRequest();
return false;
} }).addClass("tag_fixed"));
}
// now scan all the filter parameters for set values
for (var i = 0, l = fq != null ? fq.length : 0; i < l; i++) {
var f = fq[i],
vals = null,
w;
for (var wid in self.facetWidgets) {
w = self.manager.getListener(wid);
vals = w.fqParse(f);
if (!!vals)
break;
}
if (vals == null) continue;
if (!Array.isArray(vals))
vals = [ vals ];
for (var j = 0, fvl = vals.length; j < fvl; ++j) {
var v = vals[j], el,
info = (typeof w.prepareTag === "function") ?
w.prepareTag(v) :
{ title: v, count: "x", color: w.color, onMain: w.unclickHandler(v) };
links.push(el = self.renderItem(info).addClass("tag_selected " + (!!info.onAux ? "tag_open" : "tag_fixed")));
if (fvl > 1)
el.addClass("tag_combined");
}
if (fvl > 1)
el.addClass("tag_last");
}
if (links.length) {
links.push(self.renderItem({ title: "Clear", onMain: function () {
q.value = "";
for (var wid in self.facetWidgets)
self.manager.getListener(wid).clearValues();
self.manager.doRequest();
return false;
}}).addClass('tag_selected tag_clear tag_fixed'));
this.target.empty().addClass('tags').append(links);
}
else
this.target.removeClass('tags').html('<li>No filters selected!</li>');
}
};
jT.CurrentSearchWidget = a$(CurrentSearchWidgeting);
/** jToxKit - chem-informatics multi-tool-kit.
* A very simple, widget add-on for wiring the ability to change
* certain property of the agent, based on a provided UI element.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016-2017, IDEAConsult Ltd. All rights reserved.
*/
jT.Switching = function (settings) {
a$.extend(true, this, a$.common(settings, jT.Switching.prototype));
var self = this,
target$ = $(self.switchSelector, $(settings.target)[0]),
initial = _.get(self, self.switchField);
// Initialize the switcher according to the field.
if (typeof initial === 'boolean')
target$[0].checked = initial;
else
target$.val(initial);
// Now, install the handler to change the field with the UI element.
target$.on('change', function (e) {
var val = $(this).val();
a$.path(self, self.switchField, typeof initial === 'boolean' ? this.checked || val === 'on' : val);
a$.act(self, self.onSwitching, e);
e.stopPropagation();
});
};
jT.Switching.prototype = {
switchSelector: ".switcher", // A CSS selector to find the switching element.
switchField: null, // The field to be modified.
onSwitching: null // The function to be invoked, on change.
};
/** jToxKit - chem-informatics multi-tool-kit.
* A very simple, widget add-on for wiring the ability to change
* certain property of the agent, based on a provided UI element.
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2016-2017, IDEAConsult Ltd. All rights reserved.
*/
jT.Running = function (settings) {
a$.extend(true, this, a$.common(settings, jT.Running.prototype));
var self = this,
target$ = $(self.runSelector, $(settings.target)[0]),
runTarget = self.runTarget || self;
// Now, install the handler to change the field with the UI element.
target$.on('click', function (e) {
a$.act(runTarget, self.runMethod, this, e);
e.stopPropagation();
});
};
jT.Running.prototype = {
runSelector: ".switcher", // A CSS selector to find the switching element.
runMethod: null, // The method to be invoked on the given target or on self.
runTarget: null, // The target to invoke the method to - this will be used if null.
};
/** jToxKit - chem-informatics multi-tool-kit.
* Wrapper of table-relevant tools. To be assigned to specific prototype functions
*
* Author: Ivan (Jonan) Georgiev
* Copyright © 2020, IDEAConsult Ltd. All rights reserved.
*/
jT.tables = {
nextPage: function () {
if (this.entriesCount == null || this.pageStart + this.pageSize < this.entriesCount)
this.queryEntries(this.pageStart + this.pageSize);
},
prevPage: function () {
if (this.pageStart > 0)
this.queryEntries(this.pageStart - this.pageSize);
},
updateControls: function (qStart, qSize) {
var pane = $('.jtox-controls', this.rootElement);
jT.ui.updateTree(pane, {
"pagestart": qSize > 0 ? qStart + 1 : 0,
"pageend": qStart + qSize
});
pane = pane[0];
var nextBut = $('.next-field', pane);
if (this.entriesCount == null || qStart + qSize < this.entriesCount)
$(nextBut).addClass('paginate_enabled_next').removeClass('paginate_disabled_next');
else
$(nextBut).addClass('paginate_disabled_next').removeClass('paginate_enabled_next');
var prevBut = $('.prev-field', pane);
if (qStart > 0)
$(prevBut).addClass('paginate_enabled_previous').removeClass('paginate_disabled_previous');
else
$(prevBut).addClass('paginate_disabled_previous').removeClass('paginate_enabled_previous');
},
modifyColDef: function (kit, col, category, group) {
if (col.title === undefined || col.title == null)
return null;