|
47 | 47 | replace: true, |
48 | 48 | controller: [ |
49 | 49 | '$scope', '$element', '$attrs', 'tgConfig', function ($scope, $element, $attrs, tgConfig) { |
50 | | - |
51 | 50 | $scope.$type = 'TreeTable'; |
52 | 51 | $scope.dragEnabled = true; |
53 | 52 | $scope.dragDelay = 0; |
|
125 | 124 | beforeDrop: function (event) { |
126 | 125 | return true; |
127 | 126 | }, |
128 | | - calsIndent: function (level) { |
| 127 | + calsIndent: function (level, skipUnit) { |
| 128 | + var _unit = $scope.indent_unit ? $scope.indent_unit : 'px'; |
| 129 | + if (!skipUnit) { |
| 130 | + _unit = $scope.indent_unit ? $scope.indent_unit : 'px'; |
| 131 | + } else { |
| 132 | + _unit = ''; |
| 133 | + } |
129 | 134 | if (level - 1 < 1) { |
130 | | - return $scope.indent_plus + ($scope.indent_unit ? $scope.indent_unit : 'px'); |
| 135 | + return $scope.indent_plus + _unit; |
131 | 136 | } else { |
132 | | - return ($scope.indent * (level - 1)) + $scope.indent_plus + ($scope.indent_unit ? $scope.indent_unit : 'px'); |
| 137 | + return ($scope.indent * (level - 1)) + $scope.indent_plus + _unit; |
133 | 138 | } |
134 | 139 | }, |
135 | 140 | dragEnabled: function () { |
|
184 | 189 | }, |
185 | 190 | link: function (scope, element, attrs) { |
186 | 191 |
|
| 192 | + scope.$watch( |
| 193 | + attrs.treeData, function (newValue) { |
| 194 | + console.log('hre', newValue) |
| 195 | + } |
| 196 | + ); |
| 197 | + |
187 | 198 | scope.$watch( |
188 | 199 | attrs.callbacks, function (optCallbacks) { |
189 | 200 | angular.forEach( |
|
895 | 906 | dragElm.css('width', ($helper.width(scope.$element) + 10) + 'px'); |
896 | 907 | dragElm.css('z-index', 9999); |
897 | 908 |
|
898 | | - // Prevents cursor to change rapidly in Opera 12.16 and IE when dragging an element |
899 | | - var hStyle = (scope.$element[0].querySelector('.tree-table-handle') || scope.$element[0]).currentStyle; |
900 | | - if (hStyle) { |
901 | | - document.body.setAttribute( |
902 | | - 'tree-table-cursor', $document.find('body').css('cursor') || '' |
903 | | - ); |
904 | | - $document.find('body').css({'cursor': hStyle.cursor + '!important'}); |
905 | | - } |
906 | | - |
907 | 909 | var _tbody = angular.element($window.document.createElement('tbody')); |
908 | 910 | // moving item with descendant |
909 | 911 |
|
|
921 | 923 | element = element.next(); |
922 | 924 | } |
923 | 925 | } |
| 926 | + |
924 | 927 | drag_descendant(scope.$element, scope.node().__dept__); |
925 | 928 | dragElm.append(_tbody); |
926 | 929 |
|
|
992 | 995 | if ((leftElmPos + 10) > document_width) { |
993 | 996 | leftElmPos = document_width - 10; |
994 | 997 | } |
995 | | - |
996 | 998 | dragElm.css( |
997 | 999 | { |
998 | 1000 | 'left': leftElmPos + 'px', |
|
1189 | 1191 | dragInfo = null; |
1190 | 1192 | } |
1191 | 1193 |
|
1192 | | - // Restore cursor in Opera 12.16 and IE |
1193 | | - var oldCur = document.body.getAttribute('tree-table-cursor'); |
1194 | | - if (oldCur !== null) { |
1195 | | - $document.find('body').css({'cursor': oldCur}); |
1196 | | - document.body.removeAttribute('tree-table-cursor'); |
1197 | | - } |
1198 | | - |
1199 | 1194 | angular.element($document).unbind('touchend', dragEndEvent); // Mobile |
1200 | 1195 | angular.element($document).unbind('touchcancel', dragEndEvent); // Mobile |
1201 | 1196 | angular.element($document).unbind('touchmove', dragMoveEvent); // Mobile |
|
1313 | 1308 | }, |
1314 | 1309 | dragInfo: function (scope) { |
1315 | 1310 | return { |
1316 | | - node: scope.node(), |
1317 | | - scope: scope, |
1318 | | - level: scope.node().__level__, |
1319 | | - target: { |
| 1311 | + node: scope.node(), |
| 1312 | + scope: scope, |
| 1313 | + level: scope.node().__level__, |
| 1314 | + target: { |
1320 | 1315 | node: scope.prev(), |
1321 | 1316 | pos: 1, |
1322 | 1317 | }, |
1323 | | - isDirty: function (index) { |
| 1318 | + isDirty: function (index) { |
1324 | 1319 | return this.node.__index_real__ <= index && index <= this.node.__index_real__ + this.node.__dept__ - 1; |
1325 | 1320 | }, |
1326 | | - isTargetEmpty: function(){ |
| 1321 | + isTargetEmpty: function () { |
1327 | 1322 | return !this.target.node.__expanded__ || (this.target.node.__index_real__ == this.node.__parent__ && this.target.node.__children__.length == 1); |
1328 | 1323 | }, |
1329 | | - next: function () { |
| 1324 | + next: function () { |
1330 | 1325 | if (this.node.__index_real__ < this.source.length - 1) { |
1331 | 1326 | return this.source[this.node.__index_real__ + 1]; |
1332 | 1327 | } |
1333 | 1328 | return null; |
1334 | 1329 | }, |
1335 | | - prev: function () { |
| 1330 | + prev: function () { |
1336 | 1331 | if (this.node.__index_real__ > 0) { |
1337 | 1332 | return this.source[this.node.__index_real__ - 1]; |
1338 | 1333 | } |
1339 | 1334 | return null; |
1340 | 1335 | }, |
1341 | | - attach: function (node, pos) { |
| 1336 | + attach: function (node, pos) { |
1342 | 1337 | this.target.node = node; |
1343 | 1338 | this.target.pos = pos; |
1344 | 1339 | } |
|
1409 | 1404 | } |
1410 | 1405 | pos.dirAx = newAx; |
1411 | 1406 | }, |
1412 | | - replaceIndent: function (e, indent) { |
1413 | | - angular.element(e.children()[0]).css('left', this.calsIndent(indent)); |
| 1407 | + replaceIndent: function (e, indent, attr) { |
| 1408 | + attr = attr ? attr : 'left'; |
| 1409 | + angular.element(e.children()[0]).css(attr, this.calsIndent(indent)); |
1414 | 1410 | }, |
1415 | | - hidden: function (e) { |
| 1411 | + |
| 1412 | + hidden: function (e) { |
1416 | 1413 | if (angular.isFunction(e.hide)) { |
1417 | 1414 | e.hide(); |
1418 | 1415 | } else { |
|
1422 | 1419 | } |
1423 | 1420 | }; |
1424 | 1421 | }] |
| 1422 | + ).factory( |
| 1423 | + '$TreeTableConvert', function () { |
| 1424 | + return { |
| 1425 | + line2tree: function (data, primaryKey, parentKey) { |
| 1426 | + if (!data || data.length == 0 || !primaryKey || !parentKey) { |
| 1427 | + return []; |
| 1428 | + } |
| 1429 | + |
| 1430 | + var tree = [], rootIds = [], item = data[0], _primary = item[primaryKey], treeObjs = {}, parentId, parent, len = data.length, i = 0; |
| 1431 | + while (i < len) { |
| 1432 | + item = data[i++]; |
| 1433 | + _primary = item[primaryKey]; |
| 1434 | + treeObjs[_primary] = item; |
| 1435 | + parentId = item[parentKey]; |
| 1436 | + if (parentId) { |
| 1437 | + parent = treeObjs[parentId]; |
| 1438 | + if (parent.__children__) { |
| 1439 | + parent.__children__.push(item); |
| 1440 | + } else { |
| 1441 | + parent.__children__ = [item]; |
| 1442 | + } |
| 1443 | + } else { |
| 1444 | + rootIds.push(_primary); |
| 1445 | + } |
| 1446 | + } |
| 1447 | + len = rootIds.length; |
| 1448 | + for (i = 0; i < len; i++) { |
| 1449 | + tree.push(treeObjs[rootIds[i]]); |
| 1450 | + } |
| 1451 | + return tree; |
| 1452 | + }, |
| 1453 | + tree2tree: function (data, parentKey) { |
| 1454 | + var access_child = function (data) { |
| 1455 | + var _tree = []; |
| 1456 | + var _i, _len = data.length, _copy, _child; |
| 1457 | + for (_i = 0; _i < _len; _i++) { |
| 1458 | + _copy = angular.copy(data[_i]); |
| 1459 | + if (angular.isArray(_copy[parentKey]) && _copy[parentKey].length > 0) { |
| 1460 | + _child = access_child(_copy[parentKey]); |
| 1461 | + delete(_copy[parentKey]); |
| 1462 | + _copy.__children__ = _child; |
| 1463 | + } |
| 1464 | + _tree.push(_copy); |
| 1465 | + } |
| 1466 | + return _tree; |
| 1467 | + } |
| 1468 | + return access_child(data); |
| 1469 | + } |
| 1470 | + } |
| 1471 | + } |
1425 | 1472 | ).constant( |
1426 | 1473 | 'tgConfig', { |
1427 | 1474 | treeClass: 'tree-table', |
|
0 commit comments