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