Hormold

VK Change (#1391607904)

Feb 5th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.34 KB | None | 0 0
  1. Файл - profile_edit_job.js (Старый размер - 14236 | Новый - 0):
  2. 0.  - var ProfileEditorJob = {
  3. 1.  -
  4. 2.  -   init: function() {
  5. 3.  -     cur.globalCounter = 0;
  6. 4.  -     cur.worksCount = 0;
  7. 5.  -
  8. 6.  -     selectsData.setCountries(cur.selData.countries_list);
  9. 7.  -     for (var i in cur.selData.countries) {
  10. 8.  -       selectsData.setCities(i, cur.selData.countries[i]);
  11. 9.  -     }
  12. 10.  -
  13. 11.  -     if (!isVisible('works')) {
  14. 12.  -       cur.worksCount = cur.works.length;
  15. 13.  -       if (cur.worksCount) {
  16. 14.  -         for (var i = 0; i < cur.works.length; ++i) {
  17. 15.  -           ge('works').appendChild(this.genWorkRow(cur.works[i].id));
  18. 16.  -           cur.works[i] = this.initWorkRow(cur.works[i]);
  19. 17.  -         }
  20. 18.  -       } else {
  21. 19.  -         this.addWork();
  22. 20.  -       }
  23. 21.  -       show('works');
  24. 22.  -     }
  25. 23.  -
  26. 24.  -     if (cur.worksCount >= 7) {
  27. 25.  -       hide('add_work_link');
  28. 26.  -     } else {
  29. 27.  -       show('add_work_link');
  30. 28.  -     }
  31. 29.  -   },
  32. 30.  -
  33. 31.  -   genOneRow: function(field, id, label, params, attr) {
  34. 32.  -     var key = field + id;
  35. 33.  -     if (!params) {
  36. 34.  -       params = '';
  37. 35.  -     }
  38. 36.  -     return '<div class="pedit_edu_row" id="row_' + key + '"'+(attr || '')+'>' +
  39. 37.  -               '<div class="label fl_l ta_r">' + label + '</div>' +
  40. 38.  -               '<div class="labeled fl_l"><input id="' + key + '" name="' + key + '" ' + params + '/></div>' +
  41. 39.  -            '</div>';
  42. 40.  -   },
  43. 41.  -
  44. 42.  -   genWorkRow: function(work_id) {
  45. 43.  -     var dn = ' style="display: none;"';
  46. 44.  -     var html = '<div id="content' + work_id + '"><div class="pedit_job_progress"><img class="pedit_progress" src="/images/upload.gif" id="progress' + work_id + '" />' +
  47. 45.  -       '<a class="fl_r" onclick="ProfileEditorJob.deleteWork(' + work_id + ')">' + getLang('global_delete') + '</a></div>' +
  48. 46.  -       this.genOneRow('group', work_id, getLang('select_company'), 'type="text" class="dark pedit_edu_txt"') +
  49. 47.  -       //this.genOneRow('company', work_id, getLang('select_company'), 'type="text" class="text"', dn) +
  50. 48.  -       '<div id="pedit_country_row'+work_id+'">'+
  51. 49.  -       this.genOneRow('country', work_id, getLang('select_country'), '') +
  52. 50.  -       this.genOneRow('city', work_id, getLang('select_city'), '') +
  53. 51.  -       '</div><div id="details' + work_id + '" style="display: none">' +
  54. 52.  -       this.genOneRow('start', work_id, getLang('select_work_start')) +
  55. 53.  -       this.genOneRow('finish', work_id, getLang('select_work_finish')) +
  56. 54.  -       this.genOneRow('position', work_id, getLang('select_work_position'), 'id="position' + work_id + '_name"') +
  57. 55.  -     '</div></div>' +
  58. 56.  -     '<div class="deleted" id="deleted' + work_id + '"><div></div>' +
  59. 57.  -       '<a class="fl_r" onclick="ProfileEditorJob.restoreWork(' + work_id + ')">' + getLang('global_dont_delete') + '</a>' +
  60. 58.  -     '</div><div class="separator"><div></div></div>';
  61. 59.  -     return ce('div', {
  62. 60.  -       className: 'pedit_edu_big_row',
  63. 61.  -       id: 'work' + work_id,
  64. 62.  -       innerHTML: html
  65. 63.  -     }, {display: 'none'});
  66. 64.  -   },
  67. 65.  -
  68. 66.  -   get_by_id: function(elem, id) {
  69. 67.  -     if (elem.id == id) {
  70. 68.  -       return elem;
  71. 69.  -     }
  72. 70.  -     for (var i = 0; i < elem.childNodes.length; ++i) {
  73. 71.  -       var result = this.get_by_id(elem.childNodes[i], id);
  74. 72.  -       if (result) {
  75. 73.  -         return result;
  76. 74.  -       }
  77. 75.  -     }
  78. 76.  -     return false;
  79. 77.  -   },
  80. 78.  -
  81. 79.  -   initWorkRow: function(work, elem) {
  82. 80.  -     var g = elem ? function(id) { return ProfileEditorJob.get_by_id(elem, id); } : ge;
  83. 81.  -     work.uiStart = new Dropdown(g('start' + work.id), [[0, getLang('select_year_not_selected')]].concat(cur.selData.years), {
  84. 82.  -       width: 200,
  85. 83.  -       autocomplete: true,
  86. 84.  -       placeholder: getLang('select_year_not_selected'),
  87. 85.  -       placeholderColor: '#000',
  88. 86.  -       noResult: getLang('select_year_not_found'),
  89. 87.  -       onChange: function(value) {
  90. 88.  -         value = intval(value);
  91. 89.  -         var new_finish_data = [];
  92. 90.  -         if (!value) {
  93. 91.  -           work.uiStart.clear();
  94. 92.  -           new_finish_data = cur.selData.years;
  95. 93.  -         } else {
  96. 94.  -           var finish_value = intval(work.uiFinish.val());
  97. 95.  -           if (finish_value && finish_value < value) {
  98. 96.  -             work.uiFinish.val(value);
  99. 97.  -           }
  100. 98.  -           for (var i = 0; i < cur.selData.years.length; ++i) {
  101. 99.  -             if (cur.selData.years[i][0] >= value) {
  102. 100.  -               new_finish_data.push(cur.selData.years[i]);
  103. 101.  -             }
  104. 102.  -           }
  105. 103.  -         }
  106. 104.  -         work.uiFinish.setOptions({defaultItems: [[0, getLang('select_year_not_selected')]].concat(new_finish_data)});
  107. 105.  -         work.uiFinish.setData(new_finish_data);
  108. 106.  -       },
  109. 107.  -       dark: 1
  110. 108.  -     });
  111. 109.  -     work.uiStart.setData(cur.selData.years);
  112. 110.  -     work.uiFinish = new Dropdown(g('finish' + work.id), [[0, getLang('select_year_not_selected')]].concat(cur.selData.years), {
  113. 111.  -       width: 200,
  114. 112.  -       autocomplete: true,
  115. 113.  -       placeholder: getLang('select_year_not_selected'),
  116. 114.  -       placeholderColor: '#000',
  117. 115.  -       noResult: getLang('select_year_not_found'),
  118. 116.  -       onChange: function(value) {
  119. 117.  -         value = intval(value);
  120. 118.  -         var new_start_data = [];
  121. 119.  -         if (!value) {
  122. 120.  -           work.uiFinish.clear();
  123. 121.  -           new_start_data = cur.selData.years;
  124. 122.  -         } else {
  125. 123.  -           var start_value = intval(work.uiStart.val());
  126. 124.  -           if (start_value && start_value > value) {
  127. 125.  -             work.uiStart.val(value);
  128. 126.  -           }
  129. 127.  -           for (var i = 0; i < cur.selData.years.length; ++i) {
  130. 128.  -             if (cur.selData.years[i][0] <= value) {
  131. 129.  -               new_start_data.push(cur.selData.years[i]);
  132. 130.  -             }
  133. 131.  -           }
  134. 132.  -         }
  135. 133.  -         work.uiStart.setOptions({defaultItems: [[0, getLang('select_year_not_selected')]].concat(new_start_data)});
  136. 134.  -         work.uiStart.setData(new_start_data);
  137. 135.  -       },
  138. 136.  -       dark: 1
  139. 137.  -     });
  140. 138.  -     work.uiFinish.setData(cur.selData.years);
  141. 139.  -
  142. 140.  -     work.uiStart.val(work.start, true);
  143. 141.  -     work.uiFinish.val(work.finish, true);
  144. 142.  -
  145. 143.  -     work.uiPosition = new Selector(g('position' + work.id), 'select.php?act=apositions', {
  146. 144.  -       width: 200,
  147. 145.  -       multiselect: false,
  148. 146.  -       noResult: getLang('select_work_position_select'),
  149. 147.  -       introText: getLang('select_work_position_select'),
  150. 148.  -       selectedItems: [work.position_val],
  151. 149.  -       dropdown: false,
  152. 150.  -       enableCustom: true,
  153. 151.  -       progressBar: 'progress' + work.id,
  154. 152.  -       onChange: function(value) {
  155. 153.  -         var val = intval(value);
  156. 154.  -         if (!val) {
  157. 155.  -           work.uiPosition.clear();
  158. 156.  -         }
  159. 157.  -       },
  160. 158.  -       dark: 1
  161. 159.  -     });
  162. 160.  -
  163. 161.  -     ProfileEditorJob.initGroupCompany(work);
  164. 162.  -
  165. 163.  -     ge('work' + work.id).style.display = 'block';
  166. 164.  -     if (work.city || work.company_gid) {
  167. 165.  -       ge('details' + work.id).style.display = 'block';
  168. 166.  -     }
  169. 167.  -
  170. 168.  -     return work;
  171. 169.  -   },
  172. 170.  -
  173. 171.  -   initGroupCompany: function(work) {
  174. 172.  -     var opts = {
  175. 173.  -       width: 200,
  176. 174.  -       autocomplete: true,
  177. 175.  -       enableCustom: true,
  178. 176.  -       noResult: '',
  179. 177.  -       placeholder: cur.workCompanyPlaceholder,
  180. 178.  -       defaultItems: cur.groupsList,
  181. 179.  -       onChange: function(val) {
  182. 180.  -         if (parseInt(val) !== -1) {
  183. 181.  -           var gid = parseInt(val);
  184. 182.  -           var countryInfo = cur.countryInfo[gid];
  185. 183.  -           if (countryInfo && countryInfo[0]) {
  186. 184.  -             work.uiCountry.selectItem(countryInfo[0]);
  187. 185.  -             if (countryInfo[1]) {
  188. 186.  -               work.uiCity.selectItem(countryInfo[1]);
  189. 187.  -             }
  190. 188.  -           }
  191. 189.  -           var found = false;
  192. 190.  -           for (var i in cur.groupsList) {
  193. 191.  -             if (cur.groupsList[i][0] == gid) {
  194. 192.  -               found = true;
  195. 193.  -             }
  196. 194.  -           }
  197. 195.  -           if (!found && cur.searchList[gid]) {
  198. 196.  -             cur.groupsList.push(cur.searchList[gid]);
  199. 197.  -           }
  200. 198.  -         }
  201. 199.  -       },
  202. 200.  -       onData: function(data) {
  203. 201.  -         if (!cur.searchList) {
  204. 202.  -           cur.searchList = {};
  205. 203.  -         }
  206. 204.  -         for(var i in data) {
  207. 205.  -           cur.searchList[data[i][0]] = data[i];
  208. 206.  -         }
  209. 207.  -       },
  210. 208.  -       withIcons: true,
  211. 209.  -       dark: true,
  212. 210.  -       dropdown:      true,
  213. 211.  -       multiselect:   false,
  214. 212.  -       al: true,
  215. 213.  -       hideDropdown: true,
  216. 214.  -       noArr: true
  217. 215.  -     };
  218. 216.  -
  219. 217.  -     work.uiCity = new CitySelect(ge('city' + work.id), ge('row_city' + work.id), {
  220. 218.  -       width: 200,
  221. 219.  -       progressBar: 'progress' + work.id,
  222. 220.  -       country: work.country,
  223. 221.  -       city: work.city_val,
  224. 222.  -       onChange: function(value) {
  225. 223.  -         if (intval(value)) {
  226. 224.  -           show('details' + work.id);
  227. 225.  -         } else {
  228. 226.  -           hide('details' + work.id);
  229. 227.  -         }
  230. 228.  -       },
  231. 229.  -       dark: 1
  232. 230.  -     });
  233. 231.  -     work.uiCountry = new CountrySelect(ge('country' + work.id), ge('row_country' + work.id), {
  234. 232.  -       width: 200,
  235. 233.  -       progressBar: 'progress' + work.id,
  236. 234.  -       country: work.country_val,
  237. 235.  -       citySelect: work.uiCity,
  238. 236.  -       dark: 1
  239. 237.  -     });
  240. 238.  -
  241. 239.  -     if (work.company_name) {
  242. 240.  -       var companyName = winToUtf(work.company_name);
  243. 241.  -       if (work.company_gid) {
  244. 242.  -         opts.selectedItems = [work.company_gid];
  245. 243.  -       } else {
  246. 244.  -         opts.selectedItems = [[-1, companyName]];
  247. 245.  -       }
  248. 246.  -     }
  249. 247.  -     //var groupsUrl = '/adsedit?act=search_user_objects&section=groups&events_future=1';
  250. 248.  -     var groupsUrl = '/edit?act=a_career_groups';
  251. 249.  -     work.uiGroup = new Autocomplete(ge('group'+work.id), groupsUrl, opts);
  252. 250.  -   },
  253. 251.  -
  254. 252.  -   addWork: function() {
  255. 253.  -     if (cur.worksCount >= 7) {
  256. 254.  -       return false;
  257. 255.  -     }
  258. 256.  -     var new_work = {
  259. 257.  -       id: -(++cur.globalCounter),
  260. 258.  -       country: cur.selData.mem.country,
  261. 259.  -       country_val: cur.selData.mem.country_val,
  262. 260.  -       city: cur.selData.mem.city,
  263. 261.  -       city_val: cur.selData.mem.city_val,
  264. 262.  -       company_name: '',
  265. 263.  -       start: 0,
  266. 264.  -       finish: 0,
  267. 265.  -       position: 0,
  268. 266.  -       position_val: ''
  269. 267.  -     };
  270. 268.  -     ge('works').appendChild(this.genWorkRow(new_work.id));
  271. 269.  -     new_work = this.initWorkRow(new_work);
  272. 270.  -     if (!cur.works.length) {
  273. 271.  -       cur.works = new Array();
  274. 272.  -     }
  275. 273.  -     cur.works.push(new_work);
  276. 274.  -     ++cur.worksCount;
  277. 275.  -     if (cur.worksCount >= 7) {
  278. 276.  -       hide('add_work_link');
  279. 277.  -     }
  280. 278.  -     return false;
  281. 279.  -   },
  282. 280.  -
  283. 281.  -   getIndex: function(data, id) {
  284. 282.  -     for (var i = 0; i < data.length; ++i) {
  285. 283.  -       if (data[i].id == id) {
  286. 284.  -         return i;
  287. 285.  -       }
  288. 286.  -     }
  289. 287.  -     return false;
  290. 288.  -   },
  291. 289.  -
  292. 290.  -   deleteWork: function(id) {
  293. 291.  -     --cur.worksCount;
  294. 292.  -     show('add_work_link');
  295. 293.  -     if ((ge('position' + id).value.length) || (id > 0)) {
  296. 294.  -       hide('content' + id);
  297. 295.  -       ge('deleted' + id).firstChild.innerHTML = getLang('profileEdit_work_will_be_deleted');
  298. 296.  -       show('deleted' + id);
  299. 297.  -     } else {
  300. 298.  -       var index = this.getIndex(cur.works, id);
  301. 299.  -       cur.works[index] = cur.works[cur.works.length - 1];
  302. 300.  -       cur.works.pop();
  303. 301.  -       ge('work' + id).parentNode.removeChild(ge('work' + id));
  304. 302.  -       if (cur.works.length == 0) {
  305. 303.  -         this.addWork();
  306. 304.  -       }
  307. 305.  -     }
  308. 306.  -     return false;
  309. 307.  -   },
  310. 308.  -
  311. 309.  -   restoreWork: function(id) {
  312. 310.  -     if (cur.worksCount >= 7) {
  313. 311.  -       return false;
  314. 312.  -     }
  315. 313.  -     hide('deleted' + id);
  316. 314.  -     show('content' + id);
  317. 315.  -     ++cur.worksCount;
  318. 316.  -     if (cur.worksCount >= 7) {
  319. 317.  -       hide('add_work_link');
  320. 318.  -     }
  321. 319.  -     return false;
  322. 320.  -   },
  323. 321.  -
  324. 322.  -   addFields: function() {
  325. 323.  -     var params = arguments[0];
  326. 324.  -     var id = arguments[1];
  327. 325.  -     var index = arguments[2];
  328. 326.  -     for (var i = 3; i < arguments.length; ++i) {
  329. 327.  -       if (intval(ge(arguments[i] + id).value)) {
  330. 328.  -         params[arguments[i] + index] = ge(arguments[i] + id).value;
  331. 329.  -       }
  332. 330.  -     }
  333. 331.  -     return params;
  334. 332.  -   },
  335. 333.  -
  336. 334.  -   saveWorks: function(btn) {
  337. 335.  -     var params = {act: 'a_save_career', hash: ge('hash').value};
  338. 336.  -     for (var i = 0; i < cur.works.length; ++i) {
  339. 337.  -       var id = cur.works[i].id;
  340. 338.  -       params['id' + i] = id;
  341. 339.  -       if (isVisible('content' + id)) {
  342. 340.  -         params = this.addFields(params, id, i, 'start', 'finish');
  343. 341.  -         var company = cur.works[i].uiGroup.val_full();
  344. 342.  -         params['company'+i] = company[1];
  345. 343.  -         params = this.addFields(params, id, i, 'country', 'city');
  346. 344.  -         var groupId = intval(company[0]);
  347. 345.  -         if (groupId != -1) {
  348. 346.  -           params['group'+i] = groupId;
  349. 347.  -         }
  350. 348.  -
  351. 349.  -         //params = this.addTextFields(params, id, i, 'company');
  352. 350.  -
  353. 351.  -         if (ge('position' + id).value.length) {
  354. 352.  -           var position_val = cur.works[i].uiPosition.val_full();
  355. 353.  -           var position = position_val[1] || '';
  356. 354.  -           if (position.length) {
  357. 355.  -             params['position' + i] = position;
  358. 356.  -           }
  359. 357.  -         }
  360. 358.  -       } else {
  361. 359.  -         params['deleted' + i] = 1;
  362. 360.  -       }
  363. 361.  -     }
  364. 362.  -
  365. 363.  -     var doneHandler = function(response) {
  366. 364.  -       var to_remove = [];
  367. 365.  -       var worksCont = ge('works');
  368. 366.  -       var oldWorksElems = geByClass('pedit_edu_big_row', worksCont)
  369. 367.  -       for (var i in oldWorksElems) {
  370. 368.  -         worksCont.removeChild(oldWorksElems[i]);
  371. 369.  -       }
  372. 370.  -       //var i = cur.works.length;
  373. 371.  -       //while(i--) {
  374. 372.  -       var worksList = [];
  375. 373.  -
  376. 374.  -       for (var i = 0; i < cur.works.length; ++i) {
  377. 375.  -         var new_work_id = response['res' + i];
  378. 376.  -         if (intval(new_work_id)) {
  379. 377.  -           worksList[i] = this.updateWork(cur.works[i], new_work_id, worksCont);
  380. 378.  -         }
  381. 379.  -       }
  382. 380.  -       cur.works = worksList;
  383. 381.  -       cur.worksCount = cur.works.length;
  384. 382.  -       if (cur.worksCount >= 7) {
  385. 383.  -         hide('add_work_link');
  386. 384.  -       } else {
  387. 385.  -         show('add_work_link');
  388. 386.  -       }
  389. 387.  -       if (!cur.worksCount) {
  390. 388.  -         this.addWork();
  391. 389.  -       }
  392. 390.  -     }
  393. 391.  -
  394. 392.  -     ajax.post('al_profileEdit.php', params, {
  395. 393.  -       onDone: function (job_data) {
  396. 394.  -         doneHandler.call(ProfileEditorJob, job_data);
  397. 395.  -         ProfileEditor.showMsg(getLang('profileEdit_works_saved'));
  398. 396.  -       },
  399. 397.  -       showProgress: lockButton.pbind(btn),
  400. 398.  -       hideProgress: unlockButton.pbind(btn)
  401. 399.  -     });
  402. 400.  -     return false;
  403. 401.  -   },
  404. 402.  -
  405. 403.  -   updateWork: function(old_work, new_work_id, parent) {
  406. 404.  -     old_work.country = old_work.uiCountry.val();
  407. 405.  -     old_work.country_val = old_work.uiCountry.val_full();
  408. 406.  -     old_work.city = old_work.uiCity.val();
  409. 407.  -     old_work.city_val = old_work.uiCity.val_full();
  410. 408.  -     old_work.company = old_work.uiGroup.val()
  411. 409.  -     old_work.company_val = old_work.uiGroup.val_full()
  412. 410.  -     old_work.company_name = old_work.company_val[1];
  413. 411.  -     if (old_work.company_val[0] && old_work.company_val[0] != '-1') {
  414. 412.  -       old_work.company_gid = old_work.company_val[0];
  415. 413.  -     }
  416. 414.  -
  417. 415.  -     old_work.start = old_work.uiStart.val();
  418. 416.  -     old_work.finish = old_work.uiFinish.val();
  419. 417.  -     old_work.position = old_work.uiPosition.val();
  420. 418.  -     old_work.position_val = old_work.uiPosition.val_full();
  421. 419.  -
  422. 420.  -     var new_elem = this.genWorkRow(new_work_id);
  423. 421.  -     show(new_elem);
  424. 422.  -     old_work.id = new_work_id;
  425. 423.  -
  426. 424.  -     parent.appendChild(new_elem);
  427. 425.  -
  428. 426.  -     new_work = this.initWorkRow(old_work, new_elem);
  429. 427.  -
  430. 428.  -     return new_work;
  431. 429.  -   },
  432. 430.  -
  433. 431.  -   workChanged: function(work) {
  434. 432.  -     var old_position = work.position_val[1] || '', position = (work.uiPosition.val_full() || [])[1] || '';
  435. 433.  -
  436. 434.  -     return !isVisible('content' + work.id) ||
  437. 435.  -            work.country != work.uiCountry.val() || work.city != work.uiCity.val() ||
  438. 436.  -            winToUtf(work.company_name) != work.uiGroup.val_full()[1] || winToUtf(old_position) != winToUtf(position) ||
  439. 437.  -            work.start != work.uiStart.val() || work.finish != work.uiFinish.val();
  440. 438.  -   }
  441. 439.  - };
  442. 440.  -
  443. 441.  - try{stManager.done('profile_edit_job.js');}catch(e){}
  444. ------
Advertisement
Add Comment
Please, Sign In to add comment