Hormold

VK Change (#1383921903)

Nov 8th, 2013
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 67.91 KB | None | 0 0
  1. Файл - groups_edit.js (Старый размер - 56616 | Новый - 0):
  2. 0.  - var GroupsEdit = {
  3. 1.  -   uInit: function(opts) {
  4. 2.  -     GroupsEdit.uInitScroll();
  5. 3.  -     extend(cur, {
  6. 4.  -       opts: opts,
  7. 5.  -       oid: -opts.id,
  8. 6.  -       tab: opts.tab,
  9. 7.  -       searchInp: ge('gedit_users_search_inp'),
  10. 8.  -       index: {},
  11. 9.  -       cache: {},
  12. 10.  -       offsets: {},
  13. 11.  -       htmls: {},
  14. 12.  -       allshown: {},
  15. 13.  -       rnd: irand(0, 10000),
  16. 14.  -
  17. 15.  -       bigphCache: {},
  18. 16.  -       bigphShown: {},
  19. 17.  -       lang: extend(cur.lang || {}, opts.lang)
  20. 18.  -     });
  21. 19.  -     placeholderSetup(cur.searchInp, {back: true});
  22. 20.  -     elfocus(cur.searchInp);
  23. 21.  -     cur.nav.push(GroupsEdit.uNav);
  24. 22.  -     cur.destroy.push(function(c) {
  25. 23.  -       if (c == cur) GroupsEdit.uDeinitScroll();
  26. 24.  -     });
  27. 25.  -     if (cur.opts.admin) GroupsEdit.uIndex('admins', cur.opts.data.admins);
  28. 26.  -     GroupsEdit.uStart();
  29. 27.  -   },
  30. 28.  -   uNav: function(ch, from, to) {
  31. 29.  -     if (ch[0] || cur.noLocNav) return;
  32. 30.  -     var oldTab = cur.tab, newTab = to.tab || 'members';
  33. 31.  -     delete(ch.tab);
  34. 32.  -     if (!isEmpty(ch) || newTab == oldTab) return;
  35. 33.  -
  36. 34.  -     GroupsEdit.uResetSearch();
  37. 35.  -
  38. 36.  -     replaceClass(domPN(ge('gedit_tab_' + oldTab)), 'summary_tab_sel', 'summary_tab');
  39. 37.  -     replaceClass(domPN(ge('gedit_tab_' + newTab)), 'summary_tab', 'summary_tab_sel');
  40. 38.  -     hide('gedit_users_' + oldTab);
  41. 39.  -     show('gedit_users_' + newTab);
  42. 40.  -
  43. 41.  -     cur.tab = newTab;
  44. 42.  -
  45. 43.  -     GroupsEdit.uResetSearch();
  46. 44.  -     GroupsEdit.uStart();
  47. 45.  -
  48. 46.  -     nav.setLoc(to);
  49. 47.  -     return false;
  50. 48.  -   },
  51. 49.  -   uStart: function() {
  52. 50.  -     var tab = cur.tab, d = cur.opts.data[tab], nd = d, rnd = cur.rnd, ph = getLang('groups_users_search');
  53. 51.  -     cur.qShown = false;
  54. 52.  -     if (cur.opts.counts[tab] > 1000) {
  55. 53.  -       if (!d) {
  56. 54.  -         cur.offsets[tab] = ge('gedit_users_rows_' + tab).childNodes.length;
  57. 55.  -         nd = 'notavail';
  58. 56.  -         if (cur.offsets[tab] < cur.opts.counts[tab]) {
  59. 57.  -           ajax.post('groupsedit.php', {
  60. 58.  -             act: 'get_more', id: cur.opts.id, tab: tab, offset: cur.offsets[tab]
  61. 59.  -           }, {cache: 1});
  62. 60.  -         }
  63. 61.  -       }
  64. 62.  -     } else if (!d || d == 'notavail') {
  65. 63.  -       nd = 'loading';
  66. 64.  -       delete(cur.offsets[tab]);
  67. 65.  -       ajax.post('groupsedit.php', {act: 'get_list', id: cur.opts.id, tab: tab}, {onDone: function(cnt, res) {
  68. 66.  -         if (cur.rnd != rnd) return;
  69. 67.  -         cur.opts.counts[tab] = cnt;
  70. 68.  -         GroupsEdit.uIndex(tab, res);
  71. 69.  -       }});
  72. 70.  -     }
  73. 71.  -     if (tab == 'admins') {
  74. 72.  -       show('gedit_users_admsearch_btn');
  75. 73.  -       hide('gedit_users_search_btn');
  76. 74.  -       removeClass(ge('gedit_reset_search'), 'gedit_search_wide');
  77. 75.  -       removeClass(ge('gedit_users_search_inp'), 'gedit_search_wide');
  78. 76.  -     } else {
  79. 77.  -       hide('gedit_users_admsearch_btn');
  80. 78.  -       show('gedit_users_search_btn');
  81. 79.  -       addClass(ge('gedit_reset_search'), 'gedit_search_wide');
  82. 80.  -       addClass(ge('gedit_users_search_inp'), 'gedit_search_wide');
  83. 81.  -     }
  84. 82.  -     cur.opts.data[tab] = nd;
  85. 83.  -     if (nd == 'notavail' && (tab == 'declined' || tab == 'requests' || tab == 'invites')) {
  86. 84.  -       ph = getLang('groups_users_lnksearch');
  87. 85.  -     }
  88. 86.  -     val(geByClass1('input_back_content', domPS(cur.searchInp)), ph);
  89. 87.  -     GroupsEdit.uUpdateBack();
  90. 88.  -   },
  91. 89.  -   uInitScroll: function() {
  92. 90.  -     GroupsEdit.scrollnode = browser.msie6 ? pageNode : window;
  93. 91.  -     GroupsEdit.uDeinitScroll();
  94. 92.  -     addEvent(GroupsEdit.scrollnode, 'scroll', GroupsEdit.uScroll);
  95. 93.  -     addEvent(window, 'resize', GroupsEdit.uScroll);
  96. 94.  -   },
  97. 95.  -   uDeinitScroll: function() {
  98. 96.  -     removeEvent(GroupsEdit.scrollnode, 'scroll', GroupsEdit.uScroll);
  99. 97.  -     removeEvent(window, 'resize', GroupsEdit.uScroll);
  100. 98.  -   },
  101. 99.  -   uScroll: function() {
  102. 100.  -     if (browser.mobile) return;
  103. 101.  -
  104. 102.  -     var docEl = document.documentElement;
  105. 103.  -     var ch = window.innerHeight || docEl.clientHeight || bodyNode.clientHeight;
  106. 104.  -     var st = scrollGetY(), lnk = ge('gedit_users_more_' + cur.tab);
  107. 105.  -
  108. 106.  -     if (!isVisible(lnk)) return;
  109. 107.  -     if (st + ch > lnk.offsetTop) {
  110. 108.  -       lnk.onclick();
  111. 109.  -     }
  112. 110.  -   },
  113. 111.  -   uUpdateBack: function() {
  114. 112.  -     var text = (cur.tab == 'members' || cur.tab == 'unsure') ? getLang('groups_back_to_people') : ((cur.tab == 'admins') ? getLang('groups_back_to_leaders') : false);
  115. 113.  -     if (text) {
  116. 114.  -       cur._back = {
  117. 115.  -         text: text,
  118. 116.  -         show: [GroupsEdit.uInitScroll, elfocus.pbind(cur.searchInp)],
  119. 117.  -         hide: [GroupsEdit.uDeinitScroll]
  120. 118.  -       };
  121. 119.  -     } else {
  122. 120.  -       cur._back = false;
  123. 121.  -     }
  124. 122.  -   },
  125. 123.  -   uIndex: function(tab, res, noRefresh) {
  126. 124.  -     cur.opts.data[tab] = res;
  127. 125.  -     cur.cache[tab] = {all: []};
  128. 126.  -     for (var i = 0, count = res.length; i < count; ++i) {
  129. 127.  -       cur.cache[tab].all.push(i);
  130. 128.  -     }
  131. 129.  -     cur.index[tab] = new vkIndexer(cur.cache[tab].all, function(obj) {
  132. 130.  -       return cur.opts.data[tab][obj][2];
  133. 131.  -     }, noRefresh ? function(){} : GroupsEdit.uSearchUpdate);
  134. 132.  -   },
  135. 133.  -   uResetSearch: function() {
  136. 134.  -     val(cur.searchInp, '');
  137. 135.  -     elfocus(cur.searchInp);
  138. 136.  -     GroupsEdit.uSearchUpdate();
  139. 137.  -   },
  140. 138.  -   uSearch: function() {
  141. 139.  -     var q = trim(val(cur.searchInp)), tab = cur.tab, d = cur.opts.data[tab];
  142. 140.  -     clearTimeout(cur.updateTimer);
  143. 141.  -     if (d == 'notavail') {
  144. 142.  -       if (q.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/.+/)) {
  145. 143.  -         return GroupsEdit.uGetPage();
  146. 144.  -       }
  147. 145.  -     }
  148. 146.  -     if (tab == 'admins' && q.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/.+/)) {
  149. 147.  -       return GroupsEdit.uEditAdmin(GroupsEdit.uGetAddr(q));
  150. 148.  -     }
  151. 149.  -     if (tab == 'members' || tab == 'unsure' || tab == 'admins') {
  152. 150.  -       return nav.go('/search?c[section]=people&gid=' + cur.opts.id + '&c[q]=' + encodeURIComponent(q) + '&from=' + tab, false, {noback: false});
  153. 151.  -     }
  154. 152.  -     return GroupsEdit.uSearchUpdate(true);
  155. 153.  -   },
  156. 154.  -   uGetAddr: function(lnk) {
  157. 155.  -     var m = lnk.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/(.+)$/), result = m[4].substr(m[4].indexOf('#') + 1).replace(/^[\/\!]*/, '');
  158. 156.  -     if (m = result.match(/^profile\.php\?id=(\d+)/)) {
  159. 157.  -       result = intval(m[1]);
  160. 158.  -     } else {
  161. 159.  -       if (result.indexOf('?') !== -1) result = result.substr(0, result.indexOf('?'));
  162. 160.  -       if (m = result.match(/^id(\d+)/)) {
  163. 161.  -         result = intval(m[1]);
  164. 162.  -       }
  165. 163.  -     }
  166. 164.  -     return result;
  167. 165.  -   },
  168. 166.  -   uSearchUpdate: function(force) {
  169. 167.  -     if ((cur.searchInp || {}).id != 'gedit_users_search_inp') return;
  170. 168.  -
  171. 169.  -     var q = trim(val(cur.searchInp)), tab = cur.tab, d = cur.opts.data[tab];
  172. 170.  -     toggle('gedit_reset_search', !!q);
  173. 171.  -     toggle('gedit_users_additional_admins', !q && domFC(ge('gedit_users_rows_additional_admins')));
  174. 172.  -     if (!q) cur.searched = false;
  175. 173.  -     clearTimeout(cur.updateTimer);
  176. 174.  -     if (d == 'notavail') {
  177. 175.  -       if (q.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/.+/)) {
  178. 176.  -         cur.updateTimer = setTimeout(GroupsEdit.uGetPage, 1000);
  179. 177.  -         return;
  180. 178.  -       }
  181. 179.  -       if (q && force !== true) {
  182. 180.  -         cur.updateTimer = setTimeout(GroupsEdit.uSearchUpdate.pbind(true), 1000);
  183. 181.  -         return;
  184. 182.  -       }
  185. 183.  -       var cont = ge('gedit_users_rows_' + tab), more = ge('gedit_users_more_' + tab), el;
  186. 184.  -       if (q) {
  187. 185.  -         if (!cur.htmls[tab]) cur.htmls[tab] = cont;
  188. 186.  -         hide(more, 'gedit_users_summaryw_' + tab);
  189. 187.  -         domPN(cont).replaceChild(ce('div', {
  190. 188.  -           id: 'gedit_users_tmp_' + tab,
  191. 189.  -           className: 'gedit_users_rows',
  192. 190.  -           innerHTML: GroupsEdit.uGenEmpty(getLang((tab == 'members' || tab == 'unsure' || tab == 'admins' ? 'groups_too_many_enter' : 'groups_too_many_for_search')))
  193. 191.  -         }), cont);
  194. 192.  -       } else {
  195. 193.  -         if (cur.htmls[tab]) {
  196. 194.  -           el = ge('gedit_users_tmp_' + tab);
  197. 195.  -           domPN(el).replaceChild(cur.htmls[tab], el);
  198. 196.  -           debugLog(domPN(ge(domFC(el).id)));
  199. 197.  -           if (domFC(el).className == 'gedit_user' && domPN(ge(domFC(el).id)) == cur.htmls[tab]) {
  200. 198.  -             cur.htmls[tab].replaceChild(domFC(el), ge(domFC(el).id));
  201. 199.  -           }
  202. 200.  -           toggle(more, cur.offsets[tab] < cur.opts.counts[tab]);
  203. 201.  -           show('gedit_users_summaryw_' + tab);
  204. 202.  -           cur.htmls[tab] = el = false;
  205. 203.  -         }
  206. 204.  -         GroupsEdit.uUpdateSummary();
  207. 205.  -       }
  208. 206.  -     } else if (d != 'loading') {
  209. 207.  -       GroupsEdit.uShowMore(true);
  210. 208.  -     }
  211. 209.  -   },
  212. 210.  -   uUpdateSummary: function() {
  213. 211.  -     var tab = cur.tab, add = (tab == 'requests') ? '<span class="divide">|</span><span><a onclick="GroupsEdit.uApproveAll()">' + getLang('groups_approve_all') + '</a></span>' : '';
  214. 212.  -     if (trim(val(cur.searchInp)) || !isVisible('gedit_users_summaryw_' + tab)) return;
  215. 213.  -
  216. 214.  -     if (cur.opts.counts[tab] > 0) {
  217. 215.  -       val('gedit_users_summary_' + tab, getLang(cur.opts.summaries[tab], cur.opts.counts[tab], true) + add);
  218. 216.  -     } else {
  219. 217.  -       val('gedit_users_summary_' + tab, cur.opts.noSummaries[tab]);
  220. 218.  -     }
  221. 219.  -   },
  222. 220.  -   uApproveAll: function() {
  223. 221.  -     var box = showFastBox(
  224. 222.  -       getLang('groups_invitations_title'),
  225. 223.  -       getLang('groups_sure_approve_all'),
  226. 224.  -       getLang('groups_approve_all'),
  227. 225.  -       GroupsEdit.uDoApproveAll.pbind(0),
  228. 226.  -       getLang('global_cancel')
  229. 227.  -     );
  230. 228.  -   },
  231. 229.  -   uDoApproveAll: function(partcount) {
  232. 230.  -     if (!curBox()) return;
  233. 231.  -
  234. 232.  -     ajax.post('groupsedit.php', {act: 'approve_all', id: cur.opts.id, hash: cur.opts.hash, part_count: partcount}, {
  235. 233.  -       onDone: function(text, done) {
  236. 234.  -         if (text === false) return GroupsEdit.uDoApproveAll(done);
  237. 235.  -
  238. 236.  -         if (curBox()) curBox().hide();
  239. 237.  -         GroupsEdit.uShowMessage(text);
  240. 238.  -
  241. 239.  -         var l = nav.objLoc;
  242. 240.  -         if (done) {
  243. 241.  -           delete(l.tab);
  244. 242.  -         } else {
  245. 243.  -           l.tab = 'requests';
  246. 244.  -         }
  247. 245.  -         nav.go(l, false, {nocur: true});
  248. 246.  -       }, progress: curBox().progress
  249. 247.  -     });
  250. 248.  -   },
  251. 249.  -   uShowMore: function(force) {
  252. 250.  -     var tab = cur.tab, d = cur.opts.data[tab], q = trim(val(cur.searchInp)), highlight = false, rnd = cur.rnd;
  253. 251.  -     if (!d || d == 'loading' || d == 'notavail' && force) return;
  254. 252.  -
  255. 253.  -     if (d == 'notavail') {
  256. 254.  -       ajax.post('groupsedit.php', {
  257. 255.  -         act: 'get_more',
  258. 256.  -         id: cur.opts.id,
  259. 257.  -         tab: tab,
  260. 258.  -         offset: cur.offsets[tab]
  261. 259.  -       }, {onDone: function(count, html) {
  262. 260.  -         if (cur.rnd != rnd || cur.searched) return;
  263. 261.  -
  264. 262.  -         cur.opts.counts[tab] = count;
  265. 263.  -         var el = ce('div', {innerHTML: html}), cont = ge('gedit_users_rows_' + tab), i;
  266. 264.  -         for (i = domFC(el); i; i = domFC(el)) {
  267. 265.  -           if (ge(i.id)) {
  268. 266.  -             el.removeChild(i);
  269. 267.  -           } else {
  270. 268.  -             cont.appendChild(i);
  271. 269.  -             ++cur.offsets[tab];
  272. 270.  -           }
  273. 271.  -         }
  274. 272.  -         if (cur.offsets[tab] < cur.opts.counts[tab]) {
  275. 273.  -           ajax.post('groupsedit.php', {
  276. 274.  -             act: 'get_more', id: cur.opts.id, tab: tab, offset: cur.offsets[tab]
  277. 275.  -           }, {cache: 1});
  278. 276.  -         }
  279. 277.  -       }, cache: 1});
  280. 278.  -       return;
  281. 279.  -     }
  282. 280.  -     var lst = cur.cache[tab].all, m;
  283. 281.  -     if (force) {
  284. 282.  -       GroupsEdit.uUpdateSummary();
  285. 283.  -       if (cur.qShown === q) return;
  286. 284.  -       cur.qShown = q;
  287. 285.  -     }
  288. 286.  -     if (q) {
  289. 287.  -       if (q.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/.+/)) {
  290. 288.  -         var addr = GroupsEdit.uGetAddr(q);
  291. 289.  -         lst = [];
  292. 290.  -         for (var i = 0, l = d.length; i < l; ++i) {
  293. 291.  -           if (d[i][0] == addr || d[i][1] == '/' + addr) {
  294. 292.  -             lst.push(i);
  295. 293.  -           }
  296. 294.  -         }
  297. 295.  -       } else {
  298. 296.  -         lst = cur.cache[tab]['_' + q];
  299. 297.  -         if (lst === undefined) {
  300. 298.  -           var tmp = cur.index[tab].search(q), mp = {};
  301. 299.  -           lst = [];
  302. 300.  -           for (var i = 0, l = tmp.length; i < l; ++i) {
  303. 301.  -             if (!mp[tmp[i]]) {
  304. 302.  -               mp[tmp[i]] = true;
  305. 303.  -               lst.push(tmp[i]);
  306. 304.  -             }
  307. 305.  -           }
  308. 306.  -           lst.sort(function(a,b){return a-b;});
  309. 307.  -           cur.cache[tab]['_' + q] = lst;
  310. 308.  -         }
  311. 309.  -         highlight = GroupsEdit.uGetHighlight(q);
  312. 310.  -       }
  313. 311.  -     }
  314. 312.  -
  315. 313.  -     var len = lst.length, cont = ge('gedit_users_rows_' + tab), more = ge('gedit_users_more_' + tab);
  316. 314.  -     if (!len) {
  317. 315.  -       hide(more, 'gedit_users_summaryw_' + tab);
  318. 316.  -       val(cont, GroupsEdit.uGenEmpty(q ? cur.opts.nfound[tab] : getLang('groups_no_users_in_club')));
  319. 317.  -       return;
  320. 318.  -     }
  321. 319.  -
  322. 320.  -     var start = force ? 0 : cont.childNodes.length, end = Math.min(len, start + 20), html = [];
  323. 321.  -     for (var i = start; i < end; ++i) {
  324. 322.  -       var row = d[lst[i]], name = (row || {})[2];
  325. 323.  -       if (!row) continue;
  326. 324.  -       if (highlight) {
  327. 325.  -         name = name.replace(highlight.re, highlight.val);
  328. 326.  -       }
  329. 327.  -       html.push(GroupsEdit.uGenRow(tab, row, name));
  330. 328.  -     }
  331. 329.  -
  332. 330.  -     if (force) {
  333. 331.  -       val(cont, html.join(''));
  334. 332.  -       show('gedit_users_summaryw_' + tab);
  335. 333.  -       if (q) {
  336. 334.  -         val('gedit_users_summary_' + tab, getLang('groups_found_n_users', len, true));
  337. 335.  -       } else {
  338. 336.  -         GroupsEdit.uUpdateSummary();
  339. 337.  -       }
  340. 338.  -     } else {
  341. 339.  -       cont.innerHTML += html.join('');
  342. 340.  -     }
  343. 341.  -     toggle(more, end < len);
  344. 342.  -   },
  345. 343.  -   uGetPage: function(force) {
  346. 344.  -     var q = trim(val(cur.searchInp)), tab = cur.tab, rnd = cur.rnd;
  347. 345.  -     if (force !== true && cur.searched === q) return;
  348. 346.  -
  349. 347.  -     cur.searched = q;
  350. 348.  -     ajax.post('groupsedit.php', {act: 'get_page', id: cur.opts.id, tab: tab, addr: GroupsEdit.uGetAddr(q)}, {
  351. 349.  -       onDone: function(html, found) {
  352. 350.  -         if (cur.rnd != rnd) return;
  353. 351.  -
  354. 352.  -         var cont = ge('gedit_users_rows_' + tab);
  355. 353.  -         if (!cur.htmls[tab]) cur.htmls[tab] = cont;
  356. 354.  -         hide('gedit_users_more_' + tab);
  357. 355.  -         if (found) {
  358. 356.  -           show('gedit_users_summaryw_' + tab);
  359. 357.  -           val('gedit_users_summary_' + tab, getLang('groups_found_n_users', 1, true));
  360. 358.  -         } else {
  361. 359.  -           hide('gedit_users_summaryw_' + tab);
  362. 360.  -         }
  363. 361.  -         if (cont) {
  364. 362.  -           domPN(cont).replaceChild(ce('div', {
  365. 363.  -             id: 'gedit_users_tmp_' + tab,
  366. 364.  -             className: 'gedit_users_rows',
  367. 365.  -             innerHTML: html
  368. 366.  -           }), cont);
  369. 367.  -         } else {
  370. 368.  -           val('gedit_users_tmp_' + tab, html);
  371. 369.  -         }
  372. 370.  -       }
  373. 371.  -     });
  374. 372.  -   },
  375. 373.  -   uGetHighlight: function(q) {
  376. 374.  -     var indxr = cur.index[cur.tab], delimiter = indxr.delimiter, trimmer = indxr.trimmer;
  377. 375.  -
  378. 376.  -     q += ' ' + (parseLatin(q) || '');
  379. 377.  -     q = escapeRE(q).replace(/&/g, '&amp;');
  380. 378.  -     q = q.replace(trimmer, '').replace(delimiter, '|');
  381. 379.  -     return {
  382. 380.  -       re: new RegExp('(' + q + ')', 'gi'),
  383. 381.  -       val: '<span class="gedit_user_highlight">$1</span>'
  384. 382.  -     }
  385. 383.  -   },
  386. 384.  -   uGenEmpty: function(text) {
  387. 385.  -     return '<div class="gedit_users_none">' + text + '</div>';
  388. 386.  -   },
  389. 387.  -   uGenRow: function(tab, row, name) {
  390. 388.  -     var oid = row[0], href = row[1], photo = row[3], sex = row[4], infoArr = row[5], level = row[6], hash = row[7], info = '', btns = '', actions = '', nm = name || row[2], q = cur.qShown;
  391. 389.  -     if (!name && q && !q.match(/^(https?:\/\/)?([a-z0-9]+\.)*(vkontakte\.ru|vk\.com)\/.+/)) {
  392. 390.  -       highlight = GroupsEdit.uGetHighlight(q);
  393. 391.  -       nm = nm.replace(highlight.re, highlight.val);
  394. 392.  -     }
  395. 393.  -     if (infoArr[0]) { // uni
  396. 394.  -       info += '<div class="gedit_user_uni">' + infoArr[0] + '</div>';
  397. 395.  -     }
  398. 396.  -     if (level > 0) {
  399. 397.  -       info += '<div class="gedit_user_level">' + cur.opts.levels[level] + '</div>';
  400. 398.  -     }
  401. 399.  -     if (infoArr[1]) { // online
  402. 400.  -       info += '<div class="gedit_user_online">' + (getLang('global_online', sex) + (infoArr[1] != 1 ? '<b class="mob_onl gedit_mob_onl" onmouseover="mobileOnlineTip(this, {mid: ' + oid + '})" onclick="mobilePromo()"></b>' : '')) + '</div>';
  403. 401.  -     }
  404. 402.  -
  405. 403.  -     switch (tab) {
  406. 404.  -       case 'requests':
  407. 405.  -         if (level != -1) { // declined or approved request
  408. 406.  -           btns = [
  409. 407.  - '<div class="gedit_user_buttons">',
  410. 408.  -   '<div class="gedit_btns_text">', getLang(level < 0 ? 'groups_request_declined' : 'groups_request_accepted'),
  411. 409.  -     ' <a onclick="GroupsEdit.uAction(this, ', oid, ', \'', hash, '\', 0)">', getLang('global_cancel'), '</a>',
  412. 410.  -   '</div>',
  413. 411.  - '</div>'].join('');
  414. 412.  -         } else { // request
  415. 413.  -           btns = [
  416. 414.  - '<div class="gedit_user_buttons">',
  417. 415.  -   '<div class="button_blue fl_l">',
  418. 416.  -     '<button onclick="GroupsEdit.uAction(this, ', oid, ', \'', hash, '\', 1)">', getLang('groups_members_application_admit'), '</button>',
  419. 417.  -   '</div>',
  420. 418.  -   '<div class="button_cancel gedit_user_cancel_button fl_l">',
  421. 419.  -     '<div class="button" onclick="GroupsEdit.uAction(this, ', oid, ', \'', hash, '\', -1)">', getLang('groups_members_application_decline'), '</div>',
  422. 420.  -   '</div>',
  423. 421.  - '</div>'].join('');
  424. 422.  -         }
  425. 423.  -       break;
  426. 424.  -
  427. 425.  -       case 'members':
  428. 426.  -       case 'unsure':
  429. 427.  -       case 'admins':
  430. 428.  -         if (level > 3) {
  431. 429.  -           if (level < 6) {
  432. 430.  -             actions += '<a class="gedit_user_action" onclick="GroupsEdit.uMainAdmin()">' + getLang('Edit') + '</a>';
  433. 431.  -           }
  434. 432.  -         } else if (level > 0) {
  435. 433.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uEditAdmin(' + oid + ')">' + getLang('Edit') + '</a>';
  436. 434.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uRemoveAdmin(' + oid + ')">' + getLang('group_managers_demote') + '</a>';
  437. 435.  -         } else if (!level && cur.opts.admin) {
  438. 436.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uEditAdmin(' + oid + ')">' + getLang('groups_members_appoint_manager') + '</a>';
  439. 437.  -         }
  440. 438.  -         if (level < 0) {
  441. 439.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', 0)">' + getLang('groups_restore_member') + '</a>';
  442. 440.  -         } else if (level < 4) {
  443. 441.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', -1)">' + getLang('groups_members_delete') + '</a>';
  444. 442.  -         }
  445. 443.  -       break;
  446. 444.  -
  447. 445.  -       case 'declined':
  448. 446.  -         if (level < 0) {
  449. 447.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', 0)">' + getLang('groups_restore_member') + '</a>';
  450. 448.  -         } else {
  451. 449.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', -1)">' + getLang('groups_members_delete') + '</a>';
  452. 450.  -         }
  453. 451.  -       break;
  454. 452.  -
  455. 453.  -       case 'invites':
  456. 454.  -         if (level < 0) {
  457. 455.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', 0)">' + getLang('groups_send_invitation') + '</a>';
  458. 456.  -         } else {
  459. 457.  -           actions += '<a class="gedit_user_action" onclick="GroupsEdit.uAction(this, ' + oid + ', \'' + hash + '\', -1)">' + getLang('groups_members_invitations_cancel') + '</a>';
  460. 458.  -         }
  461. 459.  -       break;
  462. 460.  -     }
  463. 461.  -
  464. 462.  -     return [
  465. 463.  - '<div id="gedit_user_', tab, oid, '" class="gedit_user">',
  466. 464.  -   '<div class="gedit_user_bigph_wrap fl_l" onmouseover="GroupsEdit.bigphOver(this, ', oid, ')">',
  467. 465.  -     '<a class="gedit_user_thumb" href="', href, '"><img class="gedit_user_img" src="', photo, '" /></a>',
  468. 466.  -   '</div>',
  469. 467.  -   '<div class="gedit_user_info fl_l">',
  470. 468.  -     '<div class="gedit_user_name"><a class="gedit_user_lnk" href="', href, '">', nm, '</a></div>',
  471. 469.  -     info,
  472. 470.  -     '<div class="gedit_user_btns">', btns, '</div>',
  473. 471.  -   '</div>',
  474. 472.  -   '<div class="gedit_user_actions fl_r">', actions, '</div>',
  475. 473.  - '</div>'].join('');
  476. 474.  -   },
  477. 475.  -   bigphOver: function(obj, uid) {
  478. 476.  -     if (!cur.lang || !cur.lang.global_photo_full_size || browser.mobile) return;
  479. 477.  -     var o = obj.firstChild, ch = cur.bigphCache[uid];
  480. 478.  -     if (o.tagName != 'A' || o.className != 'gedit_bigph') {
  481. 479.  -       o = obj.insertBefore(ce('a', {className: 'gedit_bigph', href: ch && ch._id ? ('/photo' + ch._id + '?all=1') : ('/albums' + uid), innerHTML: '<span class="gedit_bigph_label">' + getLang('global_photo_full_size') + '</span>'}), obj.firstChild);
  482. 480.  -     }
  483. 481.  -     if (!o.onclick) o.onclick = GroupsEdit.bigphClick.pbind(uid);
  484. 482.  -     if (!o._uid) o._uid = uid;
  485. 483.  -
  486. 484.  -     clearTimeout(o.hideTO);
  487. 485.  -     animate(o, {marginTop: 75}, {duration: 200, transition: Fx.Transitions.easeOutCirc});
  488. 486.  -     cur.bigphShown[uid] = o;
  489. 487.  -
  490. 488.  -     if (!obj.onmouseout) obj.onmouseout = GroupsEdit.bigphOut.pbind(obj);
  491. 489.  -   },
  492. 490.  -   bigphOut: function(obj) {
  493. 491.  -     var o = obj.firstChild;
  494. 492.  -     if (!o || o.tagName != 'A' || o.className != 'gedit_bigph') return;
  495. 493.  -
  496. 494.  -     clearTimeout(o.hideTO);
  497. 495.  -     o.hideTO = setTimeout(function() {
  498. 496.  -       animate(o, {marginTop: 100}, 200);
  499. 497.  -       delete(cur.bigphShown[o._uid]);
  500. 498.  -     }, 150);
  501. 499.  -   },
  502. 500.  -   bigphClick: function(uid, ev) {
  503. 501.  -     if (checkEvent(ev) !== false) return;
  504. 502.  -
  505. 503.  -     var ch = cur.bigphCache[uid], o = cur.bigphShown[uid], obj = domPN(o);
  506. 504.  -     if (!o || !obj) return;
  507. 505.  -     if (ch === undefined) {
  508. 506.  -       ch = cur.bigphCache[uid] = 'show';
  509. 507.  -       ajax.post('al_photos.php', {act: 'fast_get_photo', oid: uid}, {onDone: function(res) {
  510. 508.  -         if (!res) {
  511. 509.  -           obj.onmouseover = function() {};
  512. 510.  -           re(o);
  513. 511.  -           return;
  514. 512.  -         }
  515. 513.  -         var sh = (cur.bigphCache[uid] == 'show');
  516. 514.  -         cur.bigphCache[uid] = res;
  517. 515.  -         o.href = '/photo' + res._id + '?all=1';
  518. 516.  -         if (sh) GroupsEdit.bigphClick(uid);
  519. 517.  -       }, onFail: function() {
  520. 518.  -         obj.onmouseover = function() {};
  521. 519.  -         re(o);
  522. 520.  -         return true;
  523. 521.  -       }});
  524. 522.  -     }
  525. 523.  -     if (ch == 'show') {
  526. 524.  -       return cancelEvent(ev);
  527. 525.  -     }
  528. 526.  -     if (!ch) return;
  529. 527.  -     return showPhoto(ch._id, 'album' + uid + '_0/rev', extend({jumpTo: {z: 'albums' + uid}}, ch), ev);
  530. 528.  -   },
  531. 529.  -   uShowMessage: function(txt) {
  532. 530.  -     showDoneBox(txt);
  533. 531.  -   },
  534. 532.  -   uEditAdmin: function(user) {
  535. 533.  -     showBox('groupsedit.php', {act: 'edit_admin', id: cur.opts.id, addr: user});
  536. 534.  -   },
  537. 535.  -   uRemoveAdmin: function(user) {
  538. 536.  -     return showBox('groupsedit.php', {act: 'edit_admin', id: cur.opts.id, addr: user, remove: 1});
  539. 537.  -   },
  540. 538.  -   uDoneAdmin: function(mid, hash) {
  541. 539.  -     var level = intval(radioBtns['admlevel'].val);
  542. 540.  -     if (cur.notSureAdmin && level >= 3) {
  543. 541.  -       return showFastBox(getLang('groups_admin_warning_title'), cur.notSureAdmin, getLang('groups_admin_do_add'), function() {
  544. 542.  -         curBox().hide();
  545. 543.  -         cur.notSureAdmin = false;
  546. 544.  -         GroupsEdit.uDoneAdmin(mid, hash);
  547. 545.  -       }, getLang('global_back'));
  548. 546.  -     }
  549. 547.  -     ajax.post('groupsedit.php', {
  550. 548.  -       act: 'done_admin',
  551. 549.  -       id: cur.opts.id,
  552. 550.  -       addr: mid,
  553. 551.  -       level: level,
  554. 552.  -       contact: isChecked('gedit_admbox_check'),
  555. 553.  -       position: val('gedit_admbox_position'),
  556. 554.  -       email: val('gedit_admbox_email'),
  557. 555.  -       phone: val('gedit_admbox_phone'),
  558. 556.  -       hash: hash
  559. 557.  -     }, {onDone: function(msg, row) {
  560. 558.  -       var tabs = ['members', 'unsure', 'admins'], i;
  561. 559.  -
  562. 560.  -       var rem = curBox().uRemove;
  563. 561.  -       if (!rem) {
  564. 562.  -         curBox().hide();
  565. 563.  -         if (msg) GroupsEdit.uShowMessage(msg);
  566. 564.  -       }
  567. 565.  -       if (!row) return;
  568. 566.  -
  569. 567.  -       for (i = 0; i < 3; ++i) {
  570. 568.  -         var t = tabs[i], d = cur.opts.data[t], found = false, j, k, l, el;
  571. 569.  -         if (isArray(d)) {
  572. 570.  -           for (j = 0, l = d.length; j < l; ++j) {
  573. 571.  -             if (d[j][0] == mid) {
  574. 572.  -               found = true;
  575. 573.  -               if (t == 'admins') {
  576. 574.  -                 if (row[6] > 0 && d[j][6] <= 0) {
  577. 575.  -                   ++cur.opts.counts[t];
  578. 576.  -                 } else if (row[6] <= 0 && d[j][6] > 0) {
  579. 577.  -                   --cur.opts.counts[t];
  580. 578.  -                 }
  581. 579.  -               }
  582. 580.  -               cur.opts.data[t][j] = row;
  583. 581.  -               break;
  584. 582.  -             }
  585. 583.  -           }
  586. 584.  -         }
  587. 585.  -         if (t == 'admins' && !found && level) {
  588. 586.  -           cur.opts.data[t].unshift(row);
  589. 587.  -           ++cur.opts.counts['admins'];
  590. 588.  -           val(cur.searchInp, '');
  591. 589.  -           GroupsEdit.uIndex(t, cur.opts.data[t]);
  592. 590.  -         } else {
  593. 591.  -           if (el = ge('gedit_user_' + t + mid)) {
  594. 592.  -             domPN(el).replaceChild(se(GroupsEdit.uGenRow(t, row)), el);
  595. 593.  -           }
  596. 594.  -           if (!found) {
  597. 595.  -             ajaxCache = {};
  598. 596.  -           }
  599. 597.  -         }
  600. 598.  -         GroupsEdit.uUpdateSummary();
  601. 599.  -       }
  602. 600.  -       if (rem) GroupsEdit.uAction(false, rem[0], rem[1], rem[2]);
  603. 601.  -     }, showProgress: curBox().showProgress, hideProgress: curBox().hideProgress});
  604. 602.  -   },
  605. 603.  -   uMainAdmin: function() {
  606. 604.  -     showBox('groupsedit.php', {act: 'main_admin', id: cur.opts.id});
  607. 605.  -   },
  608. 606.  -   uInitAdmin: function(box, hosts, extcur, lng) {
  609. 607.  -     box.setOptions({onClean: function() {
  610. 608.  -       if (window.WideDropdown) {
  611. 609.  -         WideDropdown.deinit('gedit_host_dd');
  612. 610.  -       }
  613. 611.  -     }});
  614. 612.  -     extend(cur, extcur, {
  615. 613.  -       lang: extend(cur.lang || {}, lng)
  616. 614.  -     });
  617. 615.  -     WideDropdown.init('gedit_host_dd', {
  618. 616.  -       defaultItems: hosts,
  619. 617.  -       noResult: getLang('groups_host_not_found'),
  620. 618.  -       introText: getLang('groups_choose_host'),
  621. 619.  -       onItemSelect: function(sel) {
  622. 620.  -         ge('gedit_hostbox_thumb').href = ge('gedit_hostbox_name').href = sel[4];
  623. 621.  -         ge('gedit_hostbox_img').src = sel[3];
  624. 622.  -         val(ge('gedit_hostbox_name'), sel[1]);
  625. 623.  -         cur.hostSel = sel;
  626. 624.  -         WideDropdown.clear('gedit_host_dd');
  627. 625.  -         return false;
  628. 626.  -       }
  629. 627.  -     });
  630. 628.  -     WideDropdown.select('gedit_host_dd', false, cur.hostSel);
  631. 629.  -     box.removeButtons().addButton(getLang('global_cancel'), box.hide, 'no');
  632. 630.  -     box.addButton(getLang('global_save'), GroupsEdit.uSaveAdmin);
  633. 631.  -   },
  634. 632.  -   uSaveAdmin: function() {
  635. 633.  -     ajax.post('groupsedit.php', {
  636. 634.  -       act: 'save_admin', id: cur.hostGid, oid: cur.hostSel[0], from: cur.hostFrom, hash: cur.hostHash
  637. 635.  -     }, {
  638. 636.  -       onDone: function(row, admrows, msg) {
  639. 637.  -         if (cur.hostFrom == 'page') {
  640. 638.  -           curBox().hide();
  641. 639.  -           showDoneBox(msg);
  642. 640.  -           domPN(ge('event_admin')).replaceChild(se(row), ge('event_admin'));
  643. 641.  -           return;
  644. 642.  -         }
  645. 643.  -         var t = 'admins';
  646. 644.  -         toggle('gedit_users_additional_' + t, !!admrows);
  647. 645.  -         val('gedit_users_rows_additional_' + t, admrows);
  648. 646.  -         var last = cur.opts.data[t][cur.opts.data[t].length - 1];
  649. 647.  -         if (el = ge('gedit_user_' + t + row[0])) {
  650. 648.  -           domPN(el).replaceChild(se(GroupsEdit.uGenRow(t, row)), el);
  651. 649.  -         }
  652. 650.  -         if (row[0] > 0 && last[0] < 0) {
  653. 651.  -           cur.opts.data[t].pop();
  654. 652.  -           --cur.opts.counts[t];
  655. 653.  -           if (el = ge('gedit_user_' + t + last[0])) {
  656. 654.  -             domPN(el).removeChild(el);
  657. 655.  -           }
  658. 656.  -         } else if (row[0] < 0 && last[0] > 0) {
  659. 657.  -           cur.opts.data[t].push(row);
  660. 658.  -           ++cur.opts.counts[t];
  661. 659.  -           if (el = ge('gedit_user_' + t + last[0])) {
  662. 660.  -             domPN(el).appendChild(se(GroupsEdit.uGenRow(t, row)), el);
  663. 661.  -           }
  664. 662.  -         } else {
  665. 663.  -           cur.opts.data[t][cur.opts.data[t].length - 1] = row;
  666. 664.  -           if (el = ge('gedit_user_' + t + last[0])) {
  667. 665.  -             domPN(el).replaceChild(se(GroupsEdit.uGenRow(t, row)), el);
  668. 666.  -           }
  669. 667.  -         }
  670. 668.  -         GroupsEdit.uIndex(t, cur.opts.data[t], true);
  671. 669.  -         curBox().hide();
  672. 670.  -         GroupsEdit.uShowMessage(msg);
  673. 671.  -         if (cur.tab != 'admins') nav.go(extend(nav.objLoc, {tab: 'admins'}));
  674. 672.  -       },
  675. 673.  -       showProgress: curBox().showProgress,
  676. 674.  -       hideProgress: curBox().hideProgress
  677. 675.  -     });
  678. 676.  -   },
  679. 677.  -   uAction: function(el, mid, hash, act) {
  680. 678.  -     if (!curBox() && (buttonLocked(el) || (domFC(el) || {}).className == 'progress_inline')) return;
  681. 679.  -     var tab = cur.tab;
  682. 680.  -     ajax.post('groupsedit.php', {act: 'user_action', id: cur.opts.id, addr: mid, hash: hash, action: act}, {
  683. 681.  -       onDone: function(row) {
  684. 682.  -         if (curBox()) curBox().hide();
  685. 683.  -         if (isArray(row)) {
  686. 684.  -           var tabs = (tab == 'requests' || tab == 'declined' || tab == 'invites') ? [tab] : ['members', 'unsure', 'admins'], cnt = tabs.length, i;
  687. 685.  -           for (i = 0; i < cnt; ++i) {
  688. 686.  -             var t = tabs[i], d = cur.opts.data[t], found = false, j, k, l, el;
  689. 687.  -             if (isArray(d)) {
  690. 688.  -               for (j = 0, l = d.length; j < l; ++j) {
  691. 689.  -                 if (d[j][0] == mid) {
  692. 690.  -                   found = true;
  693. 691.  -                   cur.opts.data[t][j] = row;
  694. 692.  -                   if (t != 'admins') {
  695. 693.  -                     if (act) {
  696. 694.  -                       --cur.opts.counts[t];
  697. 695.  -                     } else {
  698. 696.  -                       ++cur.opts.counts[t];
  699. 697.  -                     }
  700. 698.  -                   }
  701. 699.  -                   break;
  702. 700.  -                 }
  703. 701.  -               }
  704. 702.  -             }
  705. 703.  -             if (el = ge('gedit_user_' + t + mid)) {
  706. 704.  -               domPN(el).replaceChild(se(GroupsEdit.uGenRow(t, row)), el);
  707. 705.  -               if (t != 'admins' && d == 'notavail') {
  708. 706.  -                 if (act) {
  709. 707.  -                   --cur.opts.counts[t];
  710. 708.  -                   --cur.offsets[t];
  711. 709.  -                 } else {
  712. 710.  -                   ++cur.opts.counts[t];
  713. 711.  -                   ++cur.offsets[t];
  714. 712.  -                 }
  715. 713.  -               }
  716. 714.  -             }
  717. 715.  -             if (!found) {
  718. 716.  -               ajaxCache = {};
  719. 717.  -             }
  720. 718.  -           }
  721. 719.  -           if (tab == 'requests' && act > 0 || tab == 'admins' && act < 0) {
  722. 720.  -             cur.noLocNav = true;
  723. 721.  -           }
  724. 722.  -           GroupsEdit.uUpdateSummary();
  725. 723.  -         } else if (row) {
  726. 724.  -           GroupsEdit.uShowMessage(row);
  727. 725.  -         } else {
  728. 726.  -           GroupsEdit.uRemoveAdmin(mid).uRemove = [mid, hash, act];
  729. 727.  -         }
  730. 728.  -       },
  731. 729.  -       showProgress: function() {
  732. 730.  -         if (curBox()) {
  733. 731.  -           curBox().showProgress();
  734. 732.  -         } else if (el && el.tagName == 'BUTTON') {
  735. 733.  -           lockButton(el);
  736. 734.  -         } else {
  737. 735.  -           if (!el._s) el._s = val(el);
  738. 736.  -           val(el, '<span class="progress_inline"></span>');
  739. 737.  -         }
  740. 738.  -       },
  741. 739.  -       hideProgress: function() {
  742. 740.  -         if (curBox()) {
  743. 741.  -           curBox().hideProgress();
  744. 742.  -         } else if (el && el.tagName == 'BUTTON') {
  745. 743.  -           unlockButton(el);
  746. 744.  -         } else {
  747. 745.  -           if (el._s) {
  748. 746.  -             val(el, el._s);
  749. 747.  -             el._s = false;
  750. 748.  -           }
  751. 749.  -         }
  752. 750.  -       }
  753. 751.  -     });
  754. 752.  -   },
  755. 753.  -
  756. 754.  -   waitTwitter: function() {
  757. 755.  -     ajax.post('al_groups.php', {act: 'get_twitter_auth', gid: cur.gid}, {onDone: function(url) {
  758. 756.  -       if (url) {
  759. 757.  -         hide(cur.twitterBox.progress);
  760. 758.  -         ge('group_status_export_data').innerHTML = getLang('groups_authorize_please');
  761. 759.  -         cur.twitterBox.addButton(getLang('groups_auth_in_twitter'), function() {
  762. 760.  -           location.href = url;
  763. 761.  -         });
  764. 762.  -       } else {
  765. 763.  -         cur.twitterTimer = setTimeout(GroupsEdit.waitTwitter, 1000);
  766. 764.  -       }
  767. 765.  -     }});
  768. 766.  -   },
  769. 767.  -   startTwitter: function() {
  770. 768.  -     cur.twitterBox = showFastBox(getLang('groups_status_export'), '\
  771. 769.  - <div class="group_status_export_info">\
  772. 770.  -   <img class="groups_twitter_icon fl_l" src="/images/twitter_sync.png" />\
  773. 771.  -   <div class="groups_twitter_info fl_l">\
  774. 772.  -     <b>Twitter</b><br />' + getLang('groups_twitter_desc') + '\
  775. 773.  -   </div>\
  776. 774.  -   <br class="clear" />\
  777. 775.  - </div>\
  778. 776.  - <center id="group_status_export_data">' + getLang('groups_external_site_request') + '</center>\
  779. 777.  -     ');
  780. 778.  -     cur.twitterBox.setOptions({onHide: clearTimeout.bind(window).pbind(cur.twitterTimer)});
  781. 779.  -     cur.twitterBox.removeButtons().addButton(getLang('global_cancel'), cur.twitterBox.hide, 'no');
  782. 780.  -     show(cur.twitterBox.progress);
  783. 781.  -     ajax.post('al_groups.php', {act: 'get_twitter_auth', gid: cur.gid, first: 1}, {onDone: function() {
  784. 782.  -       cur.twitterTimer = setTimeout(GroupsEdit.waitTwitter, 1000);
  785. 783.  -     }});
  786. 784.  -   },
  787. 785.  -   checkTwitter: function() {
  788. 786.  -     ajax.post('al_groups.php', {act: 'get_twitter_name', gid: cur.gid}, {onDone: function(name) {
  789. 787.  -       if (name) {
  790. 788.  -         cur.twitterCheckTimer = false;
  791. 789.  -         var lnk = ge('name_service1');
  792. 790.  -         lnk.innerHTML = name;
  793. 791.  -         lnk.href = 'http://twitter.com/' + name;
  794. 792.  -       } else {
  795. 793.  -         cur.twitterCheckTimer = setTimeout(GroupsEdit.checkTwitter, 1000);
  796. 794.  -       }
  797. 795.  -     }});
  798. 796.  -   },
  799. 797.  -   removeTwitter: function() {
  800. 798.  -     var box = showFastBox(getLang('groups_status_export'), '<center>' + getLang('groups_status_confirm') + '</center>', getLang('global_continue'), function() {
  801. 799.  -       ajax.post('al_groups.php', {act: 'clear_twitter', gid: cur.gid, hash: cur.hash}, {progress: box.progress});
  802. 800.  -     }, getLang('global_cancel'));
  803. 801.  -   },
  804. 802.  -
  805. 803.  -   getFields: function() {
  806. 804.  -     var result = {};
  807. 805.  -     for (var i = 0; i < arguments.length; ++i) {
  808. 806.  -       var n = arguments[i];
  809. 807.  -       result[n] = cur.privacy['g_' + n][0];
  810. 808.  -     }
  811. 809.  -     return result;
  812. 810.  -   },
  813. 811.  -   nbAddr: function() {
  814. 812.  -     var tbl = ge('group_edit_addr_table');
  815. 813.  -     setStyle(tbl, 'backgroundColor', '#FAEAEA');
  816. 814.  -     setTimeout(animate.pbind(tbl, {backgroundColor: '#FFFFFF'}, 300), 400);
  817. 815.  -     elfocus('group_edit_addr');
  818. 816.  -   },
  819. 817.  -   saveInfo: function() {
  820. 818.  -     var name = trim(ge('group_edit_name').value), addr = trim(ge('group_edit_addr').value);
  821. 819.  -     if (!name) {
  822. 820.  -       return notaBene(ge('group_edit_name'));
  823. 821.  -     }
  824. 822.  -     if (!addr) {
  825. 823.  -       return GroupsEdit.nbAddr();
  826. 824.  -     }
  827. 825.  -
  828. 826.  -     var params = {
  829. 827.  -       act: 'save',
  830. 828.  -       gid: cur.gid,
  831. 829.  -       name: name,
  832. 830.  -       addr: addr,
  833. 831.  -       description: trim(ge('group_edit_desc').value),
  834. 832.  -       website: trim(ge('group_website').value),
  835. 833.  -       rss: trim(ge('group_rss').value),
  836. 834.  -       hash: cur.hash
  837. 835.  -     }, btn = ge('group_save');
  838. 836.  -     if (cur.cls == 0 || cur.cls == 2) {
  839. 837.  -       extend(params, GroupsEdit.getFields(
  840. 838.  -         'wall', 'photos', 'video', 'audio', 'docs', 'topics', 'wiki', 'access'
  841. 839.  -       ));
  842. 840.  -       params.subject = cur.subjectDD.val();
  843. 841.  -       if (cur.cls == 2) {
  844. 842.  -         extend(params, {
  845. 843.  -           start_date: val('group_start_date'),
  846. 844.  -           finish_date: isVisible('group_edit_finish_time') ? val('group_finish_date') : 0,
  847. 845.  -           host: cur.hostDD ? cur.hostDD.val() : false,
  848. 846.  -           email: val('event_mail'),
  849. 847.  -           phone: val('event_phone')
  850. 848.  -         });
  851. 849.  -       }
  852. 850.  -     } else if (cur.cls == 1) {
  853. 851.  -       extend(params, {
  854. 852.  -         pcategory: cur.pcategoryDD.val(),
  855. 853.  -         psubcategory: cur.psubcategoryDD.val(),
  856. 854.  -         public_date: val('gedit_public_date')
  857. 855.  -       });
  858. 856.  -       each(['enable_replies', 'enable_topics', 'enable_photos', 'enable_video', 'enable_audio', 'enable_links', 'enable_events', 'enable_places', 'enable_contacts'], function(i, v) {
  859. 857.  -         params[v] = isChecked(v);
  860. 858.  -       });
  861. 859.  -     }
  862. 860.  -
  863. 861.  -     ajax.post('al_groups.php', params, {onDone: function(result, oldaddr) {
  864. 862.  -       if (result < 0) {
  865. 863.  -         return GroupsEdit.nbAddr();
  866. 864.  -       }
  867. 865.  -       if (result === false) {
  868. 866.  -         return notaBene(ge('group_edit_name'));
  869. 867.  -       }
  870. 868.  -       if (nav.objLoc.act == 'edit_first') {
  871. 869.  -         return nav.go(nav.objLoc[0]);
  872. 870.  -       }
  873. 871.  -       ((cur.privacy['g_wall'][0] > 1 || cur.twitterVal) ? show : hide)('group_edit_twitter');
  874. 872.  -       var msg = ge('group_saved_msg');
  875. 873.  -       show(msg);
  876. 874.  -       msg.style.backgroundColor = '#F4EBBD';
  877. 875.  -       animate(msg, {backgroundColor: '#F9F6E7'}, 2000);
  878. 876.  -       scrollToTop();
  879. 877.  -       if (oldaddr != addr) {
  880. 878.  -         each(geByTag('a'), function() {
  881. 879.  -           this.href = this.href.replace(new RegExp('/' + oldaddr + '\\?', 'g'), '/' + addr + '?').replace(new RegExp('/' + oldaddr + '$', 'g'), '/' + addr);
  882. 880.  -         });
  883. 881.  -         nav.setLoc({0: addr, act: 'edit'});
  884. 882.  -         globalHistoryDestroy(oldaddr);
  885. 883.  -       }
  886. 884.  -       globalHistoryDestroy(addr);
  887. 885.  -     }, showProgress: lockButton.pbind(btn), hideProgress: unlockButton.pbind(btn)});
  888. 886.  -   },
  889. 887.  -
  890. 888.  -   checkAddr: function(timeout) {
  891. 889.  -     clearTimeout(cur.checkAddrTimer);
  892. 890.  -     if (timeout) {
  893. 891.  -       var inp = ge('group_edit_addr'), tmp = inp.value.replace(/[^0-9a-zA-Z_\.]/g, '');
  894. 892.  -       if (tmp != inp.value) inp.value = tmp;
  895. 893.  -       cur.checkAddrTimer = setTimeout(GroupsEdit.checkAddr.pbind(false), 1000);
  896. 894.  -       return;
  897. 895.  -     }
  898. 896.  -     var val = ge('group_edit_addr').value;
  899. 897.  -     if (val) {
  900. 898.  -       ajax.post('al_settings.php', {act: 'check_addr', addr: val, oid: -cur.gid}, {onDone: function(result, text) {
  901. 899.  -         ge('group_edit_about_addr').innerHTML = text;
  902. 900.  -       }});
  903. 901.  -     }
  904. 902.  -   },
  905. 903.  -   show: function(elem) {
  906. 904.  -     if (!isVisible(elem)) {
  907. 905.  -       slideDown(elem, 150);
  908. 906.  -     }
  909. 907.  -   },
  910. 908.  -   hide: function(elem) {
  911. 909.  -     if (isVisible(elem)) {
  912. 910.  -       slideUp(elem, 150);
  913. 911.  -     }
  914. 912.  -   },
  915. 913.  -   init: function(selData) {
  916. 914.  -     autosizeSetup('group_edit_desc', {
  917. 915.  -       minHeight: 50,
  918. 916.  -       maxHeight: 600
  919. 917.  -     });
  920. 918.  -
  921. 919.  -     cur.twitterVal = selData.twitter;
  922. 920.  -     extend(cur, {
  923. 921.  -       module: 'groups_edit',
  924. 922.  -       privacy: cur.privacy || {},
  925. 923.  -       cls: selData.cls
  926. 924.  -     });
  927. 925.  -     if (cur.cls == 0 || cur.cls == 2) {
  928. 926.  -       extend(cur, {
  929. 927.  -         subjectDD: new Dropdown(ge('group_subject'), selData.subjects, {
  930. 928.  -           width: cur.cls == 2 ? 266 : 186,
  931. 929.  -           multiselect: false,
  932. 930.  -           autocomplete: true,
  933. 931.  -           introText: getLang('groups_start_typing_subject'),
  934. 932.  -           noResult: '',
  935. 933.  -           placeholder: getLang('groups_choose_subject')
  936. 934.  -         })
  937. 935.  -       });
  938. 936.  -       if (selData.subject && selData.subject != '0') {
  939. 937.  -         cur.subjectDD.val(selData.subject);
  940. 938.  -       }
  941. 939.  -     }
  942. 940.  -     if (cur.cls == 1) {
  943. 941.  -       extend(cur, {
  944. 942.  -         pcategoryDD: new Dropdown(ge('public_type'), selData.pcategories, {
  945. 943.  -           width: 266,
  946. 944.  -           multiselect: false,
  947. 945.  -           autocomplete: false,
  948. 946.  -           onChange: function(v) {
  949. 947.  -             v = intval(v);
  950. 948.  -             if (v && (selData.psubcategories[v] || {}).length > 1) {
  951. 949.  -               cur.psubcategoryDD.setOptions({defaultItems: selData.psubcategories[v]});
  952. 950.  -               cur.psubcategoryDD.val(0);
  953. 951.  -               GroupsEdit.show(ge('group_edit_psubcategory'));
  954. 952.  -             } else {
  955. 953.  -               GroupsEdit.hide(ge('group_edit_psubcategory'));
  956. 954.  -             }
  957. 955.  -             if (selData.plabelsmap[v] !== undefined) {
  958. 956.  -               val('gedit_public_date_label', selData.plabels[selData.plabelsmap[v]]);
  959. 957.  -             } else {
  960. 958.  -               val('gedit_public_date_label', selData.plabels[selData.plabelsmap[0]]);
  961. 959.  -             }
  962. 960.  -           }
  963. 961.  -         }),
  964. 962.  -         psubcategoryDD: new Dropdown(ge('public_subtype'), selData.psubcategories[selData.pcategory || 0] || [], {
  965. 963.  -           width: 266,
  966. 964.  -           multiselect: false,
  967. 965.  -           autocomplete: false
  968. 966.  -         }),
  969. 967.  -         bdPicker: new Daypicker('gedit_public_date', {startYear: 1800, width: 266})
  970. 968.  -       });
  971. 969.  -       cur.pcategoryDD.val(selData.pcategory, true);
  972. 970.  -       cur.psubcategoryDD.val(selData.psubcategory);
  973. 971.  -     } else if (cur.cls == 2) {
  974. 972.  -       new Datepicker('group_start_date', {time: 'group_start_time', width: 140, resfmt: 'plain'});
  975. 973.  -       new Datepicker('group_finish_date', {time: 'group_finish_time', width: 140, resfmt: 'plain'});
  976. 974.  -       var width = 140 + 2 * 47 + 10, el = geByClass1('group_edit_at', ge('group_edit_start_time'));
  977. 975.  -
  978. 976.  -       width += el.offsetWidth;
  979. 977.  -       var toAdd = (266 - width), toAddLeft = Math.floor(toAdd / 2), toAddRight = toAdd - toAddLeft;
  980. 978.  -       var st = {paddingLeft: toAddLeft + 'px', paddingRight: toAddRight + 'px'};
  981. 979.  -       setStyle(el, st);
  982. 980.  -       setStyle(geByClass1('group_edit_at', ge('group_edit_finish_time')), st);
  983. 981.  -
  984. 982.  -       if (selData.hosts) {
  985. 983.  -         extend(cur, {
  986. 984.  -           hostDD: new Dropdown(ge('event_host'), selData.hosts, {
  987. 985.  -             width: 266,
  988. 986.  -             multiselect: false,
  989. 987.  -             autocomplete: false,
  990. 988.  -             selectedItems: [selData.host]
  991. 989.  -           })
  992. 990.  -         });
  993. 991.  -       }
  994. 992.  -     }
  995. 993.  -
  996. 994.  -     cur.destroy.push(function(c) {
  997. 995.  -       if (c.cls == 0) {
  998. 996.  -         c.subjectDD.destroy();
  999. 997.  -       } else if (c.cls == 1) {
  1000. 998.  -         c.pcategoryDD.destroy();
  1001. 999.  -         c.psubcategoryDD.destroy();
  1002. 1000.  -       } else if (c.cls == 2) {
  1003. 1001.  -         c.subjectDD.destroy();
  1004. 1002.  -         if (c.hostDD) c.hostDD.destroy();
  1005. 1003.  -       }
  1006. 1004.  -     });
  1007. 1005.  -
  1008. 1006.  -     placeholderSetup('group_rss');
  1009. 1007.  -   },
  1010. 1008.  -
  1011. 1009.  -   doSearchBlacklist: function() {
  1012. 1010.  -     var inp = ge('group_bl_search'), name = trim(inp.value), btn = ge('group_bl_submit');
  1013. 1011.  -     if (!name) {
  1014. 1012.  -       return elfocus(inp);
  1015. 1013.  -     }
  1016. 1014.  -
  1017. 1015.  -     return showBox('al_groups.php', {act: 'bl_edit', name: name, gid: cur.gid}, {stat: ['page.css', 'ui_controls.js', 'ui_controls.css'], dark: 1});
  1018. 1016.  -   },
  1019. 1017.  -   toggleBlacklist: function(mid, el) {
  1020. 1018.  -     if ((domFC(el) || {}).className == 'progress_inline') return;
  1021. 1019.  -     ajax.post('al_groups.php', {act: 'bl_user', mid: mid, gid: cur.gid, hash: cur.hash}, {
  1022. 1020.  -       onDone: GroupsEdit.updateBlacklist.pbind(cur.gid),
  1023. 1021.  -       showProgress: function() {
  1024. 1022.  -         if (!el._s) el._s = val(el);
  1025. 1023.  -         val(el, '<span class="progress_inline"></span>');
  1026. 1024.  -       }, hideProgress: function() {
  1027. 1025.  -         if (el._s) {
  1028. 1026.  -           val(el, el._s);
  1029. 1027.  -           el._s = false;
  1030. 1028.  -         }
  1031. 1029.  -       }
  1032. 1030.  -     });
  1033. 1031.  -   },
  1034. 1032.  -   editBlacklist: function(mid) {
  1035. 1033.  -     showBox('al_groups.php', {act: 'bl_edit', name: 'id' + mid, gid: cur.gid}, {stat: ['page.css', 'ui_controls.js', 'ui_controls.css'], dark: 1});
  1036. 1034.  -   },
  1037. 1035.  -   updateBlacklist: function(gid, msg, mid, html, delta) {
  1038. 1036.  -     if (mid && curBox()) curBox().hide();
  1039. 1037.  -     if (msg === 0) return GroupsEdit.editBlacklist(mid);
  1040. 1038.  -     if (msg) showDoneBox(msg, {out: 3000});
  1041. 1039.  -     if (nav.objLoc[0] == 'search' && nav.objLoc.from == 'ban' && nav.objLoc.gid && mid) {
  1042. 1040.  -       return nav.go(
  1043. 1041.  -         (ge('club_bl_lnk') || {href: 'club' + nav.objLoc.gid + '?act=blacklist'}).href,
  1044. 1042.  -         false,
  1045. 1043.  -         {noback: true}
  1046. 1044.  -       );
  1047. 1045.  -     }
  1048. 1046.  -     if (ge('group_bl_rows') && cur.gid == gid) {
  1049. 1047.  -       var row = ge('group_bl' + mid), newrow = se(html);
  1050. 1048.  -       if (!row && !(delta > 0)) return;
  1051. 1049.  -
  1052. 1050.  -       if (row) {
  1053. 1051.  -         domPN(row).replaceChild(newrow, row);
  1054. 1052.  -       } else if (delta > 0) {
  1055. 1053.  -         var rows = ge('group_bl_rows');
  1056. 1054.  -         rows.insertBefore(newrow, domFC(rows));
  1057. 1055.  -         re('group_bl_no');
  1058. 1056.  -       }
  1059. 1057.  -       GroupsEdit.recache(cur.offset, delta);
  1060. 1058.  -       GroupsEdit.updateBlacklistSummary(delta);
  1061. 1059.  -     }
  1062. 1060.  -   },
  1063. 1061.  -   updateBlacklistSummary: function(delta) {
  1064. 1062.  -     cur.count += delta;
  1065. 1063.  -     if (cur.count > 0) {
  1066. 1064.  -       ge('group_bl_summary').innerHTML = getLang('groups_X_banned_members', cur.count);
  1067. 1065.  -     } else {
  1068. 1066.  -       ge('group_bl_summary').innerHTML = getLang('group_no_banned_users');
  1069. 1067.  -     }
  1070. 1068.  -   },
  1071. 1069.  -   scrollResize: function() {
  1072. 1070.  -     if (browser.mobile) return;
  1073. 1071.  -
  1074. 1072.  -     var docEl = document.documentElement;
  1075. 1073.  -     var ch = window.innerHeight || docEl.clientHeight || bodyNode.clientHeight;
  1076. 1074.  -     var st = scrollGetY();
  1077. 1075.  -     var lnk = ge(cur.moreLink);
  1078. 1076.  -
  1079. 1077.  -     if (!isVisible(lnk)) return;
  1080. 1078.  -     if (st + ch > lnk.offsetTop) {
  1081. 1079.  -       cur.showMore();
  1082. 1080.  -     }
  1083. 1081.  -   },
  1084. 1082.  -   initScroll: function() {
  1085. 1083.  -     GroupsEdit.scrollnode = browser.msie6 ? pageNode : window;
  1086. 1084.  -     window.scrollTop = bodyNode.scrollTop = pageNode.scrollTop = htmlNode.scrollTop = 0;
  1087. 1085.  -
  1088. 1086.  -     addEvent(GroupsEdit.scrollnode, 'scroll', GroupsEdit.scrollResize);
  1089. 1087.  -     addEvent(window, 'resize', GroupsEdit.scrollResize);
  1090. 1088.  -     removeEvent(window, 'load', GroupsEdit.initScroll);
  1091. 1089.  -   },
  1092. 1090.  -   deinitScroll: function() {
  1093. 1091.  -     removeEvent(GroupsEdit.scrollnode, 'scroll', GroupsEdit.scrollResize);
  1094. 1092.  -     removeEvent(window, 'resize', GroupsEdit.scrollResize);
  1095. 1093.  -   },
  1096. 1094.  -   recache: function(from, delta) {
  1097. 1095.  -     if (cur.loading) {
  1098. 1096.  -       cur.loading = 1;
  1099. 1097.  -       setTimeout(GroupsEdit.recache.pbind(from, delta), 100);
  1100. 1098.  -       return;
  1101. 1099.  -     }
  1102. 1100.  -
  1103. 1101.  -     var i = cur.offset, key = '/' + nav.objLoc[0] + '#' + ajx2q(extend({offset: 12345, part: 1}, cur.moreParams));
  1104. 1102.  -     var a = ajaxCache[key.replace('12345', i)];
  1105. 1103.  -     if (a) {
  1106. 1104.  -       a[0] += delta;
  1107. 1105.  -       ajaxCache[key.replace('12345', i + delta)] = a;
  1108. 1106.  -       delete(ajaxCache[key.replace('12345', i)]);
  1109. 1107.  -     }
  1110. 1108.  -     cur.offset += delta;
  1111. 1109.  -   },
  1112. 1110.  -   loaded: function(off, rows) {
  1113. 1111.  -     cur.offset = off;
  1114. 1112.  -
  1115. 1113.  -     var cont = ge('group_bl_rows'), d = ce('div', {innerHTML: rows});
  1116. 1114.  -     while (d.firstChild) {
  1117. 1115.  -       cont.appendChild(d.firstChild);
  1118. 1116.  -     }
  1119. 1117.  -
  1120. 1118.  -     if (off >= cur.count || !rows) {
  1121. 1119.  -       hide('group_users_more');
  1122. 1120.  -       return;
  1123. 1121.  -     }
  1124. 1122.  -     cur.loading = 1;
  1125. 1123.  -     ajax.post(nav.objLoc[0], extend({offset: cur.offset, part: 1}, cur.moreParams), {cache: 1, onDone: function() {
  1126. 1124.  -       if (cur.loading == 2) {
  1127. 1125.  -         GroupsEdit.loaded.apply(window, arguments);
  1128. 1126.  -       } else {
  1129. 1127.  -         cur.loading = false;
  1130. 1128.  -       }
  1131. 1129.  -     }, onFail: function() {
  1132. 1130.  -       cur.loading = 0;
  1133. 1131.  -       return true;
  1134. 1132.  -     }});
  1135. 1133.  -   },
  1136. 1134.  -   load: function() {
  1137. 1135.  -     if (!isVisible('group_users_more') || isVisible('group_more_progress')) return;
  1138. 1136.  -     if (cur.loading) {
  1139. 1137.  -       cur.loading = 2;
  1140. 1138.  -       return;
  1141. 1139.  -     }
  1142. 1140.  -
  1143. 1141.  -     ajax.post(nav.objLoc[0], extend({offset: cur.offset, part: 1}, cur.moreParams), {onDone: GroupsEdit.loaded, onFail: function() {
  1144. 1142.  -       cur.loading = 0;
  1145. 1143.  -       return true;
  1146. 1144.  -     }, showProgress: function() {
  1147. 1145.  -       show('group_more_progress');
  1148. 1146.  -       hide(ge('group_users_more').firstChild);
  1149. 1147.  -     }, hideProgress: function() {
  1150. 1148.  -       show(ge('group_users_more').firstChild);
  1151. 1149.  -       hide('group_more_progress');
  1152. 1150.  -     }, cache: 1});
  1153. 1151.  -   },
  1154. 1152.  -
  1155. 1153.  -   initLinks: function() {
  1156. 1154.  -     placeholderSetup('group_l_search', {back: true});
  1157. 1155.  -     elfocus('group_l_search');
  1158. 1156.  -     cur.module = 'groups_edit';
  1159. 1157.  -     if (!ge('group_l_no')) {
  1160. 1158.  -       var cont = ge('group_l_rows');
  1161. 1159.  -       sorter.init(cont, {onReorder: GroupsEdit.reorderLinks, dh: 1});
  1162. 1160.  -       cur.destroy.push(cont.sorter.destroy);
  1163. 1161.  -     }
  1164. 1162.  -   },
  1165. 1163.  -   reorderLinks: function(lnk, before, after) {
  1166. 1164.  -     var lnk_id = lnk.id.replace('group_l_row', '');
  1167. 1165.  -     for (; after && (!after.id || isVisible('group_l_restore' + after.id.replace('group_l_row', ''))); ) {
  1168. 1166.  -       after = after.previousSibling;
  1169. 1167.  -     }
  1170. 1168.  -     var after_id = (after && after.id || '').replace('group_l_row', '');
  1171. 1169.  -     ajax.post('al_groups.php', {act: 'reorder_links', gid: cur.gid, hash: cur.hash, lid: lnk_id, after: after_id}, {onDone: GroupsEdit.invalidateBack});
  1172. 1170.  -   },
  1173. 1171.  -   editLink: function(id) {
  1174. 1172.  -     showBox('al_groups.php', {act: 'edit_link', lid: id, gid: cur.gid, hash: cur.hash});
  1175. 1173.  -   },
  1176. 1174.  -   invalidateBack: function() {
  1177. 1175.  -     globalHistoryDestroy(nav.objLoc[0]);
  1178. 1176.  -     globalHistoryDestroy('club' + cur.gid);
  1179. 1177.  -     globalHistoryDestroy('event' + cur.gid);
  1180. 1178.  -   },
  1181. 1179.  -   linkAction: function(el, act, id) {
  1182. 1180.  -     var del = (act == 'delete_link');
  1183. 1181.  -     if (!del && cur.count >= cur.linksLimit) {
  1184. 1182.  -       return GroupsEdit.linkMessage('<b>' + getLang('global_unknown_error') + '.</b>', true);
  1185. 1183.  -     }
  1186. 1184.  -
  1187. 1185.  -     var params = {act: act, lid: id, gid: cur.gid, hash: cur.hash};
  1188. 1186.  -     GroupsEdit.linksCount(cur.count + (del ? -1 : 1));
  1189. 1187.  -     if (!del) { // say after what link is that one
  1190. 1188.  -       var after = ge('group_l_row' + id).previousSibling
  1191. 1189.  -       for (; after && (!after.id || isVisible('group_l_restore' + after.id.replace('group_l_row', ''))); ) {
  1192. 1190.  -         after = after.previousSibling;
  1193. 1191.  -       }
  1194. 1192.  -       params.after = (after && after.id || '').replace('group_l_row', '');
  1195. 1193.  -     }
  1196. 1194.  -     ajax.post('al_groups.php', params, {onDone: function() {
  1197. 1195.  -       GroupsEdit.invalidateBack();
  1198. 1196.  -       (del ? hide : show)('group_l_actions' + id);
  1199. 1197.  -       (del ? show : hide)('group_l_restore' + id);
  1200. 1198.  -     }, onFail: function() {
  1201. 1199.  -       GroupsEdit.linksCount(cur.count + (del ? 1 : -1));
  1202. 1200.  -     }, showProgress: function() {
  1203. 1201.  -       hide('group_l_actions' + id, 'group_l_restore' + id);
  1204. 1202.  -       show('group_l_progress' + id);
  1205. 1203.  -     }, hideProgress: function() {
  1206. 1204.  -       hide('group_l_progress' + id);
  1207. 1205.  -       show((del ? 'group_l_actions' : 'group_l_restore') + id);
  1208. 1206.  -     }});
  1209. 1207.  -   },
  1210. 1208.  -   updateImgs: function() {
  1211. 1209.  -     if (cur.lnkImages.length > 1) {
  1212. 1210.  -       ge('group_al_thumb_img').parentNode.style.cursor = 'pointer';
  1213. 1211.  -     }
  1214. 1212.  -   },
  1215. 1213.  -   rotateImgs: function() {
  1216. 1214.  -     if (cur.lnkImages.length < 2) return;
  1217. 1215.  -
  1218. 1216.  -     var index = ((cur.lnkIndex || 0) + 1) % cur.lnkImages.length;
  1219. 1217.  -     ge('group_al_thumb_img').src = cur.lnkImages[index];
  1220. 1218.  -     cur.lnkIndex = index;
  1221. 1219.  -   },
  1222. 1220.  -   parseLink: function(url, cuteurl) {
  1223. 1221.  -     if (!/https?:\/\//i.test(url)) {
  1224. 1222.  -       url = 'http://' + url;
  1225. 1223.  -     }
  1226. 1224.  -     if (cuteurl && !/https?:\/\//i.test(cuteurl)) {
  1227. 1225.  -       cuteurl = 'http://' + cuteurl;
  1228. 1226.  -     }
  1229. 1227.  -     lockButton(ge('group_l_submit'));
  1230. 1228.  -
  1231. 1229.  -     var cont = ge('group_l_bar');
  1232. 1230.  -     re(cur.lnkParse);
  1233. 1231.  -     cur.lnkParse = cont.insertBefore(ce('div', {innerHTML: '\
  1234. 1232.  - <iframe class="upload_frame" name="link_parse_iframe"></iframe>\
  1235. 1233.  -    '}), cont.firstChild);
  1236. 1234.  -
  1237. 1235.  -     var parseForm = cur.lnkParse.appendChild(ce('form', {action: cur.parseUrl, method: 'post', target: 'link_parse_iframe'}));
  1238. 1236.  -     each({
  1239. 1237.  -       act: 'parse_share',
  1240. 1238.  -       from_host: locHost,
  1241. 1239.  -       mid: vk.id,
  1242. 1240.  -       hash: cur.parseHash,
  1243. 1241.  -       rhash: cur.parseRHash,
  1244. 1242.  -       url: url
  1245. 1243.  -     }, function(i, v) {
  1246. 1244.  -       parseForm.appendChild(ce('input', {type: 'hidden', name: i, value: v}));
  1247. 1245.  -     });
  1248. 1246.  -
  1249. 1247.  -     cur.lnkImages = ['/images/lnkouter100.gif'];
  1250. 1248.  -     window.onParseDone = function(data) {
  1251. 1249.  -       unlockButton(ge('group_l_submit'));
  1252. 1250.  -       GroupsEdit.addLinkBox(data.title || '', cuteurl || url);
  1253. 1251.  -       if (!data.images || !data.images.length) {
  1254. 1252.  -         return;
  1255. 1253.  -       }
  1256. 1254.  -       cur.addBox.setOptions({onClean: function() {
  1257. 1255.  -         clearInterval(cur.imgLoadInterval);
  1258. 1256.  -       }});
  1259. 1257.  -       for (var i in data.images) {
  1260. 1258.  -         var src = '', img = vkImage();
  1261. 1259.  -         if (/^\//.test(data.images[i])) {
  1262. 1260.  -           src = (/^https:\/\//i.test(url) ? 'https://' : 'http://') + GroupsEdit.getDomain(url);
  1263. 1261.  -         } else if (!/^https?:\/\//i.test(data.images[i])) {
  1264. 1262.  -           src = url.replace(/[^\/]*$/, '');
  1265. 1263.  -           if (/^https?:\/\/$/i.test(src)) {
  1266. 1264.  -             src = url + '/';
  1267. 1265.  -           }
  1268. 1266.  -         }
  1269. 1267.  -         img.src = src + data.images[i];
  1270. 1268.  -         data.images[i] = img;
  1271. 1269.  -       }
  1272. 1270.  -       cur.imgLoadInterval = setInterval(function() {
  1273. 1271.  -         var nl = 0;
  1274. 1272.  -         for (var i in data.images) {
  1275. 1273.  -           var img = data.images[i];
  1276. 1274.  -           if (!img) continue;
  1277. 1275.  -           var w = img.width, h = img.height;
  1278. 1276.  -           if (w || h) {
  1279. 1277.  -             if (w >= 50 && h >= 20) {
  1280. 1278.  -               cur.lnkImages.push(img.src);
  1281. 1279.  -               GroupsEdit.updateImgs();
  1282. 1280.  -               if (!cur.lnkIndex) GroupsEdit.rotateImgs();
  1283. 1281.  -             }
  1284. 1282.  -             data.images[i] = false;
  1285. 1283.  -           } else {
  1286. 1284.  -             ++nl;
  1287. 1285.  -           }
  1288. 1286.  -         }
  1289. 1287.  -         if (!nl) {
  1290. 1288.  -           clearInterval(cur.imgLoadInterval);
  1291. 1289.  -           cur.imgLoadInterval = true;
  1292. 1290.  -         }
  1293. 1291.  -       }, 200);
  1294. 1292.  -     }
  1295. 1293.  -
  1296. 1294.  -     window.onParseFail = function() {
  1297. 1295.  -       unlockButton(ge('group_l_submit'));
  1298. 1296.  -       GroupsEdit.addLinkBox('', cuteurl || url);
  1299. 1297.  -     }
  1300. 1298.  -
  1301. 1299.  -     parseForm.submit();
  1302. 1300.  -   },
  1303. 1301.  -   getDomain: function(url) {
  1304. 1302.  -     if (url.charAt(0) == '/') return locDomain;
  1305. 1303.  -     return url.match(/^(https?:\/\/)?([^\/]+)(\/|$)/)[2];
  1306. 1304.  -   },
  1307. 1305.  -   addLinkBox: function(title, url) {
  1308. 1306.  -     var img = cur.lnkImages[0];
  1309. 1307.  -     cur.lnk = url;
  1310. 1308.  -     cur.lnkOwnerId = cur.lnkPhotoId = false;
  1311. 1309.  -     cur.editing = false;
  1312. 1310.  -     cur.addBox = showFastBox(cur.boxTitle, '\
  1313. 1311.  - <div class="group_al_thumb select_fix fl_l" onclick="GroupsEdit.rotateImgs()">\
  1314. 1312.  -   <img src="' + img + '" id="group_al_thumb_img" />\
  1315. 1313.  - </div>\
  1316. 1314.  - <div class="group_al_info fl_l">\
  1317. 1315.  -   <input type="text" class="text" id="group_al_title" value="' + trim(title) + '" onkeypress="if (event.keyCode == 10 || event.keyCode == 13) GroupsEdit.doAddLink()" placeholder="' + getLang('group_link_add_title') + '" />\
  1318. 1316.  -   <div class="group_al_position">' + GroupsEdit.getDomain(url) + '</div>\
  1319. 1317.  - </div>\
  1320. 1318.  - <br class="clear" />', getLang('global_add'), GroupsEdit.doAddLink, getLang('global_cancel'));
  1321. 1319.  -     var inp = ge('group_al_title');
  1322. 1320.  -     placeholderSetup(inp, {back: true});
  1323. 1321.  -     elfocus(inp);
  1324. 1322.  -   },
  1325. 1323.  -   addLink: function() {
  1326. 1324.  -     var lnk = trim(ge('group_l_search').value).replace(/\s/g, '+');
  1327. 1325.  -     if (!lnk) {
  1328. 1326.  -       return elfocus('group_l_search');
  1329. 1327.  -     }
  1330. 1328.  -     cur.lnkIndex = 0;
  1331. 1329.  -     ajax.post('al_groups.php', {act: 'add_link_box', lnk: lnk}, {onDone: function(code, innerlnk, html, js) {
  1332. 1330.  -       if (code > 0) {
  1333. 1331.  -         if (code & 1) { // inner link
  1334. 1332.  -           ajax.plainpost(innerlnk, {_tmp: 1}, function(text) {
  1335. 1333.  -             var title = trim((text.match(/<title>([^<]*)/i) || {})[1] || '');
  1336. 1334.  -             cur.lnkImages = ['/images/lnkinner100.gif'];
  1337. 1335.  -             cur.lnk = innerlnk;
  1338. 1336.  -             GroupsEdit.addLinkBox(title, innerlnk);
  1339. 1337.  -           }, (code & 2) ? GroupsEdit.parseLink.pbind(html, js) : function(text) {
  1340. 1338.  -             GroupsEdit.linkMessage(getLang('groups_bad_link'), true);
  1341. 1339.  -             return elfocus('group_l_search');
  1342. 1340.  -           }, true);
  1343. 1341.  -         } else if (code & 2) {
  1344. 1342.  -           GroupsEdit.parseLink(innerlnk, html);
  1345. 1343.  -         }
  1346. 1344.  -       } else if (code < 0) {
  1347. 1345.  -         GroupsEdit.linkMessage(getLang('groups_bad_link'), true);
  1348. 1346.  -         return elfocus('group_l_search');
  1349. 1347.  -       } else {
  1350. 1348.  -         cur.lnk = innerlnk;
  1351. 1349.  -         cur.lnkOwnerId = cur.lnkPhotoId = false;
  1352. 1350.  -         cur.addBox = showFastBox(cur.boxTitle, html, getLang('global_add'), GroupsEdit.doAddLink, getLang('global_cancel'));
  1353. 1351.  -         cur.addBox.evalBox(js);
  1354. 1352.  -       }
  1355. 1353.  -     }, showProgress: lockButton.pbind(ge('group_l_submit')), hideProgress: unlockButton.pbind(ge('group_l_submit'))});
  1356. 1354.  -   },
  1357. 1355.  -   uploadImg: function() {
  1358. 1356.  -     show(cur.addBox.progress);
  1359. 1357.  -     var cont = ge('group_l_bar');
  1360. 1358.  -     var uploadCont = cont.appendChild(ce('div', {innerHTML: '<iframe class="upload_frame" name="link_upload_iframe"></iframe>'})),
  1361. 1359.  -         uploadForm = uploadCont.appendChild(ce('form', {action: '/share.php', method: 'post', target: 'link_upload_iframe'}));
  1362. 1360.  -     each({
  1363. 1361.  -       act: 'a_photo',
  1364. 1362.  -       index: 0,
  1365. 1363.  -       image: cur.lnkImages[cur.lnkIndex],
  1366. 1364.  -       extra: 'link'
  1367. 1365.  -     }, function (i, v) {
  1368. 1366.  -       uploadForm.appendChild(ce('input', {type: 'hidden', name: i, value: v}));
  1369. 1367.  -     });
  1370. 1368.  -     window.onUploadDone = function(index, params) {
  1371. 1369.  -       window.onUploadFail = window.onUploadDone = function () {};
  1372. 1370.  -       cur.lnkOwnerId = params.user_id;
  1373. 1371.  -       cur.lnkPhotoId = params.photo_id;
  1374. 1372.  -       cont.removeChild(uploadCont);
  1375. 1373.  -       cur.lnkIndex = 0;
  1376. 1374.  -       GroupsEdit.doAddLink(true);
  1377. 1375.  -     }
  1378. 1376.  -     window.onUploadFail = function(index, msg) {
  1379. 1377.  -       window.onUploadFail = window.onUploadDone = function () {};
  1380. 1378.  -       cont.removeChild(uploadCont);
  1381. 1379.  -       cur.lnkIndex = 0;
  1382. 1380.  -       GroupsEdit.doAddLink(true);
  1383. 1381.  -     }
  1384. 1382.  -     cur.lnkOwnerId = cur.lnkPhotoId = false;
  1385. 1383.  -     uploadForm.submit();
  1386. 1384.  -   },
  1387. 1385.  -   linkMessage: function(text, error) {
  1388. 1386.  -     var msg = ge('group_l_msg');
  1389. 1387.  -     msg.innerHTML = text;
  1390. 1388.  -     show(msg);
  1391. 1389.  -     var colors = error ? ['#FACEBB', '#FFEFE8', '#E89B88'] : ['#F4EBBD', '#F9F6E7', '#D4BC4C'];
  1392. 1390.  -     msg.style.backgroundColor = colors[0];
  1393. 1391.  -     each(['Left', 'Top', 'Right', 'Bottom'], function() {
  1394. 1392.  -       msg.style['border' + this + 'Color'] = colors[2];
  1395. 1393.  -     });
  1396. 1394.  -     animate(msg, {backgroundColor: colors[1]}, 2000);
  1397. 1395.  -   },
  1398. 1396.  -   linksCount: function(count) {
  1399. 1397.  -     cur.count = count;
  1400. 1398.  -     ge('group_l_summary').innerHTML = count ? getLang('links_count', count) : getLang('links_no_count');
  1401. 1399.  -     (count >= cur.linksLimit ? hide : show)('group_l_bar');
  1402. 1400.  -   },
  1403. 1401.  -   doAddLink: function(force) {
  1404. 1402.  -     if (!force && isVisible(cur.addBox.progress)) return;
  1405. 1403.  -
  1406. 1404.  -     var title = ge('group_al_title');
  1407. 1405.  -     if (title && cur.lnkIndex) {
  1408. 1406.  -       return GroupsEdit.uploadImg();
  1409. 1407.  -     }
  1410. 1408.  -     var str = (title ? title : ge('group_al_position')).value;
  1411. 1409.  -     var params = {
  1412. 1410.  -       lnk: cur.lnk,
  1413. 1411.  -       index: cur.lnkIndex,
  1414. 1412.  -       owner_id: cur.lnkOwnerId,
  1415. 1413.  -       photo_id: cur.lnkPhotoId,
  1416. 1414.  -       str: str,
  1417. 1415.  -       gid: cur.gid,
  1418. 1416.  -       lid: cur.editing,
  1419. 1417.  -       hash: cur.hash
  1420. 1418.  -     }, callback;
  1421. 1419.  -     if (cur.editing) {
  1422. 1420.  -       params.act = 'do_edit_link';
  1423. 1421.  -       callback = function(lid, thumb, title, position) {
  1424. 1422.  -         cur.addBox.hide();
  1425. 1423.  -         GroupsEdit.invalidateBack();
  1426. 1424.  -         if (thumb !== false) ge('group_l_photo' + lid).src = thumb;
  1427. 1425.  -         if (title !== false) ge('group_l_title' + lid).innerHTML = title;
  1428. 1426.  -         if (position !== false) ge('group_l_position' + lid).innerHTML = position;
  1429. 1427.  -       }
  1430. 1428.  -     } else {
  1431. 1429.  -       params.act = 'add_link';
  1432. 1430.  -       callback = function(count, text, row) {
  1433. 1431.  -         cur.addBox.hide();
  1434. 1432.  -         GroupsEdit.invalidateBack();
  1435. 1433.  -         GroupsEdit.linkMessage(text);
  1436. 1434.  -         var cont = ge('group_l_rows');
  1437. 1435.  -         cont.appendChild(ce('div', {innerHTML: row}).firstChild);
  1438. 1436.  -         var no = ge('group_l_no');
  1439. 1437.  -         if (no) {
  1440. 1438.  -           cont.removeChild(no);
  1441. 1439.  -           sorter.init(cont, {onReorder: GroupsEdit.reorderLinks, dh: 1});
  1442. 1440.  -           cur.destroy.push(cont.sorter.destroy);
  1443. 1441.  -         } else {
  1444. 1442.  -           sorter.added(cont);
  1445. 1443.  -           sorter.shift(cont);
  1446. 1444.  -         }
  1447. 1445.  -         GroupsEdit.linksCount(count);
  1448. 1446.  -         var s = ge('group_l_search');
  1449. 1447.  -         s.setValue('');
  1450. 1448.  -         elfocus(s);
  1451. 1449.  -       }
  1452. 1450.  -     }
  1453. 1451.  -     setTimeout(ajax.post.pbind('al_groups.php', params, {onDone: callback, onFail: function(text) {
  1454. 1452.  -       cur.addBox.hide();
  1455. 1453.  -       GroupsEdit.linkMessage(text || getLang('groups_bad_link'), true);
  1456. 1454.  -       return true;
  1457. 1455.  -     }, progress: cur.addBox.progress}), 0);
  1458. 1456.  -   },
  1459. 1457.  -
  1460. 1458.  -   failed: function(old, text) {
  1461. 1459.  -     GroupsEdit.setActive(old);
  1462. 1460.  -     if (!text) return;
  1463. 1461.  -
  1464. 1462.  -     setTimeout(showFastBox(getLang('global_error'), text).hide, 2000);
  1465. 1463.  -     return true;
  1466. 1464.  -   },
  1467. 1465.  -   getsect: function() {
  1468. 1466.  -     var filters = ge('group_edit_filters');
  1469. 1467.  -     if (!filters) return;
  1470. 1468.  -
  1471. 1469.  -     var current = filters.firstChild;
  1472. 1470.  -     for (; !current.tagName || !hasClass(current, 'active_link');) {
  1473. 1471.  -       current = current.nextSibling;
  1474. 1472.  -     }
  1475. 1473.  -     return current;
  1476. 1474.  -   },
  1477. 1475.  -   setActive: function(el) {
  1478. 1476.  -     var filters = ge('group_edit_filters');
  1479. 1477.  -     if (!filters) return;
  1480. 1478.  -
  1481. 1479.  -     var current = GroupsEdit.getsect();
  1482. 1480.  -     if (current != el) {
  1483. 1481.  -       current.className = '';
  1484. 1482.  -       el.className = 'active_link';
  1485. 1483.  -     }
  1486. 1484.  -   },
  1487. 1485.  -   go: function(el, ev) {
  1488. 1486.  -     var result = nav.go(el, ev, {onFail: GroupsEdit.failed.pbind(GroupsEdit.getsect())});
  1489. 1487.  -     if (result === false) {
  1490. 1488.  -       GroupsEdit.setActive(el.parentNode);
  1491. 1489.  -     }
  1492. 1490.  -   },
  1493. 1491.  -
  1494. 1492.  -   editPlace: function() {
  1495. 1493.  -     showBox('al_page.php', {act: 'edit_group_place', gid: cur.gid}, {stat: ['maps.js', 'ui_controls.js', 'ui_controls.css', 'selects.js', 'page.css'], dark: 1});
  1496. 1494.  -   },
  1497. 1495.  -   onPlaceSave: function(res) {
  1498. 1496.  -     ge('group_edit_address_link').innerHTML = res;
  1499. 1497.  -   },
  1500. 1498.  -
  1501. 1499.  -   showStickersTT: function(text) {
  1502. 1500.  -     var ttEl = ge('group_edit_addr_table');
  1503. 1501.  -     showTooltip(ttEl, {
  1504. 1502.  -       text: '<div class="stickers_side_tt_pointer"></div>' + text.replace('{link}', "<a href=\"#\" onclick=\"showBox('al_groups.php', {act: 'stickers_box', gid: cur.gid}); return false;\">").replace('{/link}', '</a>'),
  1505. 1503.  -       className: 'stickers_side_tt',
  1506. 1504.  -       slideX: 15,
  1507. 1505.  -       shift: [-276, -43, 3],
  1508. 1506.  -       nohide: 1,
  1509. 1507.  -       hasover: 1
  1510. 1508.  -     });
  1511. 1509.  -     ge('group_edit_addr').onblur = function () {
  1512. 1510.  -       GroupsEdit.checkAddr();
  1513. 1511.  -       if (!ttEl.tt || !ttEl.tt.hide) return;
  1514. 1512.  -       ttEl.tt.hide();
  1515. 1513.  -     }
  1516. 1514.  -   },
  1517. 1515.  -
  1518. 1516.  -   switchAdSubTab: function(el, wrap, link, evt, params) {
  1519. 1517.  -     if (checkEvent(evt) || hasClass(el, 'active')) return false;
  1520. 1518.  -     each(geByClass('group_ad_subtab1', ge(wrap)), function(i, v) {
  1521. 1519.  -       removeClass(v, 'active');
  1522. 1520.  -     });
  1523. 1521.  -     addClass(el, 'active');
  1524. 1522.  -     if (params.part) {
  1525. 1523.  -       var obj = nav.fromStr(link), url = obj[0];
  1526. 1524.  -       delete obj[0];
  1527. 1525.  -       ajax.post(url, extend(obj, {part: 1}), {
  1528. 1526.  -         cache: 1,
  1529. 1527.  -         onDone: params.onDone.pbind(obj)
  1530. 1528.  -       });
  1531. 1529.  -       return false;
  1532. 1530.  -     }
  1533. 1531.  -     return nav.go(link, evt);
  1534. 1532.  -   },
  1535. 1533.  -   getAdPage: function(offset, wrap) {
  1536. 1534.  -     var obj = clone(nav.objLoc), url = obj[0];
  1537. 1535.  -     delete obj[0];
  1538. 1536.  -     ajax.post(url, extend(obj, {offset: offset, part: 1}), {
  1539. 1537.  -       onDone: function(res) {
  1540. 1538.  -         ge(wrap || 'group_ad_requests_table_warp').innerHTML = res;
  1541. 1539.  -         nav.setLoc(extend(nav.objLoc, {offset: offset}));
  1542. 1540.  -       }
  1543. 1541.  -     });
  1544. 1542.  -     return false;
  1545. 1543.  -   },
  1546. 1544.  -   updateAdRequest: function(ad_id, request_id, status, hash) {
  1547. 1545.  -     return !showBox('/al_groups.php', {act: 'a_adspost_update_request', gid: cur.gid, ad_id: ad_id, request_id: request_id, status: status, hash: hash}, { params: {dark: true}});
  1548. 1546.  -   }
  1549. 1547.  - }
  1550. 1548.  -
  1551. 1549.  - try{stManager.done('groups_edit.js');}catch(e){}
  1552. ------
Advertisement
Add Comment
Please, Sign In to add comment