PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/contactcenter/js/cc.js

https://github.com/muchael/expressolivre
JavaScript | 3165 lines | 2478 code | 451 blank | 236 comment | 536 complexity | 9fb245c147be0855330935dc4aa3dc0f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-2-Clause, BSD-3-Clause, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /******************************************************************************\
  2. * eGroupWare - Contacts Center *
  3. * http://www.egroupware.org *
  4. * Written by: *
  5. * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> *
  6. * - Jonas Goes <jqhcb@users.sourceforge.net> *
  7. * sponsored by Thyamad - http://www.thyamad.com *
  8. * ------------------------------------------------------------------------- *
  9. * This program is free software; you can redistribute it and/or modify it *
  10. * under the terms of the GNU General Public License as published by the *
  11. * Free Software Foundation; either version 2 of the License, or (at your *
  12. * option) any later version. *
  13. \******************************************************************************/
  14. /***********************************************\
  15. * TODO *
  16. \***********************************************/
  17. /*
  18. * function setHeightSpace ()
  19. *
  20. */
  21. /***********************************************\
  22. * CONSTANTS *
  23. \***********************************************/
  24. var CC_STATUS_FULL_ADD = 2;
  25. var CC_STATUS_QUICK_ADD = 1;
  26. var CC_card_image_width = 245;
  27. var CC_card_image_height = 130;
  28. var CC_card_extra = 16;
  29. /***********************************************\
  30. * GLOBALS VARIABLES *
  31. \***********************************************/
  32. var owners = new Array();
  33. var flag_compartilhado = false;
  34. var qtd_compartilhado = 0;
  35. var CC_visual = 'table';
  36. /* Cards Variables */
  37. var CC_actual_letter = 'a';
  38. var CC_last_letter = 'a';
  39. var CC_actual_page = 1;
  40. var CC_npages = 0;
  41. var CC_max_cards = new Array();
  42. var CC_conn_count=0;
  43. var CC_old_icon_w = 0;
  44. var CC_old_icon_h = 0;
  45. /* Tabs Variables */
  46. var CC_last_tab = 0;
  47. /* Pseudo-Semafores */
  48. var CC_tree_available = false;
  49. var CC_full_add_const = false;
  50. var CC_full_add_photo = false;
  51. var CC_last_height = window.innerHeight;
  52. var CC_last_width = window.innerWidth;
  53. /* Contact Full Info */
  54. var CC_contact_full_info;
  55. var CC_br_index;
  56. /* Addresses Variables */
  57. var CC_addr_last_selected = 0;
  58. /* Connections Variables */
  59. var CC_conn_last_selected = 0;
  60. var not_informed_text;
  61. /* Grupos inicialmente selecionados */
  62. var CC_initial_selected_grps = new Array();
  63. /***********************************************\
  64. * FULL ADD/EDIT FUNCTIONS *
  65. \***********************************************/
  66. function createPhotoFrame()
  67. {
  68. photo_frame = document.createElement('iframe');
  69. document.body.appendChild(photo_frame);
  70. if (is_ie)
  71. {
  72. photo_form = photo_frame.contentWindow.document.createElement('form');
  73. photo_input = photo_frame.contentWindow.document.createElement('input');
  74. }
  75. else
  76. {
  77. photo_form = photo_frame.contentDocument.createElement('form');
  78. photo_input = photo_frame.contentDocument.createElement('input');
  79. }
  80. photo_frame.id = 'cc_photo_frame';
  81. photo_frame.style.position = 'absolute';
  82. //photo_frame.style.visibility = 'hidden';
  83. photo_frame.style.top = '600px';
  84. photo_frame.style.left = '0px';
  85. photo_form.id = 'cc_photo_form';
  86. photo_form.method = 'POST';
  87. photo_form.enctype = 'multipart/form-data';
  88. photo_input.id = 'cc_photo_input';
  89. photo_input.type = 'file';
  90. if (is_ie)
  91. {
  92. photo_frame.contentWindow.document.body.appendChild(photo_form);
  93. }
  94. else
  95. {
  96. photo_frame.contentDocument.body.appendChild(photo_form);
  97. }
  98. photo_form.appendChild(photo_input);
  99. }
  100. /********* Full Add Auxiliar Functions ****************/
  101. function selectOption (id, option)
  102. {
  103. var obj = Element(id);
  104. var max = obj.options.length;
  105. if (option == undefined)
  106. {
  107. obj.selectedIndex = 0;
  108. }
  109. else
  110. {
  111. for (var i = 0; i < max; i++)
  112. {
  113. if (obj.options[i].value == option)
  114. {
  115. obj.selectedIndex = i;
  116. break;
  117. }
  118. }
  119. }
  120. }
  121. function selectRadio (id, index)
  122. {
  123. var obj = Element(id);
  124. var max = obj.options.length;
  125. for (var i = 0; i < max; i++)
  126. {
  127. i == index ? obj.options[i].checked = true : obj.options[i].checked = false;
  128. }
  129. }
  130. function clearSelectBox(obj, startIndex)
  131. {
  132. var nOptions = obj.options.length;
  133. for (var i = nOptions - 1; i >= startIndex; i--)
  134. {
  135. obj.removeChild(obj.options[i]);
  136. }
  137. }
  138. /********** Open/Close FullAdd *************/
  139. function openFullAdd(){
  140. // Build the FullAdd Window.
  141. if(!fullAddWin && !is_ie)
  142. __f();
  143. resetFullAdd();
  144. populateFullAddConst();
  145. fullAddWin.open();
  146. tabs._showTab('cc_contact_tab_0');
  147. Element('cc_full_add_window_clientArea').style.background = '#EEE';
  148. Element("cc_conn_type_1").checked = false;
  149. Element("cc_conn_type_2").checked = false;
  150. Element("cc_conn_type_sel").disabled = true;
  151. Element("cc_conn_type_sel").selectedIndex = 0;
  152. Element("cc_contact_sharing").style.display = 'none';
  153. }
  154. function openFullAddShared(){
  155. if (flag_compartilhado)
  156. {
  157. if(!fullAddWin && !is_ie)
  158. __f();
  159. resetFullAdd();
  160. populateFullAddConst();
  161. fullAddWin.open();
  162. tabs._showTab('cc_contact_tab_0');
  163. Element("cc_conn_type_1").checked = false;
  164. Element("cc_conn_type_2").checked = false;
  165. Element("cc_conn_type_sel").disabled = true;
  166. Element("cc_conn_type_sel").selectedIndex = 0;
  167. Element("cc_contact_sharing").align = 'center';
  168. Element("cc_contact_sharing").style.display = 'block';
  169. Element("cc_contact_shared_types").disabled = true;
  170. populateSharingSelect();
  171. } else
  172. {
  173. if(qtd_compartilhado != 0)
  174. {
  175. ccTree.select(0.2);
  176. ccTree.setCatalog(0.2);
  177. if(!fullAddWin && !is_ie)
  178. __f();
  179. resetFullAdd();
  180. populateFullAddConst();
  181. fullAddWin.open();
  182. tabs._showTab('cc_contact_tab_0');
  183. Element("cc_conn_type_1").checked = false;
  184. Element("cc_conn_type_2").checked = false;
  185. Element("cc_conn_type_sel").disabled = true;
  186. Element("cc_conn_type_sel").selectedIndex = 0;
  187. Element("cc_contact_sharing").aling = 'center';
  188. Element("cc_contact_sharing").style.display = 'block';
  189. Element("cc_contact_shared_types").disabled = true;
  190. populateSharingSelect();
  191. } else
  192. showMessage(Element('cc_msg_err_shared').value);
  193. }
  194. if(Element('cc_full_add_window_clientArea'))
  195. Element('cc_full_add_window_clientArea').style.background = '#EEE';
  196. }
  197. function closeFullAdd(){
  198. fullAddWin.close();
  199. }
  200. /******** Contact details ***********/
  201. function openContactDetails(id){
  202. // Build the ContactDetails Window.
  203. if((typeof(contactdetailsWin) == 'undefined') && !is_ie)
  204. __cdWin();
  205. contactdetailsWin.open();
  206. populateContactDetails(id);
  207. }
  208. function populateContactDetails(id)
  209. {
  210. var handler = function(responseText)
  211. {
  212. var fieldsDiv = Element('id_cc_contact_details_fields');
  213. var data = unserialize(responseText);
  214. //alert(responseText);
  215. fieldsDiv.innerHTML = "";
  216. if (data && data.length > 0)
  217. {
  218. //fieldsDiv.innerHTML = "";
  219. var table = document.createElement("table");
  220. table.border=0;
  221. //table.style.borderBottom = '1px solid #999';
  222. //table.cellSpacing = '0';
  223. table.width = '480px';
  224. var attr_name_size = '50%';
  225. var attr_value_size = '50%';
  226. for(i = 0; i < data.length; i++)
  227. {
  228. var row = table.insertRow(i);
  229. if ((i % 2) == 0)
  230. row.setAttribute('class', 'row_off');
  231. else
  232. row.setAttribute('class', 'row_on');
  233. //row.style.borderBottom = '1px solid #999';
  234. attr_name = row.insertCell(0);
  235. attr_value = row.insertCell(1);
  236. attr_name.style.width = attr_name_size;
  237. attr_value.style.width = attr_value_size;
  238. attr_name.innerHTML = data[i]['name'];
  239. if (data[i]['type'] == 'text')
  240. attr_value.innerHTML = data[i]['value'];
  241. else
  242. {
  243. var multivalue_div = document.createElement("div");
  244. multivalue_div.style.overflow = 'auto';
  245. multivalue_div.style.height = '100px';
  246. multivalue_div.style.border = '1px solid #999';
  247. //multivalue_div.style.backgroundColor = 'transparent';
  248. for (j = 0; j < data[i]['value'].length; j++)
  249. {
  250. multivalue_div.appendChild(document.createTextNode(data[i]['value'][j]));
  251. multivalue_div.appendChild(document.createElement("br"));
  252. }
  253. attr_value.appendChild(multivalue_div);
  254. }
  255. }
  256. fieldsDiv.appendChild(table);
  257. }
  258. else
  259. fieldsDiv.innerHTML = Element('cc_contact_details_no_fields').value;
  260. };
  261. Connector.newRequest('populateContactDetails', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_contact_details&id=' + id, 'GET', handler);
  262. }
  263. function closeContactDetails(){
  264. contactdetailsWin.close();
  265. }
  266. /********** New Contact *************/
  267. function newContact(){
  268. openFullAdd();
  269. }
  270. function newSharedContact(){
  271. openFullAddShared();
  272. }
  273. /************ Edit Contact *************/
  274. function editContact (id){
  275. openFullAdd();
  276. populateFullEdit(id,'bo_people_catalog');
  277. }
  278. function editSharedContact (id){
  279. openFullAdd();
  280. populateFullEdit(id,'bo_shared_people_manager');
  281. }
  282. /************ Edit Group *************/
  283. function editGroup(id){
  284. populateEditGroup(id);
  285. ccAddGroup.window.open();
  286. }
  287. function editSharedGroup(id,shared){
  288. populateEditSharedGroup(id, shared);
  289. }
  290. /*
  291. Updates all the constant fields in the
  292. full add window, like Prefixes, Suffixes,
  293. Countries and Types
  294. */
  295. function populateSharingSelect()
  296. {
  297. var handler = function(responseText)
  298. {
  299. var data = unserialize(responseText);
  300. var sharers = Element('cc_contact_shared_types');
  301. if (typeof(data) != 'object')
  302. {
  303. showMessage(Element('cc_msg_err_contacting_server').value);
  304. fullAddWin.close();
  305. return;
  306. }else{
  307. sharers.disabled = false;
  308. j = 1;
  309. for (var i in data)
  310. {
  311. sharers.options[j] = new Option(data[i]['cn'], i);
  312. owners[j] = i;
  313. j++;
  314. }
  315. return;
  316. }
  317. };
  318. Connector.newRequest('populateSharingSelect', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_list_owners_perms_add', 'POST', handler);
  319. }
  320. function populateFullAddConst()
  321. {
  322. CC_full_add_const = false;
  323. setTimeout('populateFullAddConstAsync()', 10);
  324. }
  325. function populateFullAddConstAsync()
  326. {
  327. var handler = function(responseText)
  328. {
  329. //Element('cc_debug').innerHTML = responseText;
  330. var data = unserialize(responseText);
  331. var i = 1;
  332. var j;
  333. if (typeof(data) != 'object')
  334. {
  335. showMessage(Element('cc_msg_err_contacting_server').value);
  336. return;
  337. }
  338. /* Populate Prefixes */
  339. for (j in data[0])
  340. {
  341. Element('cc_pd_prefix').options[i] = new Option(data[0][j], j);
  342. i++;
  343. }
  344. /* Populate Suffixes */
  345. i = 1;
  346. for (j in data[1])
  347. {
  348. Element('cc_pd_suffix').options[i] = new Option(data[1][j], j);
  349. i++;
  350. }
  351. /* Populate Addresses Types */
  352. i = 1;
  353. for (j in data[2])
  354. {
  355. Element('cc_addr_types').options[i] = new Option(data[2][j], j);
  356. i++;
  357. }
  358. /* Populate Countries */
  359. i = 1;
  360. for (j in data[3])
  361. {
  362. Element('cc_addr_countries').options[i] = new Option(data[3][j], j);
  363. if (j == 'BR' || j == 'br')
  364. {
  365. CC_br_index = i;
  366. }
  367. i++;
  368. }
  369. /* Populate Connection Types */
  370. /*
  371. * Cуdigo nгo funcional com o expresso.
  372. */
  373. /*i = 1;
  374. for (j in data[4])
  375. {
  376. Element('cc_conn_type').options[i] = new Option(data[4][j], j);
  377. i++;
  378. }*/
  379. /* Populate Relations Types */
  380. /*
  381. * Cуdigo conflitante com a modificaзгo de seleзгo de grupos durante
  382. * a criaзгo de um novo contato. Tambйm foi verificado que este cуdigo nгo
  383. * й funcional.
  384. */
  385. /*
  386. i = 0;
  387. for (j in data[5])
  388. {
  389. Element('cc_rels_type').options[i] = new Option(data[5][j], j);
  390. i++;
  391. }*/
  392. /* Populate available groups */
  393. i = 0;
  394. var grupos = data[5];
  395. for (var grupo in grupos)
  396. {
  397. Element('id_grps_available').options[i] = new Option(grupos[grupo]['title'], grupos[grupo]['id_group']);
  398. i++;
  399. }
  400. CC_full_add_const = true;
  401. };
  402. Connector.newRequest('populateFullAddConst', CC_url+'get_contact_full_add_const', 'GET', handler);
  403. }
  404. /*
  405. * Funзгo que faz a seleзгo do grupo.
  406. * Autor: Luiz Carlos Viana Melo - Prognus
  407. */
  408. function selectGroup()
  409. {
  410. grps_avail = Element('id_grps_available');
  411. grps_selec = Element('id_grps_selected');
  412. for (i = 0; i < grps_avail.length; i++)
  413. {
  414. if (grps_avail.options[i].selected) {
  415. isSelected = false;
  416. for(var j = 0;j < grps_selec.options.length; j++) {
  417. if(grps_selec.options[j].value === grps_avail.options[i].value){
  418. isSelected = true;
  419. break;
  420. }
  421. }
  422. if(!isSelected){
  423. option = document.createElement('option');
  424. option.value = grps_avail.options[i].value;
  425. option.text = grps_avail.options[i].text;
  426. option.selected = false;
  427. grps_selec.options[grps_selec.options.length] = option;
  428. }
  429. }
  430. }
  431. for (j =0; j < grps_avail.options.length; j++)
  432. grps_avail.options[j].selected = false;
  433. }
  434. /*
  435. * Funзгo que remove um grupo selecionado.
  436. * Autor: Luiz Carlos Viana Melo - Prognus
  437. */
  438. function deselectGroup()
  439. {
  440. grps_selec = Element('id_grps_selected');
  441. for(var i = 0;i < grps_selec.options.length; i++)
  442. if(grps_selec.options[i].selected)
  443. grps_selec.options[i--] = null;
  444. }
  445. function populateFullEdit (id,catalog)
  446. {
  447. var handler = function(responseText)
  448. {
  449. //Element('cc_debug').innerHTML = responseText;
  450. var data = unserialize(responseText);
  451. if (typeof(data) != 'object' || data['result'] != 'ok')
  452. {
  453. showMessage(Element('cc_msg_err_contacting_server').value);
  454. return;
  455. }
  456. resetFullAdd();
  457. CC_contact_full_info = data;
  458. Element('cc_full_add_contact_id').value = data['cc_full_add_contact_id'];
  459. populatePersonalData(data['personal']);
  460. populateContactGroups(data['groups']);
  461. //populateRelations(data['relations']);
  462. };
  463. Connector.newRequest('populateFullEdit', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_full_data&id=' + id + "&catalog="+catalog, 'GET', handler);
  464. }
  465. /*
  466. * Funзгo que preenche a lista de grupos a qual o contato pertence.
  467. * Autor: Luiz Carlos Viana Melo - Prognus
  468. */
  469. function populateContactGroups(groupsData)
  470. {
  471. groups_selected = Element('id_grps_selected');
  472. var i = 0;
  473. CC_initial_selected_grps = new Array();
  474. for (var group in groupsData)
  475. {
  476. var id_group = groupsData[group]['id_group'];
  477. option = document.createElement('option');
  478. option.value = id_group;
  479. option.text = groupsData[group]['title'];
  480. option.selected = false;
  481. groups_selected.options[i++] = option;
  482. CC_initial_selected_grps[id_group] = new Array();
  483. CC_initial_selected_grps[id_group]['id_group'] = id_group;
  484. CC_initial_selected_grps[id_group]['title'] = groupsData[group]['title'];
  485. CC_initial_selected_grps[id_group]['short_name'] = groupsData[group]['short_name'];
  486. }
  487. }
  488. function populateEditGroup (id)
  489. {
  490. populateEditSharedGroup(id,false);
  491. }
  492. function populateEditSharedGroup(id,shared) {
  493. var handler = function(responseText)
  494. {
  495. var data = unserialize(responseText);
  496. Element('group_id').value = data['id_group'];
  497. var options_contact_list = Element('span_contact_list');
  498. var select_contact_list = '<select id="contact_list" multiple name="contact_list[]" style="width:280px" size="10">';
  499. select_contact_list += data['contact_list'] + "</select>";
  500. options_contact_list.innerHTML = select_contact_list;
  501. if(data['id_group']) {
  502. Element('title').value = data['title'];
  503. if(data['contact_in_list']) {
  504. for(i = 0; i < data['contact_in_list'].length; i++) {
  505. option = document.createElement('option');
  506. option.value = data['contact_in_list'][i]['id_connection'];
  507. option.text = data['contact_in_list'][i]['names_ordered']+' ('+data['contact_in_list'][i]['connection_value']+')';
  508. Element('contact_in_list').options[Element('contact_in_list').options.length] = option;
  509. }
  510. }
  511. Element('title').value = data['title'];
  512. }
  513. if (typeof(data) != 'object' || data['result'] != 'ok')
  514. {
  515. showMessage(Element('cc_msg_err_contacting_server').value);
  516. return;
  517. }
  518. ccAddGroup.setSelectedSourceLevel(ccTree.actualLevel);
  519. ccAddGroup.openEditWindow();
  520. };
  521. id = typeof(id) == 'undefined' ? id = 0 : id;
  522. ccAddGroup.clear(true);
  523. if(!shared)
  524. Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
  525. else
  526. Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id+'&shared_from='+shared, 'GET', handler);
  527. }
  528. function resetFullAdd()
  529. {
  530. /* Groups */
  531. gprs_selected = Element('id_grps_selected');
  532. if(gprs_selected != null){
  533. for (j =0; j < gprs_selected.options.length; j++) {
  534. gprs_selected.options[j].selected = false;
  535. gprs_selected.options[j--] = null;
  536. }
  537. }
  538. /* Clear information container */
  539. CC_contact_full_info = new Array();
  540. /* Clear Fields */
  541. Element('cc_full_add_form_personal').reset();
  542. Element('cc_full_add_form_addrs').reset();
  543. if(Element('cc_contact_type').value=='advanced')
  544. Element('cc_full_add_form_corporative').reset();
  545. /* Personal Data */
  546. Element('cc_full_add_contact_id').value = null;
  547. Element('cc_pd_photo').src = 'templates/default/images/photo.png';
  548. /* Addresses */
  549. resetAddressFields();
  550. /* Connections */
  551. CC_conn_last_selected = '_NONE_';
  552. Element("cc_phone_default").options.selectedIndex = '-1';
  553. Element("cc_email_default").options.selectedIndex = '-1';
  554. Element("div_cc_conn_is_default").style.display = 'none';
  555. clearConn();
  556. }
  557. function postFullAdd()
  558. {
  559. if (!checkFullAdd())
  560. {
  561. return false;
  562. }
  563. //Force emails to Lower Case
  564. txtField0 = Element("cc_conn_value_0");
  565. if (txtField0 != null && (txtField0.value.length > 0)) {
  566. txtField0.value = txtField0.value.toLowerCase();
  567. }
  568. txtField1 = Element("cc_conn_value_1");
  569. if (txtField1 != null && (txtField1.value.length > 0)) {
  570. txtField1.value = txtField1.value.toLowerCase();
  571. }
  572. /* First thing: Send Photo */
  573. if (Element('cc_pd_select_photo').value != '' && !is_ie)
  574. {
  575. var nodes;
  576. var form, frame, old_frame;
  577. CC_full_add_photo = false;
  578. old_frame = Element('cc_photo_frame');
  579. if (!old_frame)
  580. {
  581. frame = document.createElement('iframe');
  582. }
  583. else
  584. {
  585. frame = old_frame;
  586. }
  587. frame.id = 'cc_photo_frame';
  588. frame.style.visibility = 'hidden';
  589. frame.style.top = '0px';
  590. frame.style.left = '0';
  591. frame.style.position = 'absolute';
  592. document.body.appendChild(frame);
  593. form = frame.contentDocument.createElement('form');
  594. var id_contact = Element('cc_full_add_contact_id').value;
  595. form.id = 'cc_form_photo';
  596. form.method = 'POST';
  597. form.enctype = 'multipart/form-data';
  598. form.action = 'http://'+ document.domain + Element('cc_root_dir').value+'../index.php?menuaction=contactcenter.ui_data.data_manager&method=post_photo&id='+(id_contact != '' && id_contact != 'null' ? id_contact : '');
  599. var input_clone = Element('cc_pd_select_photo').cloneNode(false);
  600. form.appendChild(input_clone);
  601. frame.contentDocument.body.appendChild(form);
  602. form.submit();
  603. CC_full_add_photo = true;
  604. }
  605. else if (Element('cc_pd_select_photo_t').value != '' && is_ie)
  606. {
  607. CC_full_add_photo = false;
  608. var frame = Element('cc_photo_frame');
  609. var form = frame.contentWindow.document.all['cc_photo_form'];
  610. var id_contact = Element('cc_full_add_contact_id').value;
  611. form.action = 'http://'+ document.domain + Element('cc_root_dir').value+'../index.php?menuaction=contactcenter.ui_data.data_manager&method=post_photo&id='+(id_contact != '' && id_contact != 'null' ? id_contact : '');
  612. form.submit();
  613. setTimeout('Element(\'cc_photo_frame\').src = \'cc_photo_frame.html\'', 1000);
  614. CC_full_add_photo = true;
  615. }
  616. if (Element('cc_contact_sharing').style.display == 'none')
  617. setTimeout('postFullAddInfo()', 100);
  618. else
  619. setTimeout('postFullAddInfoShared()', 100);
  620. updateCards();
  621. }
  622. function postFullAddInfo()
  623. {
  624. var handler = function (responseText)
  625. {
  626. var data = unserialize(responseText);
  627. if (typeof(data) != 'object')
  628. {
  629. showMessage(Element('cc_msg_err_contacting_server').value);
  630. return;
  631. }
  632. if (data['status'] != 'ok')
  633. {
  634. showMessage(data['msg']);
  635. return;
  636. }
  637. fullAddWin.close();
  638. updateCards();
  639. };
  640. Connector.newRequest('postFullAddInfo', CC_url+'post_full_add', 'POST', handler, getFullAddData());
  641. }
  642. function postFullAddInfoShared()
  643. {
  644. var handler = function (responseText)
  645. {
  646. var data = unserialize(responseText);
  647. if (typeof(data) != 'object')
  648. {
  649. showMessage(Element('cc_msg_err_contacting_server').value);
  650. return;
  651. }
  652. if (data['status'] != 'ok')
  653. {
  654. showMessage(data['msg']);
  655. return;
  656. }
  657. fullAddWin.close();
  658. updateCards();
  659. };
  660. Connector.newRequest('postFullAddInfoShared', CC_url+'post_full_add_shared', 'POST', handler, getFullAddData());
  661. }
  662. function getFullAddData()
  663. {
  664. var data = new Array();
  665. var empty = true;
  666. var replacer = '__##AND##__';
  667. data['commercialAnd'] = replacer;
  668. if (Element('cc_full_add_contact_id').value != '' && Element('cc_full_add_contact_id').value != 'null')
  669. {
  670. data['id_contact'] = replaceComAnd(Element('cc_full_add_contact_id').value, replacer);
  671. data.length++;
  672. }
  673. /* Owner do contato (Para o caso de adicao de contato compartilhado) */
  674. if (Element('cc_contact_sharing').style.display == 'block')
  675. {
  676. var index = Element('cc_contact_shared_types').selectedIndex;
  677. data['owner'] = replaceComAnd(owners[index], replacer);
  678. data.length++;
  679. }
  680. /* Status: Full Added */
  681. data['id_status'] = CC_STATUS_FULL_ADD;
  682. /* Personal Data */
  683. data['alias'] = replaceComAnd(Element('cc_pd_alias').value, replacer);
  684. data['id_prefix'] = replaceComAnd(Element('cc_pd_prefix').value, replacer);
  685. data['given_names'] = replaceComAnd(Element('cc_pd_given_names').value, replacer);
  686. data['family_names'] = replaceComAnd(Element('cc_pd_family_names').value, replacer);
  687. data['names_ordered'] = replaceComAnd(data['given_names']+" "+data['family_names'], replacer);
  688. data['id_suffix'] = replaceComAnd(Element('cc_pd_suffix').value, replacer);;
  689. data['birthdate_0'] = replaceComAnd(Element('cc_pd_birthdate_0').value, replacer);
  690. data['birthdate_1'] = replaceComAnd(Element('cc_pd_birthdate_1').value, replacer);
  691. data['birthdate_2'] = replaceComAnd(Element('cc_pd_birthdate_2').value, replacer);
  692. // data['sex'] = Element('cc_pd_sex').value == 1 ? 'M' : Element('cc_pd_sex').value == 2 ? 'F' : null;
  693. data['pgp_key'] = replaceComAnd(Element('cc_pd_gpg_finger_print').value, replacer);
  694. data['notes'] = replaceComAnd(Element('cc_pd_notes').value, replacer);
  695. data.length += 14;
  696. //corporative
  697. if (document.getElementById('cc_contact_type').value == 'advanced') {
  698. data['corporate_name'] = replaceComAnd(document.getElementById('cc_name_corporate').value, replacer);
  699. data['job_title'] = replaceComAnd(document.getElementById('cc_job_title').value, replacer);
  700. data['department'] = replaceComAnd(document.getElementById('cc_department').value, replacer);
  701. data['web_page'] = replaceComAnd(document.getElementById('cc_web_page').value, replacer);
  702. data.length += 18;
  703. }
  704. /* Addresses */
  705. saveAddressFields();
  706. data['addresses'] = CC_contact_full_info['addresses'];
  707. /* Connection */
  708. saveConnFields();
  709. if (CC_contact_full_info['connections'])
  710. {
  711. var connNumber = 0;
  712. for (var type in CC_contact_full_info['connections'])
  713. {
  714. if (type == 'length')
  715. {
  716. continue;
  717. }
  718. if (typeof(data['connections']) != 'object')
  719. {
  720. data['connections'] = new Array();
  721. }
  722. for (var i in CC_contact_full_info['connections'][type])
  723. {
  724. if (i == 'length')
  725. {
  726. continue;
  727. }
  728. if (typeof(data['connections']['connection'+connNumber]) != 'object')
  729. {
  730. data['connections']['connection'+connNumber] = new Array(5);
  731. }
  732. data['connections']['connection'+connNumber]['id_connection'] = CC_contact_full_info['connections'][type][i]['id'];
  733. data['connections']['connection'+connNumber]['id_typeof_connection'] = type;
  734. data['connections']['connection'+connNumber]['connection_name'] = CC_contact_full_info['connections'][type][i]['name'];
  735. data['connections']['connection'+connNumber]['connection_value'] = CC_contact_full_info['connections'][type][i]['value'];
  736. if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value) {
  737. if(Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default").value == CC_contact_full_info['connections'][type][i]['name']){
  738. data['connections']['connection'+connNumber]['connection_is_default'] = 'TRUE';
  739. }
  740. else
  741. data['connections']['connection'+connNumber]['connection_is_default'] = 'FALSE';
  742. }
  743. // data['connections']['connection'+connNumber].length = 5;
  744. empty = false;
  745. connNumber++;
  746. data['connections'].length++;
  747. }
  748. }
  749. if (!empty)
  750. {
  751. data.length++;
  752. empty = true;
  753. }
  754. }
  755. if (CC_contact_full_info['removed_conns'])
  756. {
  757. empty = false;
  758. if (typeof(data['connections']) != 'object')
  759. {
  760. data['connections'] = new Array();
  761. data.length++;
  762. }
  763. data['connections']['removed_conns'] = CC_contact_full_info['removed_conns'];
  764. data['connections'].length++;
  765. }
  766. data['groups'] = getAddedRemovedGroups();
  767. var serial = serialize(data);
  768. return 'data=' + escape(serialize(data));
  769. }
  770. /*
  771. * Funзгo que retorna os grupos que foram anteriormente selecionados, adicionados ou removidos pelo
  772. * usuбrio. O formato retornado й um array contendo:
  773. * ['previous_selected'] {
  774. * [id_group] {
  775. * 'id_group' => o ID do grupo
  776. * 'title' => o tнtulo do grupo
  777. * }
  778. * ['added'] {
  779. * [id_group] {
  780. * 'id_group' => o ID do grupo
  781. * 'title' => o tнtulo do grupo
  782. * }
  783. * },
  784. * ['removed'] {
  785. * [id_group] {
  786. * 'id_group' => o ID do grupo
  787. * 'title' => o tнtulo do grupo
  788. * }
  789. * }
  790. * Autor: Luiz Carlos Viana Melo - Prognus
  791. */
  792. function getAddedRemovedGroups()
  793. {
  794. var selected_groups = getSelectedGroups();
  795. var added_groups = diffContactIDArray(selected_groups, CC_initial_selected_grps);
  796. var removed_groups = diffContactIDArray(CC_initial_selected_grps, selected_groups);
  797. var groups = new Array();
  798. groups['previous_selected'] = CC_initial_selected_grps;
  799. groups['added'] = added_groups;
  800. groups['removed'] = removed_groups;
  801. return groups;
  802. }
  803. /*
  804. * Funзгo que retorna os grupos que foram selecionados pelo usuбrio. O formato retornado й:
  805. * [id_group] {
  806. * 'id_group' => o ID do grupo
  807. * 'title' => o tнtulo do grupo
  808. * }
  809. * Autor: Luiz Carlos Viana Melo - Prognus
  810. */
  811. function getSelectedGroups()
  812. {
  813. var gprs_selected = Element('id_grps_selected');
  814. var data = new Array();
  815. if(gprs_selected != null){
  816. for(i = 0; i < gprs_selected.options.length; i++)
  817. {
  818. var id_group = gprs_selected.options[i].value;
  819. data[id_group] = new Array();
  820. data[id_group]['id_group'] = id_group;
  821. data[id_group]['title'] = gprs_selected.options[i].text;
  822. }
  823. }
  824. return data;
  825. }
  826. /*
  827. * Funзгo que retorna a diferenзa entre 2 arrays com ID dos contatos.
  828. * Autor: Luiz Carlos Viana Melo - Prognus
  829. */
  830. function diffContactIDArray(array1, array2)
  831. {
  832. var diff = new Array();
  833. for (var group in array1)
  834. {
  835. if (!array2[group])
  836. diff.push(array1[group]);
  837. }
  838. return diff;
  839. }
  840. function checkFullAdd()
  841. {
  842. /* Checa se o listbox esta desativado ou й nulo, ou seja, nгo existe catбlogos compartilhados com o user atual */
  843. if (!(Element('cc_contact_sharing').style.display == 'none' ))
  844. {
  845. if (Element('cc_contact_shared_types').disabled == true)
  846. {
  847. showMessage('Nenhum catбlogo compartilhado existente');
  848. return false;
  849. }
  850. if (Element('cc_contact_shared_types').selectedIndex == 0)
  851. {
  852. showMessage('Nenhum catбlogo selecionado');
  853. return false;
  854. }
  855. }
  856. /* Check Personal Data */
  857. if ($.trim(Element('cc_pd_given_names').value) == '')
  858. {
  859. showMessage(Element('cc_msg_err_empty_field').value + " => " + Element('cc_pd_given_names').name);
  860. return false;
  861. }
  862. /* Check Addresses */
  863. /* Check Connections */
  864. saveConnFields();
  865. var comp = /^[a-zA-Z\d(-)\.@_ -]{0,200}$/;
  866. haveConnections = false;
  867. if (CC_contact_full_info['connections']){
  868. for (var type in CC_contact_full_info['connections']){
  869. haveConnections = true;
  870. var reEmail = /^[a-zA-Z0-9][_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*$/;
  871. for (var i in CC_contact_full_info['connections'][type]){
  872. if(type == 1){
  873. if(!reEmail.test(CC_contact_full_info['connections'][type][i]['value'])){
  874. showMessage('Endereзo para conexгo de ' + CC_contact_full_info['connections'][type][i]['name'] + ', nгo й vбlido');
  875. return false;
  876. }
  877. }
  878. else{
  879. if((CC_contact_full_info['connections'][type][i]['value'].length < 4) ||
  880. (!comp.test(CC_contact_full_info['connections'][type][i]['value']))){
  881. showMessage('Endereзo para conexгo de ' + CC_contact_full_info['connections'][type][i]['name'] + ', nгo й vбlido');
  882. return false;
  883. }
  884. }
  885. }
  886. var _options_default = Element("cc_"+(type == 1 ? 'email' : 'phone')+"_default");
  887. if(_options_default.value == '-1') {
  888. alert(get_lang("It is necessary to choose a ") + (type == 1 ? 'Email' : get_lang('Phone ')) + get_lang('default!'));
  889. return false;
  890. }
  891. }
  892. }
  893. /* Check Relations */
  894. return true;
  895. }
  896. /********* Personal Data Functions *********/
  897. /*
  898. * data[0] => cc_pd_select_photo
  899. * data[1] => cc_pd_alias
  900. * data[2] => cc_pd_given_names
  901. * data[3] => cc_pd_family_names
  902. * data[4] => cc_pd_full_name
  903. * data[5] => cc_pd_suffix
  904. * data[6] => cc_pd_birthdate
  905. * data[7] => cc_pd_sex SELECT
  906. * data[8] => cc_pd_prefix
  907. * data[9] => cc_pd_gpg_finger_print
  908. * data[10] => cc_pd_notes
  909. */
  910. function populatePersonalData (data)
  911. {
  912. for (i in data)
  913. {
  914. switch(i)
  915. {
  916. case 'cc_pd_suffix':
  917. case 'cc_pd_sex':
  918. case 'cc_pd_prefix':
  919. selectOption(i, data[i]);
  920. break;
  921. case 'cc_pd_photo':
  922. if (data[i])
  923. {
  924. //Codigo para exibicao da imagem do contato no IE
  925. //Douglas Lopes Gomes - Prognus Software Livre
  926. if (Element(i)[1] && Element(i)[1].src){ //Se o navegador йo IE
  927. Element(i)[1].src = data[i] + '&'+ Math.random();
  928. } else { //Se o navegador nгo й o IE
  929. Element(i).src = data[i] + '&'+ Math.random();
  930. }
  931. }
  932. break;
  933. default:
  934. Element(i).value = data[i] == undefined ? '' : unescape(data[i]);
  935. }
  936. }
  937. return;
  938. }
  939. /********* End Personal Data Functions *********/
  940. /********* Addresses Functions *********/
  941. function resetAddressFields()
  942. {
  943. Element('cc_addr_types').selectedIndex = 0;
  944. Element('cc_addr_countries').selectedIndex = 0;
  945. Element('cc_addr_countries').disabled = true;
  946. Element('cc_addr_states').selectedIndex = 0;
  947. Element('cc_addr_states').disabled = true;
  948. Element('cc_addr_states_new').disabled = true;
  949. Element('cc_addr_states_new').readonly = true;
  950. Element('cc_addr_states_new').value = '';
  951. Element('cc_addr_cities').selectedIndex = 0;
  952. Element('cc_addr_cities').disabled = true;
  953. Element('cc_addr_cities_new').disabled = true;
  954. Element('cc_addr_cities_new').readonly = true;
  955. Element('cc_addr_cities_new').value = '';
  956. Element('cc_addr_id').value = '';
  957. resetAddrFillingFields();
  958. }
  959. function resetAddrFillingFields()
  960. {
  961. Element('cc_addr_1').value = '';
  962. Element('cc_addr_2').value = '';
  963. Element('cc_addr_other').value = '';
  964. Element('cc_addr_complement').value = '';
  965. Element('cc_addr_postal_code').value = '';
  966. Element('cc_addr_po_box').value = '';
  967. Element('cc_addr_is_default').checked = false;
  968. }
  969. function disableAddrFillingFields()
  970. {
  971. Element('cc_addr_1').readonly = true;
  972. Element('cc_addr_1').disabled = true;
  973. Element('cc_addr_2').readonly = true;
  974. Element('cc_addr_2').disabled = true;
  975. Element('cc_addr_other').readonly = true;
  976. Element('cc_addr_other').disabled = true;
  977. Element('cc_addr_complement').readonly = true;
  978. Element('cc_addr_complement').disabled = true;
  979. Element('cc_addr_postal_code').readonly = true;
  980. Element('cc_addr_postal_code').disabled = true;
  981. Element('cc_addr_po_box').readonly = true;
  982. Element('cc_addr_po_box').disabled = true;
  983. Element('cc_addr_is_default').readonly = true;
  984. Element('cc_addr_is_default').disabled = true;
  985. }
  986. function updateAddressFields()
  987. {
  988. var type = Element('cc_addr_types');
  989. var oldSelected = type.value;
  990. saveAddressFields();
  991. if (oldSelected == '_NONE_')
  992. {
  993. resetAddressFields();
  994. return true;
  995. }
  996. CC_addr_last_selected = type.selectedIndex;
  997. Element('cc_addr_countries').disabled = false;
  998. var data = CC_contact_full_info['addresses'];
  999. var addrIndex = 'address'+Element('cc_addr_types').value;
  1000. if (typeof(data) != 'object' || typeof(data[addrIndex]) != 'object')
  1001. {
  1002. resetAddressFields();
  1003. Element('cc_addr_countries').disabled = false;
  1004. Element('cc_addr_countries').selectedIndex = CC_br_index;
  1005. type.value = oldSelected;
  1006. updateAddrStates();
  1007. return true;
  1008. }
  1009. var addrTypeID = Element('cc_addr_types').value;
  1010. data = CC_contact_full_info['addresses'][addrIndex];
  1011. Element('cc_addr_id').value = data['id_address'] ? data['id_address'] : '';
  1012. Element('cc_addr_1').value = data['address1'] ? data['address1'] : '';
  1013. Element('cc_addr_2').value = data['address2'] ? data['address2'] : '';
  1014. Element('cc_addr_complement').value = data['complement'] ? data['complement'] : '';
  1015. Element('cc_addr_other').value = data['address_other'] ? data['address_other'] : '';
  1016. Element('cc_addr_postal_code').value = data['postal_code'] ? data['postal_code'] : '';
  1017. Element('cc_addr_po_box').value = data['po_box'] ? data['po_box'] : '';
  1018. Element('cc_addr_is_default').checked = data['address_is_default'] == '1' ? true: false;
  1019. Element('cc_addr_countries').value = data['id_country'];
  1020. updateAddrStates();
  1021. }
  1022. function updateAddrStates()
  1023. {
  1024. var states = Element('cc_addr_states');
  1025. if (Element('cc_addr_countries').value == '_NONE_')
  1026. {
  1027. states.disabled = true;
  1028. states.selectedIndex = 0;
  1029. clearSelectBox(states, 4);
  1030. updateAddrCities();
  1031. return;
  1032. }
  1033. updateAddrFillingFields();
  1034. populateStates();
  1035. }
  1036. function populateStates()
  1037. {
  1038. var states = Element('cc_addr_states');
  1039. var cities = Element('cc_addr_cities');
  1040. var handler = function (responseText)
  1041. {
  1042. var data = unserialize(responseText);
  1043. clearSelectBox(states, 1);
  1044. if (typeof(data) != 'object')
  1045. {
  1046. showMessage(Element('cc_msg_err_contacting_server').value);
  1047. return;
  1048. }
  1049. if (data['status'] == 'empty')
  1050. {
  1051. states.disabled = true;
  1052. cities.disabled = true;
  1053. states.selectedIndex = 0;
  1054. cities.selectedIndex = 0;
  1055. return;
  1056. }
  1057. else if (data['status'] != 'ok')
  1058. {
  1059. showMessage(data['msg']);
  1060. states.disabled = true;
  1061. states.selectedIndex = 0;
  1062. updateAddrCities();
  1063. return;
  1064. }
  1065. states.disabled = false;
  1066. var i = 1;
  1067. /*
  1068. for (var j in data['data'])
  1069. {
  1070. states.options[i] = new Option(data['data'][j], j);
  1071. if(i == 1) data['data'] = data['data'].sort();
  1072. i++;
  1073. }*/
  1074. jQuery.each(data['data'],function(index,value){
  1075. if (value != undefined){
  1076. states.options[i] = new Option(value, index);
  1077. if(i == 1) data['data'] = data['data'].sort();
  1078. i++;
  1079. }
  1080. });
  1081. states.disabled = false;
  1082. states.selectedIndex = 0;
  1083. data = CC_contact_full_info['addresses'];
  1084. var addrIndex = 'address'+Element('cc_addr_types').value;
  1085. if (data && data[addrIndex])
  1086. {
  1087. states.value = data[addrIndex]['id_state'];
  1088. if (states.value == '_NEW_')
  1089. {
  1090. if (CC_contact_full_info['addresses']['new_states'][addrIndex])
  1091. {
  1092. Element('cc_addr_states_new').value = CC_contact_full_info['addresses']['new_states'][addrIndex];
  1093. }
  1094. updateAddrNewStateOnMouseOut();
  1095. }
  1096. updateAddrCities();
  1097. }
  1098. };
  1099. Connector.newRequest('populateStates', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_states&country='+Element('cc_addr_countries').value, 'GET', handler);
  1100. }
  1101. function updateAddrCities()
  1102. {
  1103. var states = Element('cc_addr_states');
  1104. var cities = Element('cc_addr_cities');
  1105. var newState = Element('cc_addr_states_new');
  1106. var requestStr;
  1107. switch (states.value)
  1108. {
  1109. case '_NONE_':
  1110. newState.readonly = true;
  1111. newState.disabled = true;
  1112. newState.value = '';
  1113. cities.disabled = true;
  1114. cities.selectedIndex = 0;
  1115. updateAddrFillingFields();
  1116. return;
  1117. case '_NEW_':
  1118. newState.readonly = false;
  1119. newState.disabled = false;
  1120. updateAddrNewStateOnMouseOut();
  1121. cities.disabled = false;
  1122. clearSelectBox(cities, 3);
  1123. cities.selectedIndex = 1;
  1124. updateAddrFillingFields();
  1125. return;
  1126. case '_SEP_': return;
  1127. case '_NOSTATE_':
  1128. clearSelectBox(cities, 3);
  1129. cities.disabled = false;
  1130. cities.selectedIndex = 0;
  1131. requestStr = 'country='+Element('cc_addr_countries').value;
  1132. break;
  1133. default:
  1134. requestStr = 'country='+Element('cc_addr_countries').value+'&state='+states.value;
  1135. }
  1136. newState.readonly = true;
  1137. newState.disabled = true;
  1138. newState.value = '';
  1139. populateCities(requestStr);
  1140. }
  1141. function populateCities(requestStr)
  1142. {
  1143. var cities = Element('cc_addr_cities');
  1144. var handler = function (responseText)
  1145. {
  1146. var data = unserialize(responseText);
  1147. clearSelectBox(cities, 1);
  1148. if (typeof(data) != 'object')
  1149. {
  1150. showMessage(Element('cc_msg_err_contacting_server').value);
  1151. return;
  1152. }
  1153. if (data['status'] == 'empty')
  1154. {
  1155. cities.disabled = true;
  1156. cities.selectedIndex = 0;
  1157. return;
  1158. }
  1159. else if (data['status'] != 'ok')
  1160. {
  1161. showMessage(data['msg']);
  1162. cities.disabled = true;
  1163. cities.selectedIndex = 0;
  1164. updateAddrFillingFields();
  1165. return;
  1166. }
  1167. cities.disabled = false;
  1168. var i = 1;
  1169. /*
  1170. for (var j in data['data'])
  1171. {
  1172. cities.options[i] = new Option(data['data'][j], j);
  1173. i++;
  1174. }*/
  1175. jQuery.each(data['data'],function(index,value){
  1176. if (value != undefined){
  1177. cities.options[i] = new Option(value,index);
  1178. i++;
  1179. }
  1180. });
  1181. cities.disabled = false;
  1182. cities.selectedIndex = 0;
  1183. data = CC_contact_full_info['addresses'];
  1184. var addrIndex = 'address'+Element('cc_addr_types').value;
  1185. if (data && data[addrIndex])
  1186. {
  1187. cities.value = data[addrIndex]['id_city'];
  1188. if (cities.value == '_NEW_')
  1189. {
  1190. if (CC_contact_full_info['addresses']['new_cities'][addrIndex])
  1191. {
  1192. Element('cc_addr_cities_new').value = CC_contact_full_info['addresses']['new_cities'][addrIndex];
  1193. }
  1194. updateAddrNewCityOnMouseOut();
  1195. }
  1196. }
  1197. };
  1198. Connector.newRequest('populateCities', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_cities&'+requestStr, 'GET', handler);
  1199. }
  1200. function updateAddrNewStateOnMouseOver ()
  1201. {
  1202. if (Element('cc_addr_states_new').value == Element('cc_msg_type_state').value && Element('cc_addr_states').selectedIndex == 1)
  1203. {
  1204. Element('cc_addr_states_new').value = '';
  1205. }
  1206. }
  1207. function updateAddrNewStateOnMouseOut ()
  1208. {
  1209. if (Element('cc_addr_states_new').value.length == 0 && Element('cc_addr_states').selectedIndex == 1)
  1210. {
  1211. Element('cc_addr_states_new').value = Element('cc_msg_type_state').value;
  1212. }
  1213. }
  1214. function updateAddrFillingFields()
  1215. {
  1216. var countries = Element('cc_addr_countries');
  1217. var cities = Element('cc_addr_cities');
  1218. var newCity = Element('cc_addr_cities_new');
  1219. if (countries.value == '_NONE_')
  1220. {
  1221. newCity.readonly = true;
  1222. newCity.disabled = true;
  1223. newCity.value = '';
  1224. disableAddrFillingFields();
  1225. return;
  1226. }
  1227. Element('cc_addr_1').readonly = false;
  1228. Element('cc_addr_1').disabled = false;
  1229. Element('cc_addr_2').readonly = false;
  1230. Element('cc_addr_2').disabled = false;
  1231. Element('cc_addr_other').readonly = false;
  1232. Element('cc_addr_other').disabled = false;
  1233. Element('cc_addr_complement').readonly = false;
  1234. Element('cc_addr_complement').disabled = false;
  1235. Element('cc_addr_postal_code').readonly = false;
  1236. Element('cc_addr_postal_code').disabled = false;
  1237. Element('cc_addr_po_box').readonly = false;
  1238. Element('cc_addr_po_box').disabled = false;
  1239. Element('cc_addr_is_default').readonly = false;
  1240. Element('cc_addr_is_default').disabled = false;
  1241. switch (cities.value)
  1242. {
  1243. case '_NONE_':
  1244. newCity.readonly = true;
  1245. newCity.disabled = true;
  1246. newCity.value = '';
  1247. //resetAddrFillingFields();
  1248. return;
  1249. case '_NEW_':
  1250. newCity.readonly = false;
  1251. newCity.disabled = false;
  1252. updateAddrNewCityOnMouseOut();
  1253. break;
  1254. case '_SEP_': return;
  1255. default:
  1256. newCity.readonly = true;
  1257. newCity.disabled = true;
  1258. newCity.value = '';
  1259. }
  1260. }
  1261. function updateAddrNewCityOnMouseOver ()
  1262. {
  1263. if (Element('cc_addr_cities_new').value == Element('cc_msg_type_city').value && Element('cc_addr_cities').selectedIndex == 1)
  1264. {
  1265. Element('cc_addr_cities_new').value = '';
  1266. }
  1267. }
  1268. function updateAddrNewCityOnMouseOut ()
  1269. {
  1270. if (Element('cc_addr_cities_new').value.length == 0 && Element('cc_addr_cities').selectedIndex == 1)
  1271. {
  1272. Element('cc_addr_cities_new').value = Element('cc_msg_type_city').value;
  1273. }
  1274. }
  1275. function saveAddressFields ()
  1276. {
  1277. var lastIndex = CC_addr_last_selected;
  1278. if (lastIndex == 0)
  1279. {
  1280. return true;
  1281. }
  1282. var addrFields = new Array('cc_addr_1',
  1283. 'cc_addr_2',
  1284. 'cc_addr_complement',
  1285. 'cc_addr_other',
  1286. 'cc_addr_postal_code',
  1287. 'cc_addr_po_box',
  1288. 'cc_addr_countries',
  1289. 'cc_addr_states',
  1290. 'cc_addr_cities');
  1291. var empty = true;
  1292. for (var i = 0; i < 8; i++)
  1293. {
  1294. var field = Element(addrFields[i]);
  1295. if (field.value && field.value != '_NONE_' && field.value != '_SEP_')
  1296. {
  1297. empty = false;
  1298. }
  1299. }
  1300. if (empty)
  1301. {
  1302. return true;
  1303. }
  1304. if (!CC_contact_full_info['addresses'])
  1305. {
  1306. CC_contact_full_info['addresses'] = new Array();
  1307. }
  1308. var addrInfo = CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value];
  1309. if (!addrInfo)
  1310. {
  1311. addrInfo = new Array();
  1312. }
  1313. addrInfo['id_address'] = Element('cc_addr_id').value;
  1314. switch(Element('cc_addr_countries').value)
  1315. {
  1316. case '_SEP_':
  1317. case '_NONE_':
  1318. addrInfo['id_country'] = false;
  1319. break;
  1320. default:
  1321. addrInfo['id_country'] = Element('cc_addr_countries').value;
  1322. }
  1323. switch(Element('cc_addr_states').value)
  1324. {
  1325. case '_SEP_':
  1326. case '_NONE_':
  1327. case '_NEW_':
  1328. case '_NOSTATE_':
  1329. addrInfo['id_state'] = false;
  1330. break;
  1331. default:
  1332. addrInfo['id_state'] = Element('cc_addr_states').value;
  1333. }
  1334. switch(Element('cc_addr_cities').value)
  1335. {
  1336. case '_SEP_':
  1337. case '_NONE_':
  1338. case '_NEW_':
  1339. addrInfo['id_city'] = false;
  1340. break;
  1341. default:
  1342. addrInfo['id_city'] = Element('cc_addr_cities').value;
  1343. }
  1344. addrInfo['id_typeof_address'] = Element('cc_addr_types').options[lastIndex].value;
  1345. addrInfo['address1'] = Element('cc_addr_1').value ? Element('cc_addr_1').value : false;
  1346. addrInfo['address2'] = Element('cc_addr_2').value ? Element('cc_addr_2').value : false;
  1347. addrInfo['complement'] = Element('cc_addr_complement').value ? Element('cc_addr_complement').value : false;
  1348. addrInfo['address_other'] = Element('cc_addr_other').value ? Element('cc_addr_other').value : false;
  1349. addrInfo['postal_code'] = Element('cc_addr_postal_code').value ? Element('cc_addr_postal_code').value : false;
  1350. addrInfo['po_box'] = Element('cc_addr_po_box').value ? Element('cc_addr_po_box').value : false;
  1351. addrInfo['address_is_default'] = Element('cc_addr_is_default').checked ? '1' : '0';
  1352. CC_contact_full_info['addresses']['address'+Element('cc_addr_types').options[lastIndex].value] = addrInfo;
  1353. if (Element('cc_addr_cities').value == '_NEW_' &&
  1354. Element('cc_msg_type_city').value != Element('cc_addr_cities_new').value &&
  1355. Element('cc_addr_cities_new').value != '')
  1356. {
  1357. var addrRootInfo = CC_contact_full_info['addresses']['new_cities'];
  1358. if (!addrRootInfo)
  1359. {
  1360. addrRootInfo = new Array();
  1361. }
  1362. var i = addrRootInfo.length;
  1363. addrRootInfo[addrInfo['id_typeof_address']] = new Array();
  1364. addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
  1365. addrRootInfo[addrInfo['id_typeof_address']]['id_state'] = Element('cc_addr_states').value.charAt(0) != '_' ? Element('cc_addr_states').value : null;
  1366. addrRootInfo[addrInfo['id_typeof_address']]['city_name'] = Element('cc_addr_cities_new').value;
  1367. CC_contact_full_info['addresses']['new_cities'] = addrRootInfo;
  1368. }
  1369. if (Element('cc_addr_states').value == '_NEW_' &&
  1370. Element('cc_msg_type_state').value != Element('cc_addr_states_new').value &&
  1371. Element('cc_addr_states_new').value != '')
  1372. {
  1373. var addrRootInfo = CC_contact_full_info['addresses']['new_states'];
  1374. if (!addrRootInfo)
  1375. {
  1376. addrRootInfo = new Array();
  1377. }
  1378. var i = addrRootInfo.length;
  1379. addrRootInfo[addrInfo['id_typeof_address']] = new Array();
  1380. addrRootInfo[addrInfo['id_typeof_address']]['id_country'] = Element('cc_addr_countries').value;
  1381. addrRootInfo[addrInfo['id_typeof_address']]['state_name'] = Element('cc_addr_states_new').value;
  1382. CC_contact_full_info['addresses']['new_states'] = addrRootInfo;
  1383. }
  1384. return true;
  1385. }
  1386. /********* End Addresses Functions *********/
  1387. /********* Begin Connections Functions ************/
  1388. function connGetHTMLLine ()
  1389. {
  1390. var _label = (CC_contact_full_info['connections']
  1391. && typeof(CC_contact_full_info['connections'][CC_conn_last_selected])!= 'undefined'
  1392. && typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) != 'undefined'
  1393. ? CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]['name']
  1394. : Element("cc_conn_type_sel").value);
  1395. var cc_conn_default = Element("cc_phone_default").style.display == '' ? Element("cc_phone_default") : Element("cc_email_default");
  1396. cc_conn_default.disabled = false;
  1397. var idx_conn = 0;
  1398. for(idx_conn; idx_conn < cc_conn_default.options.length; idx_conn++)
  1399. if(cc_conn_default.options[idx_conn].value == _label)
  1400. break;
  1401. if(idx_conn == cc_conn_default.options.length)
  1402. cc_conn_default.options[idx_conn] = new Option (_label,_label, false,false);
  1403. if (!document.all)
  1404. {
  1405. if (Element("cc_conn_type_1").checked)
  1406. {
  1407. return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
  1408. //'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
  1409. '<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px; padding-left: 55px;" align="left"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+':'+'</span></td>' +
  1410. '<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px; text-transform:lowercase;" maxlength="100" type="text">&nbsp;' +
  1411. '<img align="top" alt="X" title="X" src="templates/default/images/x.png" style="width:18px; height:18px; cursor:pointer;" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"/></td>';
  1412. }
  1413. else if (Element("cc_conn_type_2").checked)
  1414. {
  1415. return '<td style="position: absolute; left: 0; top: 0; z-index: -1; visibility: hidden"><input id="cc_conn_id_' + CC_conn_count + '" type="hidden" value="_NEW_"><input id="cc_conn_is_default_' + CC_conn_count + '" type="hidden" value="false"></td>'+
  1416. //'<td style="width: 30px;" align="right"><input name="cc_conn_is_default" id="cc_conn_is_default_'+ CC_conn_count +'" type="radio"></td>'+
  1417. '<td style="width: 10px;" align="right"><input id="cc_conn_name_'+CC_conn_count+'" type="hidden"><td style="width: 100px; padding-left: 55px;" align="left"><span style="width: 150px;" id="cc_conn_label_'+CC_conn_count+'">'+_label+':'+'</span></td>' +
  1418. '<td align="left"><input id="cc_conn_value_'+ CC_conn_count +'" style="width: 150px; text-transform:lowercase;" maxlength="30" type="text" onkeyup="formatPhone(this);">&nbsp;' +
  1419. '<img align="top" alt="X" title="X" src="templates/default/images/x.png" style="width:18px; height:18px; cursor:pointer;" onclick="javascript:removeConnField(\'cc_conn_tr_' + CC_conn_count + '\')"/></td>';
  1420. }
  1421. }
  1422. else
  1423. {
  1424. var tds = new Array();
  1425. var inputs = new Array();
  1426. var img = document.createElement('img');
  1427. for (var i = 0; i < 4; i++)
  1428. {
  1429. tds[i] = document.createElement('td');
  1430. }
  1431. tds[0].style.position = 'absolute';
  1432. tds[0].style.visibility = 'hidden';
  1433. tds[0].style.zIndex = '-1';
  1434. var remove_id = 'cc_conn_tr_'+CC_conn_count;
  1435. img.alt = 'X';
  1436. img.src = 'templates/default/images/x.png';
  1437. img.style.width = '18px';
  1438. img.style.height = '18px';
  1439. img.style.cursor = 'pointer';
  1440. img.align = 'top';
  1441. img.onclick = function(e){ removeConnField(remove_id);};
  1442. for (var i = 0; i < 3; i++)
  1443. {
  1444. inputs[i] = document.createElement('input');
  1445. }
  1446. inputs[0].id = 'cc_conn_id_'+CC_conn_count;
  1447. inputs[0].type = 'hidden';
  1448. inputs[0].value = '_NEW_';
  1449. inputs[1].id = 'cc_conn_name_'+CC_conn_count;
  1450. inputs[1].type = 'hidden';
  1451. inputs[2].id = 'cc_conn_value_'+CC_conn_count;
  1452. inputs[2].type = 'text';
  1453. inputs[2].style.width = '150px';
  1454. var _span = document.createElement("SPAN");
  1455. _span.style.width = "100px";
  1456. _span.id = "cc_conn_label_"+CC_conn_count;
  1457. _span.innerHTML = _label + ':';
  1458. tds[0].appendChild(inputs[0]);
  1459. tds[1].width = '40px';
  1460. tds[1].appendChild(inputs[1]);
  1461. tds[1].align = 'left';
  1462. tds[1].style.padding = "0px 0px 0px 75px";
  1463. tds[1].appendChild(_span);
  1464. tds[2].appendChild(inputs[2]);
  1465. tds[2].align = 'left';
  1466. tds[2].innerHTML +="&nbsp;";
  1467. tds[2].appendChild(img);
  1468. return tds;
  1469. }
  1470. }
  1471. function connAddNewLine ()
  1472. {
  1473. var _emptyLine = (!CC_contact_full_info['connections']
  1474. || typeof(CC_contact_full_info['connections'][CC_conn_last_selected]) == 'undefined'
  1475. || typeof(CC_contact_full_info['connections'][CC_conn_last_selected][CC_conn_count]) == 'undefined');
  1476. if(_emptyLine) {
  1477. if(Element("cc_conn_type_sel").value == '-1'){
  1478. return false;
  1479. }
  1480. for(k = 0; k < CC_conn_count; k++) {
  1481. if(Element("cc_conn_name_"+k) && Element("cc_conn_name_"+k).value != "" && Element("cc_conn_name_"+k).value == Element("cc_conn_type_sel").value) {
  1482. alert(get_lang('You already have an entry for the type "') + Element("cc_conn_type_sel").value+'"!');
  1483. Element("cc_conn_type_sel").options.selectedIndex = 0;
  1484. return false;
  1485. }
  1486. }
  1487. }
  1488. if (!document.all)
  1489. {
  1490. var obj = addHTMLCode('cc_conn', 'cc_conn…

Large files files are truncated, but you can click here to view the full file