PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/contacts/javascript/contacts.js

http://phreedom.googlecode.com/
JavaScript | 223 lines | 186 code | 18 blank | 19 comment | 28 complexity | 1b9c04a6c8122acd325a2054bf2a6b04 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. // +-----------------------------------------------------------------+
  2. // | PhreeBooks Open Source ERP |
  3. // +-----------------------------------------------------------------+
  4. // | Copyright (c) 2008, 2009, 2010, 2011, 2012 PhreeSoft, LLC |
  5. // | http://www.PhreeSoft.com |
  6. // +-----------------------------------------------------------------+
  7. // | This program is free software: you can redistribute it and/or |
  8. // | modify it under the terms of the GNU General Public License as |
  9. // | published by the Free Software Foundation, either version 3 of |
  10. // | the License, or any later version. |
  11. // | |
  12. // | This program is distributed in the hope that it will be useful, |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  15. // | GNU General Public License for more details. |
  16. // +-----------------------------------------------------------------+
  17. // Path: /modules/contacts/javascript/contacts.js
  18. //
  19. function contactChart(func, d0) {
  20. chartProps.modID = "contacts";
  21. chartProps.divID = "contact_chart";
  22. chartProps.func = func;
  23. chartProps.d0 = d0;
  24. document.getElementById(chartProps.divID).innerHTML = ' ';
  25. phreedomChart();
  26. }
  27. function getAddress(id, type) {
  28. $.ajax({
  29. type: "GET",
  30. url: 'index.php?module=contacts&page=ajax&op=contacts&action=get_address&type='+type+'&aID='+id,
  31. dataType: ($.browser.msie) ? "text" : "xml",
  32. error: function(XMLHttpRequest, textStatus, errorThrown) {
  33. alert ("Ajax Error: " + errorThrown + '-' + XMLHttpRequest.responseText + "\nStatus: " + textStatus);
  34. },
  35. success: fillAddress
  36. });
  37. }
  38. function fillAddress(sXml) {
  39. var xml = parseXml(sXml);
  40. if (!xml) return;
  41. var message = $(xml).find("message").text();
  42. if (message) { alert (message); }
  43. else {
  44. var type = $(xml).find("type").first().text();
  45. $(xml).find("Address").each(function() {
  46. $(this).children().each(function() {
  47. var tagName = this.tagName;
  48. if (document.getElementById('address_'+type+'_'+tagName)) insertValue('address_'+type+'_'+tagName, $(this).text());
  49. });
  50. });
  51. if (type == 'im') {
  52. insertValue('i_id', $(xml).find("contact_id").text());
  53. insertValue('i_short_name', $(xml).find("short_name").text());
  54. insertValue('i_contact_first', $(xml).find("contact_first").text());
  55. insertValue('i_contact_middle',$(xml).find("contact_middle").text());
  56. insertValue('i_contact_last', $(xml).find("contact_last").text());
  57. insertValue('i_account_number',$(xml).find("account_number").text());
  58. insertValue('i_gov_id_number', $(xml).find("gov_id_number").text());
  59. }
  60. }
  61. }
  62. function copyContactAddress(type) {
  63. insertValue('address_im_primary_name', document.getElementById('address_'+type+'m_primary_name').value);
  64. insertValue('address_im_contact', document.getElementById('address_'+type+'m_contact').value);
  65. insertValue('address_im_telephone1', document.getElementById('address_'+type+'m_telephone1').value);
  66. insertValue('address_im_telephone2', document.getElementById('address_'+type+'m_telephone2').value);
  67. insertValue('address_im_telephone3', document.getElementById('address_'+type+'m_telephone3').value);
  68. insertValue('address_im_telephone4', document.getElementById('address_'+type+'m_telephone4').value);
  69. insertValue('address_im_email', document.getElementById('address_'+type+'m_email').value);
  70. insertValue('address_im_website', document.getElementById('address_'+type+'m_website').value);
  71. insertValue('address_im_address1', document.getElementById('address_'+type+'m_address1').value);
  72. insertValue('address_im_address2', document.getElementById('address_'+type+'m_address2').value);
  73. insertValue('address_im_city_town', document.getElementById('address_'+type+'m_city_town').value);
  74. insertValue('address_im_state_province', document.getElementById('address_'+type+'m_state_province').value);
  75. insertValue('address_im_postal_code', document.getElementById('address_'+type+'m_postal_code').value);
  76. insertValue('address_im_country_code', document.getElementById('address_'+type+'m_country_code').value);
  77. }
  78. function clearAddress(type) {
  79. $("#"+type+"_address_form input").val(function( i, val ) { return ''; });
  80. document.getElementById('address_'+type+'_address_id').value = 0;
  81. document.getElementById('address_'+type+'_country_code').value = default_country;
  82. if (type == 'im') {
  83. if(document.getElementById('i_id')) document.getElementById('i_id').value = '';
  84. if(document.getElementById('i_short_name')) document.getElementById('i_short_name').value = '';
  85. if(document.getElementById('i_contact_middle')) document.getElementById('i_contact_middle').value = '';
  86. if(document.getElementById('i_contact_first')) document.getElementById('i_contact_first').value = '';
  87. if(document.getElementById('i_contact_last')) document.getElementById('i_contact_last').value = '';
  88. if(document.getElementById('i_account_number')) document.getElementById('i_account_number').value = '';
  89. if(document.getElementById('i_gov_id_number')) document.getElementById('i_gov_id_number').value = '';
  90. }
  91. }
  92. function deleteAddress(id) {
  93. $.ajax({
  94. type: "GET",
  95. url: 'index.php?module=contacts&page=ajax&op=contacts&action=rm_address&aID='+id,
  96. dataType: ($.browser.msie) ? "text" : "xml",
  97. error: function(XMLHttpRequest, textStatus, errorThrown) {
  98. alert ("Ajax Error: " + errorThrown + '-' + XMLHttpRequest.responseText + "\nStatus: " + textStatus);
  99. },
  100. success: deleteAddressResp
  101. });
  102. }
  103. function deleteAddressResp(sXml) {
  104. var xml = parseXml(sXml);
  105. if (!xml) return;
  106. var rowID = $(xml).find("address_id").text();
  107. if (rowID) $('#tr_add_'+rowID).remove();
  108. var message = $(xml).find("message").text();
  109. if (message) { alert (message); }
  110. // TBD need to remove the row here
  111. }
  112. function TermsList() {
  113. var terms = document.getElementById('terms').value;
  114. window.open("index.php?module=contacts&page=popup_terms&type="+account_type+"&val="+terms,"terms","width=500px,height=300px,resizable=1,scrollbars=1,top=150,left=200");
  115. }
  116. function getPayment(id) {
  117. $.ajax({
  118. type: "GET",
  119. url: 'index.php?module=contacts&page=ajax&op=contacts&action=get_payment&pID='+id,
  120. dataType: ($.browser.msie) ? "text" : "xml",
  121. error: function(XMLHttpRequest, textStatus, errorThrown) {
  122. alert ("Ajax Error: " + errorThrown + '-' + XMLHttpRequest.responseText + "\nStatus: " + textStatus);
  123. },
  124. success: fillPayment
  125. });
  126. }
  127. function fillPayment(sXml) {
  128. var xml = parseXml(sXml);
  129. if (!xml) return;
  130. var message = $(xml).find("message").text();
  131. if (message) { alert (message); }
  132. else {
  133. document.getElementById('payment_id').value = $(xml).find("payment_id").text();
  134. document.getElementById('payment_cc_name').value = $(xml).find("field_0").text();
  135. document.getElementById('payment_cc_number').value = $(xml).find("field_1").text();
  136. document.getElementById('payment_exp_month').value = $(xml).find("field_2").text();
  137. document.getElementById('payment_exp_year').value = $(xml).find("field_3").text();
  138. document.getElementById('payment_cc_cvv2').value = $(xml).find("field_4").text();
  139. }
  140. }
  141. function clearPayment() {
  142. document.getElementById('payment_id').value = 0;
  143. document.getElementById('payment_cc_name').value = '';
  144. document.getElementById('payment_cc_number').value = '';
  145. document.getElementById('payment_exp_month').selectedIndex = 0;
  146. document.getElementById('payment_exp_year').selectedIndex = 0;
  147. document.getElementById('payment_cc_cvv2').value = '';
  148. }
  149. function deletePayment(id) {
  150. $.ajax({
  151. type: "GET",
  152. url: 'index.php?module=contacts&page=ajax&op=contacts&action=rm_payment&pID='+id,
  153. dataType: ($.browser.msie) ? "text" : "xml",
  154. error: function(XMLHttpRequest, textStatus, errorThrown) {
  155. alert ("Ajax Error: " + errorThrown + '-' + XMLHttpRequest.responseText + "\nStatus: " + textStatus);
  156. },
  157. success: deletePaymentResp
  158. });
  159. }
  160. function deletePaymentResp(sXml) {
  161. var xml = parseXml(sXml);
  162. if (!xml) return;
  163. var rowID = $(xml).find("payment_id").text();
  164. if (rowID) $('#tr_pmt_'+rowID).remove();
  165. var message = $(xml).find("message").text();
  166. if (message) { alert (message); }
  167. }
  168. function deleteCRM(id) {
  169. $.ajax({
  170. type: "GET",
  171. url: 'index.php?module=contacts&page=ajax&op=contacts&action=rm_crm&nID='+id,
  172. dataType: ($.browser.msie) ? "text" : "xml",
  173. error: function(XMLHttpRequest, textStatus, errorThrown) {
  174. alert ("Ajax Error: " + errorThrown + '-' + XMLHttpRequest.responseText + "\nStatus: " + textStatus);
  175. },
  176. success: deleteCRMResp
  177. });
  178. }
  179. function deleteCRMResp(sXml) {
  180. var xml = parseXml(sXml);
  181. if (!xml) return;
  182. var rowID = $(xml).find("crm_id").text();
  183. if (rowID) {
  184. $('#tr_crm_a_'+rowID).remove();
  185. $('#tr_crm_b_'+rowID).remove();
  186. }
  187. var message = $(xml).find("message").text();
  188. if (message) { alert (message); }
  189. }
  190. function downloadAttachment(filename) {
  191. var file_name = attachment_path+filename;
  192. $.ajax({
  193. type: "GET",
  194. url: 'index.php?module=phreedom&page=ajax&op=phreedom&action=download&file='+file_name,
  195. dataType: ($.browser.msie) ? "text" : "xml",
  196. error: function(XMLHttpRequest, textStatus, errorThrown) {
  197. alert ("Ajax Error: " + XMLHttpRequest.responseText + "\nTextStatus: " + textStatus + "\nErrorThrown: " + errorThrown);
  198. },
  199. success: downloadResponse
  200. });
  201. }
  202. function downloadResponse(sXML) {
  203. var xml = parseXml(sXml);
  204. if (!xml) return;
  205. }