Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - ads.js (Старый размер - 90231 | Новый - 0):
- 0. - var Ads = {};
- 1. -
- 2. - Ads.init = function() {
- 3. - showBackLink();
- 4. - }
- 5. -
- 6. - Ads.initOfficesMenu = function(event) {
- 7. -
- 8. - if (!window.DropdownMenu || !cur.mainNavigationOfficesItems) {
- 9. - return;
- 10. - }
- 11. -
- 12. - if (cur.navigationOficesMenu) {
- 13. - return;
- 14. - }
- 15. -
- 16. - ge('ads_navigation_offices_menu').removeAttribute('onmouseover');
- 17. -
- 18. - function hideMenu() {
- 19. - cur.navigationOficesMenu.hide();
- 20. - }
- 21. -
- 22. - var realLocation = '';
- 23. - if (location.hash.indexOf('#/') != -1 || location.hash.indexOf('#!') != -1) {
- 24. - realLocation = location.hash.replace('#/', '').replace('#!', '');
- 25. - } else {
- 26. - realLocation = location.pathname + location.search;
- 27. - }
- 28. -
- 29. - var unionId;
- 30. - var unionIdReal;
- 31. - var unionIdParam = '';
- 32. - var curItems = [];
- 33. - for (var i in cur.mainNavigationOfficesItems) {
- 34. - curItems[i] = {};
- 35. - curItems[i].onClick = hideMenu;
- 36. - for (var j in cur.mainNavigationOfficesItems[i]) {
- 37. - curItems[i][j] = cur.mainNavigationOfficesItems[i][j];
- 38. - }
- 39. - if (curItems[i].i == 'all') {
- 40. - curItems[i].h = "/ads?act=offices_list";
- 41. - } else {
- 42. - unionId = '';
- 43. - unionIdReal = intval(curItems[i].i);
- 44. - unionIdParam = '';
- 45. - if (curItems[i].i.indexOf('default') == -1) {
- 46. - unionId = unionIdReal;
- 47. - unionIdParam = "&union_id=" + unionIdReal;
- 48. - }
- 49. -
- 50. - var link = "/ads?act=office" + unionIdParam;
- 51. - if (!unionIdReal) {
- 52. - link = "/ads?act=no_office";
- 53. - } else if (cur.getOfficeLink) {
- 54. - link = cur.getOfficeLink(unionId);
- 55. - } else if (realLocation.match(/act=budget(&|$)/)) {
- 56. - link = "/ads?act=budget" + unionIdParam;
- 57. - } else if (realLocation.match(/act=export_stats(&|$)/)) {
- 58. - link = "/ads?act=export_stats" + unionIdParam;
- 59. - } else if (realLocation.match(/act=settings(&|$)/)) {
- 60. - link = "/ads?act=settings" + unionIdParam;
- 61. - }
- 62. -
- 63. - curItems[i].h = link;
- 64. - }
- 65. - }
- 66. -
- 67. - var options = {
- 68. - title: '<span id="ads_navigation_dd_menu_header_text">' + ge('ads_navigation_offices_menu_text').innerHTML + '</span>',
- 69. - containerClass: 'ads_navigation_dd_menu_header_wrap',
- 70. - target: ge('ads_navigation_offices_menu'),
- 71. - showHover: false,
- 72. - updateTarget: false,
- 73. - onSelect: function(e) {
- 74. - }
- 75. - };
- 76. - cur.navigationOficesMenu = new DropdownMenu(curItems, options);
- 77. - cur.destroy.push(function(){ cur.navigationOficesMenu.destroy(); });
- 78. - }
- 79. -
- 80. - Ads.lock = function(lockKey, onLock, onUnlock) {
- 81. - if (!cur.locks) {
- 82. - cur.locks = {};
- 83. - }
- 84. - if (cur.locks[lockKey]) {
- 85. - return false;
- 86. - }
- 87. - cur.locks[lockKey] = {onLock: onLock, onUnlock: onUnlock};
- 88. - if (isFunction(cur.locks[lockKey].onLock)) {
- 89. - cur.locks[lockKey].onLock();
- 90. - }
- 91. - return true;
- 92. - }
- 93. -
- 94. - Ads.unlock = function(lockKey) {
- 95. - if (!cur.locks) {
- 96. - cur.locks = {};
- 97. - }
- 98. - if (cur.locks[lockKey] && isFunction(cur.locks[lockKey].onUnlock)) {
- 99. - cur.locks[lockKey].onUnlock();
- 100. - }
- 101. - delete cur.locks[lockKey];
- 102. - }
- 103. -
- 104. - Ads.simpleAjax = function(url) {
- 105. - ajax.post(url, {}, {onDone: onComplete, onFail: onComplete});
- 106. - function onComplete() {
- 107. - nav.reload();
- 108. - return true;
- 109. - }
- 110. - }
- 111. -
- 112. - Ads.escapeValue = function(value) {
- 113. - return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
- 114. - }
- 115. -
- 116. - Ads.onInputEvent = function(event, func) {
- 117. - if (event.keyCode == KEY.RETURN) {
- 118. - func();
- 119. - return false;
- 120. - }
- 121. - return true;
- 122. - }
- 123. -
- 124. - Ads.onSubLinkEvent = function(event) {
- 125. - event = normEvent(event);
- 126. - var elem = event.target
- 127. - var newLink = elem.getAttribute('href_');
- 128. - if (!newLink) {
- 129. - return;
- 130. - }
- 131. - var linkElem = elem;
- 132. - while (linkElem && linkElem.nodeName !== 'A') {
- 133. - linkElem = linkElem.parentNode;
- 134. - }
- 135. - if (!linkElem) {
- 136. - return;
- 137. - }
- 138. - if (event.type === 'mouseover') {
- 139. - elem.setAttribute('href_old', linkElem.href);
- 140. - linkElem.href = newLink;
- 141. - } else if (event.type === 'mouseout') {
- 142. - var oldLink = elem.getAttribute('href_old');
- 143. - if (oldLink) {
- 144. - linkElem.href = oldLink;
- 145. - } else {
- 146. - linkElem.removeAttribute('href');
- 147. - }
- 148. - }
- 149. - }
- 150. -
- 151. - Ads.onBoxFail = function(message) {
- 152. - if (!message) {
- 153. - message = getLang('global_unknown_error');
- 154. - }
- 155. - setTimeout(function(){
- 156. - showFastBox(getLang('ads_error_box_title'), message);
- 157. - }, 1);
- 158. - return true;
- 159. - }
- 160. -
- 161. - Ads.setLoginHandlers = function(onLoginDoneNew, onLoginFailedNew) {
- 162. - var restoreOnLoginDone = function(handler) {
- 163. - if (cur.onLoginDoneWindowOld && window.onLoginDone == handler) {
- 164. - window.onLoginDone = cur.onLoginDoneWindowOld;
- 165. - delete cur.onLoginDoneWindowOld;
- 166. - }
- 167. - }
- 168. - var restoreOnLoginFailed = function(handler) {
- 169. - if (cur.onLoginFailedWindowOld && window.onLoginFailed == handler) {
- 170. - window.onLoginFailed = cur.onLoginFailedWindowOld;
- 171. - delete cur.onLoginFailedWindowOld;
- 172. - }
- 173. - }
- 174. -
- 175. - if (onLoginDoneNew) {
- 176. - if (window.onLoginDone != onLoginDoneNew) {
- 177. - cur.onLoginDoneWindowOld = window.onLoginDone;
- 178. - window.onLoginDone = onLoginDoneNew;
- 179. - cur.destroy.push(restoreOnLoginDone.pbind(onLoginDoneNew));
- 180. - }
- 181. - } else {
- 182. - restoreOnLoginDone(window.onLoginDone);
- 183. - }
- 184. -
- 185. - if (onLoginFailedNew) {
- 186. - if (window.onLoginFailed != onLoginFailedNew) {
- 187. - cur.onLoginFailedWindowOld = window.onLoginFailed;
- 188. - window.onLoginFailed = onLoginFailedNew;
- 189. - cur.destroy.push(restoreOnLoginFailed.pbind(onLoginFailedNew));
- 190. - }
- 191. - } else {
- 192. - restoreOnLoginFailed(window.onLoginFailed);
- 193. - }
- 194. - }
- 195. -
- 196. - Ads.scrollToError = function(errorElem) {
- 197. - errorElem = ge(errorElem);
- 198. - var scrollY = scrollGetY();
- 199. - var errorY = getXY(errorElem)[1];
- 200. - if (errorY < scrollY || errorY > (scrollY + lastWindowHeight / 2)) {
- 201. - errorY -= 15;
- 202. - scrollToY(errorY);
- 203. - }
- 204. - }
- 205. -
- 206. - Ads.initFixed = function(elemWrap) {
- 207. - elemWrap = ge(elemWrap);
- 208. - if (!elemWrap) return;
- 209. - var elemFixed = elemWrap.firstChild;
- 210. - if (!elemFixed) return;
- 211. -
- 212. - var scrolledNode = browser.msie6 ? pageNode : window;
- 213. - addEvent(scrolledNode, 'scroll', onScroll);
- 214. - cur.destroy.push(function() { removeEvent(scrolledNode, 'scroll', onScroll); });
- 215. -
- 216. - var poistionTop = 20;
- 217. -
- 218. - var elemWrapSize = getSize(elemWrap);
- 219. - setStyle(elemWrap, {width: elemWrapSize[0] + 'px', height: elemWrapSize[1] + 'px'});
- 220. -
- 221. - onScroll();
- 222. -
- 223. - function onScroll() {
- 224. - var elemWrapXY = getXY(elemWrap);
- 225. - var scrollY = scrollGetY();
- 226. - if (scrollY + poistionTop < elemWrapXY[1]) {
- 227. - setStyle(elemFixed, {position: 'static', top: 'auto', left: 'auto'});
- 228. - } else {
- 229. - setStyle(elemFixed, {position: 'fixed', top: poistionTop, left: elemWrapXY[0]});
- 230. - }
- 231. - }
- 232. - }
- 233. -
- 234. - //////////////////////////////////////////////////////////////////////
- 235. - // OLD
- 236. - //////////////////////////////////////////////////////////////////////
- 237. -
- 238. - Ads.updateUnionName = function(unionId, unionName) {
- 239. - var elemsTitle = geByClass('title_union_name_' + unionId);
- 240. - for (var i in elemsTitle) {
- 241. - elemsTitle[i].innerHTML = Ads.escapeValue(unionName);
- 242. - }
- 243. -
- 244. - var elemNavigation = ge('ads_navigation_union_' + unionId);
- 245. - if (elemNavigation) {
- 246. - unionName = replaceEntities(unionName);
- 247. - unionName = (unionName.length > 40 ? unionName.substr(0, 40) + '...' : unionName);
- 248. - elemNavigation.innerHTML = Ads.escapeValue(unionName);
- 249. - }
- 250. -
- 251. - var elemGeneralInfoHeader = ge('general_info_header_name_' + unionId);
- 252. - if (elemGeneralInfoHeader) {
- 253. - elemGeneralInfoHeader.innerHTML = Ads.escapeValue(unionName);
- 254. - }
- 255. - }
- 256. -
- 257. - Ads.openUnionsGeneralInfoBox = function(unionId, params) {
- 258. - var ajaxParams = {};
- 259. - ajaxParams.union_id = unionId;
- 260. - ajaxParams = extend({}, ajaxParams, params);
- 261. -
- 262. - var showOptions = {params: {}};
- 263. - showOptions.onFail = Ads.onBoxFail;
- 264. - showOptions.params.width = 300;
- 265. -
- 266. - showBox('/ads?act=a_unions_general_info_box', ajaxParams, showOptions);
- 267. - }
- 268. -
- 269. - Ads.openUnionCreateBox = function(unionId) {
- 270. - var ajaxParams = {}
- 271. - ajaxParams.union_id = unionId;
- 272. -
- 273. - var showOptions = {params: {}};
- 274. - showOptions.onFail = Ads.onBoxFail;
- 275. - showOptions.params.width = 250;
- 276. -
- 277. - showBox('/ads?act=a_union_create_box', ajaxParams, showOptions);
- 278. - }
- 279. -
- 280. - Ads.openDeleteUnionBox = function(unionType, unionId, hash, lock, unlock, updateStatus, newclass) {
- 281. - var boxTitle = '';
- 282. - var boxContent = '';
- 283. - switch (unionType) {
- 284. - case 'ad':
- 285. - boxTitle = getLang('ads_archive_box_ad_title');
- 286. - boxContent = getLang('ads_archive_box_ad_warning');
- 287. - break;
- 288. - case 'campaign':
- 289. - boxTitle = getLang('ads_archive_box_campaign_title');
- 290. - boxContent = getLang('ads_archive_box_campaign_warning');
- 291. - break;
- 292. - case 'client':
- 293. - boxTitle = getLang('ads_archive_box_client_title');
- 294. - boxContent = getLang('ads_archive_box_client_warning');
- 295. - break;
- 296. - }
- 297. -
- 298. - var boxOptions = {};
- 299. - boxOptions.title = boxTitle;
- 300. - boxOptions.bodyStyle = 'line-height: 160%;';
- 301. -
- 302. - cur.deleteConfirmBox = new MessageBox();
- 303. - cur.deleteConfirmBox.setOptions(boxOptions);
- 304. - cur.deleteConfirmBox.content(boxContent);
- 305. - cur.deleteConfirmBox.removeButtons();
- 306. - cur.deleteConfirmBox.addButton(getLang('box_cancel'), false, 'no');
- 307. - cur.deleteConfirmBox.addButton(getLang('ads_archive_box_action'), function() { Ads.deleteUnion(unionType, unionId, hash, lock, unlock, updateStatus, newclass); });
- 308. - cur.deleteConfirmBox.setControlsText('<img id="delete_union_progress" src="/images/upload.gif" style="top: 1px; display: none;">');
- 309. - cur.deleteConfirmBox.show();
- 310. - }
- 311. -
- 312. - Ads.deleteUnion = function(unionType, unionId, hash, lock, unlock, updateStatus, newclass) {
- 313. - if (!lockDeletion()) {
- 314. - return;
- 315. - }
- 316. -
- 317. - var ajaxParams = {};
- 318. - ajaxParams.union_id = unionId;
- 319. - ajaxParams.hash = hash;
- 320. - if (newclass) ajaxParams.newclass = 1;
- 321. -
- 322. - ajax.post('/ads?act=a_union_delete', ajaxParams, {onDone: onRequestComplete, onFail: onRequestComplete});
- 323. -
- 324. - function onRequestComplete(response) {
- 325. - unlockDeletion();
- 326. - if (!isObject(response) || response.error) {
- 327. - if (!isObject(response)) {
- 328. - showMessage(getLang('ads_error_unexpected_error_try_later'));
- 329. - } else {
- 330. - showMessage(response.error);
- 331. - }
- 332. - return true;
- 333. - }
- 334. - if (response && (response.ok || newclass == 2)) {
- 335. - var completeMessage = '';
- 336. - switch (unionType) {
- 337. - case 'ad': completeMessage = getLang('ads_archive_box_ad_complete'); break;
- 338. - case 'campaign': completeMessage = getLang('ads_archive_box_campaign_complete'); break;
- 339. - case 'client': completeMessage = getLang('ads_archive_box_client_complete'); break;
- 340. - }
- 341. - if (updateStatus) {
- 342. - if (newclass == 2) {
- 343. - updateStatus(response);
- 344. - } else {
- 345. - updateStatus(response.status, response.status_class, response.status_type, response.status_variants);
- 346. - }
- 347. - } else {
- 348. - showMessage(completeMessage, true, function() { nav.reload(); }, unionType);
- 349. - }
- 350. - }
- 351. - return true;
- 352. - }
- 353. -
- 354. - function showMessage(message, isSuccess, onHide, unionType) {
- 355. - var boxTitle = '';
- 356. - switch (unionType) {
- 357. - case 'ad': boxTitle = getLang('ads_archive_box_ad_title'); break;
- 358. - case 'campaign': boxTitle = getLang('ads_archive_box_campaign_title'); break;
- 359. - case 'client': boxTitle = getLang('ads_archive_box_client_title'); break;
- 360. - }
- 361. -
- 362. - var boxOptions = {};
- 363. - boxOptions.title = (isSuccess ? boxTitle : '������');
- 364. - boxOptions.width = 350;
- 365. - boxOptions.onHide = onHide;
- 366. - showFastBox(boxOptions, message);
- 367. - }
- 368. -
- 369. - function lockDeletion() {
- 370. - if (lock) {
- 371. - if (!lock()) {
- 372. - return false;
- 373. - }
- 374. - cur.deleteConfirmBox.hide();
- 375. - } else {
- 376. - if (cur.deleteUnionLocked) {
- 377. - return false;
- 378. - }
- 379. - cur.deleteUnionLocked = true;
- 380. - show('delete_union_progress');
- 381. - }
- 382. - return true;
- 383. - }
- 384. - function unlockDeletion() {
- 385. - if (unlock) {
- 386. - unlock()
- 387. - } else {
- 388. - cur.deleteUnionLocked = false;
- 389. - hide('delete_union_progress');
- 390. - }
- 391. - }
- 392. - }
- 393. -
- 394. - Ads.openChangeBudgetBox = function(unionId, moneyType, legal) {
- 395. - var ajaxParams = {};
- 396. - ajaxParams.union_id = unionId;
- 397. - if (moneyType) {
- 398. - ajaxParams[moneyType] = 1;
- 399. - }
- 400. - if (legal === 0 || legal === 1) {
- 401. - ajaxParams.legal = legal;
- 402. - }
- 403. -
- 404. - var showOptions = {params: {}};
- 405. - showOptions.onFail = Ads.onBoxFail;
- 406. - showOptions.params.width = 400;
- 407. - showOptions.params.bodyStyle = 'line-height: 160%;';
- 408. -
- 409. - cur.unionChangeBudgetBox = showBox('/ads?act=a_union_change_budget_box', ajaxParams, showOptions);
- 410. - }
- 411. -
- 412. - Ads.openReqsBox = function(event, unionId) {
- 413. - if (event && event.target.href && (event.which > 1 || event.button > 1 || event.ctrlKey || event.shiftKey || true)) {
- 414. - return true;
- 415. - }
- 416. -
- 417. - var ajaxParams = {}
- 418. - ajaxParams.union_id = unionId;
- 419. - ajaxParams.box = 1;
- 420. -
- 421. - var showOptions = {params: {}};
- 422. - showOptions.onFail = Ads.onBoxFail;
- 423. - showOptions.params.width = 400;
- 424. - showOptions.params.progress = 'reqs_progress';
- 425. -
- 426. - showBox('/ads?act=reqs_edit', ajaxParams, showOptions);
- 427. -
- 428. - return false;
- 429. - }
- 430. -
- 431. - Ads.openHelpBox = function(type, unionId) {
- 432. - var ajaxParams = {}
- 433. - ajaxParams.type = type;
- 434. - ajaxParams.union_id = unionId;
- 435. -
- 436. - var showOptions = {params: {}};
- 437. - showOptions.onFail = Ads.onBoxFail;
- 438. - showOptions.cache = 1;
- 439. - showOptions.params.width = 450;
- 440. -
- 441. - showBox('/ads?act=a_help_text', ajaxParams, showOptions);
- 442. - }
- 443. -
- 444. - Ads.openCreateOfficeBox = function() {
- 445. - var ajaxParams = {};
- 446. -
- 447. - var showOptions = {params: {}};
- 448. - showOptions.onFail = Ads.onBoxFail;
- 449. - showOptions.params.width = 350;
- 450. -
- 451. - showBox('/ads?act=a_create_office_box', ajaxParams, showOptions);
- 452. - }
- 453. -
- 454. - Ads.openDisableOfficeBox = function(unionId, hash, isCompany) {
- 455. - cur.lang.ads_disable_office_box_title = '�������� ���������� ��������';
- 456. - cur.lang.ads_disable_office_box_button = '������� �������';
- 457. - cur.lang.ads_disable_office_confirm_message = '�� ������� ��� ������ ������� ��������� �������?<br><br>����� �������� �������� � ��� ��������� ������ � ����������, �� ����� �������� �������� ����� ����������.';
- 458. - if (isCompany) {
- 459. - cur.lang.ads_disable_office_confirm_message += '<br><br>������ ����� �������� �������� ���� �������� ������ ���������� �����, ������������ � ����� ��������.';
- 460. - }
- 461. - var messageBox = showFastBox(getLang('ads_disable_office_box_title'), getLang('ads_disable_office_confirm_message'), getLang('ads_disable_office_box_button'), function() { Ads.disableOffice(unionId, hash, messageBox); }, getLang('box_cancel'));
- 462. - }
- 463. -
- 464. - Ads.disableOffice = function(unionId, hash, box) {
- 465. - var ajaxParams = {};
- 466. - ajaxParams.union_id = unionId;
- 467. - ajaxParams.hash = hash;
- 468. -
- 469. - ajax.post('/adsmoder?act=a_disable_office', ajaxParams, {onDone: onRequestComplete, onFail: onRequestComplete});
- 470. -
- 471. - function onRequestComplete(response) {
- 472. - if (response && response.redirect) {
- 473. - nav.reload();
- 474. - } else {
- 475. - box.hide();
- 476. - showFastBox(getLang('ads_error_box_title'), getLang('ads_error_text'));
- 477. - }
- 478. - return true;
- 479. - }
- 480. - }
- 481. -
- 482. - Ads.createExportSubmitButton = function(elem, bindingId, topUnionId) {
- 483. - var postIframe = ce((browser.msie && browser.version < 9.0) ? '<iframe name="secret_iframe">' : 'iframe', {name: 'secret_iframe', id: 'secret_iframe'});
- 484. - postIframe.style.display = 'none';
- 485. - document.body.appendChild(postIframe);
- 486. - var topUnionIdParam = (topUnionId ? '&union_id=' + topUnionId : '');
- 487. - var postForm = ce('form', {method: 'post', action: '/ads?act=get_export_stats' + topUnionIdParam, target: 'secret_iframe'});
- 488. - document.body.appendChild(postForm);
- 489. - var valueNames = [
- 490. - 'group_time',
- 491. - 'group_ads',
- 492. - 'method',
- 493. - 'stats_type',
- 494. - 'from_day',
- 495. - 'from_month',
- 496. - 'from_year',
- 497. - 'to_day',
- 498. - 'to_month',
- 499. - 'to_year',
- 500. - 'Ids'
- 501. - ];
- 502. - var valueContainers = {};
- 503. - for (var i = 0; i < valueNames.length; i++) {
- 504. - var curName = valueNames[i];
- 505. - valueContainers[curName] = ce('input', {
- 506. - type: 'hidden',
- 507. - id: curName + '_container_' + bindingId,
- 508. - name: curName
- 509. - });
- 510. - postForm.appendChild(valueContainers[curName]);
- 511. - }
- 512. -
- 513. - var errorBox;
- 514. - var action = function() {
- 515. - var postData = {}, elem, day;
- 516. - elem = geByClass('grouping_time_' + bindingId)[0];
- 517. - if (!elem) return;
- 518. - valueContainers.group_time.value = elem.getIndex();
- 519. -
- 520. - elem = geByClass('grouping_ads_' + bindingId)[0];
- 521. - if (!elem) return;
- 522. - valueContainers.group_ads.value = elem.getIndex();
- 523. -
- 524. - elem = geByClass('client_choose_' + bindingId);
- 525. - if (elem.length > 0) {
- 526. - elem = elem[0];
- 527. - var curClientId = elem.getIndex();
- 528. - }
- 529. -
- 530. - elem = geByClass('export_method_' + bindingId)[0];
- 531. - if (!elem) return;
- 532. - valueContainers.method.value = elem.getIndex();
- 533. - if (valueContainers.method.value == 3/*Web-interface*/) {
- 534. - postForm.target = '';
- 535. - }
- 536. -
- 537. - elem = geByClass('stats_type_' + bindingId)[0];
- 538. - if (!elem) return;
- 539. - valueContainers.stats_type.value = elem.getIndex();
- 540. -
- 541. - day = cur.exportParamsData.start_time;
- 542. - valueContainers.from_day.value = day.day;
- 543. - valueContainers.from_month.value = day.month;
- 544. - valueContainers.from_year.value = day.year;
- 545. -
- 546. - day = cur.exportParamsData.stop_time;
- 547. - valueContainers.to_day.value = day.day;
- 548. - valueContainers.to_month.value = day.month;
- 549. - valueContainers.to_year.value = day.year;
- 550. -
- 551. - if ((new Date(valueContainers.to_year.value, valueContainers.to_month.value, valueContainers.to_day.value)) <
- 552. - (new Date(valueContainers.from_year.value, valueContainers.from_month.value, valueContainers.from_day.value))) {
- 553. - showFastBox(getLang('ads_error_box_title'), getLang('ads_error_export_stat_invalid_period'));
- 554. - return;
- 555. - }
- 556. -
- 557. - var ids = [];
- 558. -
- 559. - elem = ge('paginated_table');
- 560. - var pt = elem.tableObj;
- 561. - var selection = pt.getSelection(0);
- 562. - switch (parseInt(valueContainers.group_ads.value)) {
- 563. - case 0:
- 564. - ids.push(elem.topId);
- 565. - break;
- 566. - case 1:
- 567. - for (var j = 0; j < selection.length; j++) {
- 568. - var clId = pt.content.extra['union_id'][selection[j]];
- 569. - ids.push(clId);
- 570. - }
- 571. - break;
- 572. - case 2:
- 573. - if (curClientId == 'aca') {
- 574. - for (var p in elem.contentDep) {
- 575. - if (!isNaN(Number(p))) {
- 576. - for (var i in elem.contentDep[p].extra['union_id']) {
- 577. - ids.push(elem.contentDep[p].extra['union_id'][i]);
- 578. - }
- 579. - }
- 580. - }
- 581. - } else {
- 582. - for (var i = 0; i < selection.length; i++) {
- 583. - ids.push(pt.content.extra['union_id'][selection[i]]);
- 584. - }
- 585. - }
- 586. - break;
- 587. - case 3:
- 588. - for (var i = 0; i < selection.length; i++) {
- 589. - ids.push(pt.content.extra['union_id'][selection[i]]);
- 590. - }
- 591. - break;
- 592. - default:
- 593. - return;
- 594. - }
- 595. -
- 596. - if (ids.length == 0) {
- 597. - showFastBox(getLang('ads_error_box_title'), getLang('ads_error_export_stat_no_campaigns_selected'));
- 598. - return;
- 599. -
- 600. - }
- 601. -
- 602. - valueContainers.Ids.value = '' + ids.join(',');
- 603. -
- 604. - postForm.submit();
- 605. - };
- 606. -
- 607. - createButton(elem, action);
- 608. - }
- 609. -
- 610. - Ads.createStaticDatePicker = function(elem, bindingId, classid, defaultDate) {
- 611. - elem = ge(elem);
- 612. - if (classid) elem.className = classid + '_' + bindingId;
- 613. -
- 614. - var spanDay = ce('span', {id: elem.id + '_day'}),
- 615. - spanMonth = ce('span', {id: elem.id + '_month'});
- 616. -
- 617. - if (!cur.exportParamsData) {
- 618. - cur.exportParamsData = {};
- 619. - }
- 620. - cur.exportParamsData[classid] = defaultDate;
- 621. -
- 622. - var params = {
- 623. - mode: 'd',
- 624. - day: defaultDate.day,
- 625. - month: defaultDate.month,
- 626. - year: defaultDate.year,
- 627. - width: 124,
- 628. - pastActive: true,
- 629. - onUpdate: function(d, m) {
- 630. - if (m == 'h') {
- 631. - cur.exportParamsData[classid].day = defaultDate.day;
- 632. - cur.exportParamsData[classid].month = defaultDate.month;
- 633. - cur.exportParamsData[classid].year = defaultDate.year;
- 634. - return;
- 635. - }
- 636. - if (m == 'd') {
- 637. - cur.exportParamsData[classid].day = d.d;
- 638. - } else if (m == 'm') {
- 639. - cur.exportParamsData[classid].day = 1;
- 640. - }
- 641. - cur.exportParamsData[classid].month = d.m;
- 642. - cur.exportParamsData[classid].year = d.y;
- 643. - }
- 644. - };
- 645. -
- 646. - if (!cur.exportUi) {
- 647. - cur.exportUi = {};
- 648. - }
- 649. - cur.exportUi[classid] = new Datepicker(elem, params);
- 650. - }
- 651. -
- 652. - Ads.openInnerTable = function(id, bindingId) {
- 653. - if (!id) id = 'acl';
- 654. -
- 655. - var tab = ge('paginated_table');
- 656. -
- 657. - var newOptions;
- 658. - switch (id) {
- 659. - case 'cli':
- 660. - newOptions = tab.optionsDep['cli'];
- 661. - break;
- 662. - case 'aca':
- 663. - case 'acl':
- 664. - newOptions = tab.optionsDep['default'];
- 665. - break;
- 666. - default:
- 667. - newOptions = tab.optionsDep['cam'];
- 668. - break;
- 669. - }
- 670. -
- 671. - if (id in tab.contentDep && tab.contentDep[id]) {
- 672. - var newContent = tab.contentDep[id];
- 673. - tab.tableObj.setOptions(newOptions);
- 674. - tab.tableObj.setContent(newContent);
- 675. - tab.tableObj.applyData();
- 676. - } else {
- 677. - function onDone(data) {
- 678. - var newContent = data;
- 679. - tab.contentDep[id] = newContent;
- 680. - tab.tableObj.setOptions(newOptions);
- 681. - tab.tableObj.setContent(newContent);
- 682. - tab.tableObj.applyData();
- 683. - hide('getting_campaigns_upload');
- 684. - }
- 685. - function onFail() {
- 686. - hide('getting_campaigns_upload');
- 687. - return true;
- 688. - };
- 689. - show('getting_campaigns_upload');
- 690. - ajax.post('/ads?act=a_get_client_children', {client_id: id}, {onDone: onDone, onFail: onFail});
- 691. - }
- 692. - }
- 693. -
- 694. - Ads.createStaticDropdownMenuAds = function(elem, bindingId, values, params) {
- 695. - elem = ge(elem);
- 696. -
- 697. - if (params.classname) elem.className = params.classname + '_' + bindingId;
- 698. - elem.className = elem.className + ' dd_link';
- 699. -
- 700. - elem.valueList = values;
- 701. - elem.getValue = function() {return elem.value;}
- 702. - elem.getIndex = function() {
- 703. - if (elem.index !== undefined) return elem.index;
- 704. -
- 705. - for (var i = 0; i < elem.valueList.length; i++) {
- 706. - if (elem.valueList[i][1] == elem.value) {
- 707. - return elem.valueList[i][0];
- 708. - }
- 709. - }
- 710. - return -1;
- 711. - }
- 712. -
- 713. - if (params.classname == 'client_choose') {
- 714. - onDomReady(function() {
- 715. - hide(geByClass('client_choose_row_' + bindingId)[0]);
- 716. - });
- 717. - }
- 718. - params.updateHeader = function(i, t) {
- 719. - if (!i) i = 'aca';
- 720. - Ads.openInnerTable(i, bindingId);
- 721. - elem.index = i;
- 722. - elem.value = t;
- 723. - return t;
- 724. - }
- 725. - params.onSelect = function(value) {
- 726. - if (value === undefined) value = uiDropdown.val();
- 727. - elem.value = value;
- 728. - elem.innerHTML = value;
- 729. - };
- 730. - params.target = elem;
- 731. - params.showHover = true;
- 732. - //params.alwaysMenuToUp = true;
- 733. -
- 734. - params.onSelect(values[0][1]);
- 735. -
- 736. - elem.uiDropdown = new DropdownMenu(values, params);
- 737. - Ads.makeDDScrollable(elem.uiDropdown);
- 738. - }
- 739. -
- 740. - // threshold is height of container
- 741. - Ads.makeDDScrollable = function(dd, threshold) {
- 742. - if (!dd) return;
- 743. - if (threshold === undefined) {
- 744. - threshold = 300;
- 745. - }
- 746. -
- 747. - var uiBody = dd.body,
- 748. - uiTable = geByClass('dd_menu_rows', uiBody)[0].firstChild,
- 749. - uiTableS = getSize(uiBody),
- 750. - uiTableW = uiTableS[0],
- 751. - uiTableH = uiTableS[1] - 4, // dont understand why
- 752. - barW = 6,
- 753. - barH = Math.max(20, intval(threshold * threshold / uiTableH)),
- 754. - scrollBar = ce('div', {className: 'ads_dropdown_menu_scrollbar'}, {
- 755. - top: barH / 10,
- 756. - right: 3,
- 757. - width: barW,
- 758. - height: barH
- 759. - });
- 760. -
- 761. - if (uiTableH < threshold) {
- 762. - return;
- 763. - }
- 764. -
- 765. - setStyle(uiTable.parentNode, {
- 766. - overflowY: 'hidden',
- 767. - height: threshold
- 768. - });
- 769. - uiBody.appendChild(scrollBar);
- 770. - setStyle(uiTable, 'position', 'relative');
- 771. -
- 772. - var startY = null,
- 773. - startTop = 0,
- 774. - hoverState = 0,
- 775. - hoverTimer = null;
- 776. - var onScroll = function(e) {
- 777. - var oldTop = parseFloat(getStyle(uiTable, 'top'));
- 778. - if (isNaN(oldTop)) {
- 779. - oldTop = 0;
- 780. - }
- 781. -
- 782. - var delta = e.wheelDelta ? e.wheelDelta / 120 : -e.detail / 3;
- 783. - scrollBody(oldTop + delta * 20);
- 784. -
- 785. - if (hoverTimer) {
- 786. - clearTimeout(hoverTimer);
- 787. - } else {
- 788. - doHover(1);
- 789. - }
- 790. - hoverTimer = setTimeout(function() {
- 791. - hoverTimer = null;
- 792. - doHover(-1);
- 793. - }, 200);
- 794. -
- 795. - cancelEvent(e);
- 796. - return false;
- 797. - }
- 798. - var onMouseMove = function(e) {
- 799. - if (startY === null) return;
- 800. - var y = e.pageY;
- 801. - var localD = startY - y,
- 802. - delta = 1.0 * localD * (uiTableH - threshold) / (threshold - barH - 5);
- 803. - scrollBody(startTop + delta);
- 804. - }
- 805. - var scrollBody = function(newTop) {
- 806. - newTop = Math.min(0, newTop);
- 807. - newTop = Math.max(-uiTableH + threshold, newTop);
- 808. -
- 809. - var barTop = 3 - 1.0 * newTop / (uiTableH - threshold) * (threshold - barH - 5);
- 810. - setStyle(uiTable, 'top', newTop);
- 811. - setStyle(scrollBar, 'top', barTop);
- 812. - }
- 813. - var onDown = function(e) {
- 814. - startY = e.pageY;
- 815. - startTop = parseFloat(getStyle(uiTable, 'top'));
- 816. - if (isNaN(startTop)) startTop = 0;
- 817. -
- 818. - doHover(1);
- 819. - cancelEvent(e);
- 820. - }
- 821. - var onUp = function(e) {
- 822. - if (startY !== null) {
- 823. - doHover(-1);
- 824. - }
- 825. - startY = null;
- 826. - }
- 827. - var doHover = function(dh) {
- 828. - hoverState += dh;
- 829. - if (hoverState == 0) removeClass(scrollBar, 'hovered');
- 830. - if (hoverState == 1) addClass(scrollBar, 'hovered');
- 831. - }
- 832. -
- 833. - dd.options.onShow = function() {
- 834. - scrollBody(100000);
- 835. - }
- 836. - addEvent(uiBody, 'mousewheel DOMMouseScroll', onScroll);
- 837. - addEvent(scrollBar, 'mousedown', onDown);
- 838. - addEvent(document.body, 'mouseup dragend', onUp);
- 839. - addEvent(uiBody, 'mousemove', onMouseMove);
- 840. -
- 841. - cur.destroy.push(function() {
- 842. - removeEvent(uiBody, 'mousewheel DOMMouseScroll', onScroll);
- 843. - removeEvent(scrollBar, 'mousedown', onDown);
- 844. - removeEvent(document.body, 'mouseup dragend', onUp);
- 845. - removeEvent(uiBody, 'mousemove', onMouseMove);
- 846. - });
- 847. - }
- 848. -
- 849. - // params must be ready to go to contructor
- 850. - Ads.createStaticDropdown = function(elem, bindingId, values, params) {
- 851. - elem = ge(elem);
- 852. - if (params.classname) elem.className = params.classname + '_' + bindingId;
- 853. - elem.className = elem.className + ' dd_link';
- 854. -
- 855. - elem.valueList = values;
- 856. - elem.getValue = function() {return elem.value;}
- 857. - elem.getIndex = function() {
- 858. - if (elem.index !== undefined) return elem.index;
- 859. -
- 860. - for (var i = 0; i < elem.valueList.length; i++) {
- 861. - if (elem.valueList[i][1] == elem.value) {
- 862. - return elem.valueList[i][0];
- 863. - }
- 864. - }
- 865. - return -1;
- 866. - }
- 867. -
- 868. - if (params.classname == 'client_choose') {
- 869. - onDomReady(function() {
- 870. - hide(geByClass('client_choose_row_' + bindingId)[0]);
- 871. - });
- 872. - }
- 873. -
- 874. - params.updateHeader = function(i, t) {
- 875. - if (!i) i = 0;
- 876. - //
- 877. - // grouping_time
- 878. - //
- 879. - if (elem.className.substring(0, 'grouping_time'.length) == 'grouping_time') {
- 880. - var modes = ['d', 'm', 'h'];
- 881. - cur.exportUi['start_time'].setMode(modes[i]);
- 882. - cur.exportUi['stop_time'].setMode(modes[i]);
- 883. - } else
- 884. - //
- 885. - // client_choose
- 886. - //
- 887. - if (elem.className.substring(0, 'client_choose'.length) == 'client_choose') {
- 888. - if (!i) i = 'aca';
- 889. - Ads.openInnerTable(i, bindingId);
- 890. - } else
- 891. - //
- 892. - // grouping_ads
- 893. - //
- 894. - if (elem.className.substring(0, 'grouping_ads'.length) == 'grouping_ads') {
- 895. - var label_el;
- 896. - switch (i) {
- 897. - case 0:
- 898. - hide(geByClass('client_choose_row_' + bindingId)[0]);
- 899. - Ads.openInnerTable('acl', bindingId);
- 900. -
- 901. - label_el = ge('unions_table_label_' + bindingId);
- 902. - label_el.innerHTML = getLang('ads_export_stat_data_title_campaigns');
- 903. - break;
- 904. - case 1:
- 905. - hide(geByClass('client_choose_row_' + bindingId)[0]);
- 906. - Ads.openInnerTable('cli', bindingId);
- 907. -
- 908. - label_el = ge('unions_table_label_' + bindingId);
- 909. - label_el.innerHTML = getLang('ads_export_stat_data_title_clients');
- 910. - break;
- 911. - case 2:
- 912. - var chser = geByClass('client_choose_' + bindingId)[0];
- 913. - var dd = chser.uiDropdown;
- 914. -
- 915. - var text = dd.options.updateHeader(0, chser.valueList[0][1]);
- 916. - dd.header.innerHTML = '<div>' + text + '</div>';
- 917. - if (dd.options.target) dd.options.target.innerHTML = text;
- 918. -
- 919. - show(geByClass('client_choose_row_' + bindingId)[0]);
- 920. - Ads.openInnerTable('aca', bindingId);
- 921. -
- 922. - label_el = ge('unions_table_label_' + bindingId);
- 923. - label_el.innerHTML = getLang('ads_export_stat_data_title_campaigns');
- 924. - break;
- 925. - case 3:
- 926. - Ads.openInnerTable('cam', bindingId);
- 927. - default:
- 928. - break;
- 929. - }
- 930. - }
- 931. -
- 932. - elem.index = i;
- 933. - elem.value = t;
- 934. - return t;
- 935. - }
- 936. - params.onSelect = function(value) {
- 937. - if (value === undefined) value = uiDropdown.val();
- 938. - elem.value = value;
- 939. - elem.innerHTML = value;
- 940. - };
- 941. - params.target = elem;
- 942. - params.showHover = true;
- 943. - //params.alwaysMenuToUp = true;
- 944. -
- 945. - params.onSelect(values[0][1]);
- 946. -
- 947. - elem.uiDropdown = new DropdownMenu(values, params);
- 948. - }
- 949. -
- 950. - Ads.createInlineStaticEdit = function(editElem, bindingId, params) {
- 951. - if (!params) params = {};
- 952. - editElem = ge(editElem);
- 953. - if (params.classname) editElem.className = params.classname + '_' + bindingId;
- 954. -
- 955. - var uiTimeDay, uiTimeMonth, uiTimeYear, uiAbstractDropdown;
- 956. -
- 957. - if (!params['type'] && !params['values']) return false;
- 958. -
- 959. - var defaultValue;
- 960. - if (params['default']) {
- 961. - defaultValue = params['default'];
- 962. - }
- 963. -
- 964. - var type = params['type'] || 'dropdown';
- 965. -
- 966. - switch (type) {
- 967. - case 'dropdown':
- 968. - if (params['values'] === undefined) {
- 969. - return false;
- 970. - }
- 971. - if (defaultValue === undefined) {
- 972. - defaultValue = 0;
- 973. - }
- 974. - break;
- 975. - case 'time':
- 976. - break;
- 977. - default:
- 978. - break;
- 979. - }
- 980. -
- 981. - monthNames = [
- 982. - getLang('ads_jan'),
- 983. - getLang('ads_feb'),
- 984. - getLang('ads_mar'),
- 985. - getLang('ads_apr'),
- 986. - getLang('ads_may'),
- 987. - getLang('ads_jun'),
- 988. - getLang('ads_jul'),
- 989. - getLang('ads_aug'),
- 990. - getLang('ads_sep'),
- 991. - getLang('ads_oct'),
- 992. - getLang('ads_nov'),
- 993. - getLang('ads_dec')
- 994. - ];
- 995. - saveValue(defaultValue);
- 996. -
- 997. - function saveValue(newValue) {
- 998. - editElem.value = newValue;
- 999. -
- 1000. - var newText = '';
- 1001. - switch (type) {
- 1002. - case 'time':
- 1003. - if (newValue && newValue.day && newValue.month && newValue.year) {
- 1004. - newText = newValue.day + ' ' + monthNames[newValue.month - 1] + ' ' + newValue.year;
- 1005. - }
- 1006. - break;
- 1007. - case 'dropdown':
- 1008. - if (parseInt(newValue) !== undefined) {
- 1009. - newText = params['values'][parseInt(newValue)];
- 1010. - } else
- 1011. - if (typeof newValue == 'string') {
- 1012. - newText = newValue;
- 1013. - } else {
- 1014. - for (var index in newValue) {
- 1015. - saveValue.call(this, newValue[index]);
- 1016. - return;
- 1017. - }
- 1018. - }
- 1019. - break;
- 1020. - default:
- 1021. - break;
- 1022. - }
- 1023. -
- 1024. - applyNewValue.call(this, newValue, newText);
- 1025. - }
- 1026. - function applyNewValue(newValue, newText) {
- 1027. - editElem.value = newValue;
- 1028. - editElem.innerHTML = newText;
- 1029. - }
- 1030. - function checkValue(value) {
- 1031. - return true;
- 1032. - }
- 1033. - function showLongError(error) {
- 1034. - showFastBox(getLang('ads_error_box_title'), error);
- 1035. - }
- 1036. - function updateTimeDays(month) {
- 1037. - uiTimeDay.setData(getDays(month));
- 1038. - }
- 1039. -
- 1040. - //
- 1041. - // Helpers
- 1042. - //
- 1043. - function getDays(month, year) {
- 1044. - var ret = [], days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- 1045. - if (!year) year = (new Date()).getFullYear();
- 1046. - if (month == 2 && year % 4 == 0) {
- 1047. - days[2] = 29
- 1048. - }
- 1049. - for (var i = 1, days = days[month]; i <= days; i++) {
- 1050. - ret.push(i);
- 1051. - }
- 1052. - return ret;
- 1053. - }
- 1054. - function getMonths() {
- 1055. - var months = [];
- 1056. - for (var i = 1; i <= 12; i++) {
- 1057. - months.push([i, monthNames[i - 1]]);
- 1058. - }
- 1059. - return months;
- 1060. - }
- 1061. - function getYears() {
- 1062. - var ret = [];
- 1063. - var curY = (new Date()).getFullYear();
- 1064. - for (var i = curY; i >= curY - 10; i--) {
- 1065. - ret.push(i);
- 1066. - }
- 1067. - return ret;
- 1068. - }
- 1069. - function getAssocFromValues(array) {
- 1070. - var res = [];
- 1071. - for (var i = 0; i < array.length; i++) {
- 1072. - res.push([i, array[i]]);
- 1073. - }
- 1074. - return res;
- 1075. - }
- 1076. -
- 1077. - //
- 1078. - // Events
- 1079. - //
- 1080. - function afterInit() {
- 1081. - var self = this;
- 1082. -
- 1083. - switch (type) {
- 1084. - case 'time':
- 1085. - uiTimeDay = new Dropdown(
- 1086. - geByClass('inline_time_day', this.contentTable)[0],
- 1087. - getDays(1),
- 1088. - {width: 45, height: 150, selectedItem: 1}
- 1089. - );
- 1090. - uiTimeMonth = new Dropdown(
- 1091. - geByClass('inline_time_month', this.contentTable)[0],
- 1092. - getMonths(),
- 1093. - {width: 80, height: 150, selectedItem: 1, onChange: function(value) { updateTimeDays.call(this, value); }}
- 1094. - );
- 1095. - uiTimeYear = new Dropdown(
- 1096. - geByClass('inline_time_year', this.contentTable)[0],
- 1097. - getYears(),
- 1098. - {width: 65, height: 150, selectedItem: (new Date()).getFullYear()}
- 1099. - );
- 1100. - break;
- 1101. -
- 1102. - case 'dropdown':
- 1103. - uiAbstractDropdown = new Dropdown(
- 1104. - geByClass('ads_inline_dropdown', this.contentTable)[0],
- 1105. - getAssocFromValues(params['values']),
- 1106. - {height: 150, selectedItem: 0}
- 1107. - );
- 1108. - break;
- 1109. -
- 1110. - default:
- 1111. - break;
- 1112. - }
- 1113. - }
- 1114. - function onBeforeShow() {
- 1115. - switch (type) {
- 1116. - case 'time':
- 1117. - if (defaultValue && defaultValue.day && defaultValue.month && defaultValue.year) {
- 1118. - uiTimeDay.val(defaultValue.day);
- 1119. - uiTimeMonth.val(defaultValue.month);
- 1120. - uiTimeYear.val(defaultValue.year);
- 1121. - } else {
- 1122. - editElem.innerHTML = "�� ������";
- 1123. - }
- 1124. - break;
- 1125. -
- 1126. - case 'dropdown':
- 1127. - uiAbstractDropdown.val(defaultValue);
- 1128. - break;
- 1129. -
- 1130. - default:
- 1131. - break;
- 1132. - }
- 1133. - }
- 1134. - function onShow() {
- 1135. - }
- 1136. - function onConfirm() {
- 1137. - var newValue;
- 1138. - if (type == 'time') {
- 1139. - newValue = {};
- 1140. - newValue.day = uiTimeDay.val();
- 1141. - newValue.month = uiTimeMonth.val();
- 1142. - newValue.year = uiTimeYear.val();
- 1143. - } else
- 1144. - if (type == 'dropdown') {
- 1145. - newValue = uiAbstractDropdown.val();
- 1146. - }
- 1147. -
- 1148. - saveValue.call(this, newValue);
- 1149. - return true;
- 1150. - }
- 1151. -
- 1152. - var options = {
- 1153. - afterInit: afterInit,
- 1154. - onBeforeShow: onBeforeShow,
- 1155. - onShow: onShow,
- 1156. - onConfirm: onConfirm
- 1157. - };
- 1158. -
- 1159. - switch (type) {
- 1160. - case 'time':
- 1161. - options.contentHTML =
- 1162. - '<tr>' +
- 1163. - '<td colspan="2">' +
- 1164. - '<table class="ads_inline_edit_table">' +
- 1165. - '<tr>' +
- 1166. - '<td style="white-space: nowrap; width: 200px;">' +
- 1167. - '<table class="ads_inline_edit_table">' +
- 1168. - '<tr>' +
- 1169. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_day text" style="width: 30px;" /></td>' +
- 1170. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_month text" style="width: 30px;" /></td>' +
- 1171. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_year text" style="width: 30px;" /></td>' +
- 1172. - '</tr>' +
- 1173. - '</table>' +
- 1174. - '</td>' +
- 1175. - '</tr>' +
- 1176. - '</table>' +
- 1177. - '</td>' +
- 1178. - '</tr>';
- 1179. - break;
- 1180. - case 'dropdown':
- 1181. - options.contentHTML =
- 1182. - '<tr>' +
- 1183. - '<td colspan="2">' +
- 1184. - '<table class="ads_inline_edit_table" style="width: 100%;">' +
- 1185. - '<tr><td><input type="text" class="ads_inline_dropdown text" /></td></tr>' +
- 1186. - '</table>' +
- 1187. - '</td>' +
- 1188. - '</tr>';
- 1189. - break;
- 1190. - default:
- 1191. - break;
- 1192. - }
- 1193. -
- 1194. - new InlineEdit(editElem, options);
- 1195. - }
- 1196. -
- 1197. - Ads.onInlineEditClick = function(elem, callback, rown, coln) {
- 1198. - var _t = this;
- 1199. -
- 1200. - var editElem = elem,
- 1201. - progressElem = _t.content.extra.progress_elem[rown][coln],
- 1202. - unionId = _t.content.extra.union_id[rown][coln],
- 1203. - unionType = _t.content.extra.union_type[rown][coln],
- 1204. - valueType = _t.content.extra.value_type[rown][coln],
- 1205. - initValue = _t.content.extra.init_value[rown][coln],
- 1206. - hash = _t.content.extra.hash[rown][coln],
- 1207. - additionalParams = extend(_t.content.extra.additional_params[rown][coln], {
- 1208. - valCallback: function(val) {
- 1209. - callback({
- 1210. - value: val,
- 1211. - extra: {
- 1212. - init_value: val
- 1213. - }
- 1214. - });
- 1215. - }
- 1216. - });
- 1217. -
- 1218. - var ret = Ads.createInlineEdit(editElem, progressElem, unionType, unionId, valueType, initValue, hash, additionalParams);
- 1219. - ret.obj.show();
- 1220. - }
- 1221. -
- 1222. - Ads.createInlineEdit = function(editElem, progressElem, unionType, unionId, valueType, initValue, hash, additionalParams) {
- 1223. - editElem = ge(editElem);
- 1224. - progressElem = ge(progressElem);
- 1225. - var defaultValue = initValue;
- 1226. - var bad_this = this;
- 1227. -
- 1228. - var uiTimeDay, uiTimeMonth, uiTimeHour;
- 1229. -
- 1230. - var valueGeneralType;
- 1231. - switch (valueType) {
- 1232. - case 'cost_per_click':
- 1233. - valueGeneralType = 'cost_per_click';
- 1234. - break;
- 1235. - case 'day_limit':
- 1236. - case 'month_limit':
- 1237. - case 'all_limit':
- 1238. - case 'contract_limit':
- 1239. - valueGeneralType = 'limit';
- 1240. - break;
- 1241. - case 'start_time':
- 1242. - case 'stop_time':
- 1243. - valueGeneralType = 'time';
- 1244. - break;
- 1245. - default:
- 1246. - valueGeneralType = 'text';
- 1247. - break;
- 1248. - }
- 1249. -
- 1250. - function saveValue(newValue, isRemoveValue) {
- 1251. -
- 1252. - if (valueGeneralType == 'limit') {
- 1253. - if ((!isRemoveValue && defaultValue == newValue) || (isRemoveValue && defaultValue == 0)) {
- 1254. - if (isRemoveValue) {
- 1255. - this.hide();
- 1256. - }
- 1257. - return;
- 1258. - }
- 1259. - } else {
- 1260. - if (defaultValue == newValue) {
- 1261. - return;
- 1262. - }
- 1263. - }
- 1264. -
- 1265. - var unknownError = getLang('ads_error_unexpected_error_try_later');
- 1266. -
- 1267. - var params = {};
- 1268. - params.union_id = unionId;
- 1269. - params.hash = hash;
- 1270. - extend(params, additionalParams);
- 1271. -
- 1272. - if (isRemoveValue) {
- 1273. - params[valueType] = 0;
- 1274. - } else {
- 1275. - if (valueGeneralType == 'time') {
- 1276. - params[valueType + '_day'] = newValue.day;
- 1277. - params[valueType + '_month'] = newValue.month;
- 1278. - params[valueType + '_hour'] = newValue.hour;
- 1279. - } else {
- 1280. - params[valueType] = newValue;
- 1281. - }
- 1282. - }
- 1283. -
- 1284. - var self = this;
- 1285. -
- 1286. - function onAjaxComplete(response) {
- 1287. - if (isObject(response)) {
- 1288. - if (response.error) {
- 1289. - showLongError.call(self, response.error);
- 1290. - } else if (!response.not_changed) {
- 1291. - if ((valueType + '_value') in response) {
- 1292. - applyNewValue.call(self, response[valueType + '_value'], response[valueType + '_text']);
- 1293. - } else if (response[valueType + '_value_day']) {
- 1294. - var newValue = {};
- 1295. - newValue.day = response[valueType + '_value_day'];
- 1296. - newValue.month = response[valueType + '_value_month'];
- 1297. - newValue.hour = response[valueType + '_value_hour'];
- 1298. - applyNewValue.call(self, newValue, response[valueType + '_text']);
- 1299. - } else {
- 1300. - showLongError.call(self, unknownError);
- 1301. - }
- 1302. - }
- 1303. - } else {
- 1304. - showLongError.call(self, unknownError);
- 1305. - }
- 1306. -
- 1307. - hide(progressElem);
- 1308. - show(editElem);
- 1309. -
- 1310. - return true;
- 1311. - }
- 1312. - ajax.post('/ads?act=a_unions_general_info_save', params, {onDone: onAjaxComplete, onFail: onAjaxComplete});
- 1313. -
- 1314. - hide(editElem);
- 1315. - show(progressElem);
- 1316. - if (isRemoveValue) {
- 1317. - this.hide();
- 1318. - }
- 1319. - }
- 1320. - function applyNewValue(newValue, newText) {
- 1321. - if (valueType == 'name') {
- 1322. - Ads.updateUnionName(unionId, newText);
- 1323. - }
- 1324. - defaultValue = newValue;
- 1325. - if (additionalParams.valCallback) {
- 1326. - additionalParams.valCallback(newValue);
- 1327. - } else {
- 1328. - editElem.innerHTML = newText;
- 1329. - }
- 1330. - }
- 1331. - function checkValue(value) {
- 1332. - switch (valueGeneralType) {
- 1333. - case 'cost_per_click':
- 1334. - if (value == '' || value == '0' || value == 0) {
- 1335. - return getLang('ads_error_cost_per_click_no_value');
- 1336. - }
- 1337. - if (!value.match(/[0-9.,]/)) {
- 1338. - return (additionalParams.is_cost_per_click ? getLang('ads_error_cost_per_click_invalid_value') : getLang('ads_error_cost_per_views_invalid_value'));
- 1339. - }
- 1340. - value = value.replace(',', '.');
- 1341. -
- 1342. - var valueFloat = parseFloat(value);
- 1343. - var suffixesAll = '';
- 1344. - suffixesAll += (additionalParams.is_cost_per_click ? '_click' : '_views');
- 1345. - suffixesAll += (additionalParams.is_exclusive_ad ? '_exclusive' : '');
- 1346. - suffixesAll += (additionalParams.is_app_admin ? '_app' : '');
- 1347. - var minValue = cur.unionsLimits['cost_per' + suffixesAll + '_min'];
- 1348. - var maxValue = cur.unionsLimits['cost_per' + suffixesAll + '_max'];
- 1349. - var minErrorLangKey = (additionalParams.is_cost_per_click ? 'ads_error_cost_per_click_min_value' : 'ads_error_cost_per_views_min_value');
- 1350. - var maxErrorLangKey = (additionalParams.is_cost_per_click ? 'ads_error_cost_per_click_max_value' : 'ads_error_cost_per_views_max_value');
- 1351. - if (valueFloat < minValue) {
- 1352. - return getLang(minErrorLangKey).replace('{money}', getLang('global_money_amount_rub', minValue));
- 1353. - }
- 1354. - if (valueFloat > maxValue) {
- 1355. - return getLang(maxErrorLangKey).replace('{money}', getLang('global_money_amount_rub', maxValue));
- 1356. - }
- 1357. -
- 1358. - if (!value.match(cur.unionsLimits.cost_per_click_pattern)) {
- 1359. - return (additionalParams.is_cost_per_click ? getLang('ads_error_cost_per_click_invalid_value') : getLang('ads_error_cost_per_views_invalid_value'));
- 1360. - }
- 1361. - return true;
- 1362. - case 'limit':
- 1363. - if (value == '' || value == '0' || value == 0) {
- 1364. - return getLang('ads_error_limit_no_value');
- 1365. - }
- 1366. - if (!value.match(/[0-9.,]/)) {
- 1367. - return getLang('ads_error_limit_invalid_value');
- 1368. - }
- 1369. - if (value.indexOf('.') != -1 || value.indexOf(',') != -1) {
- 1370. - return getLang('ads_error_limit_integer_value');
- 1371. - }
- 1372. - if (parseInt(value) < cur.unionsLimits.limit_min) {
- 1373. - return getLang('ads_error_limit_min_value').replace('{money}', getLang('global_money_amount_rub', cur.unionsLimits.limit_min));
- 1374. - }
- 1375. - if (parseInt(value) > cur.unionsLimits.limit_max) {
- 1376. - return getLang('ads_error_limit_large_value');
- 1377. - }
- 1378. - if (!value.match(cur.unionsLimits.limit_pattern)) {
- 1379. - return getLang('ads_error_limit_invalid_value');
- 1380. - }
- 1381. - return true;
- 1382. - }
- 1383. - switch (valueType) {
- 1384. - case 'name':
- 1385. - if (value == '') {
- 1386. - if (unionType == 4) { // Top union
- 1387. - // Nothing
- 1388. - } else if (unionType == 2) {
- 1389. - return getLang('ads_error_client_name_no_value');
- 1390. - } else if (unionType == 1) {
- 1391. - return getLang('ads_error_campaign_name_no_value');
- 1392. - }
- 1393. - }
- 1394. - return true;
- 1395. - }
- 1396. - if (additionalParams.server_check) {
- 1397. - return true;
- 1398. - } else {
- 1399. - return false;
- 1400. - }
- 1401. - }
- 1402. -
- 1403. - function showFastError(error) {
- 1404. - geByClass('ads_inline_fast_error', this.fastErrorRow)[0].innerHTML = error;
- 1405. - show(this.fastErrorRow);
- 1406. - }
- 1407. - function hideFastError() {
- 1408. - hide(this.fastErrorRow);
- 1409. - geByClass('ads_inline_fast_error', this.fastErrorRow)[0].innerHTML = '';
- 1410. - }
- 1411. - function showLongError(error) {
- 1412. - showFastBox(getLang('ads_error_box_title'), error);
- 1413. - }
- 1414. - function removeValue() {
- 1415. - saveValue.call(this, false, true);
- 1416. - return true;
- 1417. - }
- 1418. - function updateTimeDays(month) {
- 1419. - uiTimeDay.setData(getDays(month));
- 1420. - }
- 1421. -
- 1422. - //
- 1423. - // Helpers
- 1424. - //
- 1425. - function getDays(month) {
- 1426. - var ret = [], days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- 1427. - if (month == 2 && (new Date()).getFullYear() % 4 == 0) {
- 1428. - days[2] = 29
- 1429. - }
- 1430. - for (var i = 1, days = days[month]; i <= days; i++) {
- 1431. - ret.push(i);
- 1432. - }
- 1433. - return ret;
- 1434. - }
- 1435. - function getMonths() {
- 1436. - var months = [];
- 1437. - months.push([1, getLang('ads_jan')]);
- 1438. - months.push([2, getLang('ads_feb')]);
- 1439. - months.push([3, getLang('ads_mar')]);
- 1440. - months.push([4, getLang('ads_apr')]);
- 1441. - months.push([5, getLang('ads_may')]);
- 1442. - months.push([6, getLang('ads_jun')]);
- 1443. - months.push([7, getLang('ads_jul')]);
- 1444. - months.push([8, getLang('ads_aug')]);
- 1445. - months.push([9, getLang('ads_sep')]);
- 1446. - months.push([10, getLang('ads_oct')]);
- 1447. - months.push([11, getLang('ads_nov')]);
- 1448. - months.push([12, getLang('ads_dec')]);
- 1449. - return months;
- 1450. - }
- 1451. - function getHours() {
- 1452. - var ret = [];
- 1453. - for (var i = 0; i < 24; i++) {
- 1454. - ret.push([i, i + ':00']);
- 1455. - }
- 1456. - return ret;
- 1457. - }
- 1458. -
- 1459. - //
- 1460. - // Events
- 1461. - //
- 1462. - function afterInit() {
- 1463. - var self = this;
- 1464. -
- 1465. - if (valueGeneralType == 'limit' || valueGeneralType == 'time') {
- 1466. - this.removeValueAnchor = geByClass('ads_inline_edit_remove_value', this.contentTable)[0];
- 1467. - addEvent(this.removeValueAnchor, 'click', function() { removeValue.call(self); return false; });
- 1468. - }
- 1469. -
- 1470. - if (valueGeneralType == 'time') {
- 1471. - uiTimeDay = new Dropdown(
- 1472. - geByClass('inline_time_day', this.contentTable)[0],
- 1473. - getDays(1),
- 1474. - {width: 45, height: 150, selectedItem: 1}
- 1475. - );
- 1476. - uiTimeMonth = new Dropdown(
- 1477. - geByClass('inline_time_month', this.contentTable)[0],
- 1478. - getMonths(),
- 1479. - {width: 80, height: 150, selectedItem: 1, onChange: function(value) { updateTimeDays.call(this, value); }}
- 1480. - );
- 1481. - uiTimeHour = new Dropdown(
- 1482. - geByClass('inline_time_hour', this.contentTable)[0],
- 1483. - getHours(),
- 1484. - {width: 65, height: 150, selectedItem: 0}
- 1485. - );
- 1486. - }
- 1487. -
- 1488. - this.fastErrorRow = geByClass('ads_inline_fast_error_row', this.contentTable)[0];
- 1489. -
- 1490. - if (this.input) {
- 1491. - this.is_user_action = true;
- 1492. - addEvent(this.input, 'keyup', function(event) {
- 1493. - if (event.keyCode != 13) {
- 1494. - hideFastError.call(self);
- 1495. - }
- 1496. - }
- 1497. - );
- 1498. - }
- 1499. - }
- 1500. - function onBeforeShow() {
- 1501. - if (this.input) {
- 1502. - this.input.value = defaultValue;
- 1503. - }
- 1504. -
- 1505. - if (valueGeneralType == 'time') {
- 1506. - uiTimeDay.val(defaultValue.day);
- 1507. - uiTimeMonth.val(defaultValue.month);
- 1508. - uiTimeHour.val(defaultValue.hour);
- 1509. - }
- 1510. -
- 1511. - hideFastError.call(this);
- 1512. -
- 1513. - var self = this;
- 1514. - if (valueGeneralType == 'cost_per_click' && !this.recommended_cost_loaded) {
- 1515. - var recommendedCostProgress = geByClass('inline_recommended_cost_progress', this.contentTable)[0];
- 1516. - var recommendedCostText = geByClass('ads_inline_recommended_cost_text', this.contentTable)[0];
- 1517. -
- 1518. - function onDone(response) {
- 1519. - if (response && response.recommended_costs && response.recommended_costs.cost_text) {
- 1520. - recommendedCostText.innerHTML = response.recommended_costs.cost_text;
- 1521. - hide(recommendedCostProgress);
- 1522. - show(recommendedCostText);
- 1523. - if (!this.is_user_action && self.input.value == '0') {
- 1524. - self.input.value = response.recommended_costs.cost_value;
- 1525. - }
- 1526. - self.recommended_cost_loaded = true;
- 1527. - }
- 1528. - };
- 1529. - var ajaxParams = {ad_id: unionId};
- 1530. - ajax.post('/ads?act=a_get_recommended_cost', ajaxParams, {onDone: onDone});
- 1531. - }
- 1532. - }
- 1533. - function onShow() {
- 1534. - if (this.input) {
- 1535. - elfocus(this.input);
- 1536. - }
- 1537. - }
- 1538. - function onConfirm() {
- 1539. - var newValue;
- 1540. - if (valueGeneralType == 'time') {
- 1541. - newValue = {};
- 1542. - newValue.day = uiTimeDay.val();
- 1543. - newValue.month = uiTimeMonth.val();
- 1544. - newValue.hour = uiTimeHour.val();
- 1545. - } else {
- 1546. - newValue = this.input.value;
- 1547. -
- 1548. - var checkResult = checkValue.call(this, newValue, valueType);
- 1549. - if (typeof(checkResult) == 'string') {
- 1550. - showFastError.call(this, checkResult);
- 1551. - return false;
- 1552. - }
- 1553. - if (checkResult !== true) {
- 1554. - showFastError.call(this, getLang('ads_error_unknown_error'));
- 1555. - return false;
- 1556. - }
- 1557. - }
- 1558. -
- 1559. - saveValue.call(this, newValue, false);
- 1560. - return true;
- 1561. - }
- 1562. -
- 1563. - var options = {
- 1564. - afterInit: afterInit,
- 1565. - onBeforeShow: onBeforeShow,
- 1566. - onShow: onShow,
- 1567. - onConfirm: onConfirm
- 1568. - };
- 1569. -
- 1570. - switch (valueGeneralType) {
- 1571. - case 'cost_per_click':
- 1572. - options.contentHTML =
- 1573. - '<tr>' +
- 1574. - '<td colspan="2">' +
- 1575. - '<table class="ads_inline_edit_table" style="width: 100%;">' +
- 1576. - '<tr><td><input class="inlInput text" type="text" /></td></tr>' +
- 1577. - '<tr><td style="padding-top: 7px; height: 22px;">' +
- 1578. - '<img class="inline_recommended_cost_progress" src="images/upload.gif" />' +
- 1579. - '<span class="ads_inline_recommended_cost_text"></span>' +
- 1580. - '<div style="width: 275px; height: 1px;"></div>' +
- 1581. - '</td></tr>' +
- 1582. - '<tr class="ads_inline_fast_error_row"><td><div class="ads_inline_fast_error"></div></td></tr>' +
- 1583. - '</table>' +
- 1584. - '</td>' +
- 1585. - '</tr>';
- 1586. - break;
- 1587. - case 'limit':
- 1588. - options.contentHTML =
- 1589. - '<tr>' +
- 1590. - '<td colspan="2">' +
- 1591. - '<table class="ads_inline_edit_table">' +
- 1592. - '<tr>' +
- 1593. - '<td><input class="inlInput text" type="text" /></td>' +
- 1594. - '<td><a class="ads_inline_edit_remove_value" href="#">' + getLang('ads_inline_edit_remove_limit') + '</a></td>' +
- 1595. - '</tr>' +
- 1596. - '<tr class="ads_inline_fast_error_row"><td colspan="2"><div class="ads_inline_fast_error"></div></td></tr>' +
- 1597. - '</table>' +
- 1598. - '</td>' +
- 1599. - '</tr>';
- 1600. - break;
- 1601. - case 'time':
- 1602. - var removeValueText;
- 1603. - switch (valueType) {
- 1604. - case 'start_time': removeValueText = getLang('ads_inline_edit_remove_start_time'); break;
- 1605. - case 'stop_time': removeValueText = getLang('ads_inline_edit_remove_stop_time'); break;
- 1606. - }
- 1607. - options.contentHTML =
- 1608. - '<tr>' +
- 1609. - '<td colspan="2">' +
- 1610. - '<table class="ads_inline_edit_table">' +
- 1611. - '<tr>' +
- 1612. - '<td style="white-space: nowrap; width: 200px;">' +
- 1613. - '<table class="ads_inline_edit_table">' +
- 1614. - '<tr>' +
- 1615. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_day text" style="width: 30px;" /></td>' +
- 1616. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_month text" style="width: 30px;" /></td>' +
- 1617. - '<td style="padding-right: 5px;"><input type="text" class="inline_time_hour text" style="width: 30px;" /></td>' +
- 1618. - '</tr>' +
- 1619. - '</table>' +
- 1620. - '</td>' +
- 1621. - '</tr>' +
- 1622. - '<tr><td style="padding-top: 7px;"><a class="ads_inline_edit_remove_value" style="padding-left: 0;" href="#">' + removeValueText + '</a></td></tr>' +
- 1623. - '<tr class="ads_inline_fast_error_row"><td colspan="2"><div class="ads_inline_fast_error"></div></td></tr>' +
- 1624. - '</table>' +
- 1625. - '</td>' +
- 1626. - '</tr>';
- 1627. - break;
- 1628. - case 'text':
- 1629. - options.contentHTML =
- 1630. - '<tr>' +
- 1631. - '<td colspan="2">' +
- 1632. - '<table class="ads_inline_edit_table" style="width: 100%;">' +
- 1633. - '<tr><td><input class="inlInput text" type="text" /></td></tr>' +
- 1634. - '<tr class="ads_inline_fast_error_row"><td><div class="ads_inline_fast_error"></div></td></tr>' +
- 1635. - '</table>' +
- 1636. - '</td>' +
- 1637. - '</tr>';
- 1638. - break;
- 1639. - }
- 1640. -
- 1641. - var ret = {
- 1642. - target: editElem,
- 1643. - options: options
- 1644. - };
- 1645. - if (this.getOptionsOnly) { // dirty hack.
- 1646. - return ret;
- 1647. - }
- 1648. - ret.obj = new InlineEdit(editElem, options);
- 1649. -
- 1650. - var accessFunctions = {
- 1651. - applyNewValue: applyNewValue
- 1652. - }
- 1653. -
- 1654. - if (!cur.inlineEditControls) {
- 1655. - cur.inlineEditControls = {};
- 1656. - }
- 1657. - cur.inlineEditControls[valueType + '_' + unionId] = accessFunctions;
- 1658. -
- 1659. - return ret;
- 1660. - }
- 1661. -
- 1662. - Ads.createInlineDropdownMenu = function(menuElem, boxElem, progressElem, unionId, valueType, items, initValue, hash, additionalParams) {
- 1663. - menuElem = ge(menuElem);
- 1664. - boxElem = ge(boxElem);
- 1665. - progressElem = ge(progressElem);
- 1666. - var defaultValue = initValue;
- 1667. -
- 1668. - var self;
- 1669. -
- 1670. - function saveValue(newValue) {
- 1671. -
- 1672. - if (newValue == defaultValue) {
- 1673. - return;
- 1674. - }
- 1675. -
- 1676. - var unknownError = getLang('ads_error_unexpected_error_try_later');
- 1677. -
- 1678. - var params = {};
- 1679. - params.union_id = unionId;
- 1680. - params.hash = hash;
- 1681. - extend(params, additionalParams);
- 1682. - params[valueType] = newValue;
- 1683. -
- 1684. - function onAjaxComplete(response) {
- 1685. - if (isObject(response)) {
- 1686. - if (response.error) {
- 1687. - showLongError.call(self, response.error);
- 1688. - } else if (!response.not_changed) {
- 1689. - if (response[valueType + '_value'] !== undefined) {
- 1690. - applyNewValue(response[valueType + '_value'], response[valueType + '_text']);
- 1691. - if (additionalParams.reload) {
- 1692. - nav.reload();
- 1693. - }
- 1694. - } else {
- 1695. - showLongError.call(self, unknownError);
- 1696. - }
- 1697. - }
- 1698. - } else {
- 1699. - showLongError.call(self, unknownError);
- 1700. - }
- 1701. -
- 1702. - hide(progressElem);
- 1703. - show(boxElem);
- 1704. -
- 1705. - return true;
- 1706. - }
- 1707. - ajax.post('/ads?act=a_unions_general_info_save', params, {onDone: onAjaxComplete, onFail: onAjaxComplete});
- 1708. -
- 1709. - hide(boxElem);
- 1710. - show(progressElem);
- 1711. - }
- 1712. -
- 1713. - function applyNewValue(newValue, newText) {
- 1714. - defaultValue = newValue;
- 1715. - self.setOptions({title: newText});
- 1716. - menuElem.innerHTML = newText;
- 1717. - }
- 1718. - function showLongError(error) {
- 1719. - showFastBox(getLang('ads_error_box_title'), error);
- 1720. - }
- 1721. -
- 1722. - function onMenuChange(event) {
- 1723. - var newValue = event.target.index;
- 1724. - saveValue(newValue);
- 1725. - }
- 1726. -
- 1727. - var options = {};
- 1728. - options.target = menuElem;
- 1729. - options.onSelect = onMenuChange;
- 1730. - options.showHover = false;
- 1731. - options.updateTarget = false;
- 1732. - self = new DropdownMenu(items, options);
- 1733. - }
- 1734. -
- 1735. - Ads.MultiDropdownMenu = function(items, options) {
- 1736. - var dropdownMenu;
- 1737. - var selectedItems = {};
- 1738. - var curItems = [];
- 1739. -
- 1740. - function onItemClick(e) {
- 1741. - if (e.target.className == 'ads_dd_menu_item_checkbox_on') {
- 1742. - selectedItems[e.target.index] = false;
- 1743. - e.target.className = 'ads_dd_menu_item_checkbox_off';
- 1744. - } else {
- 1745. - selectedItems[e.target.index] = true;
- 1746. - e.target.className = 'ads_dd_menu_item_checkbox_on';
- 1747. - }
- 1748. - return false;
- 1749. - }
- 1750. -
- 1751. - for (var i in items) {
- 1752. - curItems[i] = {};
- 1753. - for (var j in items[i]) {
- 1754. - curItems[i][j] = items[i][j];
- 1755. - }
- 1756. - curItems[i].onClick = onItemClick;
- 1757. - curItems[i].c = 'ads_dd_menu_item_checkbox_off';
- 1758. - selectedItems[curItems[i].i] = false;
- 1759. - }
- 1760. -
- 1761. - dropdownMenu = new DropdownMenu(curItems, options);
- 1762. - dropdownMenu.getSelectedItems = function() {
- 1763. - var selectedItemsResult = [];
- 1764. - for (var i in selectedItems) {
- 1765. - if (selectedItems[i]) {
- 1766. - selectedItemsResult.push(i);
- 1767. - }
- 1768. - }
- 1769. - return selectedItemsResult;
- 1770. - }
- 1771. -
- 1772. - return dropdownMenu;
- 1773. - }
- 1774. -
- 1775. - Ads.getCampaignsTotalLabel = function(total) {
- 1776. - var type = this._curFilter;
- 1777. - if (typeof type == 'object') type = type[0];
- 1778. - if (!this._curSearchString || this._curSearchString == '') {
- 1779. - switch (type) {
- 1780. - case 0: return getLang('ads_stopped_campaigns_total', total);
- 1781. - case 1: return getLang('ads_running_campaigns_total', total);
- 1782. - case 3: return getLang('ads_planned_campaigns_total', total);
- 1783. - case 4: return getLang('ads_archived_campaigns_total', total);
- 1784. - default: return getLang('ads_active_campaigns_total', total);
- 1785. - }
- 1786. - } else {
- 1787. - switch (type) {
- 1788. - case 0: return getLang('ads_stopped_campaigns_found', total);
- 1789. - case 1: return getLang('ads_running_campaigns_found', total);
- 1790. - case 3: return getLang('ads_planned_campaigns_found', total);
- 1791. - case 4: return getLang('ads_archived_campaigns_found', total);
- 1792. - default: return getLang('ads_active_campaigns_found', total);
- 1793. - }
- 1794. - }
- 1795. - }
- 1796. -
- 1797. - Ads.getNoCampaignsLabel = function() {
- 1798. - var type = this._curFilter;
- 1799. - if (typeof type == 'object') type = type[0];
- 1800. - if (!this._curSearchString || this._curSearchString == '') {
- 1801. - switch (type) {
- 1802. - case 0: return getLang('ads_no_stopped_campaigns');
- 1803. - case 1: return getLang('ads_no_running_campaigns');
- 1804. - case 3: return getLang('ads_no_planned_campaigns');
- 1805. - case 4: return getLang('ads_no_archived_campaigns');
- 1806. - default: return getLang('ads_no_active_campaigns');
- 1807. - }
- 1808. - } else {
- 1809. - switch (type) {
- 1810. - case 0: return getLang('ads_no_stopped_campaigns_found');
- 1811. - case 1: return getLang('ads_no_running_campaigns_found');
- 1812. - case 3: return getLang('ads_no_planned_campaigns_found');
- 1813. - case 4: return getLang('ads_no_archived_campaigns_found');
- 1814. - default: return getLang('ads_no_active_campaigns_found');
- 1815. - }
- 1816. - }
- 1817. - }
- 1818. -
- 1819. - Ads.getAdsTotalLabel = function(total) {
- 1820. - var type = this._curFilter;
- 1821. - if (typeof type == 'object') type = type[0];
- 1822. - if (!this._curSearchString || this._curSearchString == '') {
- 1823. - switch (type) {
- 1824. - case 0: return getLang('ads_stopped_ads_total', total);
- 1825. - case 1: return getLang('ads_running_ads_total', total);
- 1826. - case 3: return getLang('ads_planned_ads_total', total);
- 1827. - case 4: return getLang('ads_archived_ads_total', total);
- 1828. - default: return getLang('ads_active_ads_total', total);
- 1829. - }
- 1830. - } else {
- 1831. - switch (type) {
- 1832. - case 0: return getLang('ads_stopped_ads_found', total);
- 1833. - case 1: return getLang('ads_running_ads_found', total);
- 1834. - case 3: return getLang('ads_planned_ads_found', total);
- 1835. - case 4: return getLang('ads_archived_ads_found', total);
- 1836. - default: return getLang('ads_active_ads_found', total);
- 1837. - }
- 1838. - }
- 1839. - }
- 1840. -
- 1841. - Ads.getNoAdsLabel = function() {
- 1842. - var type = this._curFilter;
- 1843. - if (typeof type == 'object') type = type[0];
- 1844. - if (!this._curSearchString || this._curSearchString == '') {
- 1845. - switch (type) {
- 1846. - case 0: return getLang('ads_no_stopped_ads');
- 1847. - case 1: return getLang('ads_no_running_ads');
- 1848. - case 3: return getLang('ads_no_planned_ads');
- 1849. - case 4: return getLang('ads_no_archived_ads');
- 1850. - default: return getLang('ads_no_active_ads');
- 1851. - }
- 1852. - } else {
- 1853. - switch (type) {
- 1854. - case 0: return getLang('ads_no_stopped_ads_found');
- 1855. - case 1: return getLang('ads_no_running_ads_found');
- 1856. - case 3: return getLang('ads_no_planned_ads_found');
- 1857. - case 4: return getLang('ads_no_archived_ads_found');
- 1858. - default: return getLang('ads_no_active_ads_found');
- 1859. - }
- 1860. - }
- 1861. - }
- 1862. -
- 1863. - Ads.getClientsTotalLabel = function(total) {
- 1864. - var type = this._curFilter;
- 1865. - if (typeof type == 'object') type = type[0];
- 1866. - if (!this._curSearchString || this._curSearchString == '') {
- 1867. - switch (type) {
- 1868. - case 4: return getLang('ads_archived_clients_total', total);
- 1869. - default: return getLang('ads_active_clients_total', total);
- 1870. - }
- 1871. - } else {
- 1872. - switch (type) {
- 1873. - case 4: return getLang('ads_archived_clients_found', total);
- 1874. - default: return getLang('ads_active_clients_found', total);
- 1875. - }
- 1876. - }
- 1877. - }
- 1878. -
- 1879. - Ads.getNoClientsLabel = function() {
- 1880. - var type = this._curFilter;
- 1881. - if (typeof type == 'object') type = type[0];
- 1882. - if (!this._curSearchString || this._curSearchString == '') {
- 1883. - switch (type) {
- 1884. - case 4: return getLang('ads_no_archived_clients');
- 1885. - default: return getLang('ads_no_active_clients');
- 1886. - }
- 1887. - } else {
- 1888. - switch (type) {
- 1889. - case 4: return getLang('ads_no_archived_clients_found');
- 1890. - default: return getLang('ads_no_active_clients_found');
- 1891. - }
- 1892. - }
- 1893. - }
- 1894. -
- 1895. - Ads.addOfficeFormatFunctions = function(options) {
- 1896. - var arrFind = function(arr, val) {
- 1897. - var i = 0;
- 1898. - for (; i < arr.length; i++) {
- 1899. - if (arr[i] === val) {
- 1900. - return i;
- 1901. - }
- 1902. - }
- 1903. - return -1;
- 1904. - }
- 1905. -
- 1906. - var ind = arrFind(options.columnClasses, 'column_name_view');
- 1907. - options.columnFormatting[ind] = function(data, rown) {
- 1908. - if (rown == -1) return data;
- 1909. - var unionId = this.content.extra.unionId[rown];
- 1910. - return '<div class="ads_paginated_table_name"><a href="/ads?act=office&union_id=' + unionId + '">' + data + '</a></div>';
- 1911. - }
- 1912. -
- 1913. - var limitFormat = function(data, rown, coln) {
- 1914. - if (rown == -1) return data;
- 1915. - var wrap;
- 1916. - try {
- 1917. - var uid = this.content.extra.uid[rown][coln];
- 1918. - if (uid) {
- 1919. - wrap = "<img id=\"inline_edit_progress" + uid + "\" src=\"/images/upload.gif\" style=\"display: none;\" /><a id=\"inline_edit_value" + uid + "\" >{value}</a>";
- 1920. - }
- 1921. - } catch (e) {
- 1922. - // Nothing
- 1923. - }
- 1924. - if (!wrap) {
- 1925. - wrap = '{value}';
- 1926. - }
- 1927. - var value = data;
- 1928. - if (data == 0) {
- 1929. - value = getLang('ads_no_money_limit');
- 1930. - } else {
- 1931. - value = this._formatData(data, 'currency_int');
- 1932. - }
- 1933. - return wrap.replace('{value}', value);
- 1934. - }
- 1935. - ind = arrFind(options.columnClasses, 'column_day_limit_view');
- 1936. - if (ind != -1) options.columnFormatting[ind] = limitFormat;
- 1937. - ind = arrFind(options.columnClasses, 'column_month_limit_view');
- 1938. - if (ind != -1) options.columnFormatting[ind] = limitFormat;
- 1939. - ind = arrFind(options.columnClasses, 'column_all_limit_view');
- 1940. - if (ind != -1) options.columnFormatting[ind] = limitFormat;
- 1941. -
- 1942. - return options;
- 1943. - }
- 1944. -
- 1945. - Ads.createOfficePaginatedTable = function(container, options, content) {
- 1946. - var getButton = function(label, callback) {
- 1947. - var div = ce('div', {className: 'button_blue'});
- 1948. - var butt = ce('button', {innerHTML: label, onclick: callback});
- 1949. - div.appendChild(butt);
- 1950. - return div;
- 1951. - }
- 1952. -
- 1953. - var statusCol = 1;
- 1954. -
- 1955. - var selected;
- 1956. -
- 1957. - var buttons = [],
- 1958. - labels = [getLang('ads_status_do_disable'),
- 1959. - getLang('ads_status_do_enable'),
- 1960. - getLang('ads_status_do_archive')];
- 1961. -
- 1962. -
- 1963. - var changeStatus = function(val) {
- 1964. - return function() {
- 1965. - var unionIds = [],
- 1966. - hashes = [],
- 1967. - hashesDel = [],
- 1968. - enable = val; // 1 - on, 0 - off, 2 - delete
- 1969. - var i;
- 1970. - for (i in selected) {
- 1971. - unionIds.push(pt.content.extra.union_id[selected[i]][statusCol]);
- 1972. - hashes.push(pt.content.extra.hash[selected[i]][statusCol]);
- 1973. - hashesDel.push(pt.content.extra.hash_delete[selected[i]][statusCol]);
- 1974. - }
- 1975. -
- 1976. - unionIds = unionIds.join(',');
- 1977. - hashes = hashes.join(',');
- 1978. - hashesDel = hashesDel.join(',');
- 1979. -
- 1980. - if (val == 2) { // delete
- 1981. - Ads.openDeleteUnionBox(cur.tableUnionTypeForDelete, unionIds, hashesDel, lockChangeStatus, unlockChangeStatus, updateStatusInTable, 2);
- 1982. - return;
- 1983. - }
- 1984. -
- 1985. - var params = {
- 1986. - union_id: unionIds,
- 1987. - hash: hashes,
- 1988. - newclass: 1,
- 1989. - enable: val
- 1990. - };
- 1991. -
- 1992. - lockChangeStatus();
- 1993. -
- 1994. - function lockChangeStatus() {
- 1995. - lockButton(buttons[val]);
- 1996. - return true;
- 1997. - };
- 1998. - function unlockChangeStatus() {
- 1999. - unlockButton(buttons[val]);
- 2000. - }
- 2001. - function updateStatusInTable(ans) {
- 2002. - if (ans['status_class']) ans = [ans];
- 2003. -
- 2004. - var errored = 0;
- 2005. - for (var i in selected) {
- 2006. - if (!ans[i]) continue;
- 2007. - if (!ans[i]['status_class']) {
- 2008. - if (ans[i]['error'] && !errored) {
- 2009. - errored = 1;
- 2010. - showFastBox(getLang('ads_cant_start_ad_box_title'), ans[i]['error']);
- 2011. - }
- 2012. - continue;
- 2013. - }
- 2014. - pt.content.types[selected[i]] = ans[i]['status_type'];
- 2015. - pt.content.extra.status_text[selected[i]][statusCol] = ans[i]['status'];
- 2016. - pt.content.extra.status_variants[selected[i]][statusCol] = ans[i]['status_variants'];
- 2017. - pt._updateValue(selected[i], statusCol, ans[i]['status_class']);
- 2018. - }
- 2019. - updateButtons.apply(pt);
- 2020. - }
- 2021. -
- 2022. - function onRequestComplete(response) {
- 2023. - // response may be object or array
- 2024. -
- 2025. - unlockChangeStatus();
- 2026. -
- 2027. - if (!response || response.error) { // no isObject or isArray check here
- 2028. - debugLog('onFail change status');
- 2029. - var errorMessage = ((response && response.error) ? response.error : getLang('ads_error_unexpected_error_try_later'));
- 2030. - showFastBox(getLang('ads_cant_start_ad_box_title'), errorMessage);
- 2031. - return true;
- 2032. - }
- 2033. -
- 2034. - var info = '';
- 2035. - if (response && response.info) {
- 2036. - info = response.info;
- 2037. - }
- 2038. - debugLog('onDone change status, ' + info);
- 2039. -
- 2040. - updateStatusInTable(response);
- 2041. - return true;
- 2042. - }
- 2043. -
- 2044. - ajax.post('/ads?act=a_union_change_status', params, {onDone: onRequestComplete, onFail: onRequestComplete});
- 2045. - };
- 2046. - }
- 2047. -
- 2048. - var updateButtons = function() {
- 2049. - selected = this.getSelection(0, 1);
- 2050. - var i;
- 2051. - for (i in buttons) {
- 2052. - hide(buttons[i]);
- 2053. - }
- 2054. - if (selected.length == 0) {
- 2055. - } else {
- 2056. - var was = [false, false];
- 2057. - var on = {on: 1, pending: 1},
- 2058. - off = {off: 1, off_red: 1, cross: 1};
- 2059. - for (i in selected) {
- 2060. - var stat = this.content.data[selected[i]][statusCol];
- 2061. - if (on[stat]) was[0] = 1;
- 2062. - if (off[stat]) was[1] = 1;
- 2063. - }
- 2064. - if (was[0]) show(buttons[0]);
- 2065. - if (was[1]) show(buttons[1]);
- 2066. - show(buttons[2]);
- 2067. - }
- 2068. - }
- 2069. -
- 2070. - options.onCheckboxPick = updateButtons;
- 2071. - options.onRefresh = updateButtons;
- 2072. -
- 2073. - options = Ads.addOfficeFormatFunctions(options);
- 2074. -
- 2075. - var i;
- 2076. - for (i = 0; i < 3; i++) {
- 2077. - buttons[i] = getButton(labels[i], changeStatus(i));
- 2078. - }
- 2079. -
- 2080. - var pt = new PaginatedTable(container, options, content);
- 2081. - // pt.getData('/ads?act=a_unions_table&union_id=1000157403&period_key=20111018&sort_key=default_r&offset={offset}&limit={limit}');
- 2082. -
- 2083. - // mass actions
- 2084. - var container = ge('pt_' + pt.globalNum + '_mass_act_default_container');
- 2085. - if (container) {
- 2086. - addClass(container, 'ads_mass_act_container');
- 2087. - container.appendChild(buttons[1]);
- 2088. - container.appendChild(buttons[0]);
- 2089. - container.appendChild(buttons[2]);
- 2090. - for (i in buttons) {
- 2091. - hide(buttons[i]);
- 2092. - }
- 2093. - show(container);
- 2094. - }
- 2095. -
- 2096. - // selecting subclasses
- 2097. - var selectSubclass = function(classes) {
- 2098. - return function() {
- 2099. - var corr = 1;
- 2100. - for (i = 0; i < pt.tableSize; i++) {
- 2101. - if (i < pt.curFrom || i > pt.curTo) continue;
- 2102. - var j = pt.permutation[i];
- 2103. - var curClass = pt.content.data[j][statusCol];
- 2104. - corr &= ((pt.selection[j] == 1) == (classes[curClass] == 1));
- 2105. - }
- 2106. - var checked = 1 ^ corr;
- 2107. - for (i = 0; i < pt.tableSize; i++) {
- 2108. - if (i < pt.curFrom || i > pt.curTo) continue;
- 2109. - var j = pt.permutation[i];
- 2110. - var curClass = pt.content.data[j][statusCol];
- 2111. - var curToggle = classes[curClass] ? checked : 0;
- 2112. - var el = ge('cb_row_' + j + '_' + pt.globalNum);
- 2113. - if (el) {
- 2114. - window[curToggle ? 'addClass' : 'removeClass'](el, 'on');
- 2115. - }
- 2116. - pt.toggleCheckbox(false, j, curToggle);
- 2117. - }
- 2118. - };
- 2119. - }
- 2120. - container = ge('select_all_link');
- 2121. - if (container) {
- 2122. - container.onclick = selectSubclass({on: 1, off: 1, off_red: 1, cross: 1, pending: 1});
- 2123. - }
- 2124. - container = ge('select_running_link');
- 2125. - if (container) {
- 2126. - container.onclick = selectSubclass({on: 1});
- 2127. - }
- 2128. - container = ge('select_stopped_link');
- 2129. - if (container) {
- 2130. - container.onclick = selectSubclass({off: 1, off_red: 1, cross: 1});
- 2131. - }
- 2132. - }
- 2133. -
- 2134. - Ads.onStatusHover = function(elem, callback, rown, coln) {
- 2135. - var _t = this;
- 2136. - var options = {
- 2137. - status: {type: this.content.data[rown][coln], title: this.content.extra.status_text[rown][coln]},
- 2138. - items: this.content.extra.status_variants[rown][coln],
- 2139. - popupTime: -1,
- 2140. - onSelect: function(event) { // copypasted
- 2141. - var index = event.target.index,
- 2142. - unionId = _t.content.extra.union_id[rown][coln],
- 2143. - hash = _t.content.extra.hash[rown][coln],
- 2144. - hashDelete = _t.content.extra.hash_delete[rown][coln];
- 2145. -
- 2146. - if (index == 'archived') {
- 2147. - setTimeout(function(){
- 2148. - Ads.openDeleteUnionBox(cur.tableUnionTypeForDelete, unionId, hashDelete, lockChangeStatus, unlockChangeStatus, updateStatusInTable, 1);
- 2149. - }, 1);
- 2150. - return;
- 2151. - }
- 2152. -
- 2153. - var params = {};
- 2154. - params.union_id = unionId;
- 2155. - params.hash = hash;
- 2156. - params.newclass = 1;
- 2157. -
- 2158. - params.enable = ((index == 'on') ? 1 : 0);
- 2159. -
- 2160. - lockChangeStatus();
- 2161. -
- 2162. - function lockChangeStatus() {
- 2163. - var selectorBox = ge('union_' + unionId + '_status_selector_box');
- 2164. - var progress = ge('union_' + unionId + '_status_progress');
- 2165. - hide(selectorBox);
- 2166. - show(progress);
- 2167. - return true;
- 2168. - };
- 2169. - function unlockChangeStatus() {
- 2170. - var selectorBox = ge('union_' + unionId + '_status_selector_box');
- 2171. - var progress = ge('union_' + unionId + '_status_progress');
- 2172. - hide(progress)
- 2173. - show(selectorBox);
- 2174. - }
- 2175. - function updateStatusInTable(status, status_class, status_type, status_variants) {
- 2176. - if (!status && !status_class) return;
- 2177. -
- 2178. - var ret = {
- 2179. - value: status_class,
- 2180. - extra: {
- 2181. - status_text: status,
- 2182. - status_variants: status_variants
- 2183. - },
- 2184. - type: status_type
- 2185. - };
- 2186. -
- 2187. - if (status_class == 'deleted') {
- 2188. - ret.listeners = false;
- 2189. - ret.extra.link_class = '';
- 2190. - }
- 2191. - callback(ret);
- 2192. - }
- 2193. -
- 2194. - function onRequestComplete(response) {
- 2195. - unlockChangeStatus();
- 2196. -
- 2197. - if (!isObject(response) || response.error) {
- 2198. - debugLog('onFail change status');
- 2199. - var errorMessage = (isObject(response) ? response.error : getLang('ads_error_unexpected_error_try_later'));
- 2200. - showFastBox(getLang('ads_cant_start_ad_box_title'), errorMessage);
- 2201. - return true;
- 2202. - }
- 2203. -
- 2204. - var info = '';
- 2205. - if (response && response.info) {
- 2206. - info = response.info;
- 2207. - }
- 2208. - debugLog('onDone change status, ' + info);
- 2209. -
- 2210. - updateStatusInTable(response.status, response.status_class, response.status_type, response.status_variants);
- 2211. - return true;
- 2212. - }
- 2213. -
- 2214. - ajax.post('/ads?act=a_union_change_status', params, {onDone: onRequestComplete, onFail: onRequestComplete});
- 2215. - }
- 2216. - };
- 2217. -
- 2218. - var sdd;
- 2219. - if (!cur._statusDropdown) {
- 2220. - var handler = elem.getAttribute('onclick');
- 2221. - sdd = cur._statusDropdown = Ads.statusDropdown(elem, options);
- 2222. - elem.setAttribute('onclick', handler);
- 2223. - elem.onclick = function(){eval(handler);};
- 2224. - } else {
- 2225. - sdd = cur._statusDropdown;
- 2226. - sdd.hideHeader();
- 2227. - clearTimeout(sdd.timer);
- 2228. - sdd.setContainer(elem);
- 2229. - sdd.setStatus(options.status);
- 2230. - sdd.setItems(options.items);
- 2231. - sdd.setHandler(options.onSelect);
- 2232. - }
- 2233. -
- 2234. - sdd.onOver();
- 2235. - }
- 2236. -
- 2237. - Ads.statusDropdown = function(container, options) {
- 2238. - container = ge(container);
- 2239. - if (!container) return false;
- 2240. -
- 2241. - options = extend({
- 2242. - popupTime: 200, // -1 means 'always show entire body'
- 2243. - status: {type: 'off', title: 'Disabled'},
- 2244. - onSelect: function() {}
- 2245. - }, options);
- 2246. -
- 2247. - var compareTypes = function(type1, type2) {
- 2248. - var same = {
- 2249. - on: {
- 2250. - on: 1,
- 2251. - pending: 1
- 2252. - },
- 2253. - off: {
- 2254. - off: 1,
- 2255. - off_red: 1,
- 2256. - cross: 1
- 2257. - },
- 2258. - archived: {
- 2259. - deleted: 1
- 2260. - }
- 2261. - };
- 2262. - if (!same[type1]) return 0;
- 2263. - return same[type1][type2] || 0;
- 2264. - }
- 2265. -
- 2266. - var items = clone(options.items);
- 2267. - for (var i in items) {
- 2268. - if (compareTypes(items[i]['i'], options.status.type)) {
- 2269. - delete items[i];
- 2270. - }
- 2271. - }
- 2272. -
- 2273. - var imgSpanFake = {className: geByClass('ads_status_image_span', container)[0].className};
- 2274. - var imgSpanHTML = '<span class="' + imgSpanFake.className + '"></span>';
- 2275. -
- 2276. - var deltaTop = 0, deltaLeft = 0;
- 2277. - if (browser.opera) deltaTop += -1;
- 2278. - if (browser.mozilla) deltaTop += -1;
- 2279. - if (browser.msie) { deltaTop += -1; deltaLeft += 1; }
- 2280. -
- 2281. - var dd = new DropdownMenu(items, {
- 2282. - title: imgSpanHTML + options.status.title,
- 2283. - target: container,
- 2284. - onSelect: options.onSelect,
- 2285. - showHover: false,
- 2286. - updateTarget: false,
- 2287. - offsetTop: -2 + deltaTop,
- 2288. - offsetLeft: -1 + deltaLeft
- 2289. - });
- 2290. - dd.hide();
- 2291. - addClass(dd.header, 'ads_dd_wide');
- 2292. - addClass(dd.body, 'ads_dd_wide');
- 2293. -
- 2294. - var showTimer, hideTimer;
- 2295. - var overListener = function() {
- 2296. - if (hideTimer) {
- 2297. - clearTimeout(hideTimer);
- 2298. - hideTimer = false;
- 2299. - }
- 2300. - if (options.popupTime == -1) {
- 2301. - dd.show();
- 2302. - return true;
- 2303. - }
- 2304. - showTimer = setTimeout(function() {
- 2305. - showTimer = false;
- 2306. - ret.showHeader();
- 2307. - }, options.popupTime);
- 2308. - };
- 2309. - var outListenerSoft = function() {
- 2310. - if (showTimer) {
- 2311. - clearTimeout(showTimer);
- 2312. - showTimer = false;
- 2313. - } else {
- 2314. - hideTimer = setTimeout(function() {
- 2315. - hideTimer = false;
- 2316. - ret.hideHeader();
- 2317. - }, 500);
- 2318. - }
- 2319. - };
- 2320. - var outListenerHard = function() {
- 2321. - hideTimer = setTimeout(function() {
- 2322. - hideTimer = false;
- 2323. - ret.hideHeader();
- 2324. - }, 500);
- 2325. - };
- 2326. -
- 2327. - if (options.popupTime != -1) {
- 2328. - addEvent(dd.header, 'click', function() {removeClass(dd.header, 'ads_dd_header_popup');});
- 2329. - addEvent(container, 'click', function() {ret.showBody();});
- 2330. -
- 2331. - addEvent(container, 'mouseover', overListener);
- 2332. - addEvent(container, 'mouseout', outListenerSoft);
- 2333. - addEvent(dd.header, 'mouseover', overListener);
- 2334. - addEvent(dd.header, 'mouseout', outListenerHard);
- 2335. - addEvent(dd.body, 'mouseover', overListener);
- 2336. - addEvent(dd.body, 'mouseout', outListenerHard);
- 2337. - }
- 2338. -
- 2339. - var clearTimers = function() {
- 2340. - if (showTimer) {
- 2341. - clearTimeout(showTimer);
- 2342. - showTimer = false;
- 2343. - }
- 2344. - if (hideTimer) {
- 2345. - clearTimeout(hideTimer);
- 2346. - hideTimer = false;
- 2347. - }
- 2348. - }
- 2349. -
- 2350. - var ret = {
- 2351. - getStatus: function() {
- 2352. - return options.status;
- 2353. - },
- 2354. - setStatus: function(status) {
- 2355. - removeClass(imgSpanFake, 'status_' + options.status.type);
- 2356. - options.status = status;
- 2357. - addClass(imgSpanFake, 'status_' + options.status.type);
- 2358. - dd.setOptions({title: '<span class="' + imgSpanFake.className + '"></span>' + options.status.title});
- 2359. - },
- 2360. - setContainer: function(newContainer) {
- 2361. - if (!newContainer) return false;
- 2362. - clearTimers();
- 2363. - if (options.popupTime != -1) {
- 2364. - removeEvent(container, 'mouseover', overListener);
- 2365. - removeEvent(container, 'mouseout', outListenerSoft);
- 2366. - removeEvent(dd.header, 'mouseover', overListener);
- 2367. - removeEvent(dd.header, 'mouseout', outListenerHard);
- 2368. - removeEvent(dd.body, 'mouseover', overListener);
- 2369. - removeEvent(dd.body, 'mouseout', outListenerHard);
- 2370. - }
- 2371. - container = newContainer;
- 2372. - dd.setOptions({target: container});
- 2373. - dd.moveToTarget();
- 2374. - if (options.popupTime != -1) {
- 2375. - addEvent(container, 'mouseover', overListener);
- 2376. - addEvent(container, 'mouseout', outListenerSoft);
- 2377. - addEvent(dd.header, 'mouseover', overListener);
- 2378. - addEvent(dd.header, 'mouseout', outListenerHard);
- 2379. - addEvent(dd.body, 'mouseover', overListener);
- 2380. - addEvent(dd.body, 'mouseout', outListenerHard);
- 2381. - }
- 2382. - },
- 2383. - setItems: function(newItems) {
- 2384. - var items = clone(newItems);
- 2385. - for (var i in items) {
- 2386. - if (compareTypes(items[i]['i'], options.status.type)) {
- 2387. - delete items[i];
- 2388. - }
- 2389. - }
- 2390. - dd.setData(items);
- 2391. - },
- 2392. - setHandler: function(handler) {
- 2393. - dd.setOptions({onSelect: handler});
- 2394. - },
- 2395. - showHeader: function() {
- 2396. - if (!dd.visible) {
- 2397. - addClass(dd.header, 'ads_dd_header_popup');
- 2398. - }
- 2399. - dd.moveToTarget();
- 2400. - show(dd.header);
- 2401. - },
- 2402. - hideHeader: function() {
- 2403. - dd.hide();
- 2404. - hide(dd.header);
- 2405. - removeClass(dd.header, 'ads_dd_header_popup');
- 2406. - },
- 2407. - showBody: function() {
- 2408. - removeClass(dd.header, 'ads_dd_header_popup');
- 2409. - dd.show();
- 2410. - },
- 2411. - hideBody: function() {
- 2412. - dd.hide();
- 2413. - },
- 2414. - onOver: overListener,
- 2415. - onOut: outListenerHard
- 2416. - };
- 2417. -
- 2418. - return ret;
- 2419. - }
- 2420. -
- 2421. - Ads.changeDemographyView = function(name, unionId, updateOnly) {
- 2422. -
- 2423. - // Change navigation
- 2424. - var navCur = ge('ads_demography_navigation_tab_' + name);
- 2425. - if (!navCur) {
- 2426. - return;
- 2427. - }
- 2428. - navCur = navCur.parentNode;
- 2429. - var navCurSelected = hasClass(navCur, 'summary_tab_sel');
- 2430. - if (navCurSelected && !updateOnly || !navCurSelected && updateOnly) {
- 2431. - return;
- 2432. - }
- 2433. - var navElems = [
- 2434. - ge('ads_demography_navigation_tab_bars_all').parentNode,
- 2435. - ge('ads_demography_navigation_tab_graphs').parentNode
- 2436. - ];
- 2437. - for (var i in navElems) {
- 2438. - var navElem = navElems[i];
- 2439. - addClass(navElem, 'summary_tab');
- 2440. - removeClass(navElem, 'summary_tab_sel');
- 2441. - }
- 2442. - addClass(navCur, 'summary_tab_sel');
- 2443. - removeClass(navCur, 'summary_tab');
- 2444. -
- 2445. - // Change graph
- 2446. - var bars1 = ge('ads_demography_bars_all_wrap1');
- 2447. - var bars2 = ge('ads_demography_bars_all_wrap2');
- 2448. - var graphs1 = ge('ads_demography_graphs_wrap1');
- 2449. - var graphs2 = ge('ads_demography_graphs_wrap2');
- 2450. -
- 2451. - if (name === 'bars_all') {
- 2452. - setStyle(bars1, {visibility: 'visible', height: getSize(bars2)[1] + 'px'})
- 2453. - setStyle(bars2, {top: '0'})
- 2454. - setStyle(graphs1, {visibility: 'hidden', height: '0'});
- 2455. - } else if (name === 'graphs') {
- 2456. - if (!Ads.loadDemography(unionId)) {
- 2457. - return;
- 2458. - }
- 2459. -
- 2460. - !cur.graphUsersStatsSexEmpty && cur.pageGraphs['ads_graph_users_stats_day_sex'].loadGraph(intval(cur.lastDemographySourceOffset));
- 2461. - !cur.graphUsersStatsAgeEmpty && cur.pageGraphs['ads_graph_users_stats_day_age'].loadGraph(intval(cur.lastDemographySourceOffset) * 3 + intval(cur.lastDemographyAgeOffset));
- 2462. - !cur.graphUsersStatsCitiesEmpty && cur.pageGraphs['ads_graph_users_stats_day_cities'].loadGraph(intval(cur.lastDemographySourceOffset));
- 2463. -
- 2464. - setStyle(graphs2, {width: getSize(graphs1)[0] + 'px'});
- 2465. - setStyle(graphs1, {visibility: 'visible', height: getSize(graphs2)[1] + 'px'});
- 2466. - setStyle(bars1, {visibility: 'hidden', height: '0'});
- 2467. - setStyle(bars2, {position: 'absolute', top: '-100000px'});
- 2468. - }
- 2469. - }
- 2470. -
- 2471. - Ads.changeDemographySource = function(name) {
- 2472. -
- 2473. - // Change navigation
- 2474. - var clicksSideNav = ge('ads_demography_navigation_clicks');
- 2475. - var viewsSideNav = ge('ads_demography_navigation_views');
- 2476. - var clicksTabNav = ge('ads_demography_navigation_tab_clicks');
- 2477. - var viewsTabNav = ge('ads_demography_navigation_tab_views');
- 2478. - if (clicksTabNav) {
- 2479. - clicksTabNav = clicksTabNav.parentNode;
- 2480. - viewsTabNav = viewsTabNav.parentNode;
- 2481. - }
- 2482. - if (name == 'clicks') {
- 2483. - if (clicksSideNav) {
- 2484. - if (hasClass(clicksSideNav, 'nav_selected')) {
- 2485. - return;
- 2486. - }
- 2487. - addClass(clicksSideNav, 'nav_selected');
- 2488. - removeClass(viewsSideNav, 'nav_selected');
- 2489. - }
- 2490. - if (clicksTabNav) {
- 2491. - if (hasClass(clicksTabNav, 'summary_tab_sel')) {
- 2492. - return;
- 2493. - }
- 2494. - addClass(clicksTabNav, 'summary_tab_sel');
- 2495. - addClass(viewsTabNav, 'summary_tab');
- 2496. - removeClass(clicksTabNav, 'summary_tab');
- 2497. - removeClass(viewsTabNav, 'summary_tab_sel');
- 2498. - }
- 2499. - } else {
- 2500. - if (clicksSideNav) {
- 2501. - if (hasClass(viewsSideNav, 'nav_selected')) {
- 2502. - return;
- 2503. - }
- 2504. - addClass(viewsSideNav, 'nav_selected');
- 2505. - removeClass(clicksSideNav, 'nav_selected');
- 2506. - }
- 2507. - if (clicksTabNav) {
- 2508. - if (hasClass(viewsTabNav, 'summary_tab_sel')) {
- 2509. - return;
- 2510. - }
- 2511. - addClass(viewsTabNav, 'summary_tab_sel');
- 2512. - addClass(clicksTabNav, 'summary_tab');
- 2513. - removeClass(viewsTabNav, 'summary_tab');
- 2514. - removeClass(clicksTabNav, 'summary_tab_sel');
- 2515. - }
- 2516. - }
- 2517. -
- 2518. - // Change graph
- 2519. - if (name == 'clicks') {
- 2520. - cur.lastDemographySourceOffset = 0;
- 2521. - if (cur.isDemographySvg) {
- 2522. - each(geByClass('ads_demography_bars_clicks'), function(i, el) { el.style.visibility = 'visible'; el.style.position = 'relative'; });
- 2523. - each(geByClass('ads_demography_bars_views'), function(i, el) { el.style.visibility = 'hidden'; el.style.position = 'absolute'; });
- 2524. - } else {
- 2525. - each(geByClass('ads_demography_bars_clicks'), show);
- 2526. - each(geByClass('ads_demography_bars_views'), hide);
- 2527. - }
- 2528. - try { cur.pageGraphs['ads_graph_users_stats_day_sex'].loadGraph(intval(cur.lastDemographySourceOffset)); } catch(e) {}
- 2529. - try { cur.pageGraphs['ads_graph_users_stats_day_age'].loadGraph(intval(cur.lastDemographySourceOffset) * 3 + intval(cur.lastDemographyAgeOffset)); } catch(e) {}
- 2530. - try { cur.pageGraphs['ads_graph_users_stats_day_cities'].loadGraph(intval(cur.lastDemographySourceOffset)); } catch(e) {}
- 2531. - } else {
- 2532. - cur.lastDemographySourceOffset = 1;
- 2533. - if (cur.isDemographySvg) {
- 2534. - each(geByClass('ads_demography_bars_views'), function(i, el) { el.style.visibility = 'visible'; el.style.position = 'relative'; });
- 2535. - each(geByClass('ads_demography_bars_clicks'), function(i, el) { el.style.visibility = 'hidden'; el.style.position = 'absolute'; });
- 2536. - } else {
- 2537. - each(geByClass('ads_demography_bars_views'), show);
- 2538. - each(geByClass('ads_demography_bars_clicks'), hide);
- 2539. - }
- 2540. - try { cur.pageGraphs['ads_graph_users_stats_day_sex'].loadGraph(intval(cur.lastDemographySourceOffset)); } catch(e) {}
- 2541. - try { cur.pageGraphs['ads_graph_users_stats_day_age'].loadGraph(intval(cur.lastDemographySourceOffset) * 3 + intval(cur.lastDemographyAgeOffset)); } catch(e) {}
- 2542. - try { cur.pageGraphs['ads_graph_users_stats_day_cities'].loadGraph(intval(cur.lastDemographySourceOffset)); } catch(e) {}
- 2543. - }
- 2544. - }
- 2545. -
- 2546. - Ads.changeDemographyAge = function(name) {
- 2547. - // Change navigation
- 2548. - var allNav = ge('ads_demography_navigation_tab_age_all').parentNode;
- 2549. - var femaleNav = ge('ads_demography_navigation_tab_age_female').parentNode;
- 2550. - var maleNav = ge('ads_demography_navigation_tab_age_male').parentNode;
- 2551. - switch (name) {
- 2552. - case 'all':
- 2553. - if (hasClass(allNav, 'summary_tab_sel')) {
- 2554. - return;
- 2555. - }
- 2556. - addClass(allNav, 'summary_tab_sel');
- 2557. - addClass(femaleNav, 'summary_tab');
- 2558. - addClass(maleNav, 'summary_tab');
- 2559. - removeClass(allNav, 'summary_tab');
- 2560. - removeClass(femaleNav, 'summary_tab_sel');
- 2561. - removeClass(maleNav, 'summary_tab_sel');
- 2562. - break;
- 2563. - case 'female':
- 2564. - if (hasClass(femaleNav, 'summary_tab_sel')) {
- 2565. - return;
- 2566. - }
- 2567. - addClass(femaleNav, 'summary_tab_sel');
- 2568. - addClass(allNav, 'summary_tab');
- 2569. - addClass(maleNav, 'summary_tab');
- 2570. - removeClass(femaleNav, 'summary_tab');
- 2571. - removeClass(allNav, 'summary_tab_sel');
- 2572. - removeClass(maleNav, 'summary_tab_sel');
- 2573. - break;
- 2574. - case 'male':
- 2575. - if (hasClass(maleNav, 'summary_tab_sel')) {
- 2576. - return;
- 2577. - }
- 2578. - addClass(maleNav, 'summary_tab_sel');
- 2579. - addClass(allNav, 'summary_tab');
- 2580. - addClass(femaleNav, 'summary_tab');
- 2581. - removeClass(maleNav, 'summary_tab');
- 2582. - removeClass(allNav, 'summary_tab_sel');
- 2583. - removeClass(femaleNav, 'summary_tab_sel');
- 2584. - break;
- 2585. - default:
- 2586. - return;
- 2587. - }
- 2588. -
- 2589. - // Change graph
- 2590. - switch (name) {
- 2591. - case 'all': cur.lastDemographyAgeOffset = 0; break;
- 2592. - case 'female': cur.lastDemographyAgeOffset = 1; break;
- 2593. - case 'male': cur.lastDemographyAgeOffset = 2; break;
- 2594. - default: return;
- 2595. - }
- 2596. - try { cur.pageGraphs['ads_graph_users_stats_day_age'].loadGraph(intval(cur.lastDemographySourceOffset) * 3 + intval(cur.lastDemographyAgeOffset)); } catch(e) {}
- 2597. - }
- 2598. -
- 2599. - Ads.loadDemography = function(unionId) {
- 2600. - if (!cur.demographyDelayed) {
- 2601. - return true;
- 2602. - }
- 2603. - if (!Ads.lock('load_demography', lock, unlock)) {
- 2604. - return false;
- 2605. - }
- 2606. -
- 2607. - var ajaxParams = {};
- 2608. - ajaxParams.union_id = unionId;
- 2609. -
- 2610. - ajax.post('/ads?act=a_users_stats', ajaxParams, {onDone: onComplete, onFail: onComplete});
- 2611. -
- 2612. - function lock() {
- 2613. - setStyle('ads_demography_navigation_tab_progress', {visibility: 'visible'});
- 2614. - }
- 2615. - function unlock() {
- 2616. - setStyle('ads_demography_navigation_tab_progress', {visibility: 'hidden'});
- 2617. - }
- 2618. - function onComplete(response) {
- 2619. - Ads.unlock('load_demography');
- 2620. - if (response && response.graphs_html && response.graphs_js) {
- 2621. - cur.demographyDelayed = false;
- 2622. - ge('ads_demography_graphs_wrap2').innerHTML = response.graphs_html;
- 2623. - eval(response.graphs_js);
- 2624. - Ads.changeDemographyView('graphs', unionId, true);
- 2625. - }
- 2626. - return true;
- 2627. - }
- 2628. -
- 2629. - return false;
- 2630. - }
- 2631. -
- 2632. - Ads.checkBudgetSumInc = function(isRequest) {
- 2633. - var budgetError = ge('budget_error');
- 2634. - var budgetErrorBox = ge('budget_error_box');
- 2635. - var budgetNoticeBox = ge('budget_notice_box');
- 2636. -
- 2637. - var strBudgetInc;
- 2638. - if (window.curLegal) {
- 2639. - strBudgetInc = ge('union_invoice_sum').value;
- 2640. - } else {
- 2641. - strBudgetInc = ge('union_budget_sum').value;
- 2642. - }
- 2643. -
- 2644. - if (!isRequest && strBudgetInc == '0') {
- 2645. - hide(budgetErrorBox);
- 2646. - show(budgetNoticeBox);
- 2647. - return false;
- 2648. - }
- 2649. -
- 2650. - strBudgetInc = strBudgetInc.replace(',', '.');
- 2651. -
- 2652. - strBudgetInc = strBudgetInc.replace(/^0+|(?:\.\d*)0+$/g, '');
- 2653. - if (strBudgetInc[0] == '.') {
- 2654. - strBudgetInc = '0' + strBudgetInc;
- 2655. - }
- 2656. - if (strBudgetInc !== '' && strBudgetInc.substr(-1) == '.') {
- 2657. - strBudgetInc = strBudgetInc.substr(0, strBudgetInc.length - 1);
- 2658. - }
- 2659. - if (strBudgetInc === '') {
- 2660. - strBudgetInc = '0';
- 2661. - }
- 2662. -
- 2663. - var isNormalCheck = true; // False if user want pay all his money.
- 2664. -
- 2665. - if (window.curIsMoney && (window.curOfficeLegal || window.userMoney > cur.unionsLimits.budget_increase_rubles_min) && !window.curLegal && window.userMoneyStr && strBudgetInc === window.userMoneyStr) {
- 2666. - isNormalCheck = false;
- 2667. - }
- 2668. -
- 2669. - if (!strBudgetInc.match(cur.unionsLimits.budget_pattern_all)) {
- 2670. - budgetError.innerHTML = window.incorrectMoneyFormat;
- 2671. - hide(budgetNoticeBox);
- 2672. - show(budgetErrorBox);
- 2673. - return false;
- 2674. - }
- 2675. -
- 2676. - if (isNormalCheck && strBudgetInc.indexOf('.') != -1) {
- 2677. - if (window.curIsMoney && !window.curLegal && (window.curOfficeLegal || window.userMoney > cur.unionsLimits.budget_increase_rubles_min)) {
- 2678. - budgetError.innerHTML = window.enterIntegerOrEqualMoney;
- 2679. - } else {
- 2680. - budgetError.innerHTML = window.enterIntegerMoney;
- 2681. - }
- 2682. - hide(budgetNoticeBox);
- 2683. - show(budgetErrorBox);
- 2684. - return false;
- 2685. - }
- 2686. -
- 2687. - var floatBudgetInc = parseFloat(strBudgetInc);
- 2688. -
- 2689. - if (strBudgetInc === '0') {
- 2690. - budgetError.innerHTML = window.enterMoneyAmount;
- 2691. - hide(budgetNoticeBox);
- 2692. - show(budgetErrorBox);
- 2693. - return false;
- 2694. - }
- 2695. -
- 2696. - if (isNormalCheck && !strBudgetInc.match(cur.unionsLimits.budget_pattern)) {
- 2697. - budgetError.innerHTML = window.incorrectMoneyFormat;
- 2698. - hide(budgetNoticeBox);
- 2699. - show(budgetErrorBox);
- 2700. - return false;
- 2701. - }
- 2702. -
- 2703. - if (!window.curLegal) {
- 2704. - if (floatBudgetInc > window.userMoney) {
- 2705. - budgetError.innerHTML = (window.curOfficeLegal ? window.lowMoneyOnAccountSimple : window.lowMoneyOnAccount);
- 2706. - hide(budgetNoticeBox);
- 2707. - show(budgetErrorBox);
- 2708. - return false;
- 2709. - }
- 2710. - }
- 2711. -
- 2712. - if (window.curIsMoney) {
- 2713. - if (window.curLegal) {
- 2714. - if (floatBudgetInc < cur.unionsLimits.budget_increase_rubles_min) {
- 2715. - budgetError.innerHTML = window.lowMoneyPaymentLegal;
- 2716. - hide(budgetNoticeBox);
- 2717. - show(budgetErrorBox);
- 2718. - return false;
- 2719. - }
- 2720. - } else {
- 2721. - if (isNormalCheck && floatBudgetInc < cur.unionsLimits.budget_increase_rubles_min) {
- 2722. - budgetError.innerHTML = window.lowMoneyPayment;
- 2723. - hide(budgetNoticeBox);
- 2724. - show(budgetErrorBox);
- 2725. - return false;
- 2726. - }
- 2727. - }
- 2728. - } else {
- 2729. - if (floatBudgetInc < cur.unionsLimits.budget_increase_votes_min) {
- 2730. - budgetError.innerHTML = window.lowMoneyPayment;
- 2731. - hide(budgetNoticeBox);
- 2732. - show(budgetErrorBox);
- 2733. - return false;
- 2734. - }
- 2735. - }
- 2736. -
- 2737. - hide(budgetErrorBox);
- 2738. - show(budgetNoticeBox);
- 2739. -
- 2740. - return strBudgetInc;
- 2741. - }
- 2742. -
- 2743. - Ads.onBudgetRublesChanged = function(delayed) {
- 2744. - if (!window.curPaymentPage) {
- 2745. - if (delayed) {
- 2746. - window.changeBudgetDelayedCounter--;
- 2747. - if (window.changeBudgetDelayedCounter == 0) {
- 2748. - Ads.checkBudgetSumInc();
- 2749. - }
- 2750. - return;
- 2751. - }
- 2752. - window.changeBudgetDelayedCounter++;
- 2753. - setTimeout(function() { Ads.onBudgetRublesChanged(true); }, 300);
- 2754. - }
- 2755. -
- 2756. - if (!window.curLegal) {
- 2757. - if (window.curIsMoney) {
- 2758. - ge('union_budget_sum_currency').innerHTML = getLang('global_money_amount_rub_text', ge('union_budget_sum').value)
- 2759. - } else {
- 2760. - ge('union_budget_sum_currency').innerHTML = getLang('global_money_amount_votes_text', ge('union_budget_sum').value)
- 2761. - }
- 2762. - } else {
- 2763. - ge('union_invoice_sum_currency').innerHTML = getLang('global_money_amount_rub_text', ge('union_invoice_sum').value)
- 2764. - if (window.curInvoiceFeeFract) {
- 2765. - var budgetSum = parseFloat(ge('union_invoice_sum').value);
- 2766. - var feeSum = (isNaN(budgetSum) ? 0 : (budgetSum / (1 - window.curInvoiceFeeFract))).toFixed(2);
- 2767. - ge('fee_money_sum_full').innerHTML = getLang('ads_payments_legal_sum_with_fee', feeSum);;
- 2768. - }
- 2769. - }
- 2770. - }
- 2771. -
- 2772. - Ads.changeBudget = function() {
- 2773. - if (window.budgetRequestInProgress) {
- 2774. - return;
- 2775. - }
- 2776. -
- 2777. - var budgetError = ge('budget_error');
- 2778. - var budgetErrorBox = ge('budget_error_box');
- 2779. - var budgetNoticeBox = ge('budget_notice_box');
- 2780. -
- 2781. - var ajaxParams = {};
- 2782. - ajaxParams.union_id = window.curUnionId;
- 2783. - ajaxParams.hash = window.curChangeBudgetHash;
- 2784. - if (!window.curIsMoney) {
- 2785. - ajaxParams.votes = 1;
- 2786. - }
- 2787. - ajaxParams.legal = window.curLegal;
- 2788. -
- 2789. - ajaxParams.money = Ads.checkBudgetSumInc(true);
- 2790. - if (ajaxParams.money == false) {
- 2791. - return;
- 2792. - }
- 2793. -
- 2794. - window.budgetRequestInProgress = true;
- 2795. -
- 2796. - function onAjaxSuccess(response) {
- 2797. - if (isObject(response)) {
- 2798. - if (response.error) {
- 2799. - budgetError.innerHTML = response.error;
- 2800. - hide(budgetNoticeBox);
- 2801. - show(budgetErrorBox);
- 2802. - window.budgetRequestInProgress = false;
- 2803. - } else {
- 2804. - var elem = ge('general_info_budget');
- 2805. - if (elem) {
- 2806. - elem.innerHTML = response.budget;
- 2807. - }
- 2808. - if (cur.unionChangeBudgetBox) {
- 2809. - cur.unionChangeBudgetBox.hide(200);
- 2810. - }
- 2811. - if (window.curLegal || window.curPaymentPage) {
- 2812. - if (window.location.toString().indexOf('budget') != -1 && !window.curPaymentPage) {
- 2813. - nav.reload();
- 2814. - } else {
- 2815. - nav.go('/ads?act=budget&union_id=' + window.curUnionId);
- 2816. - }
- 2817. - }
- 2818. - }
- 2819. - }
- 2820. - }
- 2821. - function onAjaxFail(response) {
- 2822. - budgetError.innerHTML = getLang('ads_error_unexpected_error_try_later');
- 2823. - hide(budgetNoticeBox);
- 2824. - show(budgetErrorBox);
- 2825. - window.budgetRequestInProgress = false;
- 2826. - return true;
- 2827. - }
- 2828. -
- 2829. - ajax.post('/ads?act=a_union_change_budget', ajaxParams, {onDone: onAjaxSuccess, onFail: onAjaxFail});
- 2830. - }
- 2831. -
- 2832. - Ads.showEditAdminBox = function(event, unionId, userId, userEmail, isRemove) {
- 2833. - if (event && (event.which > 1 || event.button > 1 || event.ctrlKey)) {
- 2834. - return;
- 2835. - }
- 2836. -
- 2837. - userId = intval(userId);
- 2838. -
- 2839. - if (!userId && !userEmail) {
- 2840. - var userLink = ge('ads_user_link').getValue();
- 2841. - if (!userLink) {
- 2842. - showFastBox(getLang('ads_error_box_title'), getLang('ads_edit_admin_no_user_link'));
- 2843. - return;
- 2844. - }
- 2845. - }
- 2846. -
- 2847. - if (isRemove) {
- 2848. - cur.editAdminBoxTitle = getLang('ads_edit_admin_box_title_remove');
- 2849. - } else {
- 2850. - if (userId || userEmail) {
- 2851. - cur.editAdminBoxTitle = getLang('ads_edit_admin_box_title_edit');
- 2852. - } else {
- 2853. - cur.editAdminBoxTitle = getLang('ads_edit_admin_box_title_add');
- 2854. - }
- 2855. - }
- 2856. -
- 2857. - var ajaxParams = {};
- 2858. - ajaxParams.union_id = unionId;
- 2859. - if (isRemove) {
- 2860. - ajaxParams.action = 'remove';
- 2861. - } else {
- 2862. - ajaxParams.action = 'edit';
- 2863. - }
- 2864. - if (userId) {
- 2865. - ajaxParams.user_link = userId;
- 2866. - } else if (userEmail) {
- 2867. - ajaxParams.user_link = userEmail;
- 2868. - } else {
- 2869. - ajaxParams.user_link = userLink;
- 2870. - }
- 2871. -
- 2872. - var showOptions = {params: {}};
- 2873. - showOptions.onFail = Ads.onBoxFail;
- 2874. - showOptions.params.width = 440;
- 2875. -
- 2876. - showBox('/ads?act=a_edit_admin_box', ajaxParams, showOptions);
- 2877. -
- 2878. - return false;
- 2879. - }
- 2880. -
- 2881. - Ads.showRetargetingGroupBox = function(unionId, groupId) {
- 2882. - groupId = intval(groupId);
- 2883. -
- 2884. - var ajaxParams = {};
- 2885. - ajaxParams.union_id = unionId;
- 2886. - if (groupId) {
- 2887. - ajaxParams.group_id = groupId;
- 2888. - }
- 2889. -
- 2890. - var showOptions = {params: {}};
- 2891. - showOptions.onFail = Ads.onBoxFail;
- 2892. - showOptions.params.width = 400;
- 2893. -
- 2894. - showBox('/ads?act=a_retargeting_group_box', ajaxParams, showOptions);
- 2895. -
- 2896. - return false;
- 2897. - }
- 2898. - Ads.showRetargetingGroupPixel = function(unionId, groupId, hash) {
- 2899. - groupId = intval(groupId);
- 2900. -
- 2901. - var ajaxParams = {};
- 2902. - ajaxParams.union_id = unionId;
- 2903. - ajaxParams.group_id = groupId;
- 2904. - ajaxParams.hash = hash;
- 2905. -
- 2906. - var showOptions = {params: {}};
- 2907. - showOptions.onFail = Ads.onBoxFail;
- 2908. - showOptions.params.width = 400;
- 2909. -
- 2910. - showBox('/ads?act=a_get_retargeting_pixel', ajaxParams, showOptions);
- 2911. -
- 2912. - return false;
- 2913. - }
- 2914. - Ads.deleteRetargetingGroup = function(unionId, groupId, hash) {
- 2915. - groupId = intval(groupId);
- 2916. -
- 2917. - curBox().hide();
- 2918. - showFastBox(getLang('ads_retargeting_del_confirm_title'), getLang('ads_retargeting_del_confirm_message'), getLang('box_yes'), function() {
- 2919. - ajax.post('/ads', {act: 'a_del_retargeting_group', union_id: unionId, group_id: groupId, hash: hash}, {
- 2920. - onDone: function(html) {
- 2921. - ge('ads_retargeting_groups_table').innerHTML = html;
- 2922. - curBox().hide();
- 2923. - }
- 2924. - });
- 2925. - }, getLang('box_no'));
- 2926. -
- 2927. - return false;
- 2928. - }
- 2929. -
- 2930. - try{stManager.done('ads.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment