buycourses.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. var courseOrSession = $(this).parent().parent()[0].attributes[0].value;
  36. if (courseOrSession.indexOf("session") > -1) {
  37. courseOrSession = "session_id";
  38. } else {
  39. courseOrSession = "course_id";
  40. }
  41. var courseOrSessionObject = {tab: "save_mod", visible: visible, price: price};
  42. courseOrSessionObject[courseOrSession] = course_id;
  43. $.post("function.php", courseOrSessionObject,
  44. function (data) {
  45. if (data.status == "false") {
  46. alert("Database Error");
  47. } else {
  48. courseOrSession = courseOrSession.replace("_id", "");
  49. $("#" + courseOrSession + data.course_id).children().attr("style", "display:''");
  50. $("#" + courseOrSession + data.course_id).children().next().attr("style", "display:none");
  51. $("#" + courseOrSession + data.course_id).parent().removeClass("fmod")
  52. $("#" + courseOrSession + data.course_id).parent().children().each(function () {
  53. $(this).removeClass("btop");
  54. });
  55. }
  56. }, "json");
  57. });
  58. $('#sync').click(function (e) {
  59. $.post("function.php", {tab: "sync"},
  60. function (data) {
  61. if (data.status == "false") {
  62. alert(data.contenido);
  63. } else {
  64. alert(data.contenido);
  65. location.reload();
  66. }
  67. }, "json");
  68. e.preventDefault();
  69. e.stopPropagation();
  70. });
  71. $(".filter").click(function (e) {
  72. var target = "#"+($(this).closest(".row").children().last()).attr("id");
  73. var filterFields = $(this).siblings("input");
  74. var filterFieldsData = { tab: $(this).attr("id") };
  75. $.each(filterFields, function() {
  76. // Get only the first class
  77. var className = $(this).attr("class").split(" ")[0];
  78. filterFieldsData[className] = $(this).val();
  79. });
  80. $.post("function.php", filterFieldsData,
  81. function (data) {
  82. if (data.status == "false") {
  83. alert(data.content);
  84. $(target).html('');
  85. } else {
  86. $(target).html(data.content);
  87. }
  88. $(document).ready(acciones_ajax);
  89. }, "json");
  90. e.preventDefault();
  91. e.stopPropagation();
  92. });
  93. $("#save_currency").click(function (e) {
  94. var currency_type = $("#currency_type").attr("value");
  95. $.post("function.php", {tab: "save_currency", currency: currency_type},
  96. function (data) {
  97. alert(data.content);
  98. }, "json");
  99. e.preventDefault();
  100. e.stopPropagation();
  101. });
  102. $("#save_paypal").click(function (e) {
  103. var name = $("#username").attr("value");
  104. var clave = $("#password").attr("value");
  105. var firma = $("#signature").attr("value");
  106. if ($("#sandbox").attr("checked") == "checked") {
  107. var vsandbox = "YES";
  108. } else {
  109. var vsandbox = "NO";
  110. }
  111. $.post("function.php", {tab: "save_paypal", username: name, password: clave, signature: firma, sandbox: vsandbox},
  112. function (data) {
  113. alert(data.content);
  114. }, "json");
  115. e.preventDefault();
  116. e.stopPropagation();
  117. });
  118. $("#add_account").click(function (e) {
  119. var tname = $("#tname").attr("value");
  120. var taccount = $("#taccount").attr("value");
  121. var tswift = $("#tswift").attr("value");
  122. if (tname == '' || taccount == '') {
  123. alert("Complete los campos antes de insertar");
  124. } else {
  125. $.post("function.php", {tab: "add_account", name: tname, account: taccount, swift: tswift},
  126. function (data) {
  127. location.reload();
  128. }, "json");
  129. }
  130. e.preventDefault();
  131. e.stopPropagation();
  132. });
  133. $(".delete_account").click(function (e) {
  134. var fieldName = $(this).parent().attr("id");
  135. var id = $("#id_" + fieldName).val();
  136. $.post("function.php", {tab: "delete_account", id: id},
  137. function (data) {
  138. location.reload();
  139. }, "json");
  140. e.preventDefault();
  141. e.stopPropagation();
  142. });
  143. $("#cancel_order").click(function (e) {
  144. $.post("function.php", {tab: "unset_variables"});
  145. window.location.replace("list.php");
  146. });
  147. $(".clear_order").click(function (e) {
  148. var vid = $(this).parent().attr("id");
  149. $.post("function.php", {tab: "clear_order", id: vid},
  150. function (data) {
  151. location.reload();
  152. }, "json");
  153. e.preventDefault();
  154. e.stopPropagation();
  155. });
  156. $(".confirm_order").click(function (e) {
  157. var vid = $(this).parent().attr("id");
  158. $.post("function.php", {tab: "confirm_order", id: vid},
  159. function (data) {
  160. location.reload();
  161. }, "json");
  162. e.preventDefault();
  163. e.stopPropagation();
  164. });
  165. $(".slt_tpv").change(function () {
  166. var vcod = $(this).attr("value");
  167. $.post("function.php", {tab: "activar_tpv", cod: vcod});
  168. });
  169. });
  170. function acciones_ajax() {
  171. $('.ajax').on('click', function () {
  172. var url = this.href;
  173. var dialog = $("#dialog");
  174. if ($("#dialog").length == 0) {
  175. dialog = $('<div id="dialog" style="display:none"></div>').appendTo('body');
  176. }
  177. width_value = 580;
  178. height_value = 450;
  179. resizable_value = true;
  180. new_param = get_url_params(url, 'width');
  181. if (new_param) {
  182. width_value = new_param;
  183. }
  184. new_param = get_url_params(url, 'height')
  185. if (new_param) {
  186. height_value = new_param;
  187. }
  188. new_param = get_url_params(url, 'resizable');
  189. if (new_param) {
  190. resizable_value = new_param;
  191. }
  192. // load remote content
  193. dialog.load(
  194. url,
  195. {},
  196. function (responseText, textStatus, XMLHttpRequest) {
  197. dialog.dialog({
  198. modal: true,
  199. width: width_value,
  200. height: height_value,
  201. resizable: resizable_value
  202. });
  203. });
  204. //prevent the browser to follow the link
  205. return false;
  206. });
  207. }