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