Rev 16891 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
$acl = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser = $this->currentUserHelper();
$roleName = $currentUser->getUserTypeId();
$route = $this->url('engagement/setup');
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
$this->inlineScript()->captureStart();
echo <<<JS
jQuery( document ).ready(function( $ ) {
$.validator.setDefaults({
debug: true,
highlight: function(element) {
$(element).addClass('is-invalid');
},
unhighlight: function(element) {
$(element).removeClass('is-invalid');
},
errorElement: 'span',
errorClass: 'error invalid-feedback',
errorPlacement: function(error, element) {
if(element.parent('.form-group').length) {
error.insertAfter(element);
} else if(element.parent('.toggle').length) {
error.insertAfter(element.parent().parent());
} else {
error.insertAfter(element.parent());
}
}
});
$.fn.showFormErrorValidator = function(fieldname, errors) {
var field = $(fieldname);
if(field) {
$(field).addClass('is-invalid');
var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
if(field.parent('.form-group').length) {
error.insertAfter(field);
} else if(field.parent('.toggle').length) {
error.insertAfter(field.parent().parent());
} else {
error.insertAfter(field.parent());
}
}
};
var validator = $('#form').validate({
debug: true,
onclick: false,
onkeyup: false,
ignore: [],
rules: {
'daily_pulse_how_are_you_feel': {
required: true,
min: 0,
},
'daily_pulse_climate_on_your_organization': {
required: true,
min: 0,
},
'feed_survey': {
required: true,
min: 0,
},
'internal_survey': {
required: true,
min: 0,
},
},
submitHandler: function(form)
{
$.ajax({
'dataType' : 'json',
'accept' : 'application/json',
'method' : 'post',
'url' : $('#form').attr('action'),
'data' : $('#form').serialize(),
}).done(function(response) {
NProgress.start();
if(response['success']) {
$.fn.showSuccess(response['data']);
} else {
validator.resetForm();
if(jQuery.type(response['data']) == 'string') {
$.fn.showError(response['data']);
} else {
$.each(response['data'], function( fieldname, errors ) {
$.fn.showFormErrorValidator('#form-add #' + fieldname, errors);
});
}
}
}).fail(function( jqXHR, textStatus, errorThrown) {
$.fn.showError(textStatus);
}).always(function() {
NProgress.done();
});
return false;
},
invalidHandler: function(form, validator) {
}
});
$('#form #daily_pulse_how_are_you_feel').inputNumberFormat({decimal: 0});
$('#form #daily_pulse_climate_on_your_organization').inputNumberFormat({decimal: 0});
$('#form #feed_survey').inputNumberFormat({decimal: 0});
$('#form #internal_survey').inputNumberFormat({decimal: 0});
});
JS;
$this->inlineScript()->captureEnd();
?>
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>LABEL_ENGAGEMENT (LABEL_POINTS)</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<?php
$form = $this->form;
$form->setAttributes([
'method' => 'post',
'name' => 'form',
'id' => 'form',
'action' => $route,
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="card-body">
<div class="form-group">
<?php
$element = $form->get('daily_pulse_how_are_you_feel');
$element->setOptions(['label' => 'LABEL_HOW_ARE_YOU_FEEL']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formNumber($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('daily_pulse_climate_on_your_organization');
$element->setOptions(['label' => 'LABEL_CLIMATE_ON_YOUR_ORGANIZATION']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formNumber($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('feed_survey');
$element->setOptions(['label' => 'LABEL_FEED_SURVEY']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formNumber($element);
?>
</div>
<div class="form-group">
<?php
$element = $form->get('internal_survey');
$element->setOptions(['label' => 'LABEL_INTERNAL_SURVEY']);
$element->setAttributes(['class' => 'form-control']);
echo $this->formLabel($element);
echo $this->formNumber($element);
?>
</div>
</div>
<div class="card-footer">
<div class="text-right">
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
</div>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
</div>
</div>
</div>
</section>