Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

392 lines
19 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. <div class="form-row {{ pregunta.alias }} {{ pregunta.class }}">
  2. <div class="form-holder">
  3. {% if pregunta.preTitulo is not empty %}
  4. <div class="{{ tarea[0].getProcesosId.alias }}_pretitulo">{{ pregunta.preTitulo|trans({})|raw }}</div>
  5. {% else %}
  6. <div class="{{ tarea[0].getProcesosId.alias }}_pretitulo no-contenido">{{ pregunta.preTitulo|trans({})|raw }}</div>
  7. {% endif %}
  8. <label for="{{ pregunta.alias }}" class="{{ tarea[0].getProcesosId.alias }}_nombre">{{ pregunta.nombre|trans({})|raw }}</label>
  9. {% if pregunta.descripcion is not empty %}
  10. <div class="{{ tarea[0].getProcesosId.alias }}_descripcion">{{ pregunta.descripcion|trans({})|raw }}</div>
  11. {% else %}
  12. <div class="{{ tarea[0].getProcesosId.alias }}_descripcion no-contenido">{{ pregunta.descripcion|trans({})|raw }}</div>
  13. {% endif %}
  14. {% if casoestudio is defined and casoestudio is not empty %}
  15. {% if respuestaca[pregunta.alias] is defined and respuestaca[pregunta.alias] is not empty %}
  16. <a class="btn btn-primary btn-sm casoestudiobtn" data-toggle="collapse" data-target="#casoestudio{{ pregunta.id }}">{{ 'Caso de estudio'|trans({}) }}</a>
  17. <div id="casoestudio{{ pregunta.id }}" class="collapse casoestudiodiv">
  18. <pre>{{ respuestaca[pregunta.alias]|raw }}</pre>
  19. </div>
  20. {% endif %}
  21. {% else %}
  22. <a class="btn btn-primary btn-sm casoestudiobtn no-contenido" data-toggle="collapse" data-target="#casoestudio{{ pregunta.id }}"></a>
  23. <div id="casoestudio{{ pregunta.id }}" class="collapse casoestudiodiv no-contenido">
  24. </div>
  25. {% endif %}
  26. {% if app.user.getType == 'trainer' %}
  27. <div><label>{{ 'Green Entrepreneur Answer'|trans({}) }}</label>
  28. {% if respuestas is empty %}
  29. <pre>{{ 'Not available'|trans({}) }}</pre>
  30. {% else %}
  31. {% set encontrada = false %}
  32. {% if respuesta[pregunta.alias] is defined %}
  33. {% set encontrada=true %}
  34. <pre>{{ respuesta[pregunta.alias] }}</pre>
  35. {% endif %}
  36. {% if not encontrada %}
  37. <pre>{{ 'Not available'|trans({}) }}</pre>
  38. {% endif %}
  39. {% endif %}
  40. </div>
  41. {% if pregunta.isRevisable %}
  42. <div>
  43. <label for="review-{{ pregunta.alias }}">{{ 'Supervisor Review Mark'|trans({}) }}</label>
  44. <input type="checkbox" class="form-control icheckbox_minimal" data-sonata-icheck="false" id="review-{{ pregunta.alias }}" name="review-{{ pregunta.alias }}" {% if reviewed[pregunta.alias] is defined and reviewed[pregunta.alias] == true %} checked {% endif%} %}></input>
  45. </div>
  46. <div>
  47. <label for="comment-{{ pregunta.alias }}">{{ 'Supervisor Comment'|trans({}) }}</label>
  48. <textarea class="form-control" id="comment-{{ pregunta.alias }}" name="comment-{{ pregunta.alias }}" rows="10"> {% if comentarios is defined and comentarios[pregunta.alias] is defined and comentarios[pregunta.alias].comentario is defined and comentarios[pregunta.alias].comentario is not empty %}{{ comentarios[pregunta.alias].comentario|raw}}{% endif %}</textarea>
  49. </div>
  50. {% endif %}
  51. {% endif %}
  52. {% if app.user.getType == 'green_entrepreneur' %}
  53. {% if respuestas is empty %}
  54. <span>{{ 'Select any column header before clicking Add new column button'|trans({})}}</span>
  55. <button type="btn btn-success btn-sm" id="btnAddRow{{ pregunta.alias }}">{{ 'Add New Row'|trans({}) }}</button>
  56. <button type="btn btn-danger btn-sm" id="btnAddCol{{ pregunta.alias }}">{{ 'Add New Column'|trans({}) }}</button>
  57. <br>
  58. <input id="{{ pregunta.alias }}" name="{{ pregunta.alias }}" type="hidden" value="">
  59. <table class="dataTable" id="{{ pregunta.alias }}_table"></table>
  60. {% else %}
  61. {% set encontrada = false %}
  62. {% if respuesta[pregunta.alias] is defined %}
  63. {% set encontrada=true %}
  64. <span>{{ 'Select any column header before clicking Add new column button'|trans({})}}</span>
  65. <button type="btn btn-success btn-sm" id="btnAddRow{{ pregunta.alias }}">{{ 'Add New Row'|trans({}) }}</button>
  66. <button type="btn btn-danger btn-sm" id="btnAddCol{{ pregunta.alias }}">{{ 'Add New Column'|trans({}) }}</button>
  67. <br>
  68. <input id="{{ pregunta.alias }}" name="{{ pregunta.alias }}" type="hidden" value="{{respuesta[pregunta.alias]}}">
  69. <table class="dataTable" id="{{ pregunta.alias }}_table"></table>
  70. {% if pregunta.isRevisable and reviewed[pregunta.alias] and comentarios[pregunta.alias].comentario is defined and comentarios[pregunta.alias].comentario is not empty%}
  71. <div><label>{{ 'Supervisor Comment'|trans({}) }}</label>
  72. <pre>{{ comentarios[pregunta.alias].comentario|raw }}</pre>
  73. </div>
  74. {% endif %}
  75. {% endif %}
  76. {% if not encontrada %}
  77. <span>{{ 'Select any column header before clicking Add new column button'|trans({})}}</span>
  78. <button type="btn btn-success btn-sm" id="btnAddRow{{ pregunta.alias }}">{{ 'Add New Row'|trans({}) }}</button>
  79. <button type="btn btn-danger btn-sm" id="btnAddCol{{ pregunta.alias }}">{{ 'Add New Column'|trans({}) }}</button>
  80. <br>
  81. <input id="{{ pregunta.alias }}" name="{{ pregunta.alias }}" type="hidden" value="">
  82. <table class="dataTable" id="{{ pregunta.alias }}_table"></table>
  83. {% endif %}
  84. {% endif %}
  85. {% endif %}
  86. </div>
  87. <script>
  88. var data_table{{ pregunta.alias }}, row_num{{ pregunta.alias }}, col_num{{ pregunta.alias }}, row_cell{{ pregunta.alias }}, col_cell{{ pregunta.alias }}, iter{{ pregunta.alias }}=0;
  89. var cols{{ pregunta.alias }} =[
  90. {% if respuesta[pregunta.alias] is defined and respuesta[pregunta.alias]|json_decode is not empty %}
  91. {% for field in respuesta[pregunta.alias]|json_decode[0]|cast_to_array|keys %}
  92. {% if loop.first %}
  93. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"},
  94. {% elseif loop.last %}
  95. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"}
  96. {% else %}
  97. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"},
  98. {% endif %}
  99. {% endfor %}
  100. {% else %}
  101. {% for field in pregunta.TipoPreguntaOptions|split(',') %}
  102. {% if loop.first %}
  103. { "mDataProp": "{{'Actions'|trans({})}}", sTitle: "{{'Actions'|trans({})}}", sType : "string"},
  104. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"},
  105. {% elseif loop.last %}
  106. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"}
  107. {% else %}
  108. { "mDataProp": "{{field}}", sTitle: "{{field}}", sType : "string"},
  109. {% endif %}
  110. {% endfor %}
  111. {% endif %}
  112. ];
  113. col_num{{ pregunta.alias }}={{pregunta.TipoPreguntaOptions|split(',')|length}};
  114. iter{{ pregunta.alias }}={{pregunta.TipoPreguntaOptions|split(',')|length}};
  115. if($('#{{ pregunta.alias }}').val()=== ""){
  116. var results{{ pregunta.alias }} = [{
  117. {% for field in pregunta.TipoPreguntaOptions|split(',') %}
  118. {% if loop.first %}
  119. "{{'Actions'|trans({})}}":"<a href=\"#\" class=\"btn btn-warning\" onclick=\"deleteRow{{ pregunta.alias }}(this);\">{{'Delete'|trans({})}}</a>",
  120. "{{field}}": "{{'Edit me!'|trans({})}}",
  121. {% elseif loop.last %}
  122. "{{field}}": "{{'Edit me!'|trans({})}}"
  123. {% else %}
  124. "{{field}}": "{{'Edit me!'|trans({})}}",
  125. {% endif %}
  126. {% endfor %}
  127. }];
  128. }else{
  129. var results{{ pregunta.alias }} = JSON.parse($('#{{ pregunta.alias}}').val());
  130. }
  131. function initDT{{ pregunta.alias }}(){
  132. //Construct the measurement table
  133. console.log(cols{{ pregunta.alias }});
  134. console.log(results{{ pregunta.alias }});
  135. data_table{{ pregunta.alias }} = $('#{{ pregunta.alias }}_table').dataTable({
  136. "bJQueryUI": true,
  137. "bDeferRender": true,
  138. "bInfo" : false,
  139. "bSort" : false,
  140. "bDestroy" : true,
  141. "bFilter" : false,
  142. "bPagination" : false,
  143. "aaData": results{{ pregunta.alias }},
  144. "aoColumns": cols{{ pregunta.alias }}
  145. });
  146. attachTableClickEventHandlers();
  147. $('#{{ pregunta.alias }}_table').find('tr:eq(0)')
  148. .children('th:gt(0)')
  149. .css('vertical-align', 'top')
  150. .prepend('<span class="btn btn-warning" style="cursor: pointer; width: 35px;" onclick="deleteCol{{ pregunta.alias }}(this)"><i class="fa fa-trash"></i></span>');
  151. }
  152. function attachTableClickEventHandlers(){
  153. //row/column indexing is zero based
  154. $("#{{ pregunta.alias }}_table thead tr th").click(function() {
  155. col_num{{ pregunta.alias }} = parseInt( $(this).index() );
  156. console.log("column_num ="+ col_num{{ pregunta.alias }} );
  157. });
  158. $("#{{ pregunta.alias }}_table tbody tr td").click(function() {
  159. col_cell{{ pregunta.alias }} = parseInt( $(this).index() );
  160. row_cell{{ pregunta.alias }} = parseInt( $(this).parent().index() );
  161. console.log("Row_num =" + row_cell{{ pregunta.alias }} + "  ,  column_num ="+ col_cell{{ pregunta.alias }} );
  162. });
  163. };
  164. $("#btnAddRow{{ pregunta.alias }}").click(function(e){
  165. e.preventDefault();
  166. //adding/removing row from datatable datasource
  167. var aoCols = data_table{{ pregunta.alias }}.fnSettings().aoColumns;
  168. var newRow = new Object();
  169. for(var iRec=0; iRec<aoCols.length; iRec++){
  170. if(iRec==0){
  171. newRow[aoCols[iRec].mDataProp] = "<a href=\"#\" class=\"btn btn-warning\" onclick=\"deleteRow{{ pregunta.alias }}(this);\">{{'Delete'|trans({})}}</a>";
  172. }else{
  173. newRow[aoCols[iRec].mDataProp] = '{{'Edit me!'|trans({})}}';
  174. }
  175. }
  176. results{{ pregunta.alias }}.splice(row_cell{{ pregunta.alias }}+1, 0, newRow);
  177. data_table{{ pregunta.alias }}.fnDestroy();
  178. //results.pop();
  179. initDT{{ pregunta.alias }}();
  180. cleanHeaderAndSave();
  181. addDBClikHandler{{ pregunta.alias }}();
  182. });
  183. $('#btnAddCol{{ pregunta.alias }}').click(function (e) {
  184. e.preventDefault();
  185. const { value: columnname }= Swal.fire({
  186. title: '{{'Enter new column title'|trans({})}}',
  187. input: 'text',
  188. inputValue: "",
  189. showCancelButton: true,
  190. inputValidator: (value) => {
  191. if (!value) {
  192. return '{{'You need to write something!'|trans({})}}'
  193. }else{
  194. iter{{ pregunta.alias }}++;
  195. cols{{ pregunta.alias }}.splice(col_num{{ pregunta.alias }}+1, 0, {"mDataProp": value, sTitle: value , sType : "string"});
  196. for(var iRes=0; iRes<results{{ pregunta.alias }}.length ;iRes++){
  197. results{{ pregunta.alias }}[iRes][value] = "{{'Edit me!'|trans({})}}";
  198. }
  199. col_num{{ pregunta.alias }}++;
  200. data_table{{ pregunta.alias }}.fnDestroy();
  201. $("#{{ pregunta.alias }}_table thead tr").append('<th>Col-'+iter{{ pregunta.alias }}+'</th>');
  202. initDT{{ pregunta.alias }}();
  203. cleanHeaderAndSave();
  204. addDBClikHandler{{ pregunta.alias }}();
  205. }
  206. }
  207. });
  208. });
  209. function restoreRow{{ pregunta.alias }} ( oTable, nRow ){
  210. var aData = oTable.fnGetData(nRow);
  211. var jqTds = $('>td', nRow);
  212. for ( var i=0, iLen=jqTds.length ; i<iLen ; i++ )
  213. {
  214. oTable.fnUpdate( aData[i], nRow, i, false );
  215. }
  216. };
  217. function editRow{{ pregunta.alias }} ( oTable, nRow ){
  218. var aData = oTable.fnGetData(nRow);
  219. var jqTds = $('>td', nRow);
  220. jqTds[col_cell{{ pregunta.alias }}].innerHTML = '<input type="text" id ="typ" value="'+aData[cols{{ pregunta.alias }}[col_cell{{ pregunta.alias }}].mData]+'"/>';
  221. };
  222. function saveRow{{ pregunta.alias }}( oTable, nRow ){
  223. var jqInputs = $('input', nRow);
  224. oTable.fnUpdate( jqInputs[0].value, row_cell{{ pregunta.alias }}, col_cell{{ pregunta.alias }}, false );
  225. data_table{{ pregunta.alias }}.fnDestroy();
  226. initDT{{ pregunta.alias }}();
  227. cleanHeaderAndSave();
  228. addDBClikHandler{{ pregunta.alias }}();
  229. };
  230. function deleteRow{{ pregunta.alias }}( element ){
  231. event.preventDefault();
  232. var row = $(element).parents('tbody').children().index($(element).parents('tr'));
  233. data_table{{ pregunta.alias }}.api().row($(element).parents('tr')).remove().draw();
  234. console.log(row);
  235. results{{ pregunta.alias }}.splice(row,1);
  236. data_table{{ pregunta.alias }}.fnDestroy();
  237. initDT{{ pregunta.alias }}();
  238. cleanHeaderAndSave();
  239. addDBClikHandler{{ pregunta.alias }}();
  240. };
  241. function deleteCol{{ pregunta.alias }}( element ){
  242. event.preventDefault();
  243. var col = $(element).parents('thead').children().index($(element).parents('th'));
  244. //
  245. html=$(element).parents('th').html();
  246. html=html.replace('<span class="btn btn-warning" style="cursor: pointer; width: 35px;" onclick="deleteCol{{ pregunta.alias }}(this)"><i class="fa fa-trash"></i></span>', '');
  247. console.log(html);
  248. data_table{{ pregunta.alias }}.fnDestroy();
  249. cols{{ pregunta.alias }}.splice(col,1);
  250. for(i in results{{ pregunta.alias }}) {
  251. console.log(results{{ pregunta.alias }}[i]);
  252. delete results{{ pregunta.alias }}[i][html];
  253. }
  254. $('#{{ pregunta.alias }}_table thead tr th:last').remove();
  255. $('#{{ pregunta.alias }}_table tbody tr').each(function (index){
  256. $(this).find("td:last").remove();
  257. });
  258. initDT{{ pregunta.alias }}();
  259. cleanHeaderAndSave();
  260. addDBClikHandler{{ pregunta.alias }}();
  261. }
  262. function cleanHeaderAndSave(){
  263. $('#{{ pregunta.alias }}_table').find('tr:eq(0)')
  264. .children('th:gt(0)').each(function(index){
  265. $(this).html($(this).html().replace('<span class=\"btn btn-warning\" style=\"cursor: pointer; width: 35px;\" onclick=\"deleteCol{{ pregunta.alias }}(this)\"><i class=\"fa fa-trash\"></i></span>',''))
  266. });
  267. $('#{{ pregunta.alias }}').val(JSON.stringify(tableToJSON($("#{{ pregunta.alias }}_table"))));
  268. $('#{{ pregunta.alias }}_table').find('tr:eq(0)')
  269. .children('th:gt(0)')
  270. .css('vertical-align', 'top')
  271. .prepend('<span class="btn btn-warning" style="cursor: pointer; width: 35px;" onclick="deleteCol{{ pregunta.alias }}(this)"><i class="fa fa-trash"></i></span>')
  272. }
  273. /*jQuery.extend( jQuery.fn.dataTableExt.oSort, {
  274. "date-uk-pre": function ( a ) {
  275. var ukDatea = a.split('/');
  276. return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1
  277. },
  278. "date-uk-asc": function ( a, b ) {
  279. return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  280. },
  281. "date-uk-desc": function ( a, b ) {
  282. return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  283. }
  284. } );*/
  285. /* Get the rows which are currently selected */
  286. function fnGetSelected{{ pregunta.alias }}( oTableLocal ){
  287. var aReturn = new Array();
  288. var aTrs = oTableLocal.fnGetNodes();
  289. for ( var i=0 ; i<aTrs.length ; i++ )
  290. {
  291. if ( $(aTrs[i]).hasClass('row_selected') )
  292. {
  293. aReturn.push( aTrs[i] );
  294. }
  295. }
  296. return aReturn;
  297. };
  298. function addDBClikHandler{{ pregunta.alias }}(){
  299. $('#{{ pregunta.alias }}_table tbody tr').on('dblclick', function (e) {
  300. e.preventDefault();
  301. var nRow = $(this)[0];
  302. var jqTds = $('>td', nRow);
  303. if($.trim(jqTds[0].innerHTML.substr(0,6)) != '<input')
  304. {
  305. if ( nEditing{{ pregunta.alias }} !== null && nEditing{{ pregunta.alias }} !==nRow) {
  306. console.log('Entra en distinto de null');
  307. /* Currently editing - but not this row - restore the old before continuing to edit mode */
  308. restoreRow{{ pregunta.alias }}( oTable{{ pregunta.alias }}, nEditing{{ pregunta.alias }} );
  309. nEditing{{ pregunta.alias }} = null;
  310. nEditing{{ pregunta.alias }} = nRow;
  311. editRow{{ pregunta.alias }}( oTable{{ pregunta.alias }}, nRow );
  312. }
  313. else {
  314. /* No edit in progress - let's start one */
  315. nEditing{{ pregunta.alias }} = nRow;
  316. editRow{{ pregunta.alias }}( oTable{{ pregunta.alias }}, nRow );
  317. }
  318. }
  319. } );
  320. $('#{{ pregunta.alias }}_table tbody tr').keydown(function(event){
  321. if(event.keyCode==13)
  322. {
  323. event.preventDefault();
  324. if(nEditing{{ pregunta.alias }}==null){
  325. alert("Select Row");
  326. }else{
  327. saveRow{{ pregunta.alias }}( oTable{{ pregunta.alias }}, nEditing{{ pregunta.alias }} );
  328. nEditing{{ pregunta.alias }} = null;
  329. }
  330. }
  331. /* Editing this row and want to save it */
  332. } );
  333. };
  334. function tableToJSON(tblObj){
  335. var data = [];
  336. var $headers = $(tblObj).find("th");
  337. var $rows = $(tblObj).find("tbody tr").each(function(index) {
  338. $cells = $(this).find("td");
  339. data[index] = {};
  340. $cells.each(function(cellIndex) {
  341. data[index][$($headers[cellIndex]).html()] = $(this).html();
  342. });
  343. });
  344. return data;
  345. }
  346. var nEditing{{ pregunta.alias }} = null;
  347. var oTable{{ pregunta.alias }} = null;
  348. $(document).ready(function() {
  349. initDT{{ pregunta.alias }}();
  350. oTable{{ pregunta.alias }} = data_table{{ pregunta.alias }};
  351. addDBClikHandler{{ pregunta.alias }}();
  352. } );
  353. </script>
  354. </div>