resource_sequence.tpl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. {% extends 'layout/layout_1_col.tpl'|get_template %}
  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. sequenceId = $("#sequence_id option:selected" ).val();
  92. // Load parents
  93. $('#parents').on('click', 'a.delete_vertex, a.undo_delete', function(e) {
  94. e.preventDefault();
  95. var self = $(this),
  96. parent = self.parent(),
  97. vertexId = self.attr('data-id') || 0;
  98. if (!vertexId) {
  99. return;
  100. }
  101. if (self.is('.delete_vertex')) {
  102. self.hide();
  103. parent.find('.undo_delete').show();
  104. self.parents('.parent').addClass('parent-deleted');
  105. } else if (self.is('.undo_delete')) {
  106. self.hide();
  107. parent.find('.delete_vertex').show();
  108. self.parents('.parent').removeClass('parent-deleted');
  109. }
  110. });
  111. $('#parents, #resource, #children').on('click', '.parent .sequence-id', function(e) {
  112. e.preventDefault();
  113. var itemId = $(this).parents('.parent').data('id') || 0;
  114. if (!itemId) {
  115. return;
  116. }
  117. $('button[name="set_requirement"]').prop('disabled', false);
  118. $('#requirements').prop('disabled', false);
  119. $('button[name="save_resource"]').prop('disabled', false);
  120. useAsReference(type, sequenceId, itemId);
  121. });
  122. // Button use as reference
  123. $('button[name="use_as_reference"]').click(function(e) {
  124. e.preventDefault();
  125. if (!sequenceId) {
  126. return;
  127. }
  128. $('#pnl-preview').show();
  129. $('button[name="set_requirement"], #requirements, button[name="save_resource"]').prop('disabled', false);
  130. $('#requirements').selectpicker('refresh');
  131. useAsReference(type, sequenceId);
  132. });
  133. // Button set requirement
  134. $('button[name="set_requirement"]').click(function(e) {
  135. e.preventDefault();
  136. var requirementsSelectedEl = $("#requirements option:selected");
  137. if (0 === requirementsSelectedEl.length || !sequenceId) {
  138. return;
  139. }
  140. requirementsSelectedEl.each(function() {
  141. var id = $(this).val();
  142. if ($.inArray(id, parentList) == -1) {
  143. $.ajax({
  144. url: url + '?a=get_icon&id=' + id + '&type='+type+'&sequence_id='+sequenceId,
  145. success: function (data) {
  146. $('#parents').append(data);
  147. parentList.push(id);
  148. }
  149. });
  150. }
  151. });
  152. });
  153. // Button save
  154. $('button[name="save_resource"]').click(function(e) {
  155. e.preventDefault();
  156. if (!sequenceId) {
  157. return;
  158. }
  159. var self = $(this).prop('disabled', true);
  160. // parse to integer the parents IDs
  161. parentList = parentList.map(function(id) {
  162. return parseInt(id);
  163. });
  164. var deletingVertex = new Array();
  165. // Delete all vertex confirmed to be deleted.
  166. $('#parents .parent.parent-deleted').each(function() {
  167. var self = $(this),
  168. vertexId = self.data('id') || 0,
  169. deleteVertex;
  170. deleteVertex = $.ajax(url, {
  171. data: {
  172. a: 'delete_vertex',
  173. id: resourceId,
  174. vertex_id: vertexId,
  175. type: type,
  176. sequence_id: sequenceId
  177. },
  178. success: function() {
  179. parentList.splice($.inArray(vertexId, parentList), 1);
  180. }
  181. });
  182. deletingVertex.push(deleteVertex);
  183. });
  184. $.when.apply($, deletingVertex).done(function() {
  185. if (resourceId != 0) {
  186. var params = decodeURIComponent(parentList);
  187. var savingResource = $.ajax(url, {
  188. data: {
  189. a: 'save_resource',
  190. id: resourceId,
  191. parents: params,
  192. type: type,
  193. sequence_id: sequenceId
  194. }
  195. });
  196. $.when(savingResource).done(function(response) {
  197. $('#global-modal')
  198. .find('.modal-dialog')
  199. .removeClass('modal-lg')
  200. .addClass('modal-sm');
  201. $('#global-modal')
  202. .find('.modal-body')
  203. .html(response);
  204. $('#global-modal').modal('show');
  205. self.prop('disabled', false);
  206. useAsReference(type, sequenceId);
  207. });
  208. }
  209. });
  210. });
  211. $('select#sequence_id').on('change', function() {
  212. sequenceId = $(this).val();
  213. if (sequenceId > 0) {
  214. $('#secuence-title').text(
  215. $(this).children(':selected').text()
  216. );
  217. $('#show_graph').html('');
  218. $('#pnl-configuration').show();
  219. $('#pnl-preview').hide();
  220. $('button[name="set_requirement"], #requirements, button[name="save_resource"]').prop('disabled', true);
  221. $('#item, button[name="use_as_reference"]').prop('disabled', false);
  222. return;
  223. }
  224. $('#pnl-configuration').hide();
  225. });
  226. $('form[name="frm_select_delete"]').on('submit', function (e) {
  227. var confirmDelete = confirm('{{ 'AreYouSureToDeleteJS'|get_lang }}');
  228. if (!confirmDelete) {
  229. e.preventDefault();
  230. }
  231. });
  232. $('select#sequence_id').trigger('change');
  233. });
  234. </script>
  235. <div class="panel panel-default">
  236. <div class="panel-body">
  237. <div class="section-title-sequence">{{ 'SequenceSelection' | get_lang }}</div>
  238. <div class="row">
  239. <div class="col-md-6">
  240. {{ create_sequence }}
  241. </div>
  242. <div class="col-md-6">
  243. {{ select_sequence }}
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. <div id="pnl-configuration" class="panel panel-default" style="display: none;">
  249. <div class="panel-body">
  250. <div class="section-title-sequence">{{ 'SequenceConfiguration' | get_lang }}</div>
  251. <div class="row">
  252. {{ configure_sequence }}
  253. </div>
  254. </div>
  255. </div>
  256. <div id="pnl-preview" class="panel panel-default" style="display: none;">
  257. <div class="panel-body">
  258. <div class="section-title-sequence">{{ 'SequencePreview' | get_lang }} &mdash;
  259. <span id="secuence-title"></span>
  260. </div>
  261. <div class="row">
  262. <div class="col-md-9">
  263. <h4 class="title-sequence">
  264. {{ 'ItemsTheReferenceDependsOn' | get_lang }}
  265. </h4>
  266. <div id="parents">
  267. </div>
  268. <div class="border-sequence">
  269. <div class="arrow-sequence"></div>
  270. </div>
  271. <h4 class="title-sequence">{{ 'Item' | get_lang }}</h4>
  272. <div id="resource">
  273. </div>
  274. <div class="border-sequence">
  275. <div class="arrow-sequence"></div>
  276. </div>
  277. <h4 class="title-sequence">{{ 'Dependencies' | get_lang }}</h4>
  278. <div id="children">
  279. </div>
  280. </div>
  281. <div class="col-md-3">
  282. <h4 class="title-sequence">{{ 'GraphDependencyTree' | get_lang }}</h4>
  283. <div id="show_graph"></div>
  284. </div>
  285. </div>
  286. {{ save_sequence }}
  287. </div>
  288. </div>
  289. {% endblock %}