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