Proyectos de Subversion LeadersLinked - Backend

Rev

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