diff --git a/js/tsa.js b/js/tsa.js index b41140b25ad056f191c10f9ddcb418b12222e94e..14542f34da4922013926b82f7d8fdd0a35db660b 100644 --- a/js/tsa.js +++ b/js/tsa.js @@ -9,8 +9,20 @@ var currentTab = whash.substring(5, 6); (function ($, Drupal, drupalSettings) { - var ntsa_api = drupalSettings.tsa.tsa_api; - if(ntsa_api) tsa_api = ntsa_api; + var ntsa_api = drupalSettings.tsa.tsa_api.split(','); + var ntsa_api_label = drupalSettings.tsa.tsa_api_names.split(','); + if(ntsa_api) tsa_api = ntsa_api[0]; + + if(ntsa_api.length <= 1){ + $('#api_select').hide(); + }else{ + for(let z=0; z<ntsa_api.length; z++){ + $('#api').append('<option value="'+ntsa_api[z]+'">'+ntsa_api_label[z]+'</option>'); + } + $('#api').on('change', function() { + tsa_api = this.value; + }); + } whash && $('ul.nav a[href="' + whash + '"]').tab('show'); $('.nav-tabs a').click(function (e) { diff --git a/src/Controller/tsaController.php b/src/Controller/tsaController.php index 89614334c383370cc7f20b6abd29c69e9a964f59..da38746fbfa08dd6cb8955a63387cf98292ce73c 100644 --- a/src/Controller/tsaController.php +++ b/src/Controller/tsaController.php @@ -22,6 +22,7 @@ class tsaController extends ControllerBase { $config = \Drupal::config('tsa.settings'); $tsa_api = $config->get('tsa_api'); $element['#tsa_api'] = Html::escape($tsa_api); + $element['#tsa_api_names'] = $config->get('tsa_api_names'); $element['#ext_rdt'] = $config->get('ext_rdt'); $element['#ext_rdd'] = $config->get('ext_rdd'); $element['#mainBody'] = $config->get('mainBody'); diff --git a/src/Form/tsaForm.php b/src/Form/tsaForm.php index f9b76592ae960b6ba20a1c9a3d4f36a1cd1aeace..2daab18f4d638111dd3ef06838804359ec5cf9ed 100644 --- a/src/Form/tsaForm.php +++ b/src/Form/tsaForm.php @@ -26,104 +26,112 @@ class tsaForm extends ConfigFormBase { // API $form['tsa_api'] = array( '#type' => 'textfield', - '#title' => $this->t('URL de API'), + '#title' => $this->t('URLs de APIs'), + '#description' => $this->t('Separados por coma'), '#default_value' => $config->get('tsa_api'), ); + $form['tsa_api_names'] = array( + '#type' => 'textfield', + '#title' => $this->t('Nombre de APIs'), + '#description' => $this->t('Separados por coma en el mismo orden que el campo anterior'), + '#default_value' => $config->get('tsa_api_names'), + ); + $form['ext_rdt'] = array( '#type' => 'textfield', '#title' => $this->t('Extensión Recibo Temporario'), - '#default_value' => $config->get('ext_rdt'), + '#default_value' => ($config->get('ext_rdt')) ? $config->get('ext_rdt') : '.rd.temp' ); $form['ext_rdd'] = array( '#type' => 'textfield', '#title' => $this->t('Extensión Recibo Definitivo'), - '#default_value' => $config->get('ext_rdd'), + '#default_value' => ($config->get('ext_rdd')) ? $config->get('ext_rdd') : '.rd' ); $form['mainBody'] = array( '#type' => 'textarea', '#title' => $this->t('Texto Principal'), - '#default_value' => $config->get('mainBody'), + '#default_value' => ($config->get('mainBody')) ? $config->get('mainBody') : 'El servicio de Sello de Tiempo de BFA permite demostrar digitalmente que el contenido de cualquier documento existió en un momento y que desde entonces, no ha cambiado.' ); $form['tab01'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 1: Label'), - '#default_value' => $config->get('tab01'), + '#default_value' => ($config->get('tab01')) ? $config->get('tab01') : '1. Sellar' ); $form['tab01Title'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 1: TÃtulo'), - '#default_value' => $config->get('tab01Title'), + '#default_value' => ($config->get('tab01Title')) ? $config->get('tab01Title') : 'Paso 1: Iniciar sellado' ); $form['tab01Body'] = array( '#type' => 'textarea', '#title' => $this->t('Tab 1: Texto'), - '#default_value' => $config->get('tab01Body'), + '#default_value' => ($config->get('tab01Body')) ? $config->get('tab01Body') : 'Seleccioná un archivo para generar un Sello de Tiempo. El servicio generará un <i>hash</i> (un código criptográfico asociado a dicho documento) y lo enviará a la blockchain. A continuación, se descargará automáticamente un recibo digital <b>temporario</b> (.rd.temp) que luego podrás usar para obtener el recibo digital <b>definitivo</b> (.rd) en la pestaña <i>Obtener recibo</i>.<br>Importante: El documento seleccionado nunca se sube a la red, garantizando su privacidad.' ); $form['tab02'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 2: Label'), - '#default_value' => $config->get('tab02'), + '#default_value' => ($config->get('tab02')) ? $config->get('tab02') : '2. Obtener recibo' ); $form['tab02Title'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 2: TÃtulo'), - '#default_value' => $config->get('tab02Title'), + '#default_value' => ($config->get('tab02Title')) ? $config->get('tab02Title') : 'Paso 2: Obtener recibo digital definitivo' ); $form['tab02Body'] = array( '#type' => 'textarea', '#title' => $this->t('Tab 2: Texto'), - '#default_value' => $config->get('tab02Body'), + '#default_value' => ($config->get('tab02Body')) ? $config->get('tab02Body') : 'Para obtener el recibo definitivo (.rd) de un Sello de Tiempo se debe tener el documento original y el recibo digital temporario (.rd.temp). Al seleccionar ambos archivos, el recibo se descargará automáticamente y podrás visualizar en este sitio el dÃa y la hora en que el hash del documento original fue sellado en la Blockchain Federal Argentina.' ); $form['tab02Box01'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 2: SubtÃtulo Drop 1'), - '#default_value' => $config->get('tab02Box01'), + '#default_value' => ($config->get('tab02Box01')) ? $config->get('tab02Box01') : 'Seleccioná el archivo original' ); $form['tab02Box02'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 2: SubtÃtulo Drop 2'), - '#default_value' => $config->get('tab02Box02'), + '#default_value' => ($config->get('tab02Box02')) ? $config->get('tab02Box02') : 'Seleccioná el recibo digital temporario' ); $form['tab03'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 3: Label'), - '#default_value' => $config->get('tab03'), + '#default_value' => ($config->get('tab03')) ? $config->get('tab03') : 'Verificar' ); $form['tab03Title'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 3: TÃtulo'), - '#default_value' => $config->get('tab03Title'), + '#default_value' => ($config->get('tab03Title')) ? $config->get('tab03Title') : 'Verificar un sello de tiempo' ); $form['tab03Body'] = array( '#type' => 'textarea', '#title' => $this->t('Tab 3: Texto'), - '#default_value' => $config->get('tab03Body'), + '#default_value' => ($config->get('tab03Body')) ? $config->get('tab03Body') : 'Para verificar un Sello de Tiempo se debe tener el documento original y el recibo digital definitivo (.rd). Podrá verificar el dÃa y la hora en que el hash del documento original fue sellado en la Blockchain Federal Argentina.' ); $form['tab03Box01'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 3: SubtÃtulo Drop 1'), - '#default_value' => $config->get('tab03Box01'), + '#default_value' => ($config->get('tab03Box01')) ? $config->get('tab03Box01') : 'Seleccioná el archivo original' ); $form['tab03Box02'] = array( '#type' => 'textfield', '#title' => $this->t('Tab 3: SubtÃtulo Drop 2'), - '#default_value' => $config->get('tab03Box02'), + '#default_value' => ($config->get('tab03Box02')) ? $config->get('tab03Box02') : 'Seleccioná el recibo digital definitivo' ); return $form; @@ -142,6 +150,7 @@ class tsaForm extends ConfigFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tsa.settings'); $config->set('tsa_api', $form_state->getValue('tsa_api')); + $config->set('tsa_api_names', $form_state->getValue('tsa_api_names')); $config->set('ext_rdt', $form_state->getValue('ext_rdt')); $config->set('ext_rdd', $form_state->getValue('ext_rdd')); $config->set('mainBody', $form_state->getValue('mainBody')); diff --git a/templates/tsa-template.html.twig b/templates/tsa-template.html.twig index d0f20f314e2aee71b564b6f8bdd922196d2ff7eb..6cb9d7be0b060f5ba328d45e1a5c303c978bcfb0 100644 --- a/templates/tsa-template.html.twig +++ b/templates/tsa-template.html.twig @@ -60,9 +60,15 @@ <div role="tabpanel" class="tab-pane verificarTab" id="tab_3"> <h2>{{ tab03Title }}</h2> <p>{{ tab03Body }}</p> + <div id="api_select"> + <label for="api"><h3>Seleccione un emisor de sellado</h3></label> + <select id="api" class="form-control input-lg"> + </select> + </div> <input type="hidden" name="hidden_original_file_hash_3" id="hidden_original_file_hash_3" /> <input type="hidden" name="hidden_original_file_name_3" id="hidden_original_file_name_3" /> <div id="response_3" role="alert"></div> + <div class="row"> <div class="col-md-6"> <h3>{{ tab03Box01 }}</h3> diff --git a/tsa.module b/tsa.module index 5b08ecd683234636c7211547dfa5a37716053d1a..3366b444bc665e738f55a040fcaced06c9bdcb87 100644 --- a/tsa.module +++ b/tsa.module @@ -15,6 +15,7 @@ function tsa_theme($existing, $type, $theme, $path) { 'tsa_theme' => array( 'variables' => array( 'tsa_api' => NULL, + 'tsa_api_names' => NULL, 'ext_rdt' => NULL, 'ext_rdd' => NULL, 'mainBody' => NULL, @@ -45,5 +46,7 @@ function tsa_preprocess_html(&$variables) { $config = \Drupal::config('tsa.settings'); $tsa_api = $config->get('tsa_api'); + $tsa_api_names = $config->get('tsa_api_names'); $variables['#attached']['drupalSettings']['tsa']['tsa_api'] = $tsa_api; + $variables['#attached']['drupalSettings']['tsa']['tsa_api_names'] = $tsa_api_names; } \ No newline at end of file