| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 | /*好友管理器中心 包含了 删除好友 修改好友名字等接口*/Namespace.register("U.F.M"); //好友管理器的命名空间//#region 添加好友分组/*** 弹出好友分组**/U.F.M.CreateFriendGroupPopup = function () {    var _tempel,        _temponeel,        _temptwoel;    //创建好友分组的样式    _tempel = $$("div", { "className": "UD_SYSSZS UD_SYATNL UD_SYSOU" });    _temponeel = $$("div", {}, _tempel)    _temptwoel = $$("input", { "value": "请输入你要创建的群名", "onfocus": [[U.MR.InputTip, ["this", ['请输入你要创建的群名', ""]]]], "onblur": [[U.MR.InputTip, ["this", "", '请输入你要创建的群名']]] }, _temponeel);    //弹出好友对话框    U.UI.Confirm("创建好友分组", { "width": "300px", "height": "140px" }, null, U.M.apply(null, [[U.F.M.CreateFriendGroup, [_temptwoel]]]), _tempel, $("#UD_SY")[0]); //创建一个对话框}/*** 确定添加好友** @param  {string} 好友分组id*/U.F.M.CreateFriendGroup = function (inputel) {    var _value = inputel.value, //好友分组名字        _groupid = Guid.newGuid(); //好友分组id    //好友分组的名字不能大于20    if (_value.length > 20) {        U.Alert("分组名不可超过20个字符");    }    //好友分组名字必须填写    else if (_value.isStrNull() && _value != inputel.defaultValue) {        U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "CreateFriendClass", Guid.newGuid(), US.userInfo.userid,                            _value, ""]), U.F.M.AsynCreateFriendGroup, ["", _value, _groupid]; //发送添加分组的请求    }    //没有输入的提示    else {        U.Alert("请输入正确的群名");    }}//添加好友分组异步U.F.M.AsynCreateFriendGroup = function (r) {    var _groupinfo,        context = r.context;    r = r.value; //得到服务器返回的值    _groupinfo = new U.F.T.FriendGroupEntity(context[2], context[1], ""); //初始化一个好友分组    //在好友数组的全局变量中添加好友分组的信息    US.Friend[0].unshift(_groupinfo);    //重新点击打印好友分组,重新刷新分组    $($("#UD_SYHZLTA").Child()[0]).Child()[0].onclick();    //提示创建成功    U.Alert("创建" + context[1] + "分组成功");}//#endregion//#region 删除好友/*** 删除好友** @param  {object} 删除用户信息*/U.F.M.DeleteFriend = function (friendinfo) {    //数据库中删除好友    U.A.Request(US.Auth, ["DeleteFriend", US.userInfo.userid, friendinfo.FriendsID, friendinfo.UserId],                U.F.M.AsynDeleteFriend, ["", friendinfo]); //ajax删除好友}/*** 删除好友异步** @param  {object} 删除用户信息*/U.F.M.AsynDeleteFriend = function (r) {    var _friendel,        _context = r.content,        _friendinfo = _context[1], //好友的信息        _friendclassinfo = _$(US.Friend[0]).Select({ "FriendsGroupID": friendinfo.FriendsGroupID })[0], //好友分组的信息        _friendclassuserinfo = _$(US.Friend[1]).Select({ "FriendsGroupID": friendinfo.FriendsGroupID }), //好友分组的信息        _el = $("div@TID=" + friendinfo.UserId, $("#UD_SYHZLZ")[0]),  //指定删除的好友        _switchbootom = $("#UD_SYHZLTA").Child(); //好友或者群切换按钮    _$(US.Friend[1]).Delete({ "FriendsID": friendinfo.FriendsID }); //好友集里删除好友    //判断是否在当前好友选取下    if ($(_switchbootom[0]).Child()[0].className.indexOf("UD_SYHZLTO") > -1) {        //删除好友元素        _friendel = _el.Parent();        _friendel.removeChild(_el);        //修改好友信息        $("div", _friendel.parentNode)[0].innerHTML = _friendclassinfo.FriendsGroupName + "(" + (_friendgroupinfo.length) + ")";        //如果所有好友都清空了,那么则打印空好友的提示        if (US.Friend[0].length == 1 && !_friendgroupinfo.length) {            U.F.PrintHasNoFriend(_friendel);        }    }}//#endregion//#region 添加好友/*** 添加好友** @param  {object} 用户信息* @param  {object} 回调函数* @param  {object} 删除用户信息*/U.F.M.AddFriend = function (userinfo, cb, typename) {    if (!U.U.L.isLogin(3)) {        typename = typename || "1"; //判断是添加直接对方为好友还是添加对方为好友需好友验证。        //无法加本人为好友 同时不可与本人对话        if (userInfo.userid != US.userInfo.userid) {            //在好友里获取用户            var _friendinfo = _$(US.Friend[1]).Select({ "UserId": userInfo.userid })[0];            //判断是否已经添加了用户            if (!_friendinfo) {                U.F.M.AddFriendForm(userinfo, cb, typename); //弹出添加好友框            }            //如果用户已经是自己的好友,那么直接跳出聊天            else {                U.F.W.PopupFriendsForm(_friendinfo); //弹出聊天框            }        }    }    else { U.Alert("快速登录关注他(她)吧"); }}/*** 添加好友** @param  {object} 用户信息* @param  {object} 删除用户信息*/U.F.M.AddFriendForm = function (userinfo, cb, typename) {    var i,        _formel,        _tempel,        _temponeel,        _temptwoel,        _tempthreeel,        _tempfourel,        _friendgroupinfo = US.Friend[0]; //好友分组    //创建添加好友信息分组信息    _tempel = $$("div", { "className": "UD_SYUIAC" });    _temponeel = $$("div", { "className": "UD_SYUIACA" }, _tempel);    _temptwoel = $$("div", { "className": "UD_SYUIACL" }, _temponeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACLT" }, _temptwoel);    $$("img", { "onerror": U.M.ImgError, "title": "点击查看", "src": U.M.GetImgU(userinfo.UserThumbnailImageHead) }, _tempthreeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACLB" }, _temptwoel);    $$("div", { "className": "UTDF", "innerHTML": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);    $$("div", { "className": "UTDF", "innerHTML": "性别:" + (userinfo.UserSex ? "男" : "女") }, _tempthreeel);    $$("div", { "className": "UTDF", "innerHTML": "年龄:" + (U.MT.getYearMonthDay()[0] - U.MT.getYearMonthDay(userinfo.Birthday)[0]) }, _tempthreeel);    _temptwoel = $$("div", { "className": "UD_SYUIACR" }, _temponeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACRT" }, _temptwoel);    $$("div", { "className": "UD_SYUIACRTL", "innerHTML": "备注姓名:" }, _tempthreeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACRTR" }, _tempthreeel);    $$("input", { "value": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACRB" }, _temptwoel);    $$("div", { "className": "UD_SYUIACRBL", "innerHTML": "分       组:" }, _tempthreeel);    _tempthreeel = $$("div", { "className": "UD_SYUIACRBR" }, _tempthreeel);    _tempfourel = $$("select", {}, _tempthreeel);    //添加用户到制定的好友分组处理    _tempfourel.options.length = _friendgroupinfo.length;    for (i = 0; i < _friendgroupinfo.length; i++) {        _tempfourel.options[i].text = _friendgroupinfo[i].FriendsGroupName;    }    //创建好友分组的弹框    _formel = U.UI.Confirm("是否添加好友", { "width": "450px", "height": "370px" }, null,                           [U.M.apply(null, [[U.F.M.AddFriendToDb, [userinfo, cb, _tempfourel, _temponeel, typename]]])], _tempel);    return _formel;}/*** 确定添加好友** @param  {object} 删除用户信息* @param  {function} 删除用户信息*/U.F.M.AddFriendToDb = function (userinfo, cb, selectel, loadingel, typename) {    var _friendgroupinfo = US.Friend[0][selectel.selectedIndex], //获取用户选择的分组        _groupid = _friendgroupinfo.FriendsGroupID, //好友分组id        _friendid = Guid.newGuid(); //用户在分组里面的唯一识别id    //添加好友分组的ajax    //对方发送添加好友信息给你,同意后把用户直接加到好友分组里    if (typename == "0") {        U.A.Request(US.Auth, ["AgreeAddFriend", userInfo.userid, _friendid, _groupid, (userinfo.UserNickName || userinfo.UserName), userinfo.MessageContent.toUpperCase()]),                 U.F.M.AsynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]; //添加好友到默认分组    }    //添加用户为好友    else {        U.A.Request(US.Auth, ["AddFriend", userInfo.userid, _friendid, _groupid, (userinfo.UserNickName || userinfo.UserName)]),                 U.F.M.AsynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]; //添加好友到默认分组    }    //提示    U.Alert("正在添加中...");    return false;}/*** 添加好友到分组异步** @param  {object} 添加成功后的信息*/U.F.M.AsynAddFriendToDb = function (r) {    var context = r.context,        _loadingel = context[0], //loading元素        _groupid = context[1], //群id        _userinfo = context[2], //用户的信息        _friendgroupinfo = context[3], //        _cb = context[4],        _friendid = context[5];    r = r.value;    //同意添加对方为好友的时候处理    if (r) {        //设置添加好友        U.F.M.DisplayAddFriend(_userinfo, _friendid, _groupid, _friendgroupinfo, r);        //添加好友的回调处理        if (_cb) {            _cb();        }    }    //添加对方为好友,给对方发送消息处理    else {        U.Alert("您的请求已经发送,请等待对方的同意。");    }    //关闭loading的弹窗    $(_loadingel).Parent({ usform: "true" }).remove();}/*** 添加好友成功后的处理** @param  {object} 添加成功后的信息*/U.F.M.DisplayAddFriend = function (userinfo, friendid, classid, friendgroupinfo, r) {    var _childs,        _groupel,    //好友分组的信息        _friendinfo = new U.F.T.FriendEntity(userinfo.UserIndividualitysignature, userInfo.userid, userinfo.UserImageHead,                                             userinfo.UserThumbnailImageHead, userinfo.UserNickName || userinfo.UserName,                                             userinfo.UserName, friendid, userinfo.UserNickName || userinfo.UserName, classid, 0);    _friendinfo["IsLogin"] = r[1] == "True" ? 1 : 0; //设置用户在线    US.Friend[1].unshift(_friendinfo); //添加好友到好友列表里    //打印聊天显示窗体    _groupel = $("div@TID=" + classid, $("#UD_SYHZLZ")[0]);    if (_groupel[0]) {        _childs = $(_groupel).Child(); //0 好友分组信息 1好友信息        //如果是第一次添加好友,那么提示好友的信息删除        if (US.Friend[1].length == 1) {            $("#UD_SYHZR")[0].innerText = "";        };        //打印添加的好友信息        U.F.PrintFriendOrGroup(_childs[1], [_friendinfo], true); //打印好友        //好友分组信息        _childs[0].innerText = friendgroupinfo["FriendsGroupName"] + "(" + (_$(US.Friend[1]).Select({ "FriendsGroupID": classid }).length) + ")";    };    //添加成功后打开好友聊天对话    U.F.W.PopupFriendsForm(_friendinfo);    //右边的好友窗体也重新打印    if (!US.Friend[4].length) {        U.F.PrintRightFormFriend(US.Friend[1], $("#UD_SYHRC")[0]);    }}//#endregion
 |