UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

87 lines 2.84 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').directive('tree', [ 'recursion-helper', 'commonService', function (recursionHelper, commonService) { return { restrict: 'E', replace: true, scope: { tag: '<?', uuid: '=?', disabled: '=?', visible: '=?', cssClass: '=?', onDemand: '=?', items: '=?', model: '=?', selectedNode: '=?', onNodeSelect: '=?', onNodeExpand: '=?' }, templateUrl: '/templates/framework/directives/tree/template.html', link: function (scope, element, attr) { scope.vm = {}; scope.vm.init = function () { if (angular.isUndefined(scope.disabled)) { scope.disabled = false; } if (angular.isUndefined(scope.visible)) { scope.visible = true; } if (angular.isUndefined(scope.cssClass)) { scope.cssClass = ''; } if (angular.isUndefined(scope.items)) { scope.items = []; } if (angular.isUndefined(scope.uuid)) { scope.uuid = commonService.uuid(); } scope.vm.bind(); }; scope.vm.onNodeExpand = function (node) { if (scope.disabled || node.disabled || node.waiting) return; if (angular.isFunction(scope.onNodeExpand)) { scope.onNodeExpand(node); } }; scope.vm.onNodeSelect = function (node) { if (scope.disabled || node.disabled || node.waiting) return; if (scope.selectedNode) { scope.selectedNode.selected = false; scope.selectedNode = null; } scope.selectedNode = node; scope.selectedNode.selected = true; if (node.items && node.items.length) { node.expanded = !node.expanded; } if (angular.isFunction(scope.onNodeSelect)) { scope.onNodeSelect(node); } }; scope.vm.bind = function () { scope.$on(scope.uuid, function (event, data) { switch (data.type) { case 'node-select': scope.vm.onNodeSelect(data.value); break; case 'node-expand': scope.vm.onNodeExpand(data.value); break; default: console.log('Unknown event type : ', data.type); break; } }); }; scope.vm.init(); } }; } ]); }(jQuery, angular, _, window, document));