buycourses.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* For licensing terms, see /license.txt */
  2. /**
  3. * JS library for the Chamilo buy-courses plugin
  4. * @package chamilo.plugin.buycourses
  5. */
  6. $(document).ready(function () {
  7. $("input[name='price']").change(function () {
  8. $(this).parent().next().children().attr("style", "display:none");
  9. $(this).parent().next().children().next().attr("style", "display:''");
  10. $(this).parent().parent().addClass("fmod")
  11. $(this).parent().parent().children().each(function () {
  12. $(this).addClass("btop");
  13. });
  14. });
  15. $("input[name='price']").keyup(function () {
  16. $(this).parent().next().children().attr("style", "display:none");
  17. $(this).parent().next().children().next().attr("style", "display:''");
  18. $(this).parent().parent().addClass("fmod")
  19. $(this).parent().parent().children().each(function () {
  20. $(this).addClass("btop");
  21. });
  22. });
  23. $("input[name='visible']").change(function () {
  24. $(this).parent().next().next().children().attr("style", "display:none");
  25. $(this).parent().next().next().children().next().attr("style", "display:''");
  26. $(this).parent().parent().addClass("fmod")
  27. $(this).parent().parent().children().each(function () {
  28. $(this).addClass("btop");
  29. });
  30. });
  31. $(".save").click(function () {
  32. var visible = $(this).parent().parent().prev().prev().children().attr("checked");
  33. var price = $(this).parent().parent().prev().children().attr("value");
  34. var course_id = $(this).attr('id');
  35. $.post("function.php", {tab: "save_mod", course_id: course_id, visible: visible, price: price},
  36. function (data) {
  37. if (data.status == "false") {
  38. alert("Database Error");
  39. } else {
  40. $("#course" + data.course_id).children().attr("style", "display:''");
  41. $("#course" + data.course_id).children().next().attr("style", "display:none");
  42. $("#course" + data.course_id).parent().removeClass("fmod")
  43. $("#course" + data.course_id).parent().children().each(function () {
  44. $(this).removeClass("btop");
  45. });
  46. }
  47. }, "json");
  48. });
  49. $('#sync').click(function (e) {
  50. $.post("function.php", {tab: "sync"},
  51. function (data) {
  52. if (data.status == "false") {
  53. alert(data.contenido);
  54. } else {
  55. alert(data.contenido);
  56. location.reload();
  57. }
  58. }, "json");
  59. e.preventDefault();
  60. e.stopPropagation();
  61. });
  62. $('#confirm_filter').click(function (e) {
  63. var vcourse = $("#course_name").attr("value");
  64. var pmin = $("#price_min").attr("value");
  65. var pmax = $("#price_max").attr("value");
  66. if ($("#mostrar_disponibles").attr("checked") == "checked") {
  67. var vshow = "YES";
  68. } else {
  69. var vshow = "NO";
  70. }
  71. var vcategory = $("#courses_category").attr("value");
  72. $.post("function.php", {tab: "courses_filter", course: vcourse, pricemin: pmin, pricemax: pmax, mostrar: vshow, category: vcategory},
  73. function (data) {
  74. if (data.status == "false") {
  75. alert(data.content);
  76. $("#course_results").html('');
  77. } else {
  78. $("#course_results").html(data.content);
  79. }
  80. $(document).ready(acciones_ajax);
  81. }, "json");
  82. e.preventDefault();
  83. e.stopPropagation();
  84. });
  85. $("#save_currency").click(function (e) {
  86. var currency_type = $("#currency_type").attr("value");
  87. $.post("function.php", {tab: "save_currency", currency: currency_type},
  88. function (data) {
  89. alert(data.content);
  90. }, "json");
  91. e.preventDefault();
  92. e.stopPropagation();
  93. });
  94. $("#save_paypal").click(function (e) {
  95. var name = $("#username").attr("value");
  96. var clave = $("#password").attr("value");
  97. var firma = $("#signature").attr("value");
  98. if ($("#sandbox").attr("checked") == "checked") {
  99. var vsandbox = "YES";
  100. } else {
  101. var vsandbox = "NO";
  102. }
  103. $.post("function.php", {tab: "save_paypal", username: name, password: clave, signature: firma, sandbox: vsandbox},
  104. function (data) {
  105. alert(data.content);
  106. }, "json");
  107. e.preventDefault();
  108. e.stopPropagation();
  109. });
  110. $("#add_account").click(function (e) {
  111. var tname = $("#tname").attr("value");
  112. var taccount = $("#taccount").attr("value");
  113. var tswift = $("#tswift").attr("value");
  114. if (tname == '' || taccount == '') {
  115. alert("Complete los campos antes de insertar");
  116. } else {
  117. $.post("function.php", {tab: "add_account", name: tname, account: taccount, swift: tswift},
  118. function (data) {
  119. location.reload();
  120. }, "json");
  121. }
  122. e.preventDefault();
  123. e.stopPropagation();
  124. });
  125. $(".delete_account").click(function (e) {
  126. var fieldName = $(this).parent().attr("id");
  127. var id = $("#id_" + fieldName).val();
  128. $.post("function.php", {tab: "delete_account", id: id},
  129. function (data) {
  130. location.reload();
  131. }, "json");
  132. e.preventDefault();
  133. e.stopPropagation();
  134. });
  135. $("#cancel_order").click(function (e) {
  136. $.post("function.php", {tab: "unset_variables"});
  137. window.location.replace("list.php");
  138. });
  139. $(".clear_order").click(function (e) {
  140. var vid = $(this).parent().attr("id");
  141. $.post("function.php", {tab: "clear_order", id: vid},
  142. function (data) {
  143. location.reload();
  144. }, "json");
  145. e.preventDefault();
  146. e.stopPropagation();
  147. });
  148. $(".confirm_order").click(function (e) {
  149. var vid = $(this).parent().attr("id");
  150. $.post("function.php", {tab: "confirm_order", id: vid},
  151. function (data) {
  152. location.reload();
  153. }, "json");
  154. e.preventDefault();
  155. e.stopPropagation();
  156. });
  157. $(".slt_tpv").change(function () {
  158. var vcod = $(this).attr("value");
  159. $.post("function.php", {tab: "activar_tpv", cod: vcod});
  160. });
  161. });
  162. function acciones_ajax() {
  163. $('.ajax').on('click', function () {
  164. var url = this.href;
  165. var dialog = $("#dialog");
  166. if ($("#dialog").length == 0) {
  167. dialog = $('<div id="dialog" style="display:none"></div>').appendTo('body');
  168. }
  169. width_value = 580;
  170. height_value = 450;
  171. resizable_value = true;
  172. new_param = get_url_params(url, 'width');
  173. if (new_param) {
  174. width_value = new_param;
  175. }
  176. new_param = get_url_params(url, 'height')
  177. if (new_param) {
  178. height_value = new_param;
  179. }
  180. new_param = get_url_params(url, 'resizable');
  181. if (new_param) {
  182. resizable_value = new_param;
  183. }
  184. // load remote content
  185. dialog.load(
  186. url,
  187. {},
  188. function (responseText, textStatus, XMLHttpRequest) {
  189. dialog.dialog({
  190. modal: true,
  191. width: width_value,
  192. height: height_value,
  193. resizable: resizable_value
  194. });
  195. });
  196. //prevent the browser to follow the link
  197. return false;
  198. });
  199. }