Commit dd23b036 authored by Otto Zaiser's avatar Otto Zaiser

Commit inicial

parents
.tsa .btn-pill {
border-radius: 50px;
}
.tsa form .btn-primary {
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
font-weight: normal;
}
.tsa .dropArea {
border: 1px dashed #0094D4;
background-color: #ffffff;
padding: 50px;
text-align: center;
-webkit-border-radius: 5px;
border-radius: 5px;
transition: 0.3s;
}
.tsa .hash {
word-wrap: break-word;
}
.tsa .replacedTxt {
margin-bottom: 20px;
}
.tsa .dropArea p {
margin-bottom: 5px;
}
.tsa .dropAreaVerify {
border: 1px dashed #4cae4c;
}
.tsa .dropArea:hover {
background-color: #f0f7ff;
border-style: solid;
}
.tsa .dropAreaVerify:hover {
background-color: #e5fce5;
border-style: solid;
}
.tsa .dropArea .droptxt {
font-size: 1.2em;
margin-bottom: -5px;
}
.tsa .dropArea .glyphicon-cloud-upload {
font-size: 8em;
margin-bottom: 40px;
color: #ccc;
}
@media screen and (max-width: 768px) {
.tsa .dropArea .glyphicon-cloud-upload {
font-size: 4em;
margin-bottom: 20px;
}
.tsa .dropArea {
padding: 20px;
}
}
.tsa .loading {
background-color: #0094D4;
margin-top: 5px;
display: none;
padding: 10px;
text-align: center;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.tsa [hidden]{
display: none !important;
}
.tsa .btn-lg {
min-width: 200px;
}
.tsa form{
max-width: 100%;
}
.tsa .tab-pane {
background-color: #f8f8f8;
border: 1px solid #ddd;
border-top: 0px;
padding: 40px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.tsa .nav-tabs>li.active>a, .tsa .nav-tabs>li.active>a:focus,.tsa .nav-tabs>li.active>a:hover{
background-color: #f8f8f8;
}
@media screen and (min-width: 768px) {
.tsa .nav-tabs.nav-justified>.active>a, .tsa .nav-tabs.nav-justified>.active>a:focus, .tsa .nav-tabs.nav-justified>.active>a:hover{
border-bottom-color: #f8f8f8;
}
}
.tsa .tab-pane h2 {
margin-top: 0px;
}
.tsa .nav-tabs {
font-size: 1.5em;
}
.tsa .alert {
margin-top: 15px;
}
@media screen and (max-width: 768px) {
.tsa .tab-pane {
border-top: 1px solid #ddd;
}
}
main.main-content-inside .tsa h3 {
color: #333333;
font-size: 1.2em;
margin-top: 10px;
padding: 0;
background-image: none;
}
@media screen and (max-width: 992px) {
.tsa h3 {
margin-top: 30px;
}
.tsa .nav-tabs {
font-size: 1.3em;
}
}
@media screen and (max-width: 1200px) {
.tsa .dropArea .droptxt {
font-size: 1em;
margin-bottom: 15px;
}
}
var $ = jQuery;
var tsa_api = 'https://tsaapi.bfa.ar/api/tsa/';
var loader_gif = 'lib/images/loader.svg';
var ots_api = '';
var deadline_date = new Date('2018-09-03 00:00:00');
var current_date = new Date();
var whash = window.location.hash;
var currentTab = whash.substring(5, 6);
(function ($, Drupal, drupalSettings) {
var ntsa_api = drupalSettings.tsa.tsa_api;
if(ntsa_api) tsa_api = ntsa_api;
whash && $('ul.nav a[href="' + whash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
whash = this.hash;
currentTab = whash.substring(5, 6);
window.location.hash = whash;
$('html,body').scrollTop(scrollmem);
});
for (let i = 1; i < 4; i++) {
$('#selectOriginal_' + i+', #selectOriginalArea_' + i).on('click', function () {
$('#fileUploadOriginal_' + i).click();
return false;
});
if (i == 1) {
$('#fileUploadOriginal_' + i).change(
function () {
var file = $(this).prop('files')[0];
stamp(file);
}
);
} else {
$('#fileUploadOriginal_' + i).change(
function () {
var file = $(this).prop('files')[0];
original_file_check(file);
}
);
$('#selectRecibo_' + i+', #selectReciboArea_' + i).on('click', function () {
$('#fileUploadRecibo_' + i).click();
return false;
});
$('#fileUploadRecibo_' + i).change(
function () {
var file = $(this).prop('files')[0];
ots_check(file);
}
);
}
}
})(jQuery, Drupal, drupalSettings);
function stamp(file) {
var reader = new FileReader();
reader.readAsArrayBuffer(file, "UTF-8")
reader.onload = function (evt) {
var file_contents = evt.target.result;
var hash = sha256.create();
hash.update(file_contents);
var file_hash = hash.hex();
$('#originalInfo_1').html('<p>Nombre del archivo: <b>' + file.name + '</b></p><p>Hash del archivo: <b><span class="hash">' + file_hash + '</span></b></p>');
$('#selectOriginal_1').html('Seleccioná otro archivo <span class="sr-only">para marcar</span>');
$.ajax({
url: tsa_api + "stamp/",
type: "POST",
data: {
"file_hash": file_hash
},
dataType: "json",
success: function (response) {
var ots = ' {"file_hash": "' + file_hash + '", "rd": "' + response.temporary_ots + '"}';
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {
type: "octet/stream"
}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
}());
var data = response.temporary_rd
fileName = file.name + ".rd.temp";
saveData(data, fileName);
}
});
}
}
function verify_bfa(ots) {
var pending = false;
var message = '';
$('#response_' + currentTab).removeClass();
$.ajax({
url: tsa_api + "verify/",
type: "POST",
data: {
"file_hash": ots.file_hash,
"rd": ots.rd
},
dataType: "json",
success: function (response) {
if (response.status == 'success') {
icon = 'glyphicon-ok';
st = 'alert alert-success';
response_messages = response.messages.replace(ots.file_hash, $('#hidden_original_file_name_' + currentTab).val());
} else if (response.status == 'pending') {
pending = true;
icon = 'glyphicon-time';
st = 'alert alert-warning';
response_messages = response.messages;
} else {
icon = 'glyphicon-remove';
st = 'alert alert-danger';
response_messages = response.messages;
}
message = '<span class="glyphicon ' + icon + '" aria-hidden="true"></span> ' + response_messages;
$('#response_' + currentTab).addClass(st);
$('#response_' + currentTab).html(message);
if (!pending) {
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {
type: "octet/stream"
}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
}());
var data = response.permanent_rd;
fileName = $('#hidden_original_file_name_' + currentTab).val() + ".rd";
if (currentTab == '2') {
ms = 'Seleccioná otro archivo <span class="sr-only">.rd.temp</span>';
} else if (currentTab == '3') {
ms = 'Seleccioná otro archivo <span class="sr-only">.rd</span>';
}
$('#selectRecibo_' + currentTab).html(ms);
$('#reciboInstructions_' + currentTab).hide();
if ($('#reciboInfo_' + currentTab).html().includes('.temp')) {
saveData(data, fileName);
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
responseText = 'No se encontró el archivo';
if (errorThrown == 'timeout') {
responseText = 'No se pudo conectar a Blockchain Federal Argentina';
}
if (whash == '#certificado-tab') {
rp_id = "#response_cert";
} else {
rp_id = "#response";
}
$('#response_' + currentTab).html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ' + responseText);
$('#response_' + currentTab).addClass('alert alert-danger');
},
timeout: 5000
});
}
function original_file_check(file) {
$('#response_' + currentTab).html('');
$('#response_' + currentTab).removeClass();
$('#reciboInfo_' + currentTab).html('');
$('#reciboInstructions_' + currentTab).show();
var reader = new FileReader();
reader.readAsArrayBuffer(file, "UTF-8")
reader.onload = function (evt) {
var file_contents = evt.target.result;
var hash = sha256.create();
hash.update(file_contents);
var file_hash = hash.hex();
$('#hidden_original_file_hash_' + currentTab).val(file_hash);
$('#hidden_original_file_name_' + currentTab).val(file.name);
$('#originalInfo_' + currentTab).html('<p>Nombre del archivo: <b>' + file.name + '</b></p><p>Hash del archivo: <b><span class="hash">' + file_hash + '</span></b></p>');
$('#selectOriginal_' + currentTab).html('Seleccioná otro archivo <span class="sr-only">original</span>');
};
}
function ots_check(file) {
$('#response_' + currentTab).html('');
$('#response_' + currentTab).removeClass();
var file_contents = '';
var file_hash = $('#hidden_original_file_hash_' + currentTab).val();
if (file_hash == '') {
$('#response_' + currentTab).html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Debe ingresar el archivo original');
$('#response_' + currentTab).addClass('alert alert-danger');
return;
}
var reader = new FileReader();
reader.readAsText(file, "UTF-8")
reader.onload = function (evt) {
file_contents = evt.target.result;
$('#reciboInstructions_' + currentTab).hide();
$('#reciboInfo_' + currentTab).html(file.name);
var ots = {
"file_hash": file_hash,
"rd": file_contents
}
verify_bfa(ots);
};
}
function allowDrop(e) {
e.preventDefault();
}
function dropStamp(e) {
e.preventDefault();
var file = e.dataTransfer.items[0].getAsFile();
stamp(file);
}
function dropOriginalFile(e) {
e.preventDefault();
var file = e.dataTransfer.items[0].getAsFile();
original_file_check(file);
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace Drupal\tsa\Controller;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
/**
* Defines HelloController class.
*/
class tsaController extends ControllerBase {
/**
* Display the markup.
*
* @return array
* Return markup array.
*/
public function content() {
// Default settings.
$config = \Drupal::config('tsa.settings');
$tsa_api = $config->get('tsa_api');
$element['#tsa_api'] = Html::escape($tsa_api);
$element['#ext_rdt'] = $config->get('ext_rdt');
$element['#ext_rdd'] = $config->get('ext_rdd');
$element['#mainBody'] = $config->get('mainBody');
$element['#tab01'] = $config->get('tab01');
$element['#tab01Title'] = $config->get('tab01Title');
$element['#tab01Body'] = $config->get('tab01Body');
$element['#tab02'] = $config->get('tab02');
$element['#tab02Title'] = $config->get('tab02Title');
$element['#tab02Body'] = $config->get('tab02Body');
$element['#tab02Box01'] = $config->get('tab02Box01');
$element['#tab02Box02'] = $config->get('tab02Box02');
$element['#tab03'] = $config->get('tab03');
$element['#tab03Title'] = $config->get('tab03Title');
$element['#tab03Body'] = $config->get('tab03Body');
$element['#tab03Box01'] = $config->get('tab03Box01');
$element['#tab03Box02'] = $config->get('tab03Box02');
$element['#theme'] = 'tsa_theme';
return $element;
}
}
\ No newline at end of file
<?php
namespace Drupal\tsa\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class tsaForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'tsa_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Form constructor.
$form = parent::buildForm($form, $form_state);
// Default settings.
$config = $this->config('tsa.settings');
// API
$form['tsa_api'] = array(
'#type' => 'textfield',
'#title' => $this->t('URL de API'),
'#default_value' => $config->get('tsa_api'),
);
$form['ext_rdt'] = array(
'#type' => 'textfield',
'#title' => $this->t('Extensión Recibo Temporario'),
'#default_value' => $config->get('ext_rdt'),
);
$form['ext_rdd'] = array(
'#type' => 'textfield',
'#title' => $this->t('Extensión Recibo Definitivo'),
'#default_value' => $config->get('ext_rdd'),
);
$form['mainBody'] = array(
'#type' => 'textarea',
'#title' => $this->t('Texto Principal'),
'#default_value' => $config->get('mainBody'),
);
$form['tab01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 1: Label'),
'#default_value' => $config->get('tab01'),
);
$form['tab01Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 1: Título'),
'#default_value' => $config->get('tab01Title'),
);
$form['tab01Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 1: Texto'),
'#default_value' => $config->get('tab01Body'),
);
$form['tab02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Label'),
'#default_value' => $config->get('tab02'),
);
$form['tab02Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Título'),
'#default_value' => $config->get('tab02Title'),
);
$form['tab02Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 2: Texto'),
'#default_value' => $config->get('tab02Body'),
);
$form['tab02Box01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Subtítulo Drop 1'),
'#default_value' => $config->get('tab02Box01'),
);
$form['tab02Box02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Subtítulo Drop 2'),
'#default_value' => $config->get('tab02Box02'),
);
$form['tab03'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Label'),
'#default_value' => $config->get('tab03'),
);
$form['tab03Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Título'),
'#default_value' => $config->get('tab03Title'),
);
$form['tab03Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 3: Texto'),
'#default_value' => $config->get('tab03Body'),
);
$form['tab03Box01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Subtítulo Drop 1'),
'#default_value' => $config->get('tab03Box01'),
);
$form['tab03Box02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Subtítulo Drop 2'),
'#default_value' => $config->get('tab03Box02'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('tsa.settings');
$config->set('tsa_api', $form_state->getValue('tsa_api'));
$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'));
$config->set('tab01', $form_state->getValue('tab01'));
$config->set('tab01Title', $form_state->getValue('tab01Title'));
$config->set('tab01Body', $form_state->getValue('tab01Body'));
$config->set('tab02', $form_state->getValue('tab02'));
$config->set('tab02Title', $form_state->getValue('tab02Title'));
$config->set('tab02Body', $form_state->getValue('tab02Body'));
$config->set('tab02Box01', $form_state->getValue('tab02Box01'));
$config->set('tab02Box02', $form_state->getValue('tab02Box02'));
$config->set('tab03', $form_state->getValue('tab03'));
$config->set('tab03Title', $form_state->getValue('tab03Title'));
$config->set('tab03Body', $form_state->getValue('tab03Body'));
$config->set('tab03Box01', $form_state->getValue('tab03Box01'));
$config->set('tab03Box02', $form_state->getValue('tab03Box02'));
$config->save();
return parent::submitForm($form, $form_state);
}
protected function getEditableConfigNames() {
return [
'tsa.settings',
];
}
}
{% autoescape false %}
<div class="tsa">
<p>{{ mainBody }}</p>
<ul class="nav nav-tabs nav-justified" role="tablist">
<li role="presentation" class="active"><a href="#tab_1" aria-controls="tab_1" role="tab"
data-toggle="tab">{{ tab01 }}</a></li>
<li role="presentation"><a href="#tab_2" aria-controls="tab_2" role="tab" data-toggle="tab">{{ tab02 }}</a></li>
<li role="presentation"><a href="#tab_3" aria-controls="tab_3" role="tab" data-toggle="tab">{{ tab03 }}</a></li>
</ul>
<form class="box tab-content" method="post" action="" enctype="multipart/form-data">
<div role="tabpanel" class="tab-pane active" id="tab_1">
<h2>{{ tab01Title }}</h2>
<p>{{ tab01Body }}</p>
<div id="selectOriginalArea_1" class="dropArea" ondrop="dropStamp(event)" ondragover="allowDrop(event)">
<div id="originalInfo_1" class="replacedTxt">
<div><span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá un archivo aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_1" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">para Sellar</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_1" hidden/>
<!-- <div id="ots_div" class="loading"></div> -->
<div id="response_1" role="alert"></div>
</div>
<div role="tabpanel" class="tab-pane certificadoTab" id="tab_2">
<h2>{{ tab02Title }}</h2>
<p>{{ tab02Body }}</p>
<input type="hidden" name="hidden_original_file_hash_2" id="hidden_original_file_hash_2" />
<input type="hidden" name="hidden_original_file_name_2" id="hidden_original_file_name_2" />
<div class="row">
<div class="col-md-6">
<h3>{{ tab02Box01 }}</h3>
<div id="selectOriginalArea_2" class="dropArea" ondrop="dropOriginalFile(event)"
ondragover="allowDrop(event)">
<div id="originalInfo_2" class="replacedTxt">
<div><span class=" glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>original</b> aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_2" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">original</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_2" hidden/>
</div>
<div class="col-md-6">
<h3>{{ tab02Box02 }}</h3>
<div id="selectReciboArea_2" class="dropArea" ondrop="dropOTSFile(event)" ondragover="allowDrop(event)">
<div class="replacedTxt">
<div id="reciboInfo_2"></div>
<div id="reciboInstructions_2">
<div><span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>{{ ext_rdt }}</b> aquí<br>ó</div>
</div>
</div>
<div><button type="button" id="selectRecibo_2" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">{{ ext_rdt }}</span></button></div>
</div>
<input type="file" id="fileUploadRecibo_2" hidden/>
</div>
</div>
<div id="response_2" role="alert"></div>
</div>
<div role="tabpanel" class="tab-pane verificarTab" id="tab_3">
<h2>{{ tab03Title }}</h2>
<p>{{ tab03Body }}</p>
<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 class="row">
<div class="col-md-6">
<h3>{{ tab03Box01 }}</h3>
<div id="selectOriginalArea_3" class="dropArea dropAreaVerify" ondrop="dropOriginalFile(event)"
ondragover="allowDrop(event)">
<div id="originalInfo_3" class="replacedTxt">
<div><span class=" glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>original</b> aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_3" class="btn btn-success btn-pill">Seleccioná un archivo <span class="sr-only">original</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_3" hidden/>
</div>
<div class="col-md-6">
<h3>{{ tab03Box02 }}</h3>
<div id="selectReciboArea_3" class="dropArea dropAreaVerify" ondrop="dropOTSFile(event)" ondragover="allowDrop(event)">