Proyectos de Subversion LeadersLinked - Backend

Rev

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

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