Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16841 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15337 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$routeSave       = $this->url('settings/my-private-network/logo');
9
 
16822 efrain 10
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
11
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
15337 efrain 12
 
13
 
16822 efrain 14
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));
15
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));
16
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));
15337 efrain 17
 
15831 efrain 18
 
16822 efrain 19
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/css/fileinput.css'));
20
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));
15831 efrain 21
 
22
 
23
 
15337 efrain 24
$this->inlineScript()->captureStart();
25
echo <<<JS
26
    jQuery( document ).ready(function( $ ) {
27
 
28
        $.validator.setDefaults({
29
            debug: true,
30
            highlight: function(element) {
31
                $(element).addClass('is-invalid');
32
            },
33
            unhighlight: function(element) {
34
                $(element).removeClass('is-invalid');
35
            },
36
            errorElement: 'span',
37
            errorClass: 'error invalid-feedback',
38
            errorPlacement: function(error, element) {
39
                if(element.parent('.btn-file').length) {
40
                    error.insertAfter(element.parent().parent());
16822 efrain 41
                }  else {
15337 efrain 42
                    error.insertAfter(element.parent());
43
                }
44
            }
45
        });
46
 
15423 stevensc 47
        $.fn.handleDisable = function() {
48
            const disabledValue = $('button[type="submit"]').prop('disabled')
49
            $('button[type="submit"]').prop('disabled', !disabledValue);
50
        }
15337 efrain 51
 
52
        $.fn.showFormErrorValidator = function(fieldname, errors) {
53
            var element = $(elementname);
54
            if(element) {
55
                $(element).addClass('is-invalid');
56
 
57
 
58
                var error = $('<span id="' + elementname +'-error" class="error invalid-feedback">' + errors + '</div>');
59
                if(element.parent('.btn-file').length) {
60
                    error.insertAfter(element.parent().parent());
16822 efrain 61
                }  else {
15337 efrain 62
                    error.insertAfter(element.parent());
63
                }
64
            }
65
        };
66
 
67
var validator  = $('#form').validate({
68
        debug: true,
69
        onclick: false,
70
        onkeyup: false,
71
        ignore: [],
72
        rules: {
73
            'file': {
74
                required: false,
75
                extension: 'jpg|jpeg|png',
76
                accept: 'image/jpg,image/jpeg,image/png'
77
            },
78
 
79
 
80
        },
81
        submitHandler: function(form)
82
        {
83
            var formdata = false;
84
            if (window.FormData){
85
                formdata = new FormData(form); //form[0]);
86
            }
87
 
15423 stevensc 88
            $.fn.handleDisable()
15337 efrain 89
 
90
            $.ajax({
91
                'dataType'  : 'json',
92
                'accept'    : 'application/json',
93
                'method'    : 'post',
94
                'url'       :  $('#form').attr('action'),
95
                'data'      :  formdata,
96
                'processData': false,
97
                'contentType': false,
98
            }).done(function(response) {
99
                if(response['success']) {
15423 stevensc 100
                    $.fn.showSuccess(response['data'], $.fn.handleDisable)
15337 efrain 101
 
102
                } else {
103
                    validator.resetForm();
104
                    if(jQuery.type(response['data']) == 'string') {
105
                        $.fn.showError(response['data']);
106
                    } else  {
107
                        $.each(response['data'], function( fieldname, errors ) {
108
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
109
                        });
110
                    }
111
                }
112
            }).fail(function( jqXHR, textStatus, errorThrown) {
113
                $.fn.showError(textStatus);
114
            }).always(function() {
115
                NProgress.done();
116
            });
117
            return false;
118
        },
119
        invalidHandler: function(form, validator) {
120
 
121
        }
122
    });
123
 
124
 
15831 efrain 125
    $('#form #file').fileinput({
15337 efrain 126
        theme: 'fas',
127
        language: 'es',
128
        showUpload: false,
129
        dropZoneEnabled: false,
130
        maxFileCount: 1,
131
        allowedFileExtensions: ['jpeg', 'jpg', 'png'],
132
        msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
133
    });
134
 
135
});
136
JS;
137
$this->inlineScript()->captureEnd();
138
?>
139
 
15423 stevensc 140
 
16822 efrain 141
<div class="container">
142
  	<div class="card">
143
      	<?php
144
        $form = $this->form;
145
        $form->setAttributes([
146
            'method'  => 'post',
147
            'action'  => $routeSave,
148
            'name'    => 'form',
149
            'id'      => 'form',
150
        ]);
151
 
152
        $form->prepare();
153
        echo $this->form()->openTag($form);
154
        ?>
155
  		<div class="card-body">
156
       		<h6 class="card-title">LABEL_MY_PRIVATE_NETWORK_LOGO</h6>
16841 efrain 157
			<div class="row mr-3 ">
16891 efrain 158
				<div class="col-12 mt-3">
16822 efrain 159
					<?php
15337 efrain 160
                    $element = $form->get('file');
16822 efrain 161
 
15337 efrain 162
                    $element->setAttributes(['class' => 'form-control',  'accept' => 'image/jpg,image/jpeg,image/png']);
163
                    $element->setOptions(['label' => 'LABEL_IMAGE']);
164
                    echo $this->formLabel($element);
165
                    ?>
16822 efrain 166
               		<div class="file-loading">
167
                   		<?php echo $this->formFile($element); ?>
168
                	</div>
169
 				</div>
170
           	</div>
171
        </div>
172
		<div class="card-footer text-right">
173
     		<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
174
    	</div>
175
		<?php echo $this->form()->closeTag($form); ?>
176
	</div>
177
</div>
15423 stevensc 178