Hormold

VK Change (#1380279614)

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