buycourses.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. $('#confirm_session_filter').click(function (e) {
  72. var vsession = $("#session_name").attr("value");
  73. var sessionpmin = $("#session_price_min").attr("value");
  74. var sessionpmax = $("#session_price_max").attr("value");
  75. if ($("#mostrar_disponibles").attr("checked") == "checked") {
  76. var vshow = "YES";
  77. } else {
  78. var vshow = "NO";
  79. }
  80. var vsessioncategory = $("#sessions_category").attr("value");
  81. $.post("function.php", {tab: "sessions_filter", session: vsession, pricemin: sessionpmin, pricemax: sessionpmax, mostrar: vshow, category: vsessioncategory},
  82. function (data) {
  83. if (data.status == "false") {
  84. alert(data.content);
  85. $("#session_results").html('');
  86. } else {
  87. $("#session_results").html(data.content);
  88. }
  89. $(document).ready(acciones_ajax);
  90. }, "json");
  91. e.preventDefault();
  92. e.stopPropagation();
  93. });
  94. $('#confirm_filter').click(function (e) {
  95. var vcourse = $("#course_name").attr("value");
  96. var pmin = $("#price_min").attr("value");
  97. var pmax = $("#price_max").attr("value");
  98. if ($("#mostrar_disponibles").attr("checked") == "checked") {
  99. var vshow = "YES";
  100. } else {
  101. var vshow = "NO";
  102. }
  103. var vcategory = $("#courses_category").attr("value");
  104. $.post("function.php", {tab: "courses_filter", course: vcourse, pricemin: pmin, pricemax: pmax, mostrar: vshow, category: vcategory},
  105. function (data) {
  106. if (data.status == "false") {
  107. alert(data.content);
  108. $("#course_results").html('');
  109. } else {
  110. $("#course_results").html(data.content);
  111. }
  112. $(document).ready(acciones_ajax);
  113. }, "json");
  114. e.preventDefault();
  115. e.stopPropagation();
  116. });
  117. $("#save_currency").click(function (e) {
  118. var currency_type = $("#currency_type").attr("value");
  119. $.post("function.php", {tab: "save_currency", currency: currency_type},
  120. function (data) {
  121. alert(data.content);
  122. }, "json");
  123. e.preventDefault();
  124. e.stopPropagation();
  125. });
  126. $("#save_paypal").click(function (e) {
  127. var name = $("#username").attr("value");
  128. var clave = $("#password").attr("value");
  129. var firma = $("#signature").attr("value");
  130. if ($("#sandbox").attr("checked") == "checked") {
  131. var vsandbox = "YES";
  132. } else {
  133. var vsandbox = "NO";
  134. }
  135. $.post("function.php", {tab: "save_paypal", username: name, password: clave, signature: firma, sandbox: vsandbox},
  136. function (data) {
  137. alert(data.content);
  138. }, "json");
  139. e.preventDefault();
  140. e.stopPropagation();
  141. });
  142. $("#add_account").click(function (e) {
  143. var tname = $("#tname").attr("value");
  144. var taccount = $("#taccount").attr("value");
  145. var tswift = $("#tswift").attr("value");
  146. if (tname == '' || taccount == '') {
  147. alert("Complete los campos antes de insertar");
  148. } else {
  149. $.post("function.php", {tab: "add_account", name: tname, account: taccount, swift: tswift},
  150. function (data) {
  151. location.reload();
  152. }, "json");
  153. }
  154. e.preventDefault();
  155. e.stopPropagation();
  156. });
  157. $(".delete_account").click(function (e) {
  158. var fieldName = $(this).parent().attr("id");
  159. var id = $("#id_" + fieldName).val();
  160. $.post("function.php", {tab: "delete_account", id: id},
  161. function (data) {
  162. location.reload();
  163. }, "json");
  164. e.preventDefault();
  165. e.stopPropagation();
  166. });
  167. $("#cancel_order").click(function (e) {
  168. $.post("function.php", {tab: "unset_variables"});
  169. window.location.replace("list.php");
  170. });
  171. $(".clear_order").click(function (e) {
  172. var vid = $(this).parent().attr("id");
  173. $.post("function.php", {tab: "clear_order", id: vid},
  174. function (data) {
  175. location.reload();
  176. }, "json");
  177. e.preventDefault();
  178. e.stopPropagation();
  179. });
  180. $(".confirm_order").click(function (e) {
  181. var vid = $(this).parent().attr("id");
  182. $.post("function.php", {tab: "confirm_order", id: vid},
  183. function (data) {
  184. location.reload();
  185. }, "json");
  186. e.preventDefault();
  187. e.stopPropagation();
  188. });
  189. $(".slt_tpv").change(function () {
  190. var vcod = $(this).attr("value");
  191. $.post("function.php", {tab: "activar_tpv", cod: vcod});
  192. });
  193. });
  194. function acciones_ajax() {
  195. $('.ajax').on('click', function () {
  196. var url = this.href;
  197. var dialog = $("#dialog");
  198. if ($("#dialog").length == 0) {
  199. dialog = $('<div id="dialog" style="display:none"></div>').appendTo('body');
  200. }
  201. width_value = 580;
  202. height_value = 450;
  203. resizable_value = true;
  204. new_param = get_url_params(url, 'width');
  205. if (new_param) {
  206. width_value = new_param;
  207. }
  208. new_param = get_url_params(url, 'height')
  209. if (new_param) {
  210. height_value = new_param;
  211. }
  212. new_param = get_url_params(url, 'resizable');
  213. if (new_param) {
  214. resizable_value = new_param;
  215. }
  216. // load remote content
  217. dialog.load(
  218. url,
  219. {},
  220. function (responseText, textStatus, XMLHttpRequest) {
  221. dialog.dialog({
  222. modal: true,
  223. width: width_value,
  224. height: height_value,
  225. resizable: resizable_value
  226. });
  227. });
  228. //prevent the browser to follow the link
  229. return false;
  230. });
  231. }