U.F.M.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. 好友管理器中心 包含了 删除好友 修改好友名字等接口
  3. */
  4. Namespace.register("U.F.M"); //好友管理器的命名空间
  5. //#region 添加好友分组
  6. /**
  7. * 弹出好友分组
  8. *
  9. */
  10. U.F.M.CreateFriendGroupPopup = function () {
  11. var _tempel,
  12. _temponeel,
  13. _temptwoel;
  14. //创建好友分组的样式
  15. _tempel = $$("div", { "className": "UD_SYSSZS UD_SYATNL UD_SYSOU" });
  16. _temponeel = $$("div", {}, _tempel)
  17. _temptwoel = $$("input", { "value": "请输入你要创建的群名", "onfocus": [[U.MR.InputTip, ["this", ['请输入你要创建的群名', ""]]]], "onblur": [[U.MR.InputTip, ["this", "", '请输入你要创建的群名']]] }, _temponeel);
  18. //弹出好友对话框
  19. U.UI.Confirm("创建好友分组", { "width": "300px", "height": "140px" }, null, U.M.apply(null, [[U.F.M.CreateFriendGroup, [_temptwoel]]]), _tempel, $("#UD_SY")[0]); //创建一个对话框
  20. }
  21. /**
  22. * 确定添加好友
  23. *
  24. * @param {string} 好友分组id
  25. */
  26. U.F.M.CreateFriendGroup = function (inputel) {
  27. var _value = inputel.value, //好友分组名字
  28. _groupid = Guid.newGuid(); //好友分组id
  29. //好友分组的名字不能大于20
  30. if (_value.length > 20) {
  31. U.Alert("分组名不可超过20个字符");
  32. }
  33. //好友分组名字必须填写
  34. else if (_value.isStrNull() && _value != inputel.defaultValue) {
  35. U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "CreateFriendClass", Guid.newGuid(), US.userInfo.userid,
  36. _value, ""]), U.F.M.AsynCreateFriendGroup, ["", _value, _groupid]; //发送添加分组的请求
  37. }
  38. //没有输入的提示
  39. else {
  40. U.Alert("请输入正确的群名");
  41. }
  42. }
  43. //添加好友分组异步
  44. U.F.M.AsynCreateFriendGroup = function (r) {
  45. var _groupinfo,
  46. context = r.context;
  47. r = r.value; //得到服务器返回的值
  48. _groupinfo = new U.F.T.FriendGroupEntity(context[2], context[1], ""); //初始化一个好友分组
  49. //在好友数组的全局变量中添加好友分组的信息
  50. US.Friend[0].unshift(_groupinfo);
  51. //重新点击打印好友分组,重新刷新分组
  52. $($("#UD_SYHZLTA").Child()[0]).Child()[0].onclick();
  53. //提示创建成功
  54. U.Alert("创建" + context[1] + "分组成功");
  55. }
  56. //#endregion
  57. //#region 删除好友
  58. /**
  59. * 删除好友
  60. *
  61. * @param {object} 删除用户信息
  62. */
  63. U.F.M.DeleteFriend = function (friendinfo) {
  64. //数据库中删除好友
  65. U.A.Request(US.Auth, ["DeleteFriend", US.userInfo.userid, friendinfo.FriendsID, friendinfo.UserId],
  66. U.F.M.AsynDeleteFriend, ["", friendinfo]); //ajax删除好友
  67. }
  68. /**
  69. * 删除好友异步
  70. *
  71. * @param {object} 删除用户信息
  72. */
  73. U.F.M.AsynDeleteFriend = function (r) {
  74. var _friendel,
  75. _context = r.content,
  76. _friendinfo = _context[1], //好友的信息
  77. _friendclassinfo = _$(US.Friend[0]).Select({ "FriendsGroupID": friendinfo.FriendsGroupID })[0], //好友分组的信息
  78. _friendclassuserinfo = _$(US.Friend[1]).Select({ "FriendsGroupID": friendinfo.FriendsGroupID }), //好友分组的信息
  79. _el = $("div@TID=" + friendinfo.UserId, $("#UD_SYHZLZ")[0]), //指定删除的好友
  80. _switchbootom = $("#UD_SYHZLTA").Child(); //好友或者群切换按钮
  81. _$(US.Friend[1]).Delete({ "FriendsID": friendinfo.FriendsID }); //好友集里删除好友
  82. //判断是否在当前好友选取下
  83. if ($(_switchbootom[0]).Child()[0].className.indexOf("UD_SYHZLTO") > -1) {
  84. //删除好友元素
  85. _friendel = _el.Parent();
  86. _friendel.removeChild(_el);
  87. //修改好友信息
  88. $("div", _friendel.parentNode)[0].innerHTML = _friendclassinfo.FriendsGroupName + "(" + (_friendgroupinfo.length) + ")";
  89. //如果所有好友都清空了,那么则打印空好友的提示
  90. if (US.Friend[0].length == 1 && !_friendgroupinfo.length) {
  91. U.F.PrintHasNoFriend(_friendel);
  92. }
  93. }
  94. }
  95. //#endregion
  96. //#region 添加好友
  97. /**
  98. * 添加好友
  99. *
  100. * @param {object} 用户信息
  101. * @param {object} 回调函数
  102. * @param {object} 删除用户信息
  103. */
  104. U.F.M.AddFriend = function (userinfo, cb, typename) {
  105. if (!U.U.L.isLogin(3)) {
  106. typename = typename || "1"; //判断是添加直接对方为好友还是添加对方为好友需好友验证。
  107. //无法加本人为好友 同时不可与本人对话
  108. if (userInfo.userid != US.userInfo.userid) {
  109. //在好友里获取用户
  110. var _friendinfo = _$(US.Friend[1]).Select({ "UserId": userInfo.userid })[0];
  111. //判断是否已经添加了用户
  112. if (!_friendinfo) {
  113. U.F.M.AddFriendForm(userinfo, cb, typename); //弹出添加好友框
  114. }
  115. //如果用户已经是自己的好友,那么直接跳出聊天
  116. else {
  117. U.F.W.PopupFriendsForm(_friendinfo); //弹出聊天框
  118. }
  119. }
  120. }
  121. else { U.Alert("快速登录关注他(她)吧"); }
  122. }
  123. /**
  124. * 添加好友
  125. *
  126. * @param {object} 用户信息
  127. * @param {object} 删除用户信息
  128. */
  129. U.F.M.AddFriendForm = function (userinfo, cb, typename) {
  130. var i,
  131. _formel,
  132. _tempel,
  133. _temponeel,
  134. _temptwoel,
  135. _tempthreeel,
  136. _tempfourel,
  137. _friendgroupinfo = US.Friend[0]; //好友分组
  138. //创建添加好友信息分组信息
  139. _tempel = $$("div", { "className": "UD_SYUIAC" });
  140. _temponeel = $$("div", { "className": "UD_SYUIACA" }, _tempel);
  141. _temptwoel = $$("div", { "className": "UD_SYUIACL" }, _temponeel);
  142. _tempthreeel = $$("div", { "className": "UD_SYUIACLT" }, _temptwoel);
  143. $$("img", { "onerror": U.M.ImgError, "title": "点击查看", "src": U.M.GetImgU(userinfo.UserThumbnailImageHead) }, _tempthreeel);
  144. _tempthreeel = $$("div", { "className": "UD_SYUIACLB" }, _temptwoel);
  145. $$("div", { "className": "UTDF", "innerHTML": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);
  146. $$("div", { "className": "UTDF", "innerHTML": "性别:" + (userinfo.UserSex ? "男" : "女") }, _tempthreeel);
  147. $$("div", { "className": "UTDF", "innerHTML": "年龄:" + (U.MT.getYearMonthDay()[0] - U.MT.getYearMonthDay(userinfo.Birthday)[0]) }, _tempthreeel);
  148. _temptwoel = $$("div", { "className": "UD_SYUIACR" }, _temponeel);
  149. _tempthreeel = $$("div", { "className": "UD_SYUIACRT" }, _temptwoel);
  150. $$("div", { "className": "UD_SYUIACRTL", "innerHTML": "备注姓名:" }, _tempthreeel);
  151. _tempthreeel = $$("div", { "className": "UD_SYUIACRTR" }, _tempthreeel);
  152. $$("input", { "value": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);
  153. _tempthreeel = $$("div", { "className": "UD_SYUIACRB" }, _temptwoel);
  154. $$("div", { "className": "UD_SYUIACRBL", "innerHTML": "分&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp组:" }, _tempthreeel);
  155. _tempthreeel = $$("div", { "className": "UD_SYUIACRBR" }, _tempthreeel);
  156. _tempfourel = $$("select", {}, _tempthreeel);
  157. //添加用户到制定的好友分组处理
  158. _tempfourel.options.length = _friendgroupinfo.length;
  159. for (i = 0; i < _friendgroupinfo.length; i++) {
  160. _tempfourel.options[i].text = _friendgroupinfo[i].FriendsGroupName;
  161. }
  162. //创建好友分组的弹框
  163. _formel = U.UI.Confirm("是否添加好友", { "width": "450px", "height": "370px" }, null,
  164. [U.M.apply(null, [[U.F.M.AddFriendToDb, [userinfo, cb, _tempfourel, _temponeel, typename]]])], _tempel);
  165. return _formel;
  166. }
  167. /**
  168. * 确定添加好友
  169. *
  170. * @param {object} 删除用户信息
  171. * @param {function} 删除用户信息
  172. */
  173. U.F.M.AddFriendToDb = function (userinfo, cb, selectel, loadingel, typename) {
  174. var _friendgroupinfo = US.Friend[0][selectel.selectedIndex], //获取用户选择的分组
  175. _groupid = _friendgroupinfo.FriendsGroupID, //好友分组id
  176. _friendid = Guid.newGuid(); //用户在分组里面的唯一识别id
  177. //添加好友分组的ajax
  178. //对方发送添加好友信息给你,同意后把用户直接加到好友分组里
  179. if (typename == "0") {
  180. U.A.Request(US.Auth, ["AgreeAddFriend", userInfo.userid, _friendid, _groupid, (userinfo.UserNickName || userinfo.UserName), userinfo.MessageContent.toUpperCase()]),
  181. U.F.M.AsynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]; //添加好友到默认分组
  182. }
  183. //添加用户为好友
  184. else {
  185. U.A.Request(US.Auth, ["AddFriend", userInfo.userid, _friendid, _groupid, (userinfo.UserNickName || userinfo.UserName)]),
  186. U.F.M.AsynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]; //添加好友到默认分组
  187. }
  188. //提示
  189. U.Alert("正在添加中...");
  190. return false;
  191. }
  192. /**
  193. * 添加好友到分组异步
  194. *
  195. * @param {object} 添加成功后的信息
  196. */
  197. U.F.M.AsynAddFriendToDb = function (r) {
  198. var context = r.context,
  199. _loadingel = context[0], //loading元素
  200. _groupid = context[1], //群id
  201. _userinfo = context[2], //用户的信息
  202. _friendgroupinfo = context[3], //
  203. _cb = context[4],
  204. _friendid = context[5];
  205. r = r.value;
  206. //同意添加对方为好友的时候处理
  207. if (r) {
  208. //设置添加好友
  209. U.F.M.DisplayAddFriend(_userinfo, _friendid, _groupid, _friendgroupinfo, r);
  210. //添加好友的回调处理
  211. if (_cb) {
  212. _cb();
  213. }
  214. }
  215. //添加对方为好友,给对方发送消息处理
  216. else {
  217. U.Alert("您的请求已经发送,请等待对方的同意。");
  218. }
  219. //关闭loading的弹窗
  220. $(_loadingel).Parent({ usform: "true" }).remove();
  221. }
  222. /**
  223. * 添加好友成功后的处理
  224. *
  225. * @param {object} 添加成功后的信息
  226. */
  227. U.F.M.DisplayAddFriend = function (userinfo, friendid, classid, friendgroupinfo, r) {
  228. var _childs,
  229. _groupel,
  230. //好友分组的信息
  231. _friendinfo = new U.F.T.FriendEntity(userinfo.UserIndividualitysignature, userInfo.userid, userinfo.UserImageHead,
  232. userinfo.UserThumbnailImageHead, userinfo.UserNickName || userinfo.UserName,
  233. userinfo.UserName, friendid, userinfo.UserNickName || userinfo.UserName, classid, 0);
  234. _friendinfo["IsLogin"] = r[1] == "True" ? 1 : 0; //设置用户在线
  235. US.Friend[1].unshift(_friendinfo); //添加好友到好友列表里
  236. //打印聊天显示窗体
  237. _groupel = $("div@TID=" + classid, $("#UD_SYHZLZ")[0]);
  238. if (_groupel[0]) {
  239. _childs = $(_groupel).Child(); //0 好友分组信息 1好友信息
  240. //如果是第一次添加好友,那么提示好友的信息删除
  241. if (US.Friend[1].length == 1) {
  242. $("#UD_SYHZR")[0].innerText = "";
  243. };
  244. //打印添加的好友信息
  245. U.F.PrintFriendOrGroup(_childs[1], [_friendinfo], true); //打印好友
  246. //好友分组信息
  247. _childs[0].innerText = friendgroupinfo["FriendsGroupName"] + "(" + (_$(US.Friend[1]).Select({ "FriendsGroupID": classid }).length) + ")";
  248. };
  249. //添加成功后打开好友聊天对话
  250. U.F.W.PopupFriendsForm(_friendinfo);
  251. //右边的好友窗体也重新打印
  252. if (!US.Friend[4].length) {
  253. U.F.PrintRightFormFriend(US.Friend[1], $("#UD_SYHRC")[0]);
  254. }
  255. }
  256. //#endregion