buycourses.js 8.1 KB

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