Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16891 | | 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/favicon');
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
 
14
 
15831 efrain 15
 
16929 efrain 16
 
17
 
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
 
16929 efrain 53
 
54
    var validator  = $('#form').validate({
15337 efrain 55
        debug: true,
56
        onclick: false,
57
        onkeyup: false,
58
        ignore: [],
59
        rules: {
60
            'file': {
61
                required: false,
62
                extension: 'jpg|jpeg|png',
63
                accept: 'image/jpg,image/jpeg,image/png'
64
            },
65
 
66
 
67
        },
68
        submitHandler: function(form)
69
        {
70
            var formdata = false;
71
            if (window.FormData){
72
                formdata = new FormData(form); //form[0]);
73
            }
74
 
15423 stevensc 75
            $.fn.handleDisable()
15337 efrain 76
 
77
            $.ajax({
78
                'dataType'  : 'json',
79
                'accept'    : 'application/json',
80
                'method'    : 'post',
81
                'url'       :  $('#form').attr('action'),
82
                'data'      :  formdata,
83
                'processData': false,
84
                'contentType': false,
85
            }).done(function(response) {
86
                if(response['success']) {
15423 stevensc 87
                    $.fn.showSuccess(response['data'], $.fn.handleDisable);
15337 efrain 88
 
89
                } else {
90
                    validator.resetForm();
91
                    if(jQuery.type(response['data']) == 'string') {
92
                        $.fn.showError(response['data']);
93
                    } else  {
94
                        $.each(response['data'], function( fieldname, errors ) {
95
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
96
                        });
97
                    }
98
                }
99
            }).fail(function( jqXHR, textStatus, errorThrown) {
100
                $.fn.showError(textStatus);
101
            }).always(function() {
102
                NProgress.done();
103
            });
104
            return false;
105
        },
106
        invalidHandler: function(form, validator) {
107
 
108
        }
109
    });
110
 
111
 
15831 efrain 112
    $('#form #file').fileinput({
15337 efrain 113
        theme: 'fas',
114
        language: 'es',
115
        showUpload: false,
116
        dropZoneEnabled: false,
117
        maxFileCount: 1,
118
        allowedFileExtensions: ['jpeg', 'jpg', 'png'],
119
        msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
120
    });
121
 
122
});
123
JS;
124
$this->inlineScript()->captureEnd();
125
?>
126
 
16822 efrain 127
<div class="container">
128
  	<div class="card">
129
      	<?php
130
        $form = $this->form;
131
        $form->setAttributes([
132
            'method'  => 'post',
133
            'action'  => $routeSave,
134
            'name'    => 'form',
135
            'id'      => 'form',
136
        ]);
15337 efrain 137
 
16822 efrain 138
        $form->prepare();
139
        echo $this->form()->openTag($form);
140
        ?>
141
  		<div class="card-body">
142
       		<h6 class="card-title">LABEL_MY_PRIVATE_NETWORK_FAVICO</h6>
16841 efrain 143
			<div class="row mr-3 ">
16891 efrain 144
				<div class="col-12 mt-3">
16822 efrain 145
					<?php
15337 efrain 146
                    $element = $form->get('file');
16822 efrain 147
 
15337 efrain 148
                    $element->setAttributes(['class' => 'form-control',  'accept' => 'image/jpg,image/jpeg,image/png']);
149
                    $element->setOptions(['label' => 'LABEL_IMAGE']);
150
                    echo $this->formLabel($element);
151
                    ?>
16822 efrain 152
               		<div class="file-loading">
153
                   		<?php echo $this->formFile($element); ?>
15337 efrain 154
                	</div>
16822 efrain 155
 				</div>
156
           	</div>
157
        </div>
158
		<div class="card-footer text-right">
159
     		<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
160
    	</div>
161
		<?php echo $this->form()->closeTag($form); ?>
162
	</div>
163
</div>
15831 efrain 164