PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/rucrm/modules/SMSNotifier/SMSNotifierCommon.js

https://code.google.com/p/vtiger-ru-fork/
JavaScript | 193 lines | 141 code | 33 blank | 19 comment | 34 complexity | 452233d846445c124d36e68fe39c8611 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0
  1. /*+**********************************************************************************
  2. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  3. * ("License"); You may not use this file except in compliance with the License
  4. * The Original Code is: vtiger CRM Open Source
  5. * The Initial Developer of the Original Code is vtiger.
  6. * Portions created by vtiger are Copyright (C) vtiger.
  7. * All Rights Reserved.
  8. ************************************************************************************/
  9. if(typeof(SMSNotifierCommon) == 'undefined') {
  10. var SMSNotifierCommon = {
  11. /** Wizard Container **/
  12. getWizardContainer : function() {
  13. var container = $('__smsnotifier_wizard_container__');
  14. if(!container) {
  15. container = document.createElement('div');
  16. container.className = 'layerPopup';
  17. container.id = '__smsnotifier_wizard_container__';
  18. document.body.appendChild(container);
  19. }
  20. return container;
  21. },
  22. displayWizardContainer : function(container, sourcenode) {
  23. if(typeof(container) == 'undefined') container = SMSNotifierCommon.getWizardContainer();
  24. if(container) {
  25. if(typeof(sourcenode) != 'undefined') {
  26. if(sourcenode != null) {
  27. fnvshobj(sourcenode, container.id);
  28. } else {
  29. // Place at center if not already positioned.
  30. if(container.style.top == '') {
  31. placeAtCenter(container);
  32. }
  33. }
  34. }
  35. container.show();
  36. }
  37. },
  38. hideWizardContainer : function() {
  39. if(typeof(container) == 'undefined') container = SMSNotifierCommon.getWizardContainer();
  40. if(container) {
  41. container.hide();
  42. }
  43. },
  44. /** Select Wizard **/
  45. displaySelectWizard_DetailView : function(sourcemodule, recordid) {
  46. var sourcenode = null;
  47. SMSNotifierCommon.displaySelectWizard(sourcenode, sourcemodule, recordid);
  48. },
  49. displaySelectWizard : function(sourcenode, sourcemodule, recordid) {
  50. var idstring = false;
  51. // Record id not sent directly? Could be from ListView
  52. if(typeof(recordid) == 'undefined' || recordid == null || recordid == '') {
  53. var select_options = document.getElementById('allselectedboxes').value;
  54. var x = select_options.split(';');
  55. var count = x.length;
  56. if(count > 1) {
  57. idstring=select_options;
  58. } else {
  59. alert(alert_arr.SELECT);
  60. return false;
  61. }
  62. } else {
  63. // Record id sent? Could be from DetailView
  64. idstring = recordid;
  65. }
  66. if(idstring) {
  67. var url = 'module=SMSNotifier&action=SMSNotifierAjax&ajax=true&file=SMSNotifierSelectWizard';
  68. url += '&sourcemodule=' + encodeURIComponent(sourcemodule);
  69. url += '&idstring=' + encodeURIComponent(idstring);
  70. new Ajax.Request('index.php', {
  71. queue: {position: 'end', scope: 'command'},
  72. method: 'post',
  73. postBody:url,
  74. onComplete: function(response) {
  75. SMSNotifierCommon.buildSelectWizard(response.responseText, sourcenode);
  76. }
  77. });
  78. }
  79. },
  80. buildSelectWizard : function(content, sourcenode) {
  81. var container = SMSNotifierCommon.getWizardContainer();
  82. container.innerHTML = content;
  83. SMSNotifierCommon.displayWizardContainer(container, sourcenode);
  84. },
  85. hideSelectWizard : function() {
  86. SMSNotifierCommon.hideWizardContainer();
  87. },
  88. /** Compose Wizard **/
  89. displayComposeWizard : function(form, sourcenode) {
  90. var form_phonetype_inputs = form.phonetype;
  91. if(typeof form_phonetype_inputs.length == 'undefined') {
  92. form_phonetype_inputs = [form.phonetype];
  93. }
  94. // Variables to submit for next wizard
  95. var phonefields = '';
  96. var idstring = form.idstring.value;
  97. var sourcemodule = form.sourcemodule.value;
  98. // Gather the phone fields selected.
  99. for(var index = 0; index < form_phonetype_inputs.length; ++index) {
  100. if(form_phonetype_inputs[index].checked) {
  101. phonefields += form_phonetype_inputs[index].value + ';';
  102. }
  103. }
  104. if(phonefields == '') {
  105. // TODO Show alert?
  106. return false;
  107. }
  108. var url = 'module=SMSNotifier&action=SMSNotifierAjax&ajax=true&file=SMSNotifierComposeWizard';
  109. url += '&sourcemodule=' + encodeURIComponent(sourcemodule);
  110. url += '&idstring=' + encodeURIComponent(idstring);
  111. url += '&phonefields='+ encodeURIComponent(phonefields);
  112. new Ajax.Request('index.php', {
  113. queue: {position: 'end', scope: 'command'},
  114. method: 'post',
  115. postBody:url,
  116. onComplete: function(response) {
  117. SMSNotifierCommon.buildComposeWizard(response.responseText, sourcenode);
  118. }
  119. });
  120. },
  121. buildComposeWizard : function(content, sourcenode) {
  122. var container = SMSNotifierCommon.getWizardContainer();
  123. container.innerHTML = content;
  124. SMSNotifierCommon.displayWizardContainer(container, sourcenode);
  125. },
  126. hideComposeWizard : function() {
  127. SMSNotifierCommon.hideWizardContainer();
  128. },
  129. /** Send Operation **/
  130. triggerSendSMS : function(form) {
  131. var messageTextInput = form.message;
  132. if(messageTextInput.value == '') {
  133. messageTextInput.focus();
  134. return false;
  135. }
  136. // Variables to submit for next wizard
  137. var phonefields = form.phonefields.value;
  138. var idstring = form.idstring.value;
  139. var sourcemodule = form.sourcemodule.value;
  140. var message = messageTextInput.value;
  141. $('status').show();
  142. VtigerJS_DialogBox.block();
  143. var url = 'module=SMSNotifier&action=SMSNotifierAjax&ajax=true&file=SMSNotifierSend';
  144. url += '&sourcemodule=' + encodeURIComponent(sourcemodule);
  145. url += '&idstring=' + encodeURIComponent(idstring);
  146. url += '&phonefields='+ encodeURIComponent(phonefields);
  147. url += '&message=' + encodeURIComponent(message);
  148. new Ajax.Request('index.php', {
  149. queue: {position: 'end', scope: 'command'},
  150. method: 'post',
  151. postBody:url,
  152. onComplete: function(response) {
  153. SMSNotifierCommon.hideComposeWizard();
  154. $('status').hide();
  155. VtigerJS_DialogBox.unblock();
  156. }
  157. });
  158. }
  159. };
  160. }