resource_sequence.tpl 12 KB

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