Advertisement
Guest User

Untitled

a guest
May 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 KB | None | 0 0
  1. {% extends "site_base.html" %}
  2.  
  3. {% load i18n %}
  4. {% load uni_form %}
  5. {% load ifsetting_tag %}
  6.  
  7. {% block head_title %}{% trans "Recharge" %}{% endblock %}
  8.  
  9. {% block body %}
  10. <div id='cont'>
  11. <form class="login uniForm" method="POST" action="{% url call_recharge %}">
  12. <fieldset class="inlineLabels">
  13. {{ form|as_uni_form }}
  14. <div class="form_block">
  15. <input id='submit' type="button" value="{% trans 'Recharge' %}" />
  16. </div>
  17. <div id='radiodiv'></div>
  18. </fieldset>
  19. </form>
  20. </div>
  21.  
  22. {% endblock %}
  23.  
  24. {% block extra_body %}
  25. <script src="{{ STATIC_URL }}js/jquery.maskedinput-1.2.2.min.js" type="text/javascript"></script>
  26. <script src="{{ STATIC_URL }}js/jquery.simplemodal-1.3.5.min.js" type="text/javascript"></script>
  27. <style type="text/css">
  28. #simplemodal-container a.modalCloseImg {
  29. background:url({{ STATIC_URL }}images/loadingAnimatio.gif) no-repeat; /* adjust url as required */
  30. width:25px;
  31. height:29px;
  32. display:inline;
  33. z-index:3200;
  34. position:absolute;
  35. top:-15px;
  36. right:-18px;
  37. cursor:pointer;
  38. }
  39. </style>
  40.  
  41. <script type="text/javascript">
  42.  
  43. function callModal() {
  44. $.modal("<div><h2>{% trans 'Loading...' %}</h2><img src='{{ STATIC_URL }}images/loadingAnimation.gif' /></div>",
  45. {
  46. opacity: 50,
  47. close: true,
  48. modal: true,
  49. overlayCss: {backgroundColor:"#fff"}
  50. });
  51. }
  52.  
  53. function closeModal() {
  54. $.modal.close();
  55. }
  56.  
  57. function get_value(value, id) {
  58. $('#id_product_value').val(value);
  59. $('#id_product').val(id);
  60. }
  61.  
  62. $(function() {
  63.  
  64. $('#id_phone1').focus();
  65. $('#id_phone1').mask("(99)-9999.9999");
  66. $('#id_phone2').mask("(99)-9999.9999");
  67.  
  68. $('#id_phone2').attr('readonly', 'readonly');
  69. $('#id_phone1').keyup(function() {
  70. if ( $('#id_phone1').val().indexOf('_') != -1 ) {
  71. $('#errormsg').remove();
  72. $('#id_phone2').val("");
  73. $('option[value=0]').attr('selected', 'selected');
  74. $('#id_mobile_carrier').attr('disabled', 'disabled');
  75. $('#div_radio').empty();
  76. return false;
  77. }
  78. if ( $('#id_phone1').val().indexOf('_') != -1 ) {
  79. $('#errormsg').remove();
  80. $('#id_phone1').after("<span id='errormsg'>{% trans 'Phone field must have 10 digits.' %}</span>");
  81. $('#id_phone2').attr('readonly', 'readonly');
  82. $('#id_phone2').val("");
  83. $('#id_mobile_carrier').attr('disabled', 'disabled');
  84. } else {
  85. $('#errormsg').remove();
  86. $('#id_phone2').attr('readonly', '');
  87. if ( $('#id_phone1').val() == $('#id_phone2').val() ) {
  88. $('#id_mobile_carrier').attr('disabled', '');
  89. } else {
  90. $('#id_mobile_carrier').attr('disabled', 'disabled');
  91. }
  92. }
  93. });
  94.  
  95. $('#id_mobile_carrier').attr('disabled', 'disabled');
  96. $('#id_phone2').keyup(function() {
  97. if ( $('#id_phone2').val().indexOf('_') != -1 ) {
  98. $('#errormsg').remove();
  99. $('option[value=0]').attr('selected', 'selected');
  100. $('#id_mobile_carrier').attr('disabled', 'disabled');
  101. $('#div_radio').empty();
  102. return false;
  103. }
  104. if ( $('#id_phone2').val().indexOf('_') == -1 ) {
  105. if ( $('#id_phone1').val() == $('#id_phone2').val() ) {
  106. $('#errormsg').remove();
  107. $('#id_mobile_carrier').attr('disabled', '');
  108. } else {
  109. $('#errormsg').remove();
  110. $('#id_phone2').after("<span id='errormsg'>{% trans 'You must type the same phone each time.' %}</span>");
  111. $('#id_mobile_carrier').attr('disabled', 'disabled');
  112. }
  113. } else {
  114. $('#errormsg').remove();
  115. $('#id_phone2').after("<span id='errormsg'>{% trans 'Phone field must have 10 digits.' %}</span>");
  116. $('#id_mobile_carrier').attr('disabled', 'disabled');
  117. }
  118.  
  119. });
  120.  
  121. $('#div_id_mobile_carrier').after("<p>{% trans 'Values*' %} </p><div id='div_id_price' class='ctrlHolder'><div id='div_radio'></div></div>");
  122. $('#id_mobile_carrier').change(function() {
  123. callModal();
  124. ddd = $('#id_phone1').val().substr(1, 2);
  125. $.ajax({
  126. type: "GET",
  127. url: "/gadget/get_prices/",
  128. dataType: "json",
  129. data: 'ddd=' + ddd + '&op=' + $(this).val(),
  130. success: function(data) {
  131. closeModal();
  132. $('#div_radio').empty();
  133. if ( data != '' ) {
  134. $.each(data, function(i, item){
  135. $('#div_radio').append(
  136. "<input type='radio' id='id_price' name='price' value='" + item.fields['rv_id'] + "' onclick='get_value(" + moeda2float(item.fields['price']) + ", $(this).val())'> R$ " + moeda2float(item.fields['price'])
  137. );
  138. });
  139. } else {
  140. $('#div_radio').append("{% trans 'No values founded ' %}");
  141. }
  142. },
  143. error: function(error) {
  144. closeModal();
  145. $('#div_radio').append("{% trans 'No values founded ' %}");
  146. }
  147. });
  148. });
  149.  
  150. function moeda2float(moeda){
  151. moeda = moeda.replace(".",",");
  152. return parseFloat(moeda);
  153. }
  154.  
  155. $('#submit').click(function() {
  156. if ( valid() ) {
  157. callModal();
  158. query = 'action=process' +
  159. '&ntc=' + remove_mask($('#id_phone1').val()) +
  160. '&confirm_ntc=' + remove_mask($('#id_phone2').val()) +
  161. '&value_product=' + $('#id_product_value').val() +
  162. '&username=' + $('#id_username').val() +
  163. '&password=' + $('#id_password').val() +
  164. '&type_file=xml' +
  165. '&cod_product=' + $('#id_product').val();
  166. $.ajax({
  167. type: 'POST',
  168. url: '{% url call_recharge %}',
  169. //url: '{% url auth_recharge %}',
  170. data: query,
  171. success: function(ret) {
  172. closeModal();
  173. $('#cont').html(ret);
  174. }
  175. });
  176. } else {
  177. closeModal();
  178. }
  179. });
  180.  
  181. function remove_mask(value) {
  182. if (value.indexOf('-') == -1) {
  183. return value;
  184. } else {
  185. value = value.replace(/[-]/, "");
  186. value = value.replace(/[.]/, "");
  187. value = value.replace(/[(]/, "");
  188. value = value.replace(/[)]/, "");
  189. return value;
  190. }
  191. }
  192.  
  193. function valid() {
  194. var status = true;
  195. status = status && field_valid('id_phone1');
  196. status = status && field_valid('id_phone2');
  197. status = status && field_valid('id_mobile_carrier');
  198. status = status && field_valid('id_product_value');
  199. status = status && field_valid('id_username');
  200. status = status && field_valid('id_password');
  201. status = status && field_valid('id_product');
  202. return status;
  203. }
  204.  
  205. function field_valid(field) {
  206. $('#div_' + field).removeClass('error');
  207. $('#error_1_' + field).remove();
  208. if ( $('#' + field).val() == '' || $('#' + field).val() == 0) {
  209. $('#div_' + field).addClass('error');
  210. $('label[for=' + field + ']').before("<p id='error_1_" + field + "' class='errorField'>{% trans 'This field is required.' %}</p>");
  211. return false;
  212. } else {
  213. return true;
  214. }
  215. }
  216. });
  217. </script>
  218. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement