'use strict';

angular.module('appMessage').controller('UserController', ['$scope', '$state', function($scope, $state) {

    //lxtalkClient.Invoke('{FB60F992-A0FD-47B3-AAA7-E80DF209C5A4}', '_Register', '', $scope);

    $scope.user = {
        name: '陆趣趣',
        l: '0578+0-lslqq',
        shotL: 'lslqq',
        comp: '浙江万赛软件科技有限公司',
        branch: '运维部',
        sex: '0',
        mob: '15215756180',
        sMob: '666666',
        tel: '2189026',
        duty: '运维部经理',
        officeID: '运维室001',
        email: 'lqq@wswin.cn',
        shortL: 'lszhangzhangzhang'
    };

    // $scope.getSex = function(sex) {
    //     if ($scope.user === undefined)
    //         return '保密';
    //     if ($scope.user.sex == 0)
    //         return '男';
    //     else if ($scope.user.sex == 1)
    //         return '女';
    //     else
    //         return '保密';
    // }

    $scope.update = function(userJson) {
        userJson = userJson.replace(/ /g, " ");
        userJson = userJson.replace(/\t/g, "\\t");
        var user = JSON.parse(userJson);
        $scope.user = user;
        var reg = /-([\W\w]*)/;
        var group = reg.exec($scope.user.l);
        $scope.user.shortL = group == null ? $scope.user.l : group[1];
    };
}]);

// window.onload = function() {
//     var inputBox = document.getElementById("inputBox");
//     inputBox.ondragenter = ignoreDrag;
//     inputBox.ondragover = ignoreDrag;
//     inputBox.ondrop = drop;
// }

function allowDrop(ev) {
    ev.preventDefault();
};

function drag(ev) {
    ev.dataTransfer.setData("Text", ev.target.id);
};

function drop(ev) {
    ev.preventDefault();
    //取得拖进来的文件
    var data = ev.dataTransfer;
    var files = data.files;
    var file = files[0];
    var arr = file.name.split(".");
    console.log(file);
    var reader = new FileReader();
    //告诉它在准备好数据之后做什么
    reader.onload = function(e) {
        if (file.type.indexOf("image") !== -1)
        //使用图像URL来绘制dropBox的背景
            $("#inputBox").append('<img src="' + e.target.result + '">');
        else
            $("#inputBox").append('<div class="input-file"><p><img src="../img/file/' + arr[arr.length - 1] + '.png" onError="this.src =\'../img/file/unkown.png\'"></p><span>' + file.name + '</span></div>');
    };
    reader.readAsDataURL(file);
};

// function getSuffix(item) {
//     var arr = item.fileName.split(".");
//     return '../img/file/' + arr[arr.length - 1] + '.png';
// };