Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
16285 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$route   = $this->url('tools/userfile-password-generator');
9
 
10
 
11
 
16822 efrain 12
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/nprogress/nprogress.css'));
13
$this->inlineScript()->appendFile($this->basePath('assets/vendors/nprogress/nprogress.js'));
16285 efrain 14
 
16822 efrain 15
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/jquery.validate.js'));
16
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/additional-methods.js'));
17
$this->inlineScript()->appendFile($this->basePath('assets/vendors/jquery-validation/localization/messages_es.js'));
16285 efrain 18
 
16822 efrain 19
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/css/fileinput.min.css'));
20
$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.css'));
16285 efrain 21
 
16843 efrain 22
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/piexif.js'));
23
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/plugins/sortable.js'));
16822 efrain 24
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));
25
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/locales/es.js'));
26
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/fa/theme.js'));
27
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/themes/explorer-fa/theme.js'));
16285 efrain 28
 
29
 
30
$this->inlineScript()->captureStart();
31
echo <<<JS
32
    jQuery( document ).ready(function( $ ) {
33
 
34
        $.validator.setDefaults({
35
            debug: true,
36
            highlight: function(element) {
37
                $(element).closest('.sn-field').addClass('sn-field-has-error');
38
            },
39
            unhighlight: function(element) {
40
                $(element).closest('.sn-field').removeClass('sn-field-has-error');
41
            },
42
            errorElement: 'div',
43
            errorClass: 'sn-field-invalid-feedback',
44
            errorPlacement: function(error, element) {
45
                console.log(element);
46
 
47
                if(element.parent('.sn-field').length) {
48
                    error.insertAfter(element.parent());
49
                } else if (element.parent('.fgt-sec').length) {
50
                    error.insertAfter(element.parent());
51
                } else {
52
                    error.insertAfter(element);
53
                }
54
            }
55
        });
56
 
57
        $.validator.setDefaults({
58
            debug: true,
59
            highlight: function(element) {
60
                $(element).addClass('form-group-has-error');
61
            },
62
            unhighlight: function(element) {
63
                $(element).removeClass('form-group-has-error');
64
            },
65
            errorElement: 'div',
66
            errorClass: 'form-group-invalid-feedback',
67
            errorPlacement: function(error, element) {
68
                if(element.parent('.form-group').length) {
69
                    error.insertAfter(element.parent());
70
                } else if(element.parent('.toggle').length) {
71
                    error.insertAfter(element.parent().parent());
72
                } else {
73
                    error.insertAfter(element);
74
                }
75
            }
76
        });
77
 
78
        $.fn.showFormErrorValidator = function(fieldname, errors) {
79
            var field = $(fieldname);
80
            if(field) {
81
                $(field).addClass('form-group-has-error');
82
 
83
 
84
                var error = $('<div id="' + fieldname +'-error" class="form-group-invalid-feedback">' + errors + '</div>');
85
                if(field.parent('.form-group').length) {
86
                    error.insertAfter(field.parent());
87
                } else  if(field.parent('.toggle').length) {
88
                    error.insertAfter(field.parent().parent());
89
                } else {
90
                    error.insertAfter(field);
91
                }
92
            }
93
        };
94
 
95
 
96
    var validator = $('#form').validate({
97
        debug: true,
98
        onclick: false,
99
        onkeyup: false,
100
        onfocusout: false,
101
        ignore: [],
102
        rules: {
103
            'file' : {
104
                required: true,
105
                extension: 'xls|xlsx',
106
                accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel'
107
            },
108
        },
109
 
110
        submitHandler: function(form)
111
        {
112
            NProgress.start();
113
            var formdata = false;
114
            if (window.FormData){
115
                formdata = new FormData(form);
116
            }
117
 
118
 
119
            $.ajax({
120
                'dataType'  : 'json',
121
                'accept'    : 'application/json',
122
                'method'    : 'post',
123
                'url'       : '$route',
124
                'data'      :  formdata,
125
                'processData': false,
126
                'contentType': false,
127
            }).done(function(response) {
128
                if(response['success']) {
129
 
130
 
131
                    var anchor = window.document.createElement("a");
132
                    anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
133
                    anchor.download = response['data']['basename'];
134
                    document.body.appendChild(anchor);
135
                    anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
136
                    document.body.removeChild(anchor);
137
 
138
 
139
 
140
                } else {
141
                    validator.resetForm();
142
                    if(jQuery.type(response['data']) == 'string') {
143
                        $.fn.showError(response['data']);
144
                    } else  {
145
                        $.each(response['data'], function( fieldname, errors ) {
146
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
147
                        });
148
                    }
149
                }
150
            }).fail(function( jqXHR, textStatus, errorThrown) {
151
                $.fn.showError(textStatus);
152
            }).always(function() {
153
 
154
                NProgress.done();
155
            });
156
            return false;
157
        },
158
        invalidHandler: function(form, validator) {
159
 
160
        }
161
    });
162
 
163
    $('#form #file').fileinput({
164
        theme: 'fa',
165
        language: 'es',
166
        showUpload: false,
167
        dropZoneEnabled: false,
168
        maxFileCount: 1,
169
        allowedFileExtensions: ['xls', 'xlsx'],
170
    });
171
 
172
 
173
 
174
 
175
});
176
JS;
177
$this->inlineScript()->captureEnd();
178
 
179
?>
180
 
181
 
182
 
16891 efrain 183
<div class="container">
184
	<div class="card" id="">
185
	 	<div class="card-header">
186
	 		<h6 class="card-title">LABEL_USERFILE_PASSWORD_GENERATOR</h6>
187
	 	</div>
188
	 	<?php
16285 efrain 189
                    $form = $this->form;
190
                    $form->setAttributes([
191
                        'method'    => 'post',
192
                        'name'      => 'form',
193
                        'id'        => 'form'
194
                    ]);
195
 
196
                    $form->prepare();
197
                    echo $this->form()->openTag($form);
198
                    ?>
16891 efrain 199
	 	<div class="card-body">
200
	 		<div class="row">
201
	 	         <div class="col-12 mt-3">
202
 
203
	 	         <?php
16285 efrain 204
                            $element = $form->get('file');
205
                            $element->setOptions(['label' => 'LABEL_EXCEL']);
206
                            echo $this->formLabel($element);
207
                            ?>
208
                            <div class="file-loading">
209
                                <?php
16768 efrain 210
                                $element->setAttributes(['class' => 'form-control', 'accept' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel']);
16285 efrain 211
                                echo $this->formFile($element);
212
                                ?>
213
                            </div>
16891 efrain 214
 
215
	 	         </div>
216
	 	     </div>
217
	 	</div>
218
	 	<div class="card-footer text-right">
219
	 	     <button type="submit" class="btn btn-sm btn-primary">LABEL_UPLOAD</button>
220
	 	</div>
221
	 	 	<?php echo $this->form()->closeTag($form); ?>
222
	</div>
223
 
224
</div>
16285 efrain 225
 
226
 
227
 
228
 
229
 
230
 
231
 
232