Proyectos de Subversion LeadersLinked - Backend

Rev

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