forked from samohtred/X-Tree-M
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib_data_paul.js
More file actions
2166 lines (1997 loc) · 95.4 KB
/
Copy pathlib_data_paul.js
File metadata and controls
2166 lines (1997 loc) · 95.4 KB
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
// Bridge for Paul's approach to make a MySQL database accessible through PHP (alternative to local XML based
// approach)
//
// Usecases :
// - Import data from database
// - Navigate through tree
// - Track changes (GUI + local content storage + database)
//
// Example :
// http://datokrat.sirius.uberspace.de/xtreem/getNodeInfos.php?ids[]=1
// Object {
// .name: "Was n�tzt effektiv dem Weltfrieden?",
// .content: "Eine sehr schwierige Frage, die geeignete Werkzeuge braucht, um konstruktiv diskutiert zu werden.",
// .author: {�},
// .type: "general",
// .children: (1) [�],
// .parents: [] }
// http://datokrat.sirius.uberspace.de/xtreem/create_item.php?parentnodeid=1&authorid=1&name=Titel
// http://datokrat.sirius.uberspace.de/xtreem/changeItem.php?id=1&name=NeuerName&content=NeuerContent
// Class 'lib_data_disco'
function lib_data_paul(data_src_path, data_src_params, defaultParentStorage, global_setup)
{
// import params
this.data_src_path = data_src_path;
this.data_src_params = data_src_params;
this.defaultParentStorage = defaultParentStorage;
this.data_root_id = data_src_params.root_item;
this.global_setup = global_setup; // don't change any of these setups since they're just copied by reference !!!
// tree functions
this.write_tree = lib_data_paul_write_tree.bind(this);
this.req_tree = lib_data_paul_req_tree.bind(this);
this.get_tree = lib_data_paul_get_tree.bind(this);
// item functions
this.get_multi_parents = lib_data_paul_get_multi_parents.bind(this);
this.req_all_parents = lib_data_paul_req_all_parents.bind(this);
this.get_all_parents = lib_data_paul_get_all_parents.bind(this);
this.item_exists = lib_data_paul_item_exists.bind(this);
this.create_tree_item = lib_data_paul_create_tree_item.bind(this);
this.delete_tree_item = lib_data_paul_delete_tree_item.bind(this);
this.copy_items = lib_data_paul_copy_items.bind(this);
this.clone_items = lib_data_paul_clone_items.bind(this);
this.move_items = lib_data_paul_move_items.bind(this);
// field functions
this.create_tree_item_field = lib_data_paul_create_tree_item_field.bind(this);
this.change_tree_item_field = lib_data_paul_change_tree_item_field.bind(this);
this.get_tree_item_field = lib_data_paul_get_tree_item_field.bind(this);
// object variables
this.next_id = 0; // it's necessary to know which IDs can be created for new items
this.root_id = "1";
// variables
this.req_elem_ids = [];
this.is_deleted_arr = [];
this.parent_gui_id_arr = [ null ];
this.parent_elem_id_arr = [ null ];
this.req_tree_state = "rts_idle";
this.new_item_offs = 0;
this.level_ct = 0;
this.del_item_state = "di_idle";
this.rts_ret_struct = {};
this.curr_item_parents = [];
this.move_item_state = "mis_idle";
this.eval_cat_num = c_LANG_UC_BROWSING_PANEL2_EVAL_CATS.length-1;
// constructor call
// init object variables
c_EMPTY_EVAL_STRUCT = [];
for (var i=0; i<this.eval_cat_num; i++)
{
c_EMPTY_EVAL_STRUCT[i] = {};
c_EMPTY_EVAL_STRUCT[i].avg = 0.0;
c_EMPTY_EVAL_STRUCT[i].num = 0;
}
// this.context = Context; //new Context('http://' + this.data_src_path);
// this.context.NamedValues.filter('it.NamedValueSetId == 3').toArray().then(
// function(response) {
// this.root_id = response[0].Value;
// }
// );
}
//################################################################################################
//### Tree functions
//################################################################################################
function f_IntArr2StrArr(IntArr)
{
var StrArr = [];
if (IntArr != undefined)
{
if (IntArr.length > 0)
{
for (var i=0; i<IntArr.length; i++)
StrArr[i] = IntArr[i].toString();
}
}
return StrArr;
}
function get_type_no(typeInternalStr)
{
for (var i=0; i<c_LANG_LIB_TREE_ELEMTYPE.length; i++)
{
if (typeInternalStr == c_LANG_LIB_TREE_ELEMTYPE[i][0])
return i - 1;
}
return -1;
}
function sort(tree_nodes, sibling_start, sibling_len)
{
for(var i=sibling_start; i<(sibling_start+sibling_len); i++) // loop over all sibling elements
{
var curr_winner_idx = i;
var my_type_no = get_type_no(tree_nodes[i].type);
var my_name = tree_nodes[i].name;
for(var j=i+1; j<(sibling_start+sibling_len); j++) // loop over all siblings after current elem ...
{
var cmp_type_no = get_type_no(tree_nodes[j].type);
// ... to find the elem which fits current sort position best
if ((my_type_no>cmp_type_no) || ((my_type_no == cmp_type_no) && (my_name > tree_nodes[j].name)))
{
my_type_no = cmp_type_no;
my_name = tree_nodes[j].name;
curr_winner_idx = j;
}
}
if (curr_winner_idx != i) // exchange items if necessary
{
var hlp = jQuery.extend(true, {}, tree_nodes[i]);
tree_nodes[i] = jQuery.extend(true, {}, tree_nodes[curr_winner_idx]);
tree_nodes[curr_winner_idx] = jQuery.extend(true, {}, hlp);
}
}
}
function lib_data_paul_write_tree(iparams)
{
alert("Paul : Write Tree not yet implemented");
}
function lib_data_paul_req_tree(iparams) // iparams = {elemId, lock_id, favIds, tickerIds, cb_fct_call, mode}
//
// possible values for "mode" :
// "load_all" -> on X-Tree-M start
// "tree_only" -> when only tree item is requested (Explorer Path + Tree-Nodes)
// "fav_only" -> only when favorite item is requested (only Explorer Path)
// "ticker_only" -> only when new ticker item is selected (only child nodes -> Tree Nodes)
//
{
f_append_to_pad('div_panel4_pad','lib_data_paul_req_tree');
// check if last operation is already finished
if (this.req_tree_state == "rts_idle")
{
// copy input params to save source on splice command
var iparams_cp = jQuery.extend(true, {}, iparams);
iparams_cp.elemId = [];
iparams_cp.elemId[0] = iparams.elemId[0];
// ###################################################################################################################
f_append_to_pad('div_panel4_pad','rts_idle');
// ### first inits before any sub-function call
this.rts_ret_struct.explorer_path = [];
this.rts_ret_struct.tree_nodes = [];
this.rts_ret_struct.fav = [];
this.rts_ret_struct.ticker = [];
// kill invalid Favorite ids
if ((iparams_cp.favIds.length > 0) && ( (iparams_cp.mode == "load_all") || (iparams_cp.mode == "fav_only") ))
{
for (var i=0; i<iparams_cp.favIds.length; i++)
{
if (iparams_cp.favIds[i] == null)
{
this.rts_ret_struct.fav[i] = {};
this.rts_ret_struct.fav[i].elem_id = null;
this.rts_ret_struct.fav[i].name = null;
this.rts_ret_struct.fav[i].text = null;
this.rts_ret_struct.fav[i].eval = jQuery.extend(true, [], c_EMPTY_EVAL_STRUCT);
}
else
{
this.rts_ret_struct.fav[i] = this.get_explorer_path({elem_id:iparams_cp.favIds[i], lock_id:this.data_root_id});
var myself_elem = {};
myself_elem.elem_id = iparams_cp.favIds[i];
myself_elem.name = this.get_tree_item_field(iparams_cp.favIds[i], "name");
myself_elem.text = "";
myself_elem.eval = this.get_tree_item_field(iparams_cp.favIds[i], "eval");
this.rts_ret_struct.fav[i].unshift(myself_elem);
}
}
}
var ticker_len = 0;
// kill invalid ticker ids
if (iparams_cp.tickerIds.length > 0)
{
// kill invalid ticker ids
while (iparams_cp.tickerIds[0] == null)
{
this.rts_ret_struct.ticker[ticker_len] = {};
this.rts_ret_struct.ticker[ticker_len].elem_id = null;
this.rts_ret_struct.ticker[ticker_len].name = null;
this.rts_ret_struct.ticker[ticker_len++].text = null;
iparams_cp.tickerIds.splice(0,1);
if (iparams_cp.tickerIds.length == 0)
break;
}
}
this.new_item_offs = 0;
this.level_ct = 0;
var is_multi = false;
this.new_item_offs = 0;
if (((iparams_cp.elemId[0] == iparams_cp.lock_id) && ((iparams_cp.mode == "tree_only") || ((iparams_cp.mode == "load_all") && (iparams_cp.favIds.length == 0)))) || (iparams_cp.mode == "ticker_only"))
{
this.req_tree_state = "rts_get_tree_items";
}
else
{
this.req_tree_state = "rts_get_explorer_path";
}
// assign request elements depending on mode
this.req_elem_ids = [];
switch (iparams_cp.mode)
{
case "load_all" :
if (iparams_cp.favIds.length == 0)
this.req_elem_ids[0] = iparams_cp.elemId[0];
else
this.req_elem_ids[0] = iparams_cp.favIds[0];
break;
case "tree_only" :
this.req_elem_ids[0] = iparams_cp.elemId[0];
break;
case "fav_only" :
if (iparams_cp.favIds.length == 0)
{
this.req_tree_state = "rts_idle";
eval(iparams_cp.cb_fct_call);
}
else
this.req_elem_ids[0] = iparams_cp.favIds[0];
break;
case "ticker_only" :
if (iparams_cp.tickerIds.length == 0)
{
this.req_tree_state = "rts_idle";
eval(iparams_cp.cb_fct_call);
}
else
this.req_elem_ids = iparams_cp.tickerIds[0];
break;
default :
alert("wrong mode for function \'req_tree\'");
break;
}
this.is_deleted_arr = new Array(this.req_elem_ids.length).fill(0);
// sub-function content
var do_get_tree = function(id)
{
f_append_to_pad('div_panel4_pad','Start#'+String(id));
if (this.req_elem_ids != undefined)
{
switch (this.req_tree_state)
{
// ### part 1 : Explorer Path
// # get tree part from DB for Explorer path
case "rts_get_explorer_path" :
this.req_tree_state = "wait_post_processing";
f_append_to_pad('div_panel4_pad','rts_get_explorer_path');
if (this.req_elem_ids.length > 0)
{
// generate id param list for post
var id_params = "";
for (k=0; k<this.req_elem_ids.length; k++)
{
id_params = id_params + "ids[]=" + this.req_elem_ids[k];
if (k<this.req_elem_ids.length-1)
{
id_params = id_params + "&";
}
}
if (uc_browsing_change_permission == 1)
{
id_params = id_params + "&showDeleted=1";
}
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_before_post');
// send post and handle responses
$.post(this.data_src_path+"get?"+id_params, { })
.done(function(data) {
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_after_post');
if (data != undefined)
{
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_rxdata_good');
if (data.nodes.length > 0) {
// alert("Explorer - Content : " + data[1].name);
// ### #################################################################################################################################
// # local inits
var elem_id = this.req_elem_ids[0];
var my_parent_ids = f_IntArr2StrArr(data.nodes[0].parents);
var is_multi = false;
var parent_exists = false;
// Any parents further up ?
if (my_parent_ids != undefined)
{
if (my_parent_ids.length > 0)
{
parent_exists = true;
}
// multiple parents ? -> choose one depending on Cookie
if (my_parent_ids.length > 1)
{
// read from Cookie which parent item applies here
my_parent_ids = this.get_multi_parents(elem_id, my_parent_ids);
is_multi = true;
}
}
// currently processing selected item -> fill in T0
if (iparams_cp.elemId[0] == this.req_elem_ids[0])
{
this.rts_ret_struct.tree_nodes[0] = {};
this.rts_ret_struct.tree_nodes[0].elem_id = this.req_elem_ids[0];
this.rts_ret_struct.tree_nodes[0].gui_id = "T0";
this.rts_ret_struct.tree_nodes[0].name = data.nodes[0].name;
if (data.nodes[0].parents.length > 0)
{
this.rts_ret_struct.tree_nodes[0].parent_elem_id = my_parent_ids;
this.rts_ret_struct.tree_nodes[0].parent_gui_id = "E0";
}
else
{
this.rts_ret_struct.tree_nodes[0].parent_elem_id = null;
this.rts_ret_struct.tree_nodes[0].parent_gui_id = null;
}
if (data.nodes[0].parents.length > 1)
this.rts_ret_struct.tree_nodes[0].isMultiPar = true;
else
this.rts_ret_struct.tree_nodes[0].isMultiPar = false;
this.rts_ret_struct.tree_nodes[0].description = data.nodes[0].content;
this.rts_ret_struct.tree_nodes[0].type = get_xtype("1", data.nodes[0].type);
this.rts_ret_struct.tree_nodes[0].eval = c_EMPTY_EVAL_STRUCT;
this.rts_ret_struct.tree_nodes[0].children_elem_id = f_IntArr2StrArr(data.nodes[0].children);
}
// fill in E[n]
else
{
// # create current item
this.rts_ret_struct.explorer_path[this.new_item_offs] = {};
this.rts_ret_struct.explorer_path[this.new_item_offs].elem_id = this.req_elem_ids[0];
this.rts_ret_struct.explorer_path[this.new_item_offs].gui_id = "E" + this.new_item_offs;
this.rts_ret_struct.explorer_path[this.new_item_offs].name = data.nodes[0].name;
if (my_parent_ids[0] == undefined)
{
this.rts_ret_struct.explorer_path[this.new_item_offs].parent_elem_id = null;
this.rts_ret_struct.explorer_path[this.new_item_offs].parent_gui_id = null;
}
else
{
this.rts_ret_struct.explorer_path[this.new_item_offs].parent_elem_id = my_parent_ids[0];
this.rts_ret_struct.explorer_path[this.new_item_offs].parent_gui_id = "E" + (this.new_item_offs+1);
}
this.rts_ret_struct.explorer_path[this.new_item_offs].children_elem_id = f_IntArr2StrArr(data.nodes[0].children);
this.rts_ret_struct.explorer_path[this.new_item_offs].parent_gui_id = null;
this.rts_ret_struct.explorer_path[this.new_item_offs].isMultiPar = is_multi;
this.rts_ret_struct.explorer_path[this.new_item_offs].eval = c_EMPTY_EVAL_STRUCT;
this.new_item_offs = this.new_item_offs + 1;
}
// More parents above and no LockID in sight ? -> Go on with Explorer Path
if ((parent_exists == true) && (this.req_elem_ids[0] != iparams_cp.lock_id))
{
this.level_ct++;
this.req_elem_ids = [my_parent_ids[0]];
this.req_tree_state = "rts_get_explorer_path";
do_get_tree(id+1);
}
// no more parent items further up
else
{
this.level_ct = 0;
this.new_item_offs = 1;
this.req_elem_ids = this.rts_ret_struct.tree_nodes[0].children_elem_id;
if (this.req_elem_ids == undefined)
{
this.req_tree_state = "rts_idle";
f_append_to_pad('div_panel4_pad','Callback after 1st item');
eval(iparams_cp.cb_fct_call);
}
else
{
if (this.req_elem_ids.length > 0)
{
this.req_tree_state = "rts_get_tree_items";
this.is_deleted_arr = new Array(this.req_elem_ids.length).fill(0);
if (this.rts_ret_struct.explorer_path.length >0 )
{
this.parent_gui_id_arr = [ this.rts_ret_struct.explorer_path[0].parent_gui_id ];
this.parent_elem_id_arr = [ this.rts_ret_struct.explorer_path[0].parent_elem_id ];
}
f_append_to_pad('div_panel4_pad','Go on with tree nodes');
do_get_tree(id+1);
}
else
{
this.req_tree_state = "rts_idle";
f_append_to_pad('div_panel4_pad','Callback after 1st item');
eval(iparams_cp.cb_fct_call);
}
}
}
//// Root Item -> create first Tree Node and look for parents in Explorer Path afterwards
//else
//{
// var my_ref_type = "1";
// this.rts_ret_struct.tree_nodes[0] = {};
// this.rts_ret_struct.tree_nodes[0].elem_id = this.req_elem_ids[0];
// this.rts_ret_struct.tree_nodes[0].gui_id = "T0";
// this.rts_ret_struct.tree_nodes[0].name = unescape(data.name);
// this.rts_ret_struct.tree_nodes[0].description = unescape(data.content);
// this.rts_ret_struct.tree_nodes[0].type = get_xtype(my_ref_type, data.type);
// this.rts_ret_struct.tree_nodes[0].children_elem_id = data.children;
// this.rts_ret_struct.tree_nodes[0].eval = c_EMPTY_EVAL_STRUCT;
// this.level_ct = 0;
//
// // More parents above and no LockID in sight ? -> Go on with Explorer Path
// if ((parent_exists == true) && (this.req_elem_ids[0] != iparams_cp.lock_id))
// {
// this.rts_ret_struct.tree_nodes[0].parent_elem_id = my_parent_ids[0];
// this.rts_ret_struct.tree_nodes[0].parent_gui_id = "E0";
// this.rts_ret_struct.tree_nodes[0].isMultiPar = is_multi;
// this.level_ct++;
// this.new_item_offs = 0;
// this.req_elem_ids = [my_parent_ids[0]];
// this.req_tree_state = "rts_get_explorer_path";
// }
// else
// {
// this.rts_ret_struct.tree_nodes[0].parent_elem_id = null;
// this.rts_ret_struct.tree_nodes[0].parent_gui_id = null;
// this.new_item_offs = 1;
// this.req_elem_ids = data.children;
// this.req_tree_state = "rts_get_tree_items";
// }
//
// if (this.req_elem_ids == undefined)
// {
// this.req_tree_state = "rts_idle";
// f_append_to_pad('div_panel4_pad','Callback after 1st item');
// eval(iparams_cp.cb_fct_call);
// }
//
// do_get_tree(id+1);
//}
// // end of Explorer Path algorithm
// {
// // favorite item processing has been running
// if ((iparams_cp.mode == "fav_only") || ((iparams_cp.mode == "load_all")&&(iparams_cp.favIds.length > 0)))
// {
// var fav_len = this.rts_ret_struct.fav.length;
// ret_struct.fav[fav_len] = jQuery.extend(true, [], ret_struct.explorer_path);
// ret_struct.fav[fav_len++].unshift(jQuery.extend(true, {}, ret_struct.tree_nodes[0]));
// ret_struct.explorer_path = [];
// iparams_cp.favIds.splice(0,1);
// req_elem_ids = iparams_cp.elemId[0];
// this.new_item_offs = 0;
// if (iparams_cp.favIds.length > 0)
// {
// this.req_tree_state = "rts_get_explorer_path";
// req_elem_ids = iparams_cp.favIds[0];
// }
// else
// {
// if ((iparams_cp.mode == "load_all") && (iparams_cp.elemId[0] != iparams_cp.lock_id))
// {
// this.req_tree_state = "rts_get_explorer_path";
// }
// else // "fav_only" finished
// {
// offline_proc = false;
// this.req_tree_state = "rts_idle";
// this.rts_ret_struct = ret_struct;
// eval(iparams_cp.cb_fct_call);
// }
// }
// }
// // Explorer path processing finished
// else
// {
// this.req_tree_state = "rts_get_tree_items";
// T0_avail = false;
// // default : parent should be evaluated prior to actual elem
// // (exception : when elem == locked_item)
// if (iparams_cp.elemId[0] != iparams_cp.lock_id)
// {
// T0_avail = true;
// ret_struct.tree_nodes[0].elem_id = ret_struct.explorer_path[0].elem_id;;
// ret_struct.tree_nodes[0].gui_id = "E0";
// }
// if (((iparams_cp.mode == "load_all") || (iparams_cp.mode == "ticker_only")) && (iparams_cp.tickerIds.length > 0))
// req_elem_ids = iparams_cp.tickerIds[0];
// else
// req_elem_ids = ret_struct.explorer_path[0].elem_id; //iparams_cp.elemId[0]; //
//
// ret_struct.tree_nodes[0].elem_id = req_elem_ids;
// }
// // delete whole offline_queue
// offline_queue.splice(0,offline_queue.length);
// }
// ### ##################################################################################################################################
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_call_do_get_tree');
}
}
else
{
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_rxdata_bad');
alert("Get Tree Part (rts_get_explorer_path) : Data undefined");
this.req_elem_ids = [];
this.req_tree_state = "rts_idle";
}
}.bind(this))
.fail(function()
{
f_append_to_pad('div_panel4_pad','rts_get_explorer_path_failed');
alert("Get Tree Part (rts_get_explorer_path) : failed !");
this.req_elem_ids = [];
this.req_tree_state = "rts_idle";
}
);
}
break;
// ### part 2 : Tree Nodes
// # get tree part from DB for Tree Display
case "rts_get_tree_items" :
this.req_tree_state = "wait_post_processing";
f_append_to_pad('div_panel4_pad','rts_get_tree_items');
if (this.req_elem_ids.length > 0)
{
// generate id param list for post
var id_params = "";
for (k=0; k<this.req_elem_ids.length; k++)
{
id_params = id_params + "ids[]=" + this.req_elem_ids[k];
if (k<this.req_elem_ids.length-1)
{
id_params = id_params + "&";
}
}
if (uc_browsing_change_permission == 1)
{
id_params = id_params + "&showDeleted=1";
}
f_append_to_pad('div_panel4_pad','rts_get_tree_items_before_post');
// send post and handle responses
$.post(this.data_src_path+"get?"+id_params, { })
.done(function(data) {
f_append_to_pad('div_panel4_pad','rts_get_tree_items_after_post');
// check if returned data is valid
if (data != undefined)
{
f_append_to_pad('div_panel4_pad','rts_get_tree_items_rxdata_good');
// check if there's at least one element
if (data.nodes.length > 0) {
// # local inits
// var my_item_ids_int = Object.keys(data);
var child_elem_ids = []; // to be filled with new child nodes
var local_is_deleted_arr = [];
var local_parent_gui_id_arr = [];
var local_parent_elem_id_arr = [];
var is_multi = false;
// # traverse all loaded items
for (var k=0; k<this.req_elem_ids.length; k++)
{
this.rts_ret_struct.tree_nodes[this.new_item_offs] = {};
this.rts_ret_struct.tree_nodes[this.new_item_offs].elem_id = this.req_elem_ids[k];
this.rts_ret_struct.tree_nodes[this.new_item_offs].gui_id = "T" + this.new_item_offs;
this.rts_ret_struct.tree_nodes[this.new_item_offs].name = data.nodes[k].name;
if (data.nodes[k].parents.length > 0)
{
data.nodes[k].parents = f_IntArr2StrArr(data.nodes[k].parents);
// $$$ HIER MUSS ETWAS GEMACHT WERDEN !!! $$$
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_elem_id = data.nodes[k].parents[0];
}
else
if (data.nodes[k].del_parents != undefined)
{
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_elem_id = data.nodes[k].del_parents[0];
}
if (this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_elem_id == undefined)
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_elem_id = null;
var m=0;
while ((m<this.rts_ret_struct.tree_nodes.length) && (this.rts_ret_struct.tree_nodes[m].elem_id != data.nodes[k].parents[0])) {m++;}
if (m<this.rts_ret_struct.tree_nodes.length)
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_gui_id = this.rts_ret_struct.tree_nodes[m].gui_id;
else
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_gui_id = null;
this.rts_ret_struct.tree_nodes[this.new_item_offs].isMultiPar = false;
this.rts_ret_struct.tree_nodes[this.new_item_offs].description = data.nodes[k].content;
this.rts_ret_struct.tree_nodes[this.new_item_offs].type = get_xtype("1", data.nodes[k].type);
if (this.is_deleted_arr[k] == 1)
{
this.rts_ret_struct.tree_nodes[this.new_item_offs].is_deleted = 1;
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_gui_id = this.parent_gui_id_arr[k];
this.rts_ret_struct.tree_nodes[this.new_item_offs].parent_elem_id = this.parent_elem_id_arr[k];
}
this.rts_ret_struct.tree_nodes[this.new_item_offs].eval = c_EMPTY_EVAL_STRUCT;
child_elem_ids = child_elem_ids.concat(data.nodes[k].children);
local_is_deleted_arr = local_is_deleted_arr.concat(new Array(data.nodes[k].children.length).fill(0));
local_parent_gui_id_arr = local_parent_gui_id_arr.concat(new Array(data.nodes[k].children.length).fill(this.rts_ret_struct.tree_nodes[this.new_item_offs].gui_id));
local_parent_elem_id_arr = local_parent_elem_id_arr.concat(new Array(data.nodes[k].children.length).fill(this.rts_ret_struct.tree_nodes[this.new_item_offs].elem_id));
if (data.nodes[k].del_children != undefined)
{
child_elem_ids = child_elem_ids.concat(data.nodes[k].del_children);
local_is_deleted_arr = local_is_deleted_arr.concat(new Array(data.nodes[k].del_children.length).fill(1));
local_parent_gui_id_arr = local_parent_gui_id_arr.concat(new Array(data.nodes[k].del_children.length).fill(this.rts_ret_struct.tree_nodes[this.new_item_offs].gui_id));
local_parent_elem_id_arr = local_parent_elem_id_arr.concat(new Array(data.nodes[k].del_children.length).fill(this.rts_ret_struct.tree_nodes[this.new_item_offs].elem_id));
}
this.new_item_offs++;
}
child_elem_ids = f_IntArr2StrArr(child_elem_ids);
this.req_elem_ids = jQuery.extend(true, [], child_elem_ids);
this.is_deleted_arr = jQuery.extend(true, [], local_is_deleted_arr);
this.parent_gui_id_arr = jQuery.extend(true, [], local_parent_gui_id_arr);
this.parent_elem_id_arr = jQuery.extend(true, [], local_parent_elem_id_arr);
if (this.req_elem_ids.length != 0)
{
// ... and start next step
this.req_tree_state = "rts_get_tree_items";
do_get_tree(id+1);
}
else
{
this.req_tree_state = "rts_idle";
f_append_to_pad('div_panel4_pad','Callback');
eval(iparams_cp.cb_fct_call);
}
// // multiple parents ? -> choose one depending on Cookie
// if (my_parent_ids.length > 1)
// {
// // read from Cookie which parent item applies here
// my_parent_ids = this.get_multi_parents(elem_id, my_parent_ids);
// is_multi = true;
// }
// // Selected Item does not equal the Root Item
// if (this.new_item_offs > -1)
// {
// // # create current item
// ret_struct.explorer_path[this.new_item_offs] = {};
// ret_struct.explorer_path[this.new_item_offs].elem_id = this.req_elem_ids[0][0];
// ret_struct.explorer_path[this.new_item_offs].gui_id = "E" + this.new_item_offs;
// ret_struct.explorer_path[this.new_item_offs].name = data.name;
// ret_struct.explorer_path[this.new_item_offs].parent_elem_id = my_parent_ids[0];
// ret_struct.explorer_path[this.new_item_offs].children_elem_id = data.children;
// ret_struct.explorer_path[this.new_item_offs].parent_gui_id = null;
// ret_struct.explorer_path[this.new_item_offs].isMultiPar = is_multi;
// // More parents above and no LockID in sight ? -> Go on with Explorer Path
// if ((parent_exists == true) && (my_parent_ids[0] != iparams_cp.lock_id))
// {
// ret_struct.explorer_path[this.new_item_offs].parent_gui_id = "E" + (this.new_item_offs+1);
// this.level_ct++;
// this.new_item_offs = this.new_item_offs + 1;
// this.req_elem_ids = [my_parent_ids[0]];
// this.req_tree_state = "rts_get_explorer_path";
// }
// // no more parent items further up
// else
// {
// this.level_ct = 0;
// this.new_item_offs = 0;
// this.req_elem_ids = ret_struct.explorer_path[0].children_elem_id;
// this.req_tree_state = "rts_get_tree_items";
// }
// }
// // Root Item -> create first Tree Node
// else
// {
// var my_ref_type = "1";
// ret_struct.tree_nodes[0] = {};
// ret_struct.tree_nodes[0].elem_id = this.req_elem_ids[0][0];
// ret_struct.tree_nodes[0].gui_id = "T0";
// var my_name = data.name;
// if ((my_name == null) || (my_name == ""))
// my_name = unescape(data.content);
// ret_struct.tree_nodes[0].name = my_name;
// ret_struct.tree_nodes[0].description = unescape(data.content);
// ret_struct.tree_nodes[0].type = get_xtype(my_ref_type, data.type);
// ret_struct.tree_nodes[0].parent_elem_id = null;
// ret_struct.tree_nodes[0].parent_gui_id = null;
// ret_struct.tree_nodes[0].isMultiPar = false;
// this.level_ct = 0;
// this.new_item_offs = 1;
// this.req_elem_ids = data.children;
// this.req_tree_state = "rts_get_tree_items";
// }
//
//
//### To be continued (much can be used from Explorer Path) ###
// // get tree part including Content Objects
// $.post(this.data_src_path+"get?ids[]="+req_elem_ids[0], { })
// .done(function(data) {
// if (data != undefined)
// {
// this.req_tree_state = "rts_proc_tree_items";
// if (((iparams_cp.mode == "load_all") || (iparams_cp.mode == "ticker_only")) && (iparams_cp.tickerIds.length != 0))
// {
// // create ticker itself ...
// ret_struct.ticker[ticker_len] = {};
// ret_struct.ticker[ticker_len].elem_id = req_elem_ids[0];
// var my_name = data[req_elem_ids[0]].name;
// if (my_name == null)
// my_name = unescape(data[req_elem_ids[0]].content);
// ret_struct.ticker[ticker_len].name = my_name;
// // ... and its children
// ret_struct.ticker[ticker_len].text = " +++ ";
// for (var i=0; i<data[req_elem_ids[0]].children.length; i++)
// {
// my_name = data[req_elem_ids[0]].children[i].name;
// if (my_name == null)
//// my_name = "kein Titel";
// my_name = unescape(data[req_elem_ids[0]].children[i].content);
// ret_struct.ticker[ticker_len].text = ret_struct.ticker[ticker_len].text + my_name + " +++ ";
// }
// ticker_len++;
// // prepare next run
// iparams_cp.tickerIds.splice(0,1);
//
// if (iparams_cp.tickerIds.length > 0)
// {
// // kill invalid ticker ids
// while (iparams_cp.tickerIds[0] == null)
// {
// ret_struct.ticker[ticker_len] = {};
// ret_struct.ticker[ticker_len].elem_id = null;
// ret_struct.ticker[ticker_len].name = null;
// ret_struct.ticker[ticker_len++].text = null;
// iparams_cp.tickerIds.splice(0,1);
// if (iparams_cp.tickerIds.length == 0)
// break;
// }
// }
// if (iparams_cp.tickerIds.length > 0)
// {
// this.req_tree_state = "rts_get_tree_items";
// req_elem_ids = iparams_cp.tickerIds[0];
// }
// else
// {
// if (iparams_cp.mode == "ticker_only") // "ticker_only" finished
// {
// offline_proc = false;
// this.req_tree_state = "rts_idle";
// this.rts_ret_struct = ret_struct;
// eval(iparams_cp.cb_fct_call);
// }
// else
// {
// this.req_tree_state = "rts_get_tree_items";
// req_elem_ids = ret_struct.explorer_path[0].elem_id;
// ret_struct.tree_nodes[0].elem_id = req_elem_ids;
// }
// }
//
// }
// else
// {
// // put results into an offline processing queue
// offline_queue[0] = {};
// offline_queue[0] = jQuery.extend(true, {}, data[req_elem_ids[0]]);
}
}
else
{
f_append_to_pad('div_panel4_pad','rts_get_tree_items_rxdata_bad');
alert("Get Tree Part (rts_get_tree_items) : Data undefined");
this.req_elem_ids = [];
this.req_tree_state = "rts_idle";
}
}.bind(this))
.fail(function() {
f_append_to_pad('div_panel4_pad','rts_get_tree_items_failed');
alert("Get Tree Part (rts_get_tree_items) : failed !");
this.req_elem_ids = [];
this.req_tree_state = "rts_idle";
}
);
}
break;
// case "rts_proc_tree_items" :
// if (offline_queue.length > 0)
// {
// // # local inits
// var curr_item_offs = sibling_start+sibling_ct;
// var is_multi = false;
//
// // # extract name of current item
// var my_name = offline_queue[0].name;
// if (my_name == null)
// my_name = unescape(offline_queue[0].content);
// // # extract type of current item
// var my_ref_type = "1";
// if (offline_queue[0].parents != undefined)
// {
// if (offline_queue[0].parents.length > 0)
// {
// // # save Default parent node to Cookie if multiple parents are available
// if (offline_queue[0].parents.length > 1)
// {
// is_multi = true;
//// this.default_parent_setup_obj.write(offline_queue[0].initData.Id, ret_struct.tree_nodes[curr_item_offs].parent_elem_id);
// }
// // # search for default parent object to get Reference Type
// var myRefersTo = offline_queue[0].parents;
// for (var i=0; i<myRefersTo.length; i++)
// {
// if (ret_struct.tree_nodes[curr_item_offs].parent_elem_id == myRefersTo[i])
// {
//// my_ref_type = myRefersTo[i].initData.ReferenceTypeId;
// }
// }
// }
// }
//
// if (ret_struct.tree_nodes[curr_item_offs].elem_id != offline_queue[0].Ids)
// {
// alert("Shift between current index and current object!");
// }
//
//
// // # update current tree item
// if (this.global_setup.debugMode)
// ret_struct.tree_nodes[curr_item_offs].name = my_name +'('+my_ref_type+','+offline_queue[0].type+')';
// else
// ret_struct.tree_nodes[curr_item_offs].name = my_name;
// ret_struct.tree_nodes[curr_item_offs].description = unescape(offline_queue[0].content);
// ret_struct.tree_nodes[curr_item_offs].type = get_xtype(my_ref_type, offline_queue[0].type);
// ret_struct.tree_nodes[curr_item_offs].isMultiPar = is_multi;
//
// // # Max. number of levels reached or no further child levels available ?
// if ((this.level_ct >= this.global_setup.tree_max_child_depth) || (offline_queue[0].children == undefined))
// {
// this.req_tree_state = "rts_proc_tree_items";
// } else
// if (offline_queue[0].children.length == 0)
// {
// this.req_tree_state = "rts_proc_tree_items";
// } else
// // # Load boundary reached -> load further tree levels from database
// if (offline_queue[0].children[0] == undefined)
// {
// this.req_tree_state = "rts_get_tree_items";
// req_elem_ids = offline_queue[0].Ids;
// }
// // # add child nodes
// else
// {
// this.req_tree_state = "rts_proc_tree_items";
// var append_idx = offline_queue.length;
// for (var i=0; i<offline_queue[0].children.length; i++)
// {
// offline_queue[append_idx] = jQuery.extend(true, {}, offline_queue[0].children[i].initData.Referrer);
// ret_struct.tree_nodes[this.new_item_offs] = {};
// ret_struct.tree_nodes[this.new_item_offs].parent_elem_id = ret_struct.tree_nodes[curr_item_offs].elem_id;
// ret_struct.tree_nodes[this.new_item_offs].parent_gui_id = ret_struct.tree_nodes[curr_item_offs].gui_id;
// ret_struct.tree_nodes[this.new_item_offs].elem_id = offline_queue[0].initData.ReferredFrom[i].initData.ReferrerId;
// // correct gui_id of clicked Elem to make sure it is selected after loading
// if ((T0_avail == true) && (ret_struct.tree_nodes[this.new_item_offs].elem_id == iparams_cp.elemId[0]))
// {
// T0_avail = false;
// ret_struct.tree_nodes[this.new_item_offs].gui_id = "T0";
// }
// else
// ret_struct.tree_nodes[this.new_item_offs].gui_id = "T" + this.new_item_offs;
// this.new_item_offs++;
// children_len++;
// append_idx++;
// }
// }
//
// // calculate what item is next
// if (this.req_tree_state != "rts_get_tree_items")
// {
// if (sibling_ct >= (sibling_len-1))
// {
// sort(ret_struct.tree_nodes, sibling_start, sibling_len);
// this.level_ct++;
//
// sibling_start = children_start;
// sibling_len = children_len;
// sibling_ct = 0;
// children_start = this.new_item_offs;
// children_len = 0;
// }
// else
// {
// sibling_ct++;
// }
// offline_queue.splice(0,1);
// }
// }
// else
// {
// offline_proc = false;
// this.req_tree_state = "rts_idle";
// // erase E0 from Tree Nodes if necessary and execute callback function
// if (iparams_cp.elemId[0] != iparams_cp.lock_id)
// ret_struct.tree_nodes.splice(0,1);
// this.rts_ret_struct = ret_struct;
// eval(iparams_cp.cb_fct_call);
// }
// break;
case "rts_idle" :
break;
default :
f_append_to_pad('div_panel4_pad','Unknown case entry');
this.req_elem_ids = [];
this.req_tree_state = "rts_idle";
break;
} // switch (this.req_tree_state)
}
else
{
this.req_tree_state = "rts_idle";
f_append_to_pad('div_panel4_pad','Callback after empty list');
eval(iparams_cp.cb_fct_call);
}
f_append_to_pad('div_panel4_pad','Stop#'+String(id));
// alert('do_get_tree finished!');
}.bind(this) // var do_get_tree = function()
// actual sub-function call (first time without blocking wait for result)
do_get_tree(0);
} // if (this.req_tree_state == "rts_idle")
else
{
f_append_to_pad('div_panel4_pad','Get Tree already running - leaving !');
// alert("Get Tree already running !");
}
}
function lib_data_paul_get_tree(iparams)
{
// return JSON.parse("{\"fav\":[],\"ticker\":[],\"explorer_path\":[],\"tree_nodes\":[{\"parent_elem_id\":\"\",\"parent_gui_id\":\"\",\"elem_id\":\"1\",\"gui_id\":\"T0\",\"name\":\"aufWaren-/Personen-Austausch›\",\"type\":\"topic\",\"description\":\"\",\"eval\":[{\"avg\":0,\"num\":0},{\"avg\":0,\"num\":0},{\"avg\":0,\"num\":0}],\"isMultiPar\":false}]}");
return this.rts_ret_struct;