resource_sequence.html.twig 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. {% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
  2. {% block content %}
  3. {% autoescape false %}
  4. <script>
  5. var url = '{{ _p.web_ajax }}sequence.ajax.php';
  6. var parentList = [];
  7. var resourceId = 0;
  8. var sequenceId = 0;
  9. function useAsReference(type, sequenceId, itemId) {
  10. var id = itemId || $("#item option:selected").val();
  11. sequenceId = $("#sequence_id option:selected").val();
  12. // Cleaning parent list.
  13. parentList = [];
  14. // Check if data exists and load parents
  15. $.ajax({
  16. url: url + '?a=load_resource&load_resource_type=parent&id=' + id + '&type=' + type + '&sequence_id=' + sequenceId,
  17. success: function (data) {
  18. if (data) {
  19. var loadingResources = new Array(),
  20. listLoaded = data.split(',');
  21. listLoaded.forEach(function (value) {
  22. var loadResource = $.ajax(url, {
  23. data: {
  24. a: 'get_icon',
  25. id: value,
  26. type: type,
  27. sequence_id: sequenceId,
  28. show_delete: 1
  29. },
  30. success: function () {
  31. parentList.push(value);
  32. }
  33. });
  34. loadingResources.push(loadResource);
  35. });
  36. if (loadingResources.length) {
  37. $.when.apply($, loadingResources).done(function () {
  38. if (loadingResources.length === 1) {
  39. $('#parents').append(arguments[0]);
  40. return;
  41. }
  42. var i;
  43. for (i = 0; i < arguments.length; i++) {
  44. $('#parents').append(arguments[i][0]);
  45. if (i !== arguments.length - 1) {
  46. $('#parents').append('<em class="fa fa-plus fa-3x sequence-plus-icon"></em>');
  47. }
  48. }
  49. });
  50. }
  51. }
  52. }
  53. });
  54. // Check if data exists and load children
  55. $.ajax({
  56. url: url + '?a=load_resource&load_resource_type=children&id=' + id + '&type=' + type + '&sequence_id=' + sequenceId,
  57. success: function (data) {
  58. if (data) {
  59. var listLoaded = data.split(',');
  60. listLoaded.forEach(function (value) {
  61. $.ajax({
  62. url: url + '?a=get_icon&id=' + value + '&type=' + type + '&sequence_id=' + sequenceId,
  63. success: function (data) {
  64. $('#children').append(data);
  65. }
  66. });
  67. });
  68. }
  69. }
  70. });
  71. // Cleaning
  72. $('#parents').html('');
  73. $('#children').html('');
  74. $.ajax({
  75. url: url + '?a=get_icon&id=' + id + '&type=' + type + '&sequence_id=' + sequenceId,
  76. success: function (data) {
  77. $('#resource').html(data);
  78. parentList.push(id);
  79. resourceId = id;
  80. }
  81. });
  82. $.ajax({
  83. url: url + '?a=graph&type=' + type + '&sequence_id=' + sequenceId,
  84. success: function (data) {
  85. $('#show_graph').html(data);
  86. }
  87. });
  88. }
  89. $(function() {
  90. var type = $('input[name="sequence_type"]').val();
  91. // By default "set requirement" is set to false
  92. $('button[name="set_requirement"]').prop('disabled', true);
  93. $('#requirements').prop('disabled', true);
  94. $('button[name="save_resource"]').prop('disabled', true);
  95. sequenceId = $("#sequence_id option:selected").val();
  96. // Load parents
  97. $('#parents').on('click', 'a.delete_vertex, a.undo_delete', function (e) {
  98. e.preventDefault();
  99. var self = $(this),
  100. parent = self.parent(),
  101. vertexId = self.attr('data-id') || 0;
  102. if (!vertexId) {
  103. return;
  104. }
  105. if (self.is('.delete_vertex')) {
  106. self.hide();
  107. parent.find('.undo_delete').show();
  108. self.parents('.parent').addClass('parent-deleted');
  109. } else if (self.is('.undo_delete')) {
  110. self.hide();
  111. parent.find('.delete_vertex').show();
  112. self.parents('.parent').removeClass('parent-deleted');
  113. }
  114. });
  115. $('#parents, #resource, #children').on('click', '.parent .sequence-id', function (e) {
  116. e.preventDefault();
  117. var itemId = $(this).parents('.parent').data('id') || 0;
  118. if (!itemId) {
  119. return;
  120. }
  121. $('button[name="set_requirement"]').prop('disabled', false);
  122. $('#requirements').prop('disabled', false);
  123. $('button[name="save_resource"]').prop('disabled', false);
  124. useAsReference(type, sequenceId, itemId);
  125. });
  126. // Button use as reference
  127. $('button[name="use_as_reference"]').click(function () {
  128. $('button[name="set_requirement"]').prop('disabled', false);
  129. $('#requirements').prop('disabled', false);
  130. $('#requirements').selectpicker('refresh');
  131. $('button[name="save_resource"]').prop('disabled', false);
  132. useAsReference(type, sequenceId);
  133. return false;
  134. });
  135. // Button set requirement
  136. $('button[name="set_requirement"]').click(function () {
  137. $("#requirements option:selected").each(function () {
  138. var id = $(this).val();
  139. if ($.inArray(id, parentList) == -1) {
  140. $.ajax({
  141. url: url + '?a=get_icon&id=' + id + '&type=' + type + '&sequence_id=' + sequenceId,
  142. success: function (data) {
  143. $('#parents').append(data);
  144. parentList.push(id);
  145. }
  146. });
  147. }
  148. });
  149. return false;
  150. });
  151. // Button save
  152. $('button[name="save_resource"]').click(function (e) {
  153. e.preventDefault();
  154. var self = $(this).prop('disabled', true);
  155. // parse to integer the parents IDs
  156. parentList = parentList.map(function (id) {
  157. return parseInt(id);
  158. });
  159. var deletingVertex = new Array();
  160. // Delete all vertex confirmed to be deleted.
  161. $('#parents .parent.parent-deleted').each(function () {
  162. var self = $(this),
  163. vertexId = self.data('id') || 0,
  164. deleteVertex;
  165. deleteVertex = $.ajax(url, {
  166. data: {
  167. a: 'delete_vertex',
  168. id: resourceId,
  169. vertex_id: vertexId,
  170. type: type,
  171. sequence_id: sequenceId
  172. },
  173. success: function () {
  174. parentList.splice($.inArray(vertexId, parentList), 1);
  175. }
  176. });
  177. deletingVertex.push(deleteVertex);
  178. });
  179. $.when.apply($, deletingVertex).done(function () {
  180. if (resourceId != 0) {
  181. var params = decodeURIComponent(parentList);
  182. var savingResource = $.ajax(url, {
  183. data: {
  184. a: 'save_resource',
  185. id: resourceId,
  186. parents: params,
  187. type: type,
  188. sequence_id: sequenceId
  189. }
  190. });
  191. $.when(savingResource).done(function (response) {
  192. $('#global-modal')
  193. .find('.modal-dialog')
  194. .removeClass('modal-lg')
  195. .addClass('modal-sm');
  196. $('#global-modal')
  197. .find('.modal-body')
  198. .html(response);
  199. $('#global-modal').modal('show');
  200. self.prop('disabled', false);
  201. useAsReference(type, sequenceId);
  202. });
  203. }
  204. });
  205. });
  206. $('select#sequence_id').on('change', function () {
  207. sequenceId = $(this).val();
  208. });
  209. });
  210. </script>
  211. <div class="panel panel-default">
  212. <div class="panel-body">
  213. <div class="section-title-sequence">{{ 'SequenceSelection' | get_lang }}</div>
  214. <div class="row">
  215. <div class="col-md-6">
  216. {{ create_sequence }}
  217. </div>
  218. <div class="col-md-6">
  219. {{ select_sequence }}
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <div class="panel panel-default">
  225. <div class="panel-body">
  226. <div class="section-title-sequence">{{ 'SequenceConfiguration' | get_lang }}</div>
  227. <div class="row">
  228. {{ configure_sequence }}
  229. </div>
  230. </div>
  231. </div>
  232. <div class="panel panel-default">
  233. <div class="panel-body">
  234. <div class="section-title-sequence">{{ 'SequencePreview' | get_lang }}</div>
  235. <div class="row">
  236. <div class="col-md-9">
  237. <h4 class="title-sequence">
  238. {{ 'ItemsTheReferenceDependsOn' | get_lang }}
  239. </h4>
  240. <div id="parents">
  241. </div>
  242. <div class="border-sequence">
  243. <div class="arrow-sequence"></div>
  244. </div>
  245. <h4 class="title-sequence">{{ 'Item' | get_lang }}</h4>
  246. <div id="resource">
  247. </div>
  248. <div class="border-sequence">
  249. <div class="arrow-sequence"></div>
  250. </div>
  251. <h4 class="title-sequence">{{ 'Dependencies' | get_lang }}</h4>
  252. <div id="children">
  253. </div>
  254. </div>
  255. <div class="col-md-3">
  256. <h4 class="title-sequence">{{ 'GraphDependencyTree' | get_lang }}</h4>
  257. <div id="show_graph"></div>
  258. </div>
  259. </div>
  260. {{ save_sequence }}
  261. </div>
  262. </div>
  263. {% endautoescape %}
  264. {% endblock %}