'use strict';

angular.module('appMessage').controller('GroupsinfoController', ['$scope', function($scope) {
    //lxtalkClient.Invoke('{15180DEF-D508-45F7-BAEB-6486CD8752C8}', '_Register', '', $scope);
    $scope.searchClass = "允许任何人加入该群";
    $scope.groupUsers = [
        { loginName: "0578+0+lsswsrj", displayName: "万赛软件维护", manger: 0 },
        { loginName: "0578+0+lsslqq", displayName: "陆趣趣", manger: 1 },
        { loginName: "0578+0+lssdgf", displayName: "戴国峰", manger: 1 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
        { loginName: "0578+0+lsszlg", displayName: "郑连根", manger: 2 },
        { loginName: "0578+0+lsslzy", displayName: "蓝梓洋", manger: 2 },
    ];

    $scope.$on('$viewContentLoaded', function() {
        var tbody = $("#content>table>tbody")[0];
        var rMenu = $("#rMenu")[0];
        tbody.oncontextmenu = function() { return false }; //禁止鼠标右键菜单显示
        rMenu.oncontextmenu = function() { return false };
        //console.log(tbody);
        tbody.onmouseup = function(e) {
            if (e.button === 2) { //如果button=1（鼠标左键），button=2（鼠标右键），button=0（鼠标中间键）
                console.log(e);
                console.log(e.clientX, e.clientY);
                if (e.clientX > 390 && e.clientY > 350) {
                    rMenu.style.top = (e.clientY - 5) - 130 + 'px'; //鼠标点击时给右键菜单定位X、Y轴坐标
                    rMenu.style.left = (e.clientX + 10) - 115 + 'px';
                } else if (e.clientX > 390) {
                    rMenu.style.top = (e.clientY - 5) + 'px';
                    rMenu.style.left = (e.clientX + 10) - 115 + 'px';
                } else if (e.clientY > 350) {
                    rMenu.style.top = (e.clientY - 5) - 130 + 'px';
                    rMenu.style.left = (e.clientX + 10) + 'px';
                } else if (e.clientX <= 390 && e.clientY <= 350) {
                    rMenu.style.top = (e.clientY - 5) + 'px';
                    rMenu.style.left = (e.clientX + 10) + 'px';
                }
                rMenu.style.display = 'block';
            } else {
                rMenu.style.display = 'none';
            }
        }
    });

    $scope.searchUser = function() {
        var users = $("#content>table>tbody>tr");
        //console.log(users);
        if ($scope.searchName !== "") {
            users.addClass("hide");
            for (var i = 0, len = users.length; i < len; i++) {
                if (users[i].firstElementChild.nextElementSibling.firstElementChild.value.indexOf($scope.searchName) !== -1 || users[i].firstElementChild.nextElementSibling.nextElementSibling.firstElementChild.value.indexOf($scope.searchName) !== -1)
                    $(users[i]).removeClass("hide");
            }
        } else if ($scope.searchName == "")
            users.removeClass("hide");
    };

    $scope.getMangerIco = function(user) {
        if (user.manger == 0)
            return '../img/groupManger.png';
        else if (user.manger == 1)
            return '../img/mangers.png';
        else if (user.manger == 2)
            return '';
    };

    $scope.activeTable = function($event) {
        $scope.rMouseEvent = $event;
        var activeClick = $($event.target);
        //console.log($event);
        if ($event.button == 0 || $event.button == 2) {
            $("#content>table>tbody>tr").removeClass("activebcolor");
            $(activeClick[0].parentElement).addClass("activebcolor");
            $(activeClick[0].parentElement.parentElement).addClass("activebcolor");
        }
    };

    $scope.userView = function() {
        var userObj = $scope.rMouseEvent.currentTarget;
        var loginName = userObj.firstElementChild.nextElementSibling.firstElementChild.value;
        var userName = userObj.firstElementChild.nextElementSibling.nextElementSibling.firstElementChild.value;
        console.log(loginName, userName);
        $("#rMenu")[0].style.display = 'none';
    };

}]);