role-manage.js 3.69 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
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
infrastructureModule.directive('roleManage', ['$log',
    function ($log) {
        'use strict';
        $log.debug('roleManage.ctor()...');

        return {
            restrict: 'E',
            templateUrl: '/app/admin/infrastructure/roleManage/views/role-manage.html' + '?_=' + Math.random(),
            replace: true,
            scope: {},
            controller: 'RoleManageController',
            link: function (scope, element) {
                $(document).on({
                    mouseenter: function (e) {
                        $(this).css('font-weight', 'bold');
                    },
                    mouseleave: function (e) {
                        $(this).css('font-weight', 'normal');
                    }
                }, '.icon-role-category-modify,.icon-role-category-delete,.ng-inline-edit__button');

                $(document).on('click', '.ng-inline-edit__button--edit', function () {
                     
                });

                Split(['#left-container', '#right-container'], {
                    //An array of initial sizes of the elements, specified as percentage values. Example: Setting the initial sizes to 25% and 75%.
                    sizes: [22, 78],

                    //An array of minimum sizes of the elements, specified as pixel values. Example: Setting the minimum sizes to 100px and 300px, respectively.
                    minSize: [250, 750],

                    onDragEnd: function () {
                        //$timeout(function () {
                        //    $rootScope.$broadcast(enums.vatEvent.layoutChanged, {});
                        //}, 700);
                    }
                })
            }
        };
    }
]);


infrastructureModule.directive('roleNameUnique', ['$q', 'roleService', function ($q, roleService) {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            if (!ctrl) return;

            ctrl.$asyncValidators.roleNameUnique = function (modelValue, viewValue) {
                if (ctrl.$isEmpty(modelValue)) {
                    $q.resolve();
                }

                var def = $q.defer();

                var newRoleName = $('#EditRoleName').val(); //scope.roleUpdatedModel.editRoleName;
                var oldRoleName = scope.selectedRole.name;

                roleService.validateRoleNameUnique(newRoleName, oldRoleName)
                    .success(function (data, status, headers, config) {
                        if (data) {
                            def.resolve();
                        } else {
                            def.reject();
                        }
                    })
                    .error(function (data, status, headers, config) {
                        def.reject();
                    });

                return def.promise;
            };
        }
    }
}]);

infrastructureModule.directive("editableDiv", function () {
    return {
        restrict: "A",
        require: "ngModel",
        link: function (scope, element, attrs, ngModel) {

            function read() {
                // view -> model
                var html = element.html();
                html = html.replace(/ /g, "\u00a0");
                ngModel.$setViewValue(html);
            }
            // model -> view
            ngModel.$render = function () {
                element.html(ngModel.$viewValue || "");
            };

            element.bind("blur", function () {
                scope.$apply(read);
            });
            element.bind("keydown keypress", function (event) {
                if (event.which === 13) {
                    this.blur();
                    event.preventDefault();
                }
            });
        }
    };
});