Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15423 | Rev 16822 | 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
 
10
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
11
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
12
 
13
 
14
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
15
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
16
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
17
 
15831 efrain 18
 
19
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/css/fileinput.css'));
20
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/fileinput.js'));
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());
41
                } else if(element.parent('.toggle').length) {
42
                    error.insertAfter(element.parent().parent());
43
                } else {
44
                    error.insertAfter(element.parent());
45
                }
46
            }
47
        });
48
 
15423 stevensc 49
        $.fn.handleDisable = function() {
50
            const disabledValue = $('button[type="submit"]').prop('disabled')
51
            $('button[type="submit"]').prop('disabled', !disabledValue);
52
        }
15337 efrain 53
 
54
        $.fn.showFormErrorValidator = function(fieldname, errors) {
55
            var element = $(elementname);
56
            if(element) {
57
                $(element).addClass('is-invalid');
58
 
59
 
60
                var error = $('<span id="' + elementname +'-error" class="error invalid-feedback">' + errors + '</div>');
61
                if(element.parent('.btn-file').length) {
62
                    error.insertAfter(element.parent().parent());
63
                } else if(element.parent('.toggle').length) {
64
                    error.insertAfter(element.parent().parent());
65
                } else {
66
                    error.insertAfter(element.parent());
67
                }
68
            }
69
        };
70
 
71
var validator  = $('#form').validate({
72
        debug: true,
73
        onclick: false,
74
        onkeyup: false,
75
        ignore: [],
76
        rules: {
77
            'file': {
78
                required: false,
79
                extension: 'jpg|jpeg|png',
80
                accept: 'image/jpg,image/jpeg,image/png'
81
            },
82
 
83
 
84
        },
85
        submitHandler: function(form)
86
        {
87
            var formdata = false;
88
            if (window.FormData){
89
                formdata = new FormData(form); //form[0]);
90
            }
91
 
15423 stevensc 92
            $.fn.handleDisable()
15337 efrain 93
 
94
            $.ajax({
95
                'dataType'  : 'json',
96
                'accept'    : 'application/json',
97
                'method'    : 'post',
98
                'url'       :  $('#form').attr('action'),
99
                'data'      :  formdata,
100
                'processData': false,
101
                'contentType': false,
102
            }).done(function(response) {
103
                if(response['success']) {
15423 stevensc 104
                    $.fn.showSuccess(response['data'], $.fn.handleDisable)
15337 efrain 105
 
106
                } else {
107
                    validator.resetForm();
108
                    if(jQuery.type(response['data']) == 'string') {
109
                        $.fn.showError(response['data']);
110
                    } else  {
111
                        $.each(response['data'], function( fieldname, errors ) {
112
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
113
                        });
114
                    }
115
                }
116
            }).fail(function( jqXHR, textStatus, errorThrown) {
117
                $.fn.showError(textStatus);
118
            }).always(function() {
119
                NProgress.done();
120
            });
121
            return false;
122
        },
123
        invalidHandler: function(form, validator) {
124
 
125
        }
126
    });
127
 
128
 
15831 efrain 129
    $('#form #file').fileinput({
15337 efrain 130
        theme: 'fas',
131
        language: 'es',
132
        showUpload: false,
133
        dropZoneEnabled: false,
134
        maxFileCount: 1,
135
        allowedFileExtensions: ['jpeg', 'jpg', 'png'],
136
        msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
137
    });
138
 
139
});
140
JS;
141
$this->inlineScript()->captureEnd();
142
?>
143
 
144
<!-- Content Header (Page header) -->
145
<section class="content-header">
15423 stevensc 146
    <div class="container-fluid">
147
        <div class="row mb-2">
148
            <div class="col-sm-12">
149
                <h1>LABEL_MY_PRIVATE_NETWORK_LOGO</h1>
150
            </div>
151
        </div>
152
        <div class="row mb-2">
153
            <div class="col-sm-12">
154
                <?php
155
                $form = $this->form;
15337 efrain 156
                $form->setAttributes([
157
                    'method'  => 'post',
15423 stevensc 158
                    'action'  => $routeSave,
15337 efrain 159
                    'name'    => 'form',
160
                    'id'      => 'form',
161
                ]);
15423 stevensc 162
 
15337 efrain 163
                $form->prepare();
164
                echo $this->form()->openTag($form);
15423 stevensc 165
                ?>
166
                <div class="form-group">
167
                    <?php
15337 efrain 168
                    $element = $form->get('file');
15423 stevensc 169
 
15337 efrain 170
                    $element->setAttributes(['class' => 'form-control',  'accept' => 'image/jpg,image/jpeg,image/png']);
171
                    $element->setOptions(['label' => 'LABEL_IMAGE']);
172
                    echo $this->formLabel($element);
173
                    ?>
174
                    <div class="file-loading">
15423 stevensc 175
                        <?php echo $this->formFile($element); ?>
176
                    </div>
177
 
178
                </div>
179
                <div class="form-group">
180
                    <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
181
                </div>
182
                <?php echo $this->form()->closeTag($form); ?>
183
            </div>
184
        </div>
185
    </div><!-- /.container-fluid -->
186
</section>