Yang UI, Yang Utils - split services into separate files
[dlux.git] / modules / common-yangutils-resources / src / main / resources / yangutils / services / node-wrapper.services.js
1 define([], function () {
2     'use strict';
3
4     function NodeWrapperService(constants, RequestBuilderService, RestrictionsService, TypeWrapperService,
5                                 ListFilteringService, EventDispatcherService, FilterNodeWrapperService){
6         var comparePropToElemByName = function comparePropToElemByName(propName, elemName) {
7             // AUGMENT FIX
8             // return propName === elemName; //TODO also check by namespace - redundancy?
9
10             return (propName.indexOf(':') > -1 ? propName.split(':')[1] : propName) === elemName; //TODO also check by namespace - redundancy?
11         };
12
13         var equalArrays = function (arrA, arrB) {
14             var match = (arrA.length === arrB.length) && arrA.length > 0;
15
16             if (match) {
17                 var i = 0;
18                 while (i < arrA.length && match) {
19                     var valMatch = arrA[i] === arrB[i];
20                     match = match && valMatch;
21                     i++;
22                 }
23             }
24             return match;
25         };
26
27         var equalListElems = function (listElemA, listElemB, refKey) {
28             var getKeyValue = function (data, label, module) {
29                     if (data && data.hasOwnProperty(label)) {
30                         return data[label];
31                     } else if (data && data.hasOwnProperty(module + ':' + label)) {
32                         return data[module + ':' + label];
33                     } else {
34                         return null;
35                     }
36                 },
37                 getKeyArrayValues = function (data, refKey) {
38                     return refKey.map(function (key) {
39                         return getKeyValue(data, key.label, key.module);
40                     }).filter(function (item) {
41                         return item !== null;
42                     });
43                 },
44                 keyValuesA = getKeyArrayValues(listElemA, refKey);
45             var keyValuesB = getKeyArrayValues(listElemB, refKey);
46
47             return equalArrays(keyValuesA, keyValuesB);
48         };
49
50         var checkListElemKeys = function (listData, refKey) {
51             var doubleKeyIndexes = [],
52                 checkedElems = [];
53
54             listData.forEach(function (item, index) {
55                 var duplitactes = checkedElems.filter(function (checked) {
56                     var isDuplicate = equalListElems(item, checked.item, refKey);
57                     if (isDuplicate && doubleKeyIndexes.indexOf(checked.index) === -1) {
58                         doubleKeyIndexes.push(checked.index);
59                     }
60                     return isDuplicate;
61                 });
62
63                 if (duplitactes.length) {
64                     //item is already in checkedElems so we don't need to push it again
65                     doubleKeyIndexes.push(index);
66                 } else {
67                     checkedElems.push({index: index, item: item});
68                 }
69             });
70
71             return doubleKeyIndexes;
72         };
73
74         var parseRestrictText = function (text) {
75             return text.split('|').map(function (elem) {
76                 var subElems = elem.split('..');
77                 return subElems.length === 1 ? RestrictionsService.getEqualsFnc(subElems[0]) :
78                     RestrictionsService.getMinMaxFnc(subElems[0], subElems[1]);
79             });
80         };
81
82
83         var getTypes = function (node) {
84             var types = [];
85
86             var getTypesRecursive = function (node, types) {
87                 types.push(node);
88
89                 node.getChildren('type').forEach(function (child) {
90                     getTypesRecursive(child, types);
91                 });
92             };
93
94             node.getChildren('type').forEach(function (child) {
95                 //console.info('child', child);
96                 getTypesRecursive(child, types);
97             });
98
99             return types;
100         };
101
102         var wrapper = {
103             wrap: function (node) {
104                 if (this.hasOwnProperty(node.type)) {
105                     this[node.type](node);
106                 }
107             },
108             wrapAll: function (node) {
109                 var self = this;
110                 self.wrap(node);
111                 node.children.forEach(function (child) {
112                     self.wrapAll(child);
113                 });
114             },
115             checkKeyDuplicity: function (listData, refKey) {
116                 return checkListElemKeys(listData, refKey);
117             },
118             leaf: function (node) {
119                 node.value = '';
120                 node.valueIsValid = true;
121                 node.typeChild = node.getChildren('type')[0];
122
123                 node.buildRequest = function (builder, req, module) {
124                     var value = node.typeChild.getValue(),
125                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
126
127                     if(node.isKey()) {
128                         EventDispatcherService.dispatch(constants.EV_FILL_PATH, node, value);
129                     }
130
131                     if (value) {
132                         builder.insertPropertyToObj(req, labelWithModule, value);
133                         return true;
134                     }
135
136                     return false;
137                 };
138
139                 node.fill = function (name, data) {
140                     var match = '';
141
142                     match = comparePropToElemByName(name, node.label);
143                     if (match) {
144                         node.value = data.toString();
145                         if (node.typeChild) {
146                             node.typeChild.fill(node.value);
147                         }
148                     }
149                     return match;
150                 };
151
152                 node.clear = function () {
153                     node.value = '';
154
155                     if (node.typeChild) {
156                         node.typeChild.clear();
157                     }
158                 };
159
160                 node.isFilled = function () {
161                     var filled = node.typeChild.getValue() ? true : false;
162                     return filled;
163                 };
164
165                 node.checkValueType = function () {
166                     node.valueIsValid = node.typeChild ? node.typeChild.check(node.value) : true;
167                 };
168
169                 node.isKey = function() {
170                     return node.parent && node.parent.type === 'list' && node.parent.refKey && node.parent.refKey.indexOf(node) !== -1;
171                 };
172             },
173             type: function (node) {
174                 TypeWrapperService.wrapAll(node);
175             },
176             length: function (node) {
177                 node.restrictions = parseRestrictText(node.label);
178             },
179             range: function (node) {
180                 node.restrictions = parseRestrictText(node.label);
181             },
182             pattern: function (node) {
183                 node.restrictions = [RestrictionsService.getReqexpValidationFnc(node.label)];
184             },
185             // enum: function (node) {
186             // },
187             // bit: function (node) {
188             // },
189             // position: function (node) {
190             // },
191             container: function (node) {
192                 node.expanded = false;
193
194                 node.toggleExpand = function () {
195                     node.expanded = !node.expanded;
196                 };
197
198                 node.buildRequest = function (builder, req, module) {
199                     var added = false,
200                         name = node.label,
201                         objToAdd = builder.createObj(),
202                         builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
203                         checkEmptyContainer = function(type, obj) { //TODO: absolete after when statement is implemented
204                             return !!(type === 'case' || !$.isEmptyObject(objToAdd));
205                         },
206                         checkPresence = function(containerNode) {
207                             return containerNode.children.some(function(ch) {
208                                 return ch.type === 'presence';
209                             });
210                         },
211                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
212
213                     if (builderNodes.length) {
214                         builderNodes.forEach(function (child) {
215                             var childAdded = child.buildRequest(builder, objToAdd, node.module);
216                             added = added || childAdded;
217                         });
218                     } else  {
219                         added = true;
220                     }
221
222
223
224                     if (added && (checkEmptyContainer(node.parent ? node.parent.type : 'blanktype', objToAdd) || checkPresence(node))) {
225                         builder.insertPropertyToObj(req, labelWithModule, objToAdd);
226                     }
227
228                     return added;
229                 };
230
231                 node.fill = function (name, data) {
232                     var match = comparePropToElemByName(name, node.label),
233                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
234
235                     if (match && nodesToFill.length) {
236                         nodesToFill.forEach(function (child) {
237                             for (var prop in data) {
238                                 child.fill(prop, data[prop]);
239                             }
240                         });
241
242                         node.expanded = match;
243                     }
244
245                     return match;
246                 };
247
248                 node.clear = function () {
249                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
250                     node.nodeType = constants.NODE_UI_DISPLAY;
251
252                     if (nodesToClear.length) {
253                         nodesToClear.forEach(function (child) {
254                             child.clear();
255                         });
256                     }
257                 };
258
259                 node.isFilled = function () {
260                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
261                         return child.isFilled();
262                     });
263                 };
264             },
265             rpc: function (node) {
266                 node.expanded = true;
267                 node.buildRequest = function (builder, req, module) {
268                     var added = false,
269                         name = node.label,
270                         objToAdd = builder.createObj(),
271                         builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
272                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
273
274                     if (builderNodes.length) {
275                         builderNodes.forEach(function (child) {
276                             var childAdded = child.buildRequest(builder, objToAdd, node.module);
277                             added = added || childAdded;
278                         });
279                     } else {
280                         added = true;
281                         objToAdd = constants.NULL_DATA;
282                     }
283
284                     if (added) {
285                         builder.insertPropertyToObj(req, labelWithModule, objToAdd);
286                     }
287
288                     return added;
289                 };
290
291                 node.fill = function (name, data) {
292                     var filled = false,
293                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
294
295                     nodesToFill.forEach(function (child) {
296                         var childFilled = child.fill(name, data);
297                         filled = filled || childFilled;
298                     });
299
300                     node.expanded = filled;
301
302                     return filled;
303                 };
304
305                 node.clear = function () {
306                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
307
308                     if (nodesToClear.length) {
309                         nodesToClear.forEach(function (child) {
310                             child.clear();
311                         });
312                     }
313                 };
314
315                 node.isFilled = function () {
316                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
317                         return child.isFilled();
318                     });
319                 };
320
321             },
322             input: function (node) {
323                 node.expanded = true;
324
325                 node.buildRequest = function (builder, req, module) {
326                     var added = false,
327                         name = node.label,
328                         objToAdd = builder.createObj(),
329                         builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY),
330                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
331
332                     if (builderNodes.length) {
333
334                         builderNodes.forEach(function (child) {
335                             var childAdded = child.buildRequest(builder, objToAdd, node.module);
336                             added = added || childAdded;
337                         });
338                     } else {
339                         added = true;
340                     }
341
342                     if (added) {
343                         builder.insertPropertyToObj(req, labelWithModule, objToAdd);
344                     }
345
346                     return added;
347                 };
348
349                 node.fill = function (name, data) {
350                     var match = comparePropToElemByName(name, node.label),
351                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
352
353                     if (match && nodesToFill.length) {
354                         nodesToFill.forEach(function (child) {
355                             for (var prop in data) {
356                                 child.fill(prop, data[prop]);
357                             }
358                         });
359                         node.expanded = match;
360                     }
361
362                     return match;
363                 };
364
365                 node.clear = function () {
366                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
367
368                     if (nodesToClear.length) {
369                         nodesToClear.forEach(function (child) {
370                             child.clear();
371                         });
372                     }
373                 };
374
375                 node.isFilled = function () {
376                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
377                         return child.isFilled();
378                     });
379                 };
380
381             },
382             output: function (node) {
383                 node.expanded = true;
384
385                 node.buildRequest = function (builder, req) {
386                     // var added = false,
387                     //     name = node.label,
388                     //     objToAdd = builder.createObj(),
389                     //     builderNodes = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
390
391                     // if (builderNodes.length) {
392                     //     builderNodes.forEach(function (child) {
393                     //         var childAdded = child.buildRequest(builder, objToAdd);
394                     //         added = added || childAdded;
395                     //     });
396                     // } else {
397                     //     added = true;
398                     // }
399
400                     // if (added) {
401                     //     builder.insertPropertyToObj(req, name, objToAdd);
402                     // }
403
404                     // return added;
405                 };
406
407                 node.fill = function (name, data) {
408                     var match = comparePropToElemByName(name, node.label),
409                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
410
411                     if (match && nodesToFill.length) {
412                         nodesToFill.forEach(function (child) {
413                             for (var prop in data) {
414                                 child.fill(prop, data[prop]);
415                             }
416                         });
417                         node.expanded = match;
418                     }
419
420                     return match;
421                 };
422
423                 node.clear = function () {
424                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
425
426                     if (nodesToClear.length) {
427                         nodesToClear.forEach(function (child) {
428                             child.clear();
429                         });
430                     }
431                 };
432
433                 node.isFilled = function () {
434                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
435                         return child.isFilled();
436                     });
437                 };
438
439             },
440             case: function (node) {
441
442                 node.buildRequest = function (builder, req, module) {
443                     var added = false;
444
445                     node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
446                         var childAdded = child.buildRequest(builder, req, module);
447                         added = added || childAdded;
448                     });
449
450                     return added;
451                 };
452
453                 node.fill = function (name, data) {
454                     var filled = false,
455                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
456
457                     nodesToFill.forEach(function (child) {
458                         var childFilled = child.fill(name, data);
459                         filled = filled || childFilled;
460                     });
461
462                     return filled;
463                 };
464
465                 node.clear = function () {
466                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
467
468                     nodesToClear.forEach(function (child) {
469                         child.clear();
470                     });
471                 };
472
473                 node.isFilled = function () {
474                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
475                         return child.isFilled();
476                     });
477                 };
478             },
479             choice: function (node) {
480                 node.choice = null;
481                 node.expanded = true;
482
483                 node.buildRequest = function (builder, req, module) {
484                     var added = false;
485
486                     if (node.choice) {
487                         added = node.choice.buildRequest(builder, req, module);
488                     }
489
490                     return added;
491                 };
492
493                 node.fill = function (name, data) {
494                     var filled = false,
495                         nodesToFill = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
496
497                     nodesToFill.forEach(function (child) {
498                         var childFilled = child.fill(name, data);
499
500                         if (childFilled) {
501                             node.choice = child;
502                         }
503
504                         filled = filled || childFilled;
505                         if (filled) {
506                             return false;
507                         }
508                     });
509
510                     return filled;
511                 };
512
513                 node.clear = function () {
514                     node.nodeType = constants.NODE_UI_DISPLAY;
515
516                     if (node.choice) {
517                         node.choice.clear();
518                         node.choice = null;
519                     }
520                 };
521
522                 node.isFilled = function () {
523                     return node.choice !== null;
524                 };
525             },
526             'leaf-list': function (node) {
527                 node.value = [];
528                 node.expanded = true;
529
530                 node.toggleExpand = function () {
531                     node.expanded = !node.expanded;
532                 };
533
534                 node.addListElem = function () {
535                     var newElement = {
536                         value: ''
537                     };
538                     node.value.push(newElement);
539                 };
540
541                 node.removeListElem = function (elem) {
542                     node.value.splice(node.value.indexOf(elem), 1);
543                 };
544
545                 node.buildRequest = function (builder, req, module) {
546                     var valueArray = [],
547                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
548
549                     for (var i = 0; i < node.value.length; i++) {
550                         valueArray.push(node.value[i].value);
551                     }
552
553                     if (valueArray.length > 0) {
554                         builder.insertPropertyToObj(req, labelWithModule, valueArray);
555                         return true;
556                     }
557
558                     return false;
559
560                 };
561
562
563                 node.fill = function (name, array) {
564                     var match = comparePropToElemByName(name, node.label),
565                         newLeafListItem;
566
567                     if (match) {
568
569                         for (var i = 0; i < array.length; i++) {
570                             newLeafListItem = {
571                                 value: array[i]
572                             };
573                             node.value.push(newLeafListItem);
574                         }
575
576                     }
577                     return match;
578                 };
579
580                 node.clear = function () {
581                     node.nodeType = constants.NODE_UI_DISPLAY;
582                     node.value = [];
583                 };
584
585                 node.isFilled = function () {
586                     return node.value.length > 0;
587                 };
588
589             },
590             key: function (node) {
591                 // do this only on list, not on listElem because deepCopy on list doesn't copy property keys to listElem => don't do this when button for add new list is clicked
592                 if (node.parent.hasOwnProperty('refKey')) {
593                     var keyLabels = node.label.split(' '),
594                         keyNodes = node.parent.getChildren(null, null, constants.NODE_UI_DISPLAY).filter(function (child) {
595                             return keyLabels.indexOf(child.label) > -1;
596                         }),
597                         getRefKeyArray = function(keys){
598                             var refKeyArray = [];
599                             keyLabels.forEach(function(keyLabel){
600                                 var nk = keys.filter(function(k){
601                                     return keyLabel === k.label;
602                                 });
603
604                                 if ( nk.length ) {
605                                     refKeyArray.push(nk[0]);
606                                 }
607                             });
608                             return refKeyArray;
609                         };
610
611                     node.parent.refKey = getRefKeyArray(keyNodes);
612                 }
613             },
614             config: function (node) {
615                 node.parent.isConfigStm = (node.label === 'true');
616             },
617             list: function (node) {
618                 node.refKey = [];
619                 node.doubleKeyIndexes = [];
620                 node.actElemStructure = null;
621                 node.actElemIndex = -1;
622                 node.listData = [];
623                 node.expanded = true;
624                 node.filters = [];
625                 node.filterNodes = [];
626                 node.searchedPath = [];
627                 node.referenceNode = null;
628                 node.filteredListData = [];
629                 node.currentFilter = 0;
630
631                 node.toggleExpand = function () {
632                     node.expanded = !node.expanded;
633                 };
634
635                 node.createStructure = function () {
636                     if (node.actElemStructure === null) {
637                         var copy = node.deepCopy(['augmentionGroups', 'augmentationId']);
638                         wrapper._listElem(copy);
639                         node.actElemStructure = copy;
640                         node.actElemStructure.getActElemIndex = node.getActElemIndex;
641                     }
642                 };
643
644                 node.getActElemIndex = function() {
645                     return node.actElemIndex;
646                 };
647
648                 node.addListElem = function () {
649                     node.createStructure();
650                     var newElemData = {};
651                     node.listData.push(newElemData);
652                     node.changeActElementData(node.listData.length - 1,true);
653                 };
654
655                 node.buildActElemData = function () {
656                     var list = [],
657                         result;
658                     if (node.actElemStructure) {
659                         node.actElemStructure.listElemBuildRequest(RequestBuilderService, list, node.module);
660                         result = list[0] ? list[0] : {};
661                     }
662                     return result;
663                 };
664
665                 node.changeActElementData = function (index,fromAdd) {
666                     var storeData = node.buildActElemData();
667                     node.expanded = true;
668
669                     if (node.actElemIndex > -1) { //we are changing already existing data
670                         if(node.filteredListData && node.filteredListData.length){
671                             node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
672                             node.filteredListData[node.actElemIndex] = storeData;
673                             if(fromAdd){
674                                 ListFilteringService.clearFilterData(node, true, false);
675                             }
676                         }else{
677                             node.listData[node.actElemIndex] = storeData;
678                         }
679                     }
680                     node.actElemIndex = index;
681
682                     var actData = null;
683                     if(!(node.filteredListData && node.filteredListData.length)){
684                         actData = node.listData[node.actElemIndex];
685                     }else{
686                         actData = node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])];
687                     }
688
689                     node.actElemStructure.clear();
690                     for (var prop in actData) {
691                         node.actElemStructure.fillListElement(prop, actData[prop]);
692                     }
693
694                     EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
695                 };
696
697                 node.removeListElem = function (elemIndex,fromFilter) {
698
699                     if(fromFilter){
700                         elemIndex = node.listData.indexOf(node.filteredListData[elemIndex]);
701                     }
702
703                     node.listData.splice(elemIndex, 1);
704                     node.actElemIndex = node.listData.length - 1;
705
706                     if(fromFilter){
707                         ListFilteringService.clearFilterData(node,true,false);
708                     }
709
710                     if (node.actElemIndex === -1) {
711                         node.actElemStructure = null;
712                     } else {
713                         var actData = node.listData[node.actElemIndex];
714
715                         node.actElemStructure.clear();
716                         for (var prop in actData) {
717                             node.actElemStructure.fillListElement(prop, actData[prop]);
718                         }
719                     }
720
721                     EventDispatcherService.dispatch(constants.EV_LIST_CHANGED, node.actElemStructure);
722                 };
723
724                 node.buildRequest = function (builder, req, module) {
725                     var added = false;
726                     //store entered data
727                     var storeData = node.buildActElemData(),
728                         labelWithModule = (module !== node.module ? node.module + ':' : '') + node.label;
729
730                     if (node.actElemIndex > -1) {
731                         if(node.filteredListData && node.filteredListData.length){
732                             node.listData[node.listData.indexOf(node.filteredListData[node.actElemIndex])] = storeData;
733                             node.filteredListData[node.actElemIndex] = storeData;
734                         }else{
735                             node.listData[node.actElemIndex] = storeData;
736                         }
737                     }
738
739                     added = node.listData.filter(function (data) {
740                             return $.isEmptyObject(data) === false;
741                         }).length > 0;
742
743                     var buildedDataCopy = node.listData.slice().map(function (item) {
744                         var newItem = {};
745                         for(var prop in item){
746                             if(prop != '$$hashKey'){
747                                 newItem[prop] = item[prop];
748                             }
749                         }
750                         return newItem;
751                     }).filter(function(item){
752                         return Object.keys(item).length !== 0;
753                     });
754
755                     // check of listElems keyValues duplicity
756                     if(node.filteredListData && node.filteredListData.length){
757                         node.doubleKeyIndexes = wrapper.checkKeyDuplicity(node.filteredListData, node.refKey);
758                     }else{
759                         node.doubleKeyIndexes = wrapper.checkKeyDuplicity(node.listData, node.refKey);
760                     }
761
762                     if (added) {
763                         builder.insertPropertyToObj(req, labelWithModule, buildedDataCopy);
764                     }
765
766                     return added;
767                 };
768
769                 node.fill = function (name, array) { //data is array
770
771                     var match = comparePropToElemByName(name, node.label);
772
773                     if (match && array.length) {
774                         node.createStructure();
775                         node.listData = array.slice();
776                         node.actElemIndex = node.listData.length - 1;
777                         for (var prop in node.listData[node.actElemIndex]) {
778                             node.actElemStructure.fillListElement(prop, node.listData[node.actElemIndex][prop]);
779                         }
780                     }
781
782                     return (match && array.length > 0);
783                 };
784
785                 node.clear = function () {
786                     while (node.listData.length > 0) {
787                         node.listData.pop();
788                     }
789                     while (node.filteredListData.length > 0) {
790                         node.filteredListData.pop();
791                     }
792
793                     node.actElemIndex = -1;
794                     node.actElemStructure = null;
795                     node.nodeType = constants.NODE_UI_DISPLAY;
796                 };
797
798                 node.isFilled = function () {
799                     return node.listData.length > 0;
800                 };
801
802                 node.createListName = function (index) {
803                     var name = '',
804                         val = '',
805                         currentList = null;
806
807                     if(node.filteredListData && node.filteredListData.length){
808                         currentList = node.filteredListData;
809                     }else{
810                         currentList = node.listData;
811                     }
812
813                     if (index > -1) {
814                         node.actElemStructure.refKey.forEach(function (key) {
815                             var keyLabel = '';
816                             if(index === node.getActElemIndex()) {
817                                 val = key.value !== '' ? key.label + ':' + key.value : '';
818                             } else {
819                                 var prop = '';
820                                 if (!($.isEmptyObject(currentList[index]))) {
821                                     if(currentList[index][key.label]) {
822                                         prop = key.label;
823                                     } else if(currentList[index][key.module + ':' + key.label]) {
824                                         prop = key.module + ':' + key.label;
825                                     }
826                                     val = prop ? key.label + ':' + currentList[index][prop] : prop;
827                                 }
828                             }
829
830                             name = name ? (name + (val ? (' ' + val) : '')) : (name + (val ? (' <' + val) : ''));
831                         });
832                     }
833
834                     if (name) {
835                         name = name + '>';
836                     }
837
838                     return name;
839                 };
840
841                 node.getNewFilterElement = function (){
842                     return node.getChildrenForFilter().map(function(element){
843                         FilterNodeWrapperService.init(element);
844                         var copy = element.deepCopyForFilter();
845                         wrapper.wrapAll(copy);
846                         FilterNodeWrapperService.wrapForFilter(copy);
847                         return copy;
848                     });
849                 };
850             },
851             _listElem: function (node) {
852                 node.refKey = [];
853
854                 node.listElemBuildRequest = function (builder, req, module) {
855                     var added = false,
856                         objToAdd = builder.createObj();
857
858                     node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
859                         var childAdded = child.buildRequest(builder, objToAdd, node.module);
860                         added = added || childAdded;
861                     });
862
863                     if (added) {
864                         builder.insertObjToList(req, objToAdd);
865                     }
866
867                     return added;
868                 };
869
870                 node.fillListElement = function (name, data) {
871                     var filled = false;
872
873                     node.getChildren(null, null, constants.NODE_UI_DISPLAY).forEach(function (child) {
874                         var childFilled = child.fill(name, data);
875                         filled = filled || childFilled;
876                     });
877
878                     return filled;
879                 };
880
881                 node.isFilled = function () {
882                     return node.getChildren(null, null, constants.NODE_UI_DISPLAY).some(function (child) {
883                         return child.isFilled();
884                     });
885                 };
886
887                 node.clear = function () {
888                     var nodesToClear = node.getChildren(null, null, constants.NODE_UI_DISPLAY);
889
890                     if (nodesToClear.length) {
891                         nodesToClear.forEach(function (child) {
892                             child.clear();
893                         });
894                     }
895                 };
896
897                 node.children.forEach(function (child) {
898                     wrapper.wrapAll(child);
899                 });
900             }
901         };
902
903         wrapper.__test = {
904             comparePropToElemByName: comparePropToElemByName,
905             equalArrays: equalArrays,
906             equalListElems: equalListElems,
907             parseRestrictText: parseRestrictText,
908             getTypes: getTypes,
909             checkListElemKeys: checkListElemKeys
910         };
911
912         return wrapper;
913     }
914
915     NodeWrapperService.$inject=['constants', 'RequestBuilderService', 'RestrictionsService', 'TypeWrapperService',
916                                 'ListFilteringService', 'EventDispatcherService', 'FilterNodeWrapperService'];
917
918     return NodeWrapperService;
919
920 });