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